queue.logic.php 13 KB

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