queue.logic.php 17 KB

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