queue.logic.php 14 KB

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