PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/public/module/basedataconfig/cheap_shop.php

https://github.com/karlom/gameadmin
PHP | 379 lines | 293 code | 42 blank | 44 comment | 52 complexity | 0c54bdf2390e713c7f530772f32a4d52 MD5 | raw file
  1. <?php
  2. include_once '../../../protected/config/config.php';
  3. include_once SYSDIR_ADMIN_INCLUDE . '/global.php';
  4. include_once SYSDIR_ADMIN_DICT . '/dict.php';
  5. include_once SYSDIR_ADMIN_DICT . '/arrItemsAll.php';
  6. global $lang,$activityType;
  7. $action = isset($_GET['action']) ? SS($_GET['action']) : "";
  8. if("setOnlineCheapShop" == $action ){//设置在线商店促销
  9. // $content = SS($_POST['content']);
  10. /*
  11. if($content){
  12. $api = "setloginnotice";
  13. $params = array(
  14. "content" => SS($_POST['content']),
  15. );
  16. $loginNoticeServerList = $_POST['loginNoticeServerList'];
  17. if($loginNoticeServerList){
  18. $log = new AdminLogClass();
  19. foreach($loginNoticeServerList as $key => $value){
  20. $httpResult = interfaceRequest($api, $params, 'GET', 60, $value);
  21. if(1 == $httpResult['result']){
  22. $msg[] = $lang->verify->opSuc.":{$value}";
  23. //写日志
  24. $log->Log(AdminLogClass::SET_NOTICE,$lang->verify->opSuc.":{$value}",'','','','');
  25. }else{
  26. $msg[] = $lang->page->errorReason.":{$value}".$httpResult['errorMsg'];
  27. }
  28. }
  29. }
  30. }else{
  31. $msg[] = $lang->page->errorReason.":".$lang->msg->loginNoticeContentIsNull;
  32. }*/
  33. $cheapshop = array();
  34. $itemCount = count($_GET['item']);
  35. $cheapShopList = array();
  36. $startTime = strtotime($_GET['start_time']);
  37. $keepTime = strtotime($_GET['end_time']) - $startTime;
  38. $existID = 0;
  39. for($i = 1; $i <= $itemCount; $i++)
  40. {
  41. $cheapShopList[$i] = array(
  42. 'itemID' => intval( $_GET['itemid'][$i]),
  43. 'priceOld' => intval($_GET['old_price'][$i]),
  44. 'priceNew' => intval($_GET['new_price'][$i]),
  45. 'cnt' => intval($_GET['cnt'][$i]),
  46. 'keepTime' => intval($keepTime),
  47. 'bind' => intval($_GET['isbind'][$i]),
  48. 'startTime' => intval($startTime),
  49. 'limitPerson' => intval($_GET['buy_num'][$i]),
  50. );
  51. }
  52. // if ( ( $existID = checkDateValid($startTime, $startTime + $keepTime, 0) ) && $existID == 0)
  53. // {
  54. //$inValid = true;
  55. $ret = interfaceRequest('setcheapshop', array('cheapshop' => json_encode( $cheapShopList ), 'type' => 1 ));
  56. if($ret['result'] == 1)
  57. {
  58. $cache = ExtMemcache::instance();
  59. $cache->delete('shopInfo');
  60. }
  61. // }
  62. /* else
  63. {
  64. $msg[] = "日期和其它配置(#$existID)重叠,请重设!";
  65. }*/
  66. $cheapShopShow['start_time'] = date('Y-m-d H:i:s', $startTime );
  67. $cheapShopShow['end_time'] = date('Y-m-d H:i:s', $startTime + $keepTime );
  68. $cheapShopShow['data'] = $cheapShopList;
  69. $smarty->assign('cheapShopShow', $cheapShopShow);
  70. $smarty->assign('existID', $existID);
  71. // dump($_POST);
  72. }else if("view" == $action){//查看某个促销的设置
  73. $id = intval($_GET['id']);
  74. $sql = "select * from ".T_CHEAP_SHOP." where id={$id}";
  75. $result = GFetchRowOne($sql);
  76. $cheapShopList = array();
  77. $result['data'] = json_decode($result['content'], true);
  78. $result['end_time'] = $result['end_time'] > 0 ? date("Y-m-d H:i:s", $result['end_time']) : 0;
  79. $result['start_time'] = $result['start_time'] > 0 ? date("Y-m-d H:i:s", $result['start_time']) : 0;
  80. $cheapShopList['id'] = $result['id'];
  81. $cheapShopList['data'] = $result['data'];
  82. $cheapShopList['start_time'] = $result['start_time'];
  83. $cheapShopList['end_time'] = $result['end_time'];
  84. $cheapShopList['title'] = $result['title'];
  85. $cheapShopList['date_type'] = $result['date_type'];
  86. if($result['date_type'] == 1){
  87. list($cheapShopList['start_open_day'], $cheapShopList['start_open_hour'], $cheapShopList['start_open_minute']) = Datatime::timestampToDayHourMinute($result['start_open_day_time']);
  88. list($cheapShopList['end_open_day'], $cheapShopList['end_open_hour'], $cheapShopList['end_open_minute']) = Datatime::timestampToDayHourMinute($result['end_open_day_time']);
  89. }
  90. $action = "set";
  91. $smarty->assign('action', $action);
  92. $smarty->assign('cheapShopShow', $cheapShopList);
  93. }else if("set" == $action){//设置某个促销
  94. $id = intval($_GET['id']);
  95. $cheapShopShow['title'] = SS($_GET['title']);
  96. $cheapShopShow['mtime'] = NOW_TIMESTAMP;
  97. $itemId = $_GET['itemid'];
  98. $newPrice = $_GET['new_price'];
  99. $oldPrice = $_GET['old_price'];
  100. $cnt = $_GET['cnt'];
  101. $buyNum = $_GET['buy_num'];
  102. $isbind = $_GET['isbind'];
  103. $cheapShopShow['date_type'] = intval($_GET['date_type']);
  104. $cheapShopShow['status'] = 0; //重置状态为未开始
  105. $inValid = false;
  106. $existID = 0;
  107. if($cheapShopShow['date_type'] === 0)
  108. {// 按确切日期
  109. $cheapShopShow['start_time'] = strtotime(SS($_GET['start_time']));
  110. $cheapShopShow['end_time'] = strtotime(SS($_GET['end_time']));
  111. $cheapShopShow['start_open_day_time'] = 0;
  112. $cheapShopShow['end_open_day_time'] = 0;
  113. if ( ($existID = checkDateValid($cheapShopShow['start_time'], $cheapShopShow['end_time'], 0, $id) ) && $existID > 0){
  114. $inValid = true;
  115. }
  116. }
  117. if($cheapShopShow['date_type'] === 1)
  118. {// 按开服日期
  119. $cheapShopShow['start_time'] = 0;
  120. $cheapShopShow['end_time'] = 0;
  121. $cheapShopShow['start_open_day_time'] = Datatime::dayHourMinuteToTimestamp( intval(SS($_GET['start_open_day'])), intval(SS($_GET['start_open_hour'])), intval(SS($_GET['start_open_minute'])) );
  122. $cheapShopShow['end_open_day_time'] = Datatime::dayHourMinuteToTimestamp( intval(SS($_GET['end_open_day'])), intval(SS($_GET['end_open_hour'])), intval(SS($_GET['end_open_minute'])) );
  123. if ( ( $existID = checkDateValid($cheapShopShow['start_open_day_time'], $cheapShopShow['end_open_day_time'], 1, $id) ) && $existID > 0 ){
  124. $inValid = true;
  125. }
  126. }
  127. $cache = ExtMemcache::instance();
  128. $itemList = $cache->get("cheapShopList");
  129. foreach($itemId as $key => $value){
  130. if($value){
  131. $itemArr = array();
  132. $itemArr['itemID'] = intval($value);
  133. $itemArr['priceOld'] = intval($oldPrice[$key]);
  134. $itemArr['priceNew'] = intval($newPrice[$key]);
  135. $itemArr['cnt'] = intval($cnt[$key]);
  136. $itemArr['limitPerson'] = intval($buyNum[$key]);
  137. $itemArr['bind'] = intval($isbind[$key]);
  138. $itemArr['keepTime'] = intval($cheapShopShow['end_time']) - intval($cheapShopShow['start_time']);
  139. $itemArr['startTime'] = intval($cheapShopShow['start_time']);
  140. $cheapShopShow['data'][] = $itemArr;
  141. }
  142. }
  143. $cheapShopShow['content'] = json_encode($cheapShopShow['data']);
  144. $cheapShopShowTmp = $cheapShopShow;
  145. $cheapShopShowTmp['start_time'] = date('Y-m-d H:i:s', $cheapShopShowTmp['start_time'] );
  146. $cheapShopShowTmp['end_time'] = date('Y-m-d H:i:s', $cheapShopShowTmp['end_time'] );
  147. $smarty->assign('cheapShopShow', $cheapShopShowTmp);
  148. $smarty->assign('existID', $existID);
  149. unset($cheapShopShow['data']);
  150. if(!$inValid)
  151. {
  152. if($id){
  153. $cheapShopShow['id'] = $id;
  154. $sql = makeUpdateSqlFromArray($cheapShopShow, T_CHEAP_SHOP);
  155. }else{
  156. $sql = makeInsertSqlFromArray($cheapShopShow, T_CHEAP_SHOP);
  157. }
  158. GQuery($sql);
  159. }else{
  160. $msg[] = "日期和其它配置(#$existID)重叠,请重设!";
  161. }
  162. }else if("new" == $action){//新增促销
  163. $cheapShopShow['date_type'] = 0;
  164. $cheapShopShow['data'][] = array('bind' => 1);
  165. $action = "set";
  166. $smarty->assign('action', $action);
  167. $smarty->assign('cheapShopShow', $cheapShopShow);
  168. }else if("del" == $action){//删除促销
  169. $id = intval($_GET['id']);
  170. $sql = "delete from ".T_CHEAP_SHOP." where id={$id}";
  171. GQuery($sql);
  172. }else if("sendthis" == $action){//发送促销
  173. $id = intval($_GET['id']);
  174. // 获取所选的配置信息
  175. $sql = "SELECT * FROM " . T_CHEAP_SHOP . ' WHERE id = ' . $id;
  176. $profile = GFetchRowOne($sql);
  177. if(isset($profile['id']) && Validator::stringNotEmpty($profile['content']))
  178. {
  179. $params = json_decode($profile['content'], true);
  180. foreach ($params as &$param)
  181. {
  182. if($profile['date_type'] == 0)
  183. {// 确切日期
  184. $param['startTime'] = $profile['start_time'];
  185. $param['keepTime'] = $profile['end_time'] - $profile['start_time'];
  186. }
  187. else
  188. {// 按开服日期
  189. $param['startTime'] = $profile['start_open_day_time'] + strtotime(ONLINEDATE);
  190. $param['keepTime'] = $profile['end_open_day_time'] - $profile['start_open_day_time'];
  191. }
  192. }
  193. $ret = interfaceRequest('setcheapshop', array('cheapshop' => json_encode($params), 'type' => 1 ));
  194. if($ret['result'] == 1)
  195. {
  196. // 删除旧的缓存
  197. $cache = ExtMemcache::instance();
  198. $cache->delete('shopInfo');
  199. // 把当前进行的配置改成已结束
  200. $sql = "UPDATE ".T_CHEAP_SHOP." SET status = 2 WHERE status = 1";
  201. GQuery($sql);
  202. // 更新当前配置状态为进行中
  203. $sql = "UPDATE ".T_CHEAP_SHOP." SET status = 1 WHERE id = " . $id;
  204. GQuery($sql);
  205. }
  206. }
  207. }else if("getItemPrice" == $action){//获取商城物品的原价
  208. $cache = ExtMemcache::instance();
  209. $itemList = $cache->get("shopList");
  210. $itemId = intval($_GET['item_id']);
  211. $oldPrice = $itemList[$itemId]['oldPrice'];
  212. if($oldPrice){
  213. $return = array("result" => 1, "oldPrice" => $oldPrice);
  214. }else{
  215. $return = array("result" => 0);
  216. }
  217. echo json_encode($return);
  218. exit();
  219. }
  220. $api = "getcheapshop";
  221. //$httpResult = interfaceRequest($api, array());
  222. //dump($httpResult);
  223. $cheapShopInfo = getCheapShopInfo();
  224. if(1 == $cheapShopInfo['result']){
  225. $cheapShopList = $cheapShopInfo['config'];
  226. $cache = ExtMemcache::instance();
  227. $cache->set("shopList", $cheapShopList, true, MEMCACHE_COMPRESS, 3600);
  228. /*不需要CheapShopConfig的物品
  229. foreach($cheapShopList as $k => $v){
  230. $itemList[$v['itemID']] = $arrItemsAll[$v['itemID']]['name'];
  231. }*/
  232. if("now" == $action){
  233. $cheapShopInfo = getCheapShopInfo(true);
  234. $cheapShopNow = $cheapShopInfo['mem'];
  235. $cheapShopList = array();
  236. // dump($cheapShopInfo);
  237. foreach($cheapShopNow as $key => $value){
  238. if(is_array($value)){
  239. $value['endTime'] = date("Y-m-d H:i:s", $value['startTime'] + $value['keepTime']);
  240. $value['startTime'] = date("Y-m-d H:i:s", $value['startTime']);
  241. $value['startTime'] = $value['startTime'];
  242. $cheapShopList['data'][] = $value;
  243. }
  244. }
  245. $cheapShopList['start_time'] = $value['startTime'];
  246. $cheapShopList['end_time'] = $value['endTime'];
  247. $action = "setOnlineCheapShop";
  248. $smarty->assign('action', $action);
  249. $smarty->assign('cheapShopShow', $cheapShopList);
  250. }
  251. }else{
  252. $msg[] = $lang->page->errorReason.":".$cheapShopInfo['errorMsg'];
  253. }
  254. foreach ($arrItemsAll as $key => $value){
  255. $itemList[$key] = $value['name'];
  256. }
  257. $smarty->assign('itemList', $itemList);
  258. $sql = "select * from ".T_CHEAP_SHOP." order by end_time desc,id desc";
  259. $cheapShopList = GFetchRowSet($sql);
  260. foreach($cheapShopList as $key => &$value){
  261. $value['content'] = json_decode($value['content'], true);
  262. if($value['date_type'] == 1){
  263. list($value['start_open_day'], $value['start_open_hour'], $value['start_open_minute']) = Datatime::timestampToDayHourMinute($value['start_open_day_time']);
  264. list($value['end_open_day'], $value['end_open_hour'], $value['end_open_minute']) = Datatime::timestampToDayHourMinute($value['end_open_day_time']);
  265. $endTime = $value['end_open_day_time'] + strtotime(ONLINEDATE);
  266. $value['start_date'] = date('Y-m-d, H:i:s', $value['start_open_day_time'] + strtotime(ONLINEDATE));
  267. $value['end_date'] = date('Y-m-d, H:i:s', $value['end_open_day_time'] + strtotime(ONLINEDATE));
  268. }else{
  269. $value['start_date'] = date('Y-m-d, H:i:s', $value['start_time']);
  270. $value['end_date'] = date('Y-m-d, H:i:s', $value['end_time']);
  271. $endTime = $value['end_time'];
  272. }
  273. $value['actualEndtime'] = $endTime;
  274. $value['isTimeOut'] = $endTime < NOW_TIMESTAMP ? 1 : 0;
  275. }
  276. $cheapShopList = sortArrayByKey($cheapShopList, 'actualEndtime', 'asc');
  277. $smarty->assign('lang', $lang);
  278. $smarty->assign('msg', $msg);
  279. $smarty->assign('activityType', $activityType);
  280. $smarty->assign('onlineDateTimestamp', strtotime(ONLINEDATE));
  281. $smarty->assign('arrItemsAll', $arrItemsAll);
  282. $smarty->assign('cheapShopList', $cheapShopList);
  283. $smarty->display('module/basedataconfig/cheap_shop.tpl');
  284. function getCheapShopInfo( $forceRemote = false )
  285. {
  286. $api = 'getcheapshop';
  287. $cacheKey = 'shopInfo';
  288. $cache = ExtMemcache::instance();
  289. if( $forceRemote )
  290. {
  291. $cache->delete($cacheKey);
  292. }
  293. $cheapShopInfo = $cache->get($cacheKey);
  294. if ( !$cheapShopInfo )
  295. {// 缓存不存在,从远程获取
  296. $ret = interfaceRequest($api, array('type' => 1));
  297. $cheapShopInfo = array();
  298. if( $ret['result'] == 1 )
  299. {
  300. $cheapShopInfo = $ret;
  301. }
  302. $cache->set($cacheKey, $cheapShopInfo, true, MEMCACHE_COMPRESSED, 300);
  303. }
  304. return $cheapShopInfo;
  305. }
  306. function checkDateValid($startTime, $endTime, $type = 0, $id = null)
  307. {
  308. $excludeCondition = '';
  309. $return = 0;
  310. $onlineDateTimestamp = strtotime(ONLINEDATE);
  311. if ($id != null)
  312. {
  313. $excludeCondition = ' AND id <> ' . $id;
  314. }
  315. if($type == 0)
  316. {
  317. $startOpenDayTime = $startTime - $onlineDateTimestamp;
  318. $endOpenDayTime = $endTime - $onlineDateTimestamp;
  319. }else{
  320. $startOpenDayTime = $startTime;
  321. $endOpenDayTime = $endTime;
  322. $startTime = $startTime + $onlineDateTimestamp;
  323. $endTime = $endTime + $onlineDateTimestamp;
  324. }
  325. $sql = 'SELECT id FROM ' . T_CHEAP_SHOP . " WHERE date_type = 0 AND ( (start_time > $startTime AND start_time < $endTime) OR (end_time > $startTime AND end_time < $endTime ) OR (start_time < $startTime AND end_time > $endTime ) )" . $excludeCondition . ' LIMIT 1';
  326. $result = GFetchRowOne($sql);
  327. if($result['id'] > 0){// 与确切时间类型重叠
  328. $return = $result['id'];
  329. }else{// 与开服时间类型重叠
  330. $sql = 'SELECT id FROM ' . T_CHEAP_SHOP . " WHERE date_type = 1 AND ( (start_open_day_time > $startOpenDayTime AND start_open_day_time < $endOpenDayTime) OR (end_open_day_time > $startOpenDayTime AND end_open_day_time < $endOpenDayTime ) OR (start_open_day_time < $startOpenDayTime AND end_open_day_time > $endOpenDayTime ) )" . $excludeCondition . ' LIMIT 1';
  331. $result = GFetchRowOne($sql);
  332. if($result['id'] > 0){
  333. $return = $result['id'];
  334. }
  335. }
  336. return $return;
  337. }