queue.logic.php 19 KB

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