queue.logic.php 21 KB

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