queue.logic.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. require_once (BASE_ROOT_PATH . '/helper/stat_helper.php');
  24. class queueLogic
  25. {
  26. /**
  27. * push app内容跳转类型
  28. * @var array
  29. */
  30. protected $go_type = array(
  31. '',//跳转到app首页
  32. 'bonus',//红包页
  33. );
  34. /**
  35. * 添加会员积分
  36. * @param unknown $member_info
  37. */
  38. public function addPoint($member_info)
  39. {
  40. $points_model = Model('points');
  41. $points_model->savePointsLog('login', array('pl_memberid' => $member_info['member_id'], 'pl_membername' => $member_info['member_name']), true);
  42. return callback(true);
  43. }
  44. /**
  45. * 添加会员经验值
  46. * @param unknown $member_info
  47. */
  48. public function addExppoint($member_info)
  49. {
  50. $exppoints_model = Model('exppoints');
  51. $exppoints_model->saveExppointsLog('login', array('exp_memberid' => $member_info['member_id'], 'exp_membername' => $member_info['member_name']), true);
  52. return callback(true);
  53. }
  54. /**
  55. * 更新抢购信息
  56. * @param unknown $groupbuy_info
  57. * @throws Exception
  58. */
  59. public function editGroupbuySaleCount($groupbuy_info)
  60. {
  61. $model_groupbuy = Model('groupbuy');
  62. $data = array();
  63. $data['buyer_count'] = array('exp', 'buyer_count+1');
  64. $data['buy_quantity'] = array('exp', 'buy_quantity+' . $groupbuy_info['quantity']);
  65. $update = $model_groupbuy->editGroupbuy($data, array('groupbuy_id' => $groupbuy_info['groupbuy_id']));
  66. if (!$update) {
  67. return callback(false, '更新抢购信息失败groupbuy_id:' . $groupbuy_info['groupbuy_id']);
  68. } else {
  69. return callback(true);
  70. }
  71. }
  72. /**
  73. * 更新使用的代金券状态
  74. * @param $input_voucher_list
  75. * @throws Exception
  76. */
  77. public function editVoucherState($voucher_list)
  78. {
  79. $model_voucher = Model('voucher');
  80. $send = new memsg\message_sender();
  81. foreach ($voucher_list as $store_id => $voucher_info) {
  82. $update = $model_voucher->editVoucher(array('voucher_state' => 2), array('voucher_id' => $voucher_info['voucher_id']), $voucher_info['voucher_owner_id']);
  83. if ($update) {
  84. // 发送用户店铺消息
  85. $send->set('member_id', $voucher_info['voucher_owner_id']);
  86. $send->set('code', 'voucher_use');
  87. $param = array();
  88. $param['voucher_code'] = $voucher_info['voucher_code'];
  89. $param['voucher_url'] = urlShop('member_voucher', 'index');
  90. $send->send($param);
  91. } else {
  92. return callback(false, '更新代金券状态失败vcode:' . $voucher_info['voucher_code']);
  93. }
  94. }
  95. return callback(true);
  96. }
  97. /**
  98. * 下单变更库存销量
  99. * @param unknown $goods_buy_quantity
  100. */
  101. public function createOrderUpdateStorage($goods_buy_quantity)
  102. {
  103. $model_goods = Model('goods');
  104. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  105. $data = array();
  106. $data['goods_storage'] = array('exp', 'goods_storage-' . $quantity);
  107. $data['goods_salenum'] = array('exp', 'goods_salenum+' . $quantity);
  108. $result = $model_goods->editGoodsById($data, $goods_id);
  109. }
  110. if (!$result) {
  111. return callback(false, '变更商品库存与销量失败');
  112. } else {
  113. return callback(true);
  114. }
  115. }
  116. /**
  117. * 取消订单变更库存销量
  118. * @param unknown $goods_buy_quantity
  119. */
  120. public function cancelOrderUpdateStorage($goods_buy_quantity)
  121. {
  122. $model_goods = Model('goods');
  123. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  124. $data = array();
  125. $data['goods_storage'] = array('exp', 'goods_storage+' . $quantity);
  126. $data['goods_salenum'] = array('exp', 'goods_salenum-' . $quantity);
  127. $result = $model_goods->editGoodsById($data, $goods_id);
  128. }
  129. if (!$result) {
  130. return callback(false, '变更商品库存与销量失败');
  131. } else {
  132. return callback(true);
  133. }
  134. }
  135. /**
  136. * 更新F码为使用状态
  137. * @param int $fc_id
  138. */
  139. public function updateGoodsFCode($fc_ids)
  140. {
  141. $update = Model('goods_fcode')->editGoodsFCode(array('fc_state' => 1), array('fc_id' => array('in',$fc_ids)));
  142. if (!$update) {
  143. return callback(false, '更新F码使用状态失败fc_ids:' . implode(',',$fc_ids));
  144. } else {
  145. return callback(true);
  146. } }
  147. /**
  148. * 删除购物车
  149. * @param unknown $cart
  150. */
  151. public function delCart($cart)
  152. {
  153. if (!is_array($cart['cart_ids']) || empty($cart['buyer_id'])) return callback(true);
  154. $del = Model('cart')->delCart('db', array('buyer_id' => $cart['buyer_id'], 'cart_id' => array('in', $cart['cart_ids'])));
  155. if (!$del) {
  156. return callback(false, '删除购物车数据失败');
  157. } else {
  158. return callback(true);
  159. }
  160. }
  161. /**
  162. * 根据商品id更新促销价格
  163. *
  164. * @param int /array $goods_commonid
  165. * @return boolean
  166. */
  167. public function updateGoodsPromotionPriceByGoodsId($goods_id)
  168. {
  169. $update = Model('goods')->editGoodsPromotionPrice(array('goods_id' => array('in', $goods_id)));
  170. if (!$update) {
  171. return callback(false, '根据商品ID更新促销价格失败');
  172. } else {
  173. return callback(true);
  174. }
  175. }
  176. /**
  177. * 根据商品公共id更新促销价格
  178. *
  179. * @param int /array $goods_commonid
  180. * @return boolean
  181. */
  182. public function updateGoodsPromotionPriceByGoodsCommonId($goods_commonid)
  183. {
  184. $update = Model('goods')->editGoodsPromotionPrice(array('goods_commonid' => array('in', $goods_commonid)));
  185. if (!$update) {
  186. return callback(false, '根据商品公共id更新促销价格失败');
  187. } else {
  188. return callback(true);
  189. }
  190. }
  191. /**
  192. * 发送店铺消息
  193. */
  194. public function sendStoreMsg($param)
  195. {
  196. $send = new sendStoreMsg();
  197. $send->set('code', $param['code']);
  198. $send->set('store_id', $param['store_id']);
  199. $send->send($param['param']);
  200. return callback(true);
  201. }
  202. /**
  203. * 发送会员消息
  204. */
  205. public function sendMemberMsg($param)
  206. {
  207. $send = new memsg\message_sender();
  208. $send->set('code', $param['code']);
  209. $send->set('member_id', $param['member_id']);
  210. $send->set('sms_param', $param['sms_param']);
  211. if (!empty($param['number']['mobile'])) $send->set('mobile', $param['number']['mobile']);
  212. if (!empty($param['number']['email'])) $send->set('email', $param['number']['email']);
  213. $send->send($param['param']);
  214. return callback(true);
  215. }
  216. /**
  217. * 生成商品F码
  218. */
  219. public function createGoodsFCode($param)
  220. {
  221. Log::record("createGoodsFCode {$param['goods_commonid']},{$param['fc_count']},{$param['fc_prefix']},{$param['fc_validate']}",Log::DEBUG);
  222. $gen = new fcode\generator($param['goods_commonid'],$param['fc_count'],$param['fc_prefix'],$param['fc_validate']);
  223. $url = $gen->make();
  224. Log::record("createGoodsFCode url={$url}",Log::DEBUG);
  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 callback(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 callback(false);
  380. }
  381. $push = new push_sender();
  382. $push->send($param);
  383. return callback(true);
  384. }
  385. /**
  386. * 发短信
  387. * @param $param
  388. *
  389. * @return bool
  390. */
  391. public function sendSMS($param)
  392. {
  393. if (empty($param) || empty($param['mobile']) || empty($param['type'])) {
  394. Log::record("sms info: 数据有误! param:" . json_encode($param),Log::ERR);
  395. return callback(false);
  396. }
  397. try {
  398. $sms = new Sms();
  399. $status = $sms->send($param['mobile'], $param);
  400. Log::record("sms info: status:" . json_encode($status) . "\t param:" . json_encode($param),Log::DEBUG);
  401. } catch (Exception $e) {
  402. Log::record("sms info: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param),Log::ERR);
  403. }
  404. return callback(true);
  405. }
  406. public function sendBonusAndSMS($params)
  407. {
  408. $input_type = $params['member']['input_type'];
  409. if($input_type == 'mobiles') {
  410. $members = member_helper::from_mobiles($params['member']['data'],$error);
  411. }
  412. elseif($input_type == 'sql') {
  413. $members = member_helper::from_sql($params['member']['data']);
  414. }
  415. else {
  416. return callback(false,'sendBonusAndSMS 错误的人员输入类型.');
  417. }
  418. $fSendSms = $params['sms']['open'];
  419. $smscode = $params['sms']['template_id'];
  420. $rate = $params['bonus']['rate'];
  421. $bless = $params['bonus']['bless'];
  422. $amount = $params['bonus']['amount'];
  423. $chunks = array_chunk($members,1000);
  424. foreach ($chunks as $chunk)
  425. {
  426. $chunk = member_helper::exmembers($chunk,$params['member']['ex_lrlz'],$params['member']['ex_brand']);
  427. $ids = [];
  428. foreach ($chunk as $member) {
  429. $ids[] = $member['member_id'];
  430. }
  431. $ret = account_helper::add_bonus($rate,$amount,$ids,$bless);
  432. if($ret == false) continue;
  433. if($fSendSms)
  434. {
  435. $iconut = 0;
  436. $sms = new Sms();
  437. foreach ($chunk as $member)
  438. {
  439. $mobile = $member['member_mobile'];
  440. try {
  441. $status = $sms->send_oper($mobile, $smscode);
  442. Log::record("sms info: status:" . json_encode($status),Log::DEBUG);
  443. } catch (Exception $e) {
  444. Log::record("sms info: fall error\treturn:" . $e->getMessage(),Log::ERR);
  445. }
  446. ++$iconut;
  447. if($iconut == 10) {
  448. sleep(2);
  449. $iconut = 0;
  450. }
  451. }
  452. }
  453. }
  454. return callback(true);
  455. }
  456. public function sendPushOrSMS($params)
  457. {
  458. $input_type = $params['member']['input_type'];
  459. if($input_type == 'mobiles') {
  460. $members = member_helper::from_mobiles($params['member']['data'],$error);
  461. }
  462. elseif($input_type == 'sql') {
  463. $members = member_helper::from_sql($params['member']['data']);
  464. }
  465. else {
  466. return callback(false,'sendBonusAndSMS 错误的人员输入类型.');
  467. }
  468. $send_type = $params['send']['type'];
  469. $content = $params['send']['data'];
  470. $chunks = array_chunk($members,1000);
  471. foreach ($chunks as $chunk)
  472. {
  473. $chunk = member_helper::exmembers($chunk,$params['member']['ex_lrlz'],$params['member']['ex_brand']);
  474. if($send_type == 'sms')
  475. {
  476. $iconut = 0;
  477. $sms = new Sms();
  478. foreach ($chunk as $member)
  479. {
  480. try {
  481. $mobile = $member['member_mobile'];
  482. $status = $sms->send_oper($mobile, $content);
  483. Log::record("sms info: status:" . json_encode($status),Log::DEBUG);
  484. } catch (Exception $e) {
  485. Log::record("sms info: fall error\treturn:" . $e->getMessage(),Log::ERR);
  486. }
  487. ++$iconut;
  488. if($iconut == 10) {
  489. sleep(2);
  490. $iconut = 0;
  491. }
  492. }
  493. }
  494. elseif($send_type == 'push')
  495. {
  496. foreach ($chunk as $member) {
  497. push_helper::oper_push($member['member_id'], $content);
  498. }
  499. }
  500. else {
  501. }
  502. }
  503. return callback(true);
  504. }
  505. /**
  506. * 订阅快递鸟
  507. * @param $param
  508. *
  509. * @return bool
  510. */
  511. public function subscribeKDN($param)
  512. {
  513. if (empty($param) || empty($param['order_sn'])) {
  514. Log::record("kdn_helper: 数据有误! param:" . json_encode($param));
  515. return callback(false);
  516. }
  517. try {
  518. kdn_helper::subscribe($param['order_sn']);
  519. } catch (Exception $e) {
  520. Log::record("kdn_helper: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param));
  521. }
  522. return callback(true);
  523. }
  524. /**
  525. * 根据上传的通讯录生成好友关系
  526. */
  527. public function generateRelations($param)
  528. {
  529. if (empty($param["member_id"])) {
  530. return false;
  531. }
  532. try {
  533. Model("mobile_contacts")->genRelations($param["member_id"]);
  534. } catch (Exception $e) {
  535. Log::record("generateRelations: fall error\treturn:" . $e->getMessage());
  536. }
  537. return true;
  538. }
  539. public function savelog($param)
  540. {
  541. statistics_helper::instance()->add_logs($param);
  542. return callback(true);
  543. }
  544. public function click_goods($param)
  545. {
  546. $goods_id = intval($param['goods_id']);
  547. if($goods_id > 0) {
  548. $mod_goods = Model('goods');
  549. $mod_goods->editGoodsById(array('goods_click' => array('exp', 'goods_click + 1')), $goods_id);
  550. return callback(true);
  551. }
  552. else {
  553. return callback(false,"click_goods 错误的goods_id");
  554. }
  555. }
  556. public function invite_user_register($param)
  557. {
  558. $member_id = $param['member_id'];
  559. $relay_id = $param['relay_id'];
  560. $password = $param['password'];
  561. if($member_id < 0) {
  562. return callback(false,"invite_user_register 错误的member_id");
  563. }
  564. login_helper::onInvite($member_id,$relay_id,$password);
  565. return callback(true);
  566. }
  567. public function onPredeposit($param)
  568. {
  569. Log::record('queue::onPredeposit',Log::DEBUG);
  570. account_helper::onPredeposit($param['change_type'],$param['buyer_id'],$param['order_sn']);
  571. return callback(true);
  572. }
  573. public function onPaySuccess($param)
  574. {
  575. $pay_sn = $param['pay_sn'];
  576. account_helper::onPaySuccess($pay_sn);
  577. return callback(true);
  578. }
  579. public function reset_fcode($param)
  580. {
  581. $pay_sn = $param['pay_sn'];
  582. if(empty($pay_sn)) {
  583. return callback(false);
  584. }
  585. $num = \fcode\operator::reset($pay_sn);
  586. if($num > 0) {
  587. return callback(true);
  588. } else {
  589. return callback(false);
  590. }
  591. }
  592. public function onUseBonus($param)
  593. {
  594. stat_helper::onUseBonus($param);
  595. return callback(true);
  596. }
  597. }