queue.logic.php 22 KB

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