queue.logic.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. /**
  3. * 队列
  4. *
  5. * 方法名需要和 QueueClient::push中第一个参数一致,如:
  6. * QueueClient::push('editGroupbuySaleCount',$groupbuy_info);
  7. * public function editGroupbuySaleCount($groupbuy_info){...}
  8. *
  9. */
  10. defined('InShopNC') or exit('Access Invalid!');
  11. require_once(BASE_ROOT_PATH . '/helper/push_app.php');
  12. class queueLogic
  13. {
  14. /**
  15. * push app内容跳转类型
  16. * @var array
  17. */
  18. protected $go_type = array(
  19. '',//跳转到app首页
  20. 'bonus',//红包页
  21. );
  22. /**
  23. * 添加会员积分
  24. * @param unknown $member_info
  25. */
  26. public function addPoint($member_info)
  27. {
  28. $points_model = Model('points');
  29. $points_model->savePointsLog('login', array('pl_memberid' => $member_info['member_id'], 'pl_membername' => $member_info['member_name']), true);
  30. return callback(true);
  31. }
  32. /**
  33. * 添加会员经验值
  34. * @param unknown $member_info
  35. */
  36. public function addExppoint($member_info)
  37. {
  38. $exppoints_model = Model('exppoints');
  39. $exppoints_model->saveExppointsLog('login', array('exp_memberid' => $member_info['member_id'], 'exp_membername' => $member_info['member_name']), true);
  40. return callback(true);
  41. }
  42. /**
  43. * 更新抢购信息
  44. * @param unknown $groupbuy_info
  45. * @throws Exception
  46. */
  47. public function editGroupbuySaleCount($groupbuy_info)
  48. {
  49. $model_groupbuy = Model('groupbuy');
  50. $data = array();
  51. $data['buyer_count'] = array('exp', 'buyer_count+1');
  52. $data['buy_quantity'] = array('exp', 'buy_quantity+' . $groupbuy_info['quantity']);
  53. $update = $model_groupbuy->editGroupbuy($data, array('groupbuy_id' => $groupbuy_info['groupbuy_id']));
  54. if (!$update) {
  55. return callback(false, '更新抢购信息失败groupbuy_id:' . $groupbuy_info['groupbuy_id']);
  56. } else {
  57. return callback(true);
  58. }
  59. }
  60. /**
  61. * 更新使用的代金券状态
  62. * @param $input_voucher_list
  63. * @throws Exception
  64. */
  65. public function editVoucherState($voucher_list)
  66. {
  67. $model_voucher = Model('voucher');
  68. $send = new sendMemberMsg();
  69. foreach ($voucher_list as $store_id => $voucher_info) {
  70. $update = $model_voucher->editVoucher(array('voucher_state' => 2), array('voucher_id' => $voucher_info['voucher_id']), $voucher_info['voucher_owner_id']);
  71. if ($update) {
  72. // 发送用户店铺消息
  73. $send->set('member_id', $voucher_info['voucher_owner_id']);
  74. $send->set('code', 'voucher_use');
  75. $param = array();
  76. $param['voucher_code'] = $voucher_info['voucher_code'];
  77. $param['voucher_url'] = urlShop('member_voucher', 'index');
  78. $send->send($param);
  79. } else {
  80. return callback(false, '更新代金券状态失败vcode:' . $voucher_info['voucher_code']);
  81. }
  82. }
  83. return callback(true);
  84. }
  85. /**
  86. * 下单变更库存销量
  87. * @param unknown $goods_buy_quantity
  88. */
  89. public function createOrderUpdateStorage($goods_buy_quantity)
  90. {
  91. $model_goods = Model('goods');
  92. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  93. $data = array();
  94. $data['goods_storage'] = array('exp', 'goods_storage-' . $quantity);
  95. $data['goods_salenum'] = array('exp', 'goods_salenum+' . $quantity);
  96. $result = $model_goods->editGoodsById($data, $goods_id);
  97. }
  98. if (!$result) {
  99. return callback(false, '变更商品库存与销量失败');
  100. } else {
  101. return callback(true);
  102. }
  103. }
  104. /**
  105. * 取消订单变更库存销量
  106. * @param unknown $goods_buy_quantity
  107. */
  108. public function cancelOrderUpdateStorage($goods_buy_quantity)
  109. {
  110. $model_goods = Model('goods');
  111. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  112. $data = array();
  113. $data['goods_storage'] = array('exp', 'goods_storage+' . $quantity);
  114. $data['goods_salenum'] = array('exp', 'goods_salenum-' . $quantity);
  115. $result = $model_goods->editGoodsById($data, $goods_id);
  116. }
  117. if (!$result) {
  118. return callback(false, '变更商品库存与销量失败');
  119. } else {
  120. return callback(true);
  121. }
  122. }
  123. /**
  124. * 更新F码为使用状态
  125. * @param int $fc_id
  126. */
  127. public function updateGoodsFCode($fc_id)
  128. {
  129. $update = Model('goods_fcode')->editGoodsFCode(array('fc_state' => 1), array('fc_id' => $fc_id));
  130. if (!$update) {
  131. return callback(false, '更新F码使用状态失败fc_id:' . $fc_id);
  132. } else {
  133. return callback(true);
  134. }
  135. }
  136. /**
  137. * 删除购物车
  138. * @param unknown $cart
  139. */
  140. public function delCart($cart)
  141. {
  142. if (!is_array($cart['cart_ids']) || empty($cart['buyer_id'])) return callback(true);
  143. $del = Model('cart')->delCart('db', array('buyer_id' => $cart['buyer_id'], 'cart_id' => array('in', $cart['cart_ids'])));
  144. if (!$del) {
  145. return callback(false, '删除购物车数据失败');
  146. } else {
  147. return callback(true);
  148. }
  149. }
  150. /**
  151. * 根据商品id更新促销价格
  152. *
  153. * @param int /array $goods_commonid
  154. * @return boolean
  155. */
  156. public function updateGoodsPromotionPriceByGoodsId($goods_id)
  157. {
  158. $update = Model('goods')->editGoodsPromotionPrice(array('goods_id' => array('in', $goods_id)));
  159. if (!$update) {
  160. return callback(false, '根据商品ID更新促销价格失败');
  161. } else {
  162. return callback(true);
  163. }
  164. }
  165. /**
  166. * 根据商品公共id更新促销价格
  167. *
  168. * @param int /array $goods_commonid
  169. * @return boolean
  170. */
  171. public function updateGoodsPromotionPriceByGoodsCommonId($goods_commonid)
  172. {
  173. $update = Model('goods')->editGoodsPromotionPrice(array('goods_commonid' => array('in', $goods_commonid)));
  174. if (!$update) {
  175. return callback(false, '根据商品公共id更新促销价格失败');
  176. } else {
  177. return callback(true);
  178. }
  179. }
  180. /**
  181. * 发送店铺消息
  182. */
  183. public function sendStoreMsg($param)
  184. {
  185. $send = new sendStoreMsg();
  186. $send->set('code', $param['code']);
  187. $send->set('store_id', $param['store_id']);
  188. $send->send($param['param']);
  189. return callback(true);
  190. }
  191. /**
  192. * 发送会员消息
  193. */
  194. public function sendMemberMsg($param)
  195. {
  196. $send = new sendMemberMsg();
  197. $send->set('code', $param['code']);
  198. $send->set('member_id', $param['member_id']);
  199. if (!empty($param['number']['mobile'])) $send->set('mobile', $param['number']['mobile']);
  200. if (!empty($param['number']['email'])) $send->set('email', $param['number']['email']);
  201. $send->send($param['param']);
  202. return callback(true);
  203. }
  204. /**
  205. * 生成商品F码
  206. */
  207. public function createGoodsFCode($param)
  208. {
  209. $insert = array();
  210. for ($i = 0; $i < $param['fc_count']; $i++) {
  211. $array = array();
  212. $array['goods_commonid'] = $param['goods_commonid'];
  213. $array['fc_code'] = strtoupper($param['fc_prefix']) . mt_rand(100000, 999999);
  214. $insert[$array['fc_code']] = $array;
  215. }
  216. if (!empty($insert)) {
  217. $insert = array_values($insert);
  218. $insert = Model('goods_fcode')->addGoodsFCodeAll($insert);
  219. if (!$insert) {
  220. return callback(false, '生成商品F码失败goods_commonid:' . $param['goods_commonid']);
  221. }
  222. }
  223. return callback(true);
  224. }
  225. /**
  226. * 生成商品二维码
  227. */
  228. public function createGoodsQRCode($param)
  229. {
  230. if (empty($param['goodsid_array'])) {
  231. return callback(true);
  232. }
  233. // 生成商品二维码
  234. require_once(BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'index.php');
  235. $PhpQRCode = new PhpQRCode();
  236. $PhpQRCode->set('pngTempDir', BASE_UPLOAD_PATH . DS . ATTACH_STORE . DS . $param['store_id'] . DS);
  237. foreach ($param['goodsid_array'] as $goods_id) {
  238. // 生成商品二维码
  239. $PhpQRCode->set('date', urlShop('goods', 'index', array('goods_id' => $goods_id)));
  240. $PhpQRCode->set('pngTempName', $goods_id . '.png');
  241. $PhpQRCode->init();
  242. }
  243. return callback(true);
  244. }
  245. /**
  246. * 清理特殊商品促销信息
  247. */
  248. public function clearSpecialGoodsPromotion($param)
  249. {
  250. // 抢购
  251. Model('groupbuy')->delGroupbuy(array('goods_commonid' => $param['goods_commonid']));
  252. // 显示折扣
  253. Model('p_xianshi_goods')->delXianshiGoods(array('goods_id' => array('in', $param['goodsid_array'])));
  254. // 优惠套装
  255. Model('p_bundling')->delBundlingGoods(array('goods_id' => array('in', $param['goodsid_array'])));
  256. // 更新促销价格
  257. Model('goods')->editGoods(array('goods_promotion_price' => array('exp', 'goods_price'), 'goods_promotion_type' => 0), array('goods_commonid' => $param['goods_commonid']));
  258. return callback(true);
  259. }
  260. /**
  261. * 删除(买/卖家)订单全部数量缓存
  262. * @param array $data 订单信息
  263. * @return boolean
  264. */
  265. public function delOrderCountCache($order_info)
  266. {
  267. if (empty($order_info)) return callback(true);
  268. $model_order = Model('order');
  269. if ($order_info['order_id']) {
  270. $order_info = $model_order->getOrderInfo(array('order_id' => $order_info['order_id']), array(), 'buyer_id,store_id');
  271. }
  272. $model_order->delOrderCountCache('buyer', $order_info['buyer_id']);
  273. $model_order->delOrderCountCache('store', $order_info['store_id']);
  274. return callback(true);
  275. }
  276. /**
  277. * 发送兑换码
  278. * @param unknown $param
  279. * @return boolean
  280. */
  281. public function sendVrCode($param)
  282. {
  283. if (empty($param) && !is_array($param)) return callback(true);
  284. $condition = array();
  285. $condition['order_id'] = $param['order_id'];
  286. $condition['buyer_id'] = $param['buyer_id'];
  287. $condition['vr_state'] = 0;
  288. $condition['refund_lock'] = 0;
  289. $code_list = Model('vr_order')->getOrderCodeList($condition, 'vr_code,vr_indate');
  290. if (empty($code_list)) return callback(true);
  291. $content = '';
  292. foreach ($code_list as $v) {
  293. $content .= $v['vr_code'] . ',';
  294. }
  295. $tpl_info = Model('mail_templates')->getTplInfo(array('code' => 'send_vr_code'));
  296. $data = array();
  297. $data['site_name'] = C('site_name');
  298. $data['vr_code'] = rtrim($content, ',');
  299. $message = ncReplaceText($tpl_info['content'], $data);
  300. $sms = new Sms();
  301. $result = $sms->send($param["buyer_phone"], $message);
  302. if (!$result) {
  303. return callback(false, '兑换码发送失败order_id:' . $param['order_id']);
  304. } else {
  305. return callback(true);
  306. }
  307. }
  308. /**
  309. * 添加订单自提表内容
  310. */
  311. public function saveDeliveryOrder($param)
  312. {
  313. if (!is_array($param['order_sn_list'])) return callback(true);
  314. $data = array();
  315. $model_delivery_order = Model('delivery_order');
  316. foreach ($param['order_sn_list'] as $order_id => $v) {
  317. $data['order_id'] = $order_id;
  318. $data['order_sn'] = $v['order_sn'];
  319. $data['addtime'] = $v['add_time'];
  320. $data['dlyp_id'] = $param['dlyp_id'];
  321. $data['reciver_name'] = $param['reciver_name'];
  322. $data['reciver_telphone'] = $param['tel_phone'];
  323. $data['reciver_mobphone'] = $param['mob_phone'];
  324. $insert = $model_delivery_order->addDeliveryOrder($data);
  325. if (!$insert) {
  326. return callback(false, '保存自提站订单信息失败order_sn:' . $v['order_sn']);
  327. }
  328. }
  329. return callback(true);
  330. }
  331. /**
  332. * 发送提货码短信消息
  333. */
  334. public function sendPickupcode($param)
  335. {
  336. $dorder_info = Model('delivery_order')->getDeliveryOrderInfo(array('order_id' => $param['order_id']), 'reciver_mobphone');
  337. $tpl_info = Model('mail_templates')->getTplInfo(array('code' => 'send_pickup_code'));
  338. $data = array();
  339. $data['site_name'] = C('site_name');
  340. $data['pickup_code'] = $param['pickup_code'];
  341. $message = ncReplaceText($tpl_info['content'], $data);
  342. $sms = new Sms();
  343. $result = $sms->send($dorder_info['reciver_mobphone'], $message);
  344. if (!$result) {
  345. return callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']);
  346. } else {
  347. return callback(true);
  348. }
  349. }
  350. /**
  351. * 刷新搜索索引
  352. */
  353. public function flushIndexer()
  354. {
  355. require_once(BASE_DATA_PATH . '/api/xs/lib/XS.php');
  356. $obj_doc = new XSDocument();
  357. $obj_xs = new XS(C('fullindexer.appname'));
  358. $obj_xs->index->flushIndex();
  359. }
  360. /**
  361. * 推送服务
  362. * @param $param array
  363. * 共有三个key : member_id , text, go_type
  364. * @return bool
  365. */
  366. public function upushSendMsg($param)
  367. {
  368. if(empty($param) || empty($param['member_id']) || empty($param['text'])){
  369. Log::record("push info: 数据有误! param:".json_encode($param)."\t session:".json_encode($_SESSION));
  370. return false;
  371. }
  372. if(!isset($param['go_type'])){
  373. $param['go_type'] = '';
  374. }
  375. if(!in_array($param['go_type'],$this->go_type)){
  376. Log::record("push info: go_type参数有误! param:".json_encode($param)."\t session:".json_encode($_SESSION));
  377. return false;
  378. }
  379. $push = new push_app();
  380. try{
  381. //androd
  382. $return = $push->sendAndroidCustomizedcast($param);
  383. Log::record("push info: androd\treturn:".json_encode($return)."\t param:".json_encode($param));
  384. } catch (Exception $e) {
  385. Log::record("push info: androd fall error\treturn:".$e->getMessage()."\t param:".json_encode($param));
  386. }
  387. try{
  388. //ios
  389. $return = $push->sendIOSCustomizedcast($param);
  390. Log::record("push info: ios\treturn:".json_encode($return)."\t param:".json_encode($param));
  391. } catch (Exception $e) {
  392. Log::record("push info: ios fall error\treturn:".$e->getMessage()."\t param:".json_encode($param));
  393. }
  394. return true;
  395. }
  396. }