queue.logic.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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_HELPER_PATH . '/push_sender.php');
  12. require_once(BASE_HELPER_PATH . '/sms_helper.php');
  13. require_once(BASE_HELPER_PATH . '/kdn_helper.php');
  14. require_once(BASE_HELPER_PATH . '/statistics_helper.php');
  15. require_once(BASE_HELPER_PATH . '/member_helper.php');
  16. require_once(BASE_HELPER_PATH . '/account_helper.php');
  17. require_once(BASE_HELPER_PATH . '/fcode/generator.php');
  18. require_once(BASE_HELPER_PATH . '/memsg/message_sender.php');
  19. require_once(BASE_HELPER_PATH . '/login_helper.php');
  20. require_once(BASE_HELPER_PATH . '/fcode/mfcode.php');
  21. require_once(BASE_HELPER_PATH . '/fcode/operator.php');
  22. require_once(BASE_HELPER_PATH . '/user_session/fcode.php');
  23. require_once(BASE_HELPER_PATH . '/stat_helper.php');
  24. require_once(BASE_HELPER_PATH . '/message/publisher.php');
  25. require_once(BASE_HELPER_PATH . '/search/tcp_client.php');
  26. require_once(BASE_HELPER_PATH . '/ugc_helper.php');
  27. require_once(BASE_HELPER_PATH . '/room_helper.php');
  28. require_once(BASE_HELPER_PATH . '/mcard/mcard.php');
  29. require_once(BASE_HELPER_PATH . '/util_helper.php');
  30. require_once(BASE_HELPER_PATH . '/third_author/signaturer.php');
  31. class queueLogic
  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. public function makeMemberMiniQrCode($params)
  72. {
  73. $member_id = intval($params['member_id']);
  74. $resp = thrid_author\signaturer::instance()->minicode("/pages/index/index?relay_id={$member_id}&channel=0",430);
  75. if(!empty($resp))
  76. {
  77. $passwd = util::passwd;
  78. $name = md5("{$member_id}.{$passwd}") . ".png";
  79. $save_path = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
  80. $length = file_put_contents($save_path,$resp);
  81. if(!$length) {
  82. Log::record("Cannot write file: {$save_path}",Log::ERR);
  83. }
  84. }
  85. else {
  86. Log::record("request mini code error when member_id = {$member_id}",Log::ERR);
  87. }
  88. }
  89. //邀请好友成功后向,邀请者发送微信push消息。
  90. public function sendInviterSubMsg($params)
  91. {
  92. $inviter_id = $params['inviter_id'];
  93. $invitee_id = $params['invitee_id'];
  94. $mod_member = Model('member');
  95. $items = $mod_member->field('member_id,member_wxopenid,member_nickname,member_time')
  96. ->where(['member_id' => ['in',[$inviter_id,$invitee_id]]])
  97. ->select();
  98. foreach ($items as $item) {
  99. if($item['member_id'] == $inviter_id) {
  100. $inviter = $item;
  101. }
  102. else {
  103. $invitee = $item;
  104. }
  105. }
  106. if(empty($inviter) || empty($invitee) || empty($inviter['member_wxopenid'])) {
  107. return callback(false, '向邀请者发送微信push消息错误');
  108. }
  109. $tmpid = 'zBNktaey9EM2DcBzUNsjnAan2NvYpj_nKZDY__f9pGA'; //这个是
  110. $openid = $inviter['member_wxopenid'];
  111. $time = strftime('%Y年%m月%d日',$invitee['member_time']);
  112. $data = ['thing4' => ['value' => $invitee['member_nickname'] ], 'time3' => ['value' => "{$time}"]];
  113. $ret = thrid_author\signaturer::instance()->send_submsg($openid,$tmpid,'pages/index/index',$data);
  114. if($ret) {
  115. return callback(true, "向邀请者{$inviter_id}发送微信push消息成功");
  116. } else {
  117. return callback(false, "向邀请者{$inviter_id}发送微信push消息错误");
  118. }
  119. }
  120. /**
  121. * 更新使用的代金券状态
  122. * @param $input_voucher_list
  123. * @throws Exception
  124. */
  125. public function editVoucherState($voucher_list)
  126. {
  127. $model_voucher = Model('voucher');
  128. $send = new memsg\message_sender();
  129. foreach ($voucher_list as $store_id => $voucher_info) {
  130. $update = $model_voucher->editVoucher(['voucher_state' => 2], ['voucher_id' => $voucher_info['voucher_id']], $voucher_info['voucher_owner_id']);
  131. if ($update) {
  132. // 发送用户店铺消息
  133. $send->set('member_id', $voucher_info['voucher_owner_id']);
  134. $send->set('code', 'voucher_use');
  135. $param = array();
  136. $param['voucher_code'] = $voucher_info['voucher_code'];
  137. $param['voucher_url'] = urlShop('member_voucher', 'index');
  138. $send->send($param);
  139. } else {
  140. return callback(false, '更新代金券状态失败vcode:' . $voucher_info['voucher_code']);
  141. }
  142. }
  143. return callback(true);
  144. }
  145. /**
  146. * 下单变更库存销量
  147. * @param unknown $goods_buy_quantity
  148. */
  149. public function createOrderUpdateStorage($goods_buy_quantity)
  150. {
  151. $model_goods = Model('goods');
  152. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  153. $data = array();
  154. $data['goods_storage'] = array('exp', 'goods_storage-' . $quantity);
  155. $data['goods_salenum'] = array('exp', 'goods_salenum+' . $quantity);
  156. $result = $model_goods->editGoodsById($data, $goods_id);
  157. }
  158. if (!$result) {
  159. return callback(false, '变更商品库存与销量失败');
  160. } else {
  161. return callback(true);
  162. }
  163. }
  164. /**
  165. * 取消订单变更库存销量
  166. * @param unknown $goods_buy_quantity
  167. */
  168. public function cancelOrderUpdateStorage($goods_buy_quantity)
  169. {
  170. $model_goods = Model('goods');
  171. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  172. $data = array();
  173. $data['goods_storage'] = array('exp', 'goods_storage+' . $quantity);
  174. $data['goods_salenum'] = array('exp', 'goods_salenum-' . $quantity);
  175. $result = $model_goods->editGoodsById($data, $goods_id);
  176. }
  177. if (!$result) {
  178. return callback(false, '变更商品库存与销量失败');
  179. } else {
  180. return callback(true);
  181. }
  182. }
  183. /**
  184. * 更新F码为使用状态
  185. * @param int $fc_id
  186. */
  187. public function updateGoodsFCode($fc_ids)
  188. {
  189. $update = Model('goods_fcode')->editGoodsFCode(array('fc_state' => 1,'consume_time' => time()), array('fc_id' => array('in',$fc_ids)));
  190. if (!$update) {
  191. return callback(false, '更新F码使用状态失败fc_ids:' . implode(',',$fc_ids));
  192. } else {
  193. return callback(true);
  194. }
  195. }
  196. /**
  197. * 删除购物车
  198. * @param unknown $cart
  199. */
  200. public function delCart($cart)
  201. {
  202. if (!is_array($cart['cart_ids']) || empty($cart['buyer_id'])) return callback(true);
  203. $del = Model('cart')->delCart('db', array('buyer_id' => $cart['buyer_id'], 'cart_id' => array('in', $cart['cart_ids'])));
  204. if (!$del) {
  205. return callback(false, '删除购物车数据失败');
  206. } else {
  207. return callback(true);
  208. }
  209. }
  210. /**
  211. * 根据商品id更新促销价格
  212. *
  213. * @param int /array $goods_commonid
  214. * @return boolean
  215. */
  216. public function updateGoodsPromotionPriceByGoodsId($goods_id)
  217. {
  218. $update = Model('goods')->editGoodsPromotionPrice(array('goods_id' => array('in', $goods_id)));
  219. if (!$update) {
  220. return callback(false, '根据商品ID更新促销价格失败');
  221. } else {
  222. return callback(true);
  223. }
  224. }
  225. /**
  226. * 根据商品公共id更新促销价格
  227. *
  228. * @param int /array $goods_commonid
  229. * @return boolean
  230. */
  231. public function updateGoodsPromotionPriceByGoodsCommonId($goods_commonid)
  232. {
  233. $update = Model('goods')->editGoodsPromotionPrice(array('goods_commonid' => array('in', $goods_commonid)));
  234. if (!$update) {
  235. return callback(false, '根据商品公共id更新促销价格失败');
  236. } else {
  237. return callback(true);
  238. }
  239. }
  240. /**
  241. * 发送店铺消息
  242. */
  243. public function sendStoreMsg($param)
  244. {
  245. $send = new sendStoreMsg();
  246. $send->set('code', $param['code']);
  247. $send->set('store_id', $param['store_id']);
  248. $send->send($param['param']);
  249. return callback(true);
  250. }
  251. /**
  252. * 发送会员消息
  253. */
  254. public function sendMemberMsg($param)
  255. {
  256. $send = new memsg\message_sender();
  257. $send->set('code', $param['code']);
  258. $send->set('member_id', $param['member_id']);
  259. $send->set('sms_param', $param['sms_param']);
  260. if (!empty($param['number']['mobile'])) $send->set('mobile', $param['number']['mobile']);
  261. if (!empty($param['number']['email'])) $send->set('email', $param['number']['email']);
  262. $send->send($param['param']);
  263. return callback(true);
  264. }
  265. /**
  266. * 生成商品F码
  267. */
  268. public function createGoodsFCode($param)
  269. {
  270. Log::record("createGoodsFCode {$param['goods_commonid']},{$param['fc_count']},{$param['fc_prefix']},{$param['fc_validate']}",Log::DEBUG);
  271. $gen = new fcode\generator($param['goods_commonid'],$param['fc_count'],$param['fc_prefix'],$param['fc_validate']);
  272. $url = $gen->make();
  273. Log::record("createGoodsFCode url={$url}",Log::DEBUG);
  274. return callback(true);
  275. }
  276. /**
  277. * 生成商品二维码
  278. */
  279. public function createGoodsQRCode($param)
  280. {
  281. if (empty($param['goodsid_array'])) {
  282. return callback(true);
  283. }
  284. // 生成商品二维码
  285. require_once(BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'index.php');
  286. $PhpQRCode = new PhpQRCode();
  287. $PhpQRCode->set('pngTempDir', BASE_UPLOAD_PATH . DS . ATTACH_STORE . DS . $param['store_id'] . DS);
  288. foreach ($param['goodsid_array'] as $goods_id) {
  289. // 生成商品二维码
  290. $PhpQRCode->set('date', urlShop('goods', 'index', array('goods_id' => $goods_id)));
  291. $PhpQRCode->set('pngTempName', $goods_id . '.png');
  292. $PhpQRCode->init();
  293. }
  294. return callback(true);
  295. }
  296. /**
  297. * 清理特殊商品促销信息
  298. */
  299. public function clearSpecialGoodsPromotion($param)
  300. {
  301. // 抢购
  302. Model('groupbuy')->delGroupbuy(array('goods_commonid' => $param['goods_commonid']));
  303. // 显示折扣
  304. Model('p_xianshi_goods')->delXianshiGoods(array('goods_id' => array('in', $param['goodsid_array'])));
  305. // 优惠套装
  306. Model('p_bundling')->delBundlingGoods(array('goods_id' => array('in', $param['goodsid_array'])));
  307. // 更新促销价格
  308. Model('goods')->editGoods(array('goods_promotion_price' => array('exp', 'goods_price'), 'goods_promotion_type' => 0), array('goods_commonid' => $param['goods_commonid']));
  309. return callback(true);
  310. }
  311. /**
  312. * 删除(买/卖家)订单全部数量缓存
  313. * @param array $data 订单信息
  314. * @return boolean
  315. */
  316. public function delOrderCountCache($order_info)
  317. {
  318. if (empty($order_info)) return callback(true);
  319. $model_order = Model('order');
  320. if ($order_info['order_id']) {
  321. $order_info = $model_order->getOrderInfo(array('order_id' => $order_info['order_id']), array(), 'buyer_id,store_id');
  322. }
  323. $model_order->delOrderCountCache('buyer', $order_info['buyer_id']);
  324. $model_order->delOrderCountCache('store', $order_info['store_id']);
  325. return callback(true);
  326. }
  327. /**
  328. * 发送兑换码
  329. * @param unknown $param
  330. * @return boolean
  331. */
  332. public function sendVrCode($param)
  333. {
  334. if (empty($param) && !is_array($param)) return callback(true);
  335. $condition = array();
  336. $condition['order_id'] = $param['order_id'];
  337. $condition['buyer_id'] = $param['buyer_id'];
  338. $condition['vr_state'] = 0;
  339. $condition['refund_lock'] = 0;
  340. $code_list = Model('vr_order')->getOrderCodeList($condition, 'vr_code,vr_indate');
  341. if (empty($code_list)) return callback(true);
  342. $content = '';
  343. foreach ($code_list as $v) {
  344. $content .= $v['vr_code'] . ',';
  345. }
  346. $tpl_info = Model('mail_templates')->getTplInfo(array('code' => 'send_vr_code'));
  347. $data = array();
  348. $data['site_name'] = C('site_name');
  349. $data['vr_code'] = rtrim($content, ',');
  350. $message = ncReplaceText($tpl_info['content'], $data);
  351. $sms = new Sms();
  352. $result = $sms->send($param["buyer_phone"], $message);
  353. if (!$result) {
  354. return callback(false, '兑换码发送失败order_id:' . $param['order_id']);
  355. } else {
  356. return callback(true);
  357. }
  358. }
  359. /**
  360. * 添加订单自提表内容
  361. */
  362. public function saveDeliveryOrder($param)
  363. {
  364. if (!is_array($param['order_sn_list'])) return callback(true);
  365. $data = array();
  366. $model_delivery_order = Model('delivery_order');
  367. foreach ($param['order_sn_list'] as $order_id => $v) {
  368. $data['order_id'] = $order_id;
  369. $data['order_sn'] = $v['order_sn'];
  370. $data['addtime'] = $v['add_time'];
  371. $data['dlyp_id'] = $param['dlyp_id'];
  372. $data['reciver_name'] = $param['reciver_name'];
  373. $data['reciver_telphone'] = $param['tel_phone'];
  374. $data['reciver_mobphone'] = $param['mob_phone'];
  375. $insert = $model_delivery_order->addDeliveryOrder($data);
  376. if (!$insert) {
  377. return callback(false, '保存自提站订单信息失败order_sn:' . $v['order_sn']);
  378. }
  379. }
  380. return callback(true);
  381. }
  382. /**
  383. * 发送提货码短信消息
  384. */
  385. public function sendPickupcode($param)
  386. {
  387. $dorder_info = Model('delivery_order')->getDeliveryOrderInfo(array('order_id' => $param['order_id']), 'reciver_mobphone');
  388. $tpl_info = Model('mail_templates')->getTplInfo(array('code' => 'send_pickup_code'));
  389. $data = array();
  390. $data['site_name'] = C('site_name');
  391. $data['pickup_code'] = $param['pickup_code'];
  392. $message = ncReplaceText($tpl_info['content'], $data);
  393. $sms = new Sms();
  394. $result = $sms->send($dorder_info['reciver_mobphone'], $message);
  395. if (!$result) {
  396. return callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']);
  397. } else {
  398. return callback(true);
  399. }
  400. }
  401. /**
  402. * 刷新搜索索引
  403. */
  404. public function flushIndexer()
  405. {
  406. require_once(BASE_DATA_PATH . '/api/xs/lib/XS.php');
  407. $obj_doc = new XSDocument();
  408. $obj_xs = new XS(C('fullindexer.appname'));
  409. $obj_xs->index->flushIndex();
  410. }
  411. /**
  412. * 推送服务
  413. * @param $param array
  414. * 共有三个key : member_id , text, go_type
  415. * @return bool
  416. */
  417. public function upushSendMsg($param)
  418. {
  419. if (empty($param) || empty($param['alias']) || empty($param['text'])) {
  420. Log::record("push info: 数据有误! param:" . json_encode($param) . "\t session:" . json_encode($_SESSION));
  421. return callback(false);
  422. }
  423. $push = new push_sender();
  424. $push->send($param);
  425. return callback(true);
  426. }
  427. public function sendPushMessage($param)
  428. {
  429. $push = new push_sender();
  430. $push->send_message($param);
  431. return callback(true);
  432. }
  433. /**
  434. * 发短信
  435. * @param $param
  436. *
  437. * @return bool
  438. */
  439. public function sendSMS($param)
  440. {
  441. if (empty($param) || empty($param['mobile']) || empty($param['type'])) {
  442. Log::record("sms info: 数据有误! param:" . json_encode($param),Log::ERR);
  443. return callback(false);
  444. }
  445. try {
  446. $sms = new Sms();
  447. $status = $sms->send($param['mobile'], $param);
  448. Log::record("sms info: status:" . json_encode($status) . "\t param:" . json_encode($param),Log::DEBUG);
  449. } catch (Exception $e) {
  450. Log::record("sms info: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param),Log::ERR);
  451. }
  452. return callback(true);
  453. }
  454. public function sendOperSMS($params)
  455. {
  456. if (empty($params) || empty($params['mobile']) || empty($params['type'])) {
  457. Log::record("sms info: 数据有误! param:" . json_encode($params),Log::ERR);
  458. return callback(false);
  459. }
  460. try
  461. {
  462. $datas = [];
  463. foreach ($params as $key => $val)
  464. {
  465. if($key == 'mobile') {
  466. $mobile = $val;
  467. }
  468. elseif ($key == 'type') {
  469. $type = $val;
  470. }
  471. else {
  472. $datas[$key] = $val;
  473. }
  474. }
  475. $sms = new Sms();
  476. $status = $sms->send_oper($mobile,$type,$datas);
  477. Log::record("sms info: status:" . json_encode($status) . "\t param:" . json_encode($params),Log::DEBUG);
  478. } catch (Exception $e) {
  479. Log::record("sms info: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($params),Log::ERR);
  480. }
  481. return callback(true);
  482. }
  483. public function sendBonusAndSMS($params)
  484. {
  485. $input_type = $params['member']['input_type'];
  486. if($input_type == 'mobiles') {
  487. $members = member_helper::from_mobiles($params['member']['data'],$error);
  488. }
  489. elseif($input_type == 'sql') {
  490. $members = member_helper::from_sql($params['member']['data']);
  491. }
  492. else {
  493. return callback(false,'sendBonusAndSMS 错误的人员输入类型.');
  494. }
  495. $fSendSms = $params['sms']['open'];
  496. $smscode = $params['sms']['template_id'];
  497. $rate = $params['bonus']['rate'];
  498. $bless = $params['bonus']['bless'];
  499. $amount = $params['bonus']['amount'];
  500. $can_share = intval($params['bonus']['can_share']);
  501. $chunks = array_chunk($members,1000);
  502. foreach ($chunks as $chunk)
  503. {
  504. $chunk = member_helper::exmembers($chunk,$params['member']['ex_lrlz'],$params['member']['ex_brand']);
  505. $ids = [];
  506. foreach ($chunk as $member) {
  507. $ids[] = $member['member_id'];
  508. }
  509. $ret = account_helper::add_bonus($rate,$amount,$ids,$bless,$can_share);
  510. if($ret == false) continue;
  511. if($fSendSms)
  512. {
  513. $iconut = 0;
  514. $sms = new Sms();
  515. foreach ($chunk as $member)
  516. {
  517. $mobile = $member['member_mobile'];
  518. try {
  519. $status = $sms->send_oper($mobile, $smscode);
  520. Log::record("sms info: status:" . json_encode($status),Log::DEBUG);
  521. } catch (Exception $e) {
  522. Log::record("sms info: fall error\treturn:" . $e->getMessage(),Log::ERR);
  523. }
  524. ++$iconut;
  525. if($iconut == 10) {
  526. sleep(2);
  527. $iconut = 0;
  528. }
  529. }
  530. }
  531. }
  532. return callback(true);
  533. }
  534. public function sendPushOrSMS($params)
  535. {
  536. $input_type = $params['member']['input_type'];
  537. if($input_type == 'mobiles') {
  538. $members = member_helper::from_mobiles($params['member']['data'],$error);
  539. }
  540. elseif($input_type == 'sql') {
  541. $members = member_helper::from_sql($params['member']['data']);
  542. }
  543. else {
  544. return callback(false,'sendBonusAndSMS 错误的人员输入类型.');
  545. }
  546. $send_type = $params['send']['type'];
  547. $content = $params['send']['data'];
  548. $chunks = array_chunk($members,1000);
  549. foreach ($chunks as $chunk)
  550. {
  551. $chunk = member_helper::exmembers($chunk,$params['member']['ex_lrlz'],$params['member']['ex_brand']);
  552. if($send_type == 'sms')
  553. {
  554. $iconut = 0;
  555. $sms = new Sms();
  556. foreach ($chunk as $member)
  557. {
  558. try {
  559. $mobile = $member['member_mobile'];
  560. $status = $sms->send_oper($mobile, $content);
  561. Log::record("sms info: status:" . json_encode($status),Log::DEBUG);
  562. } catch (Exception $e) {
  563. Log::record("sms info: fall error\treturn:" . $e->getMessage(),Log::ERR);
  564. }
  565. ++$iconut;
  566. if($iconut == 10) {
  567. sleep(2);
  568. $iconut = 0;
  569. }
  570. }
  571. }
  572. elseif($send_type == 'push')
  573. {
  574. foreach ($chunk as $member) {
  575. push_helper::oper_push($member['member_id'], $content);
  576. }
  577. }
  578. else {
  579. }
  580. }
  581. return callback(true);
  582. }
  583. /**
  584. * 订阅快递鸟
  585. * @param $param
  586. *
  587. * @return bool
  588. */
  589. public function subscribeKDN($param)
  590. {
  591. if (empty($param) || empty($param['order_sn'])) {
  592. Log::record("kdn_helper: 数据有误! param:" . json_encode($param));
  593. return callback(false);
  594. }
  595. try {
  596. kdn_helper::subscribe($param['order_sn']);
  597. } catch (Exception $e) {
  598. Log::record("kdn_helper: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param));
  599. }
  600. return callback(true);
  601. }
  602. /**
  603. * 根据上传的通讯录生成好友关系
  604. */
  605. public function generateRelations($param)
  606. {
  607. if (empty($param["member_id"])) {
  608. return false;
  609. }
  610. try {
  611. Model("mobile_contacts")->genRelations($param["member_id"]);
  612. } catch (Exception $e) {
  613. Log::record("generateRelations: fall error\treturn:" . $e->getMessage());
  614. }
  615. return true;
  616. }
  617. public function savelog($param)
  618. {
  619. statistics_helper::instance()->add_logs($param);
  620. return callback(true);
  621. }
  622. public function click_goods($param)
  623. {
  624. $goods_id = intval($param['goods_id']);
  625. if($goods_id > 0) {
  626. $mod_goods = Model('goods');
  627. $mod_goods->editGoodsById(array('goods_click' => array('exp', 'goods_click + 1')), $goods_id);
  628. return callback(true);
  629. }
  630. else {
  631. return callback(false,"click_goods 错误的goods_id");
  632. }
  633. }
  634. public function reset_fcode($param)
  635. {
  636. $pay_sn = $param['pay_sn'];
  637. if(empty($pay_sn)) {
  638. return callback(false);
  639. }
  640. $num = \fcode\operator::reset($pay_sn);
  641. if($num > 0) {
  642. return callback(true);
  643. } else {
  644. return callback(false);
  645. }
  646. }
  647. public function onUseBonus($param)
  648. {
  649. stat_helper::onUseBonus($param);
  650. return callback(true);
  651. }
  652. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  653. public function onAsyncRegister($param)
  654. {
  655. $user = $param['user'];
  656. $inviter = $param['inviter'];
  657. if($user < 0) {
  658. return callback(false,"onRegisterFromBonus 错误的member_id");
  659. }
  660. account_helper::onAsyncRegister($user,$inviter);
  661. return callback(true);
  662. }
  663. public function onAsyncStatus($param)
  664. {
  665. Log::record(__METHOD__,Log::DEBUG);
  666. account_helper::onAsyncStatus($param['member_id']);
  667. return callback(true);
  668. }
  669. public function onAsyncTopup($param)
  670. {
  671. Log::record(__METHOD__,Log::DEBUG);
  672. account_helper::onAsyncTopup($param['member_id']);
  673. return callback(true);
  674. }
  675. public function onPredeposit($param)
  676. {
  677. Log::record('queue::onPredeposit',Log::DEBUG);
  678. account_helper::onPredeposit($param['change_type'],$param['buyer_id'],$param['order_sn']);
  679. return callback(true);
  680. }
  681. public function onBonusChange($param)
  682. {
  683. Log::record('queue::onPredeposit',Log::DEBUG);
  684. account_helper::onPredeposit($param['change_type'],$param['buyer_id'],$param['order_sn']);
  685. return callback(true);
  686. }
  687. public function onAsyncOrderPaied($param)
  688. {
  689. $pay_sn = $param['pay_sn'];
  690. account_helper::onAsyncOrderPaied($pay_sn);
  691. return callback(true);
  692. }
  693. public function onAsyncOrderSended($param)
  694. {
  695. $pay_sn = $param['pay_sn'];
  696. $logistics_no = $param['logistics_no'];
  697. $logistics_company = $param['logistics_company'];
  698. account_helper::onAsyncOrderSended($pay_sn,$logistics_no,$logistics_company);
  699. return callback(true);
  700. }
  701. public function onAsyncOrderComplete($param)
  702. {
  703. $pay_sn = $param['pay_sn'];
  704. if(!empty($pay_sn)) {
  705. account_helper::onAsyncOrderComplete($pay_sn);
  706. }
  707. return callback(true);
  708. }
  709. public function onAsyncOrderCancel($param)
  710. {
  711. $pay_sn = $param['pay_sn'];
  712. $order_sn = $param['order_sn'];
  713. if(!empty($pay_sn) && !empty($order_sn)) {
  714. account_helper::onAsyncOrderCancel($pay_sn,$order_sn);
  715. }
  716. return callback(true);
  717. }
  718. public function onAsyncOrderEvaluate($param)
  719. {
  720. $pay_sn = $param['pay_sn'];
  721. if(!empty($pay_sn)) {
  722. account_helper::onAsyncOrderEvaluate($pay_sn);
  723. }
  724. return callback(true);
  725. }
  726. public function onAsyncBroadcastOrder($param)
  727. {
  728. $pay_sn = $param['pay_sn'];
  729. $amount = $param['amount'];
  730. $days = $param['days'];
  731. if(!empty($pay_sn) && !empty($amount)) {
  732. account_helper::onAsyncBroadcastOrder($pay_sn,$amount,$days);
  733. }
  734. return callback(true);
  735. }
  736. public function onAsyncBroadcastNormal($param)
  737. {
  738. $filters = $param['filters'];
  739. $oper_param = $param['oper_param'];
  740. $send_params = $param['send_params'];
  741. if(!empty($oper_param) && !empty($filters) && !empty($send_params)) {
  742. account_helper::onAsyncBroadcastNormal($filters,$oper_param,$send_params);
  743. }
  744. return callback(true);
  745. }
  746. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  747. public function onAsyncUgcPublish($param)
  748. {
  749. $spid = $param['special_id'];
  750. account_helper::onAsyncUgcPublish($spid);
  751. return callback(true);
  752. }
  753. public function onAsyncUgcDel($param)
  754. {
  755. $spid = $param['special_id'];
  756. account_helper::onAsyncUgcDel($spid);
  757. return callback(true);
  758. }
  759. public function onAsyncUgcSubmit($param)
  760. {
  761. $spid = $param['special_id'];
  762. $user = $param['user_id'];
  763. account_helper::onAsyncUgcSubmit($spid,$user);
  764. return callback(true);
  765. }
  766. public function onAsyncUgcSupport($param)
  767. {
  768. $spid = $param['special_id'];
  769. $user = $param['user_id'];
  770. $comment_id = $param['comment_id'];
  771. account_helper::onAsyncUgcSupport($spid,$comment_id,$user);
  772. return callback(true);
  773. }
  774. public static function onAsyncUgcAppreciate($param)
  775. {
  776. $spid = $param['special_id'];
  777. $user = $param['user_id'];
  778. $rate = $param['rate'];
  779. $amount = $param['amount'];
  780. account_helper::onAsyncUgcAppreciate($spid,$user,$rate,$amount);
  781. return callback(true);
  782. }
  783. public function onAsyncUgcComment($param)
  784. {
  785. $special_id = intval($param['special_id']);
  786. $comment_id = intval($param['comment_id']);
  787. $user_id = intval($param['user_id']);
  788. account_helper::onAsyncUgcComment($special_id,$comment_id,$user_id);
  789. return callback(true);
  790. }
  791. public function onClickSpecial($param)
  792. {
  793. $special_id = intval($param['special_id']);
  794. if($special_id > 0) {
  795. Model()->table('mb_special')->where(['special_id' => $special_id])->update(['clicks' => ['exp', 'clicks + 1']]);
  796. }
  797. return callback(true);
  798. }
  799. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  800. public function onAsyncBargain($param)
  801. {
  802. $type = $param['type'];
  803. $bargain_id = intval($param['bargain_id']);
  804. if(empty($type) || $bargain_id <= 0) {
  805. return callback(false);
  806. }
  807. else {
  808. account_helper::onAsyncBargain($type,$bargain_id);
  809. return callback(true);
  810. }
  811. }
  812. public function UpdateSotreLocation($param)
  813. {
  814. $store_id = intval($param['store_id']);
  815. if($store_id <= 0) {
  816. return callback(false);
  817. }
  818. else {
  819. $ret = geo_helper::instance()->update_store($store_id);
  820. return callback($ret);
  821. }
  822. }
  823. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  824. public function OnUpdateRoom($param)
  825. {
  826. $roomid = intval($param['room_id']);
  827. if($roomid <= 0) {
  828. return callback(false);
  829. }
  830. else {
  831. Log::record("OnUpdateRoom Start",Log::DEBUG);
  832. $ret = room_helper::OnUpdateRoom($roomid);
  833. return callback($ret);
  834. }
  835. }
  836. public function OnGoodsConvert($params)
  837. {
  838. $appid = $params['appid'];
  839. $convert_sn = $params['convert_sn'];
  840. $return_url = $params['return_url'];
  841. $data['success'] = $params['success'] == true ? 1 : 0;
  842. $data['convert_sn'] = $params['convert_sn'];
  843. $data['appid'] = $params['appid'];
  844. if(empty($return_url) || empty($appid) || empty($convert_sn)) {
  845. return callback(false);
  846. }
  847. else {
  848. https_request($return_url,$data);
  849. return callback(true);
  850. }
  851. }
  852. //虚拟订单下单成功,回调事件.
  853. public function OnVrOrderSuccess($params)
  854. {
  855. $order_sn = $params['order_sn'];
  856. $model_order = Model('vr_order');
  857. $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
  858. $goods_id = $order['goods_id'];
  859. if($order['order_state'] == ORDER_STATE_NEW)
  860. {
  861. global $config;
  862. $handlers = $config['vgoods_handlers'];
  863. if(array_key_exists($goods_id,$handlers))
  864. {
  865. $handler = $handlers[$goods_id];
  866. $method = $handler['order_method'];
  867. if(!empty($method)) {
  868. $ret = $this->$method($order);
  869. if(!$ret) {
  870. return callback(false);
  871. }
  872. }
  873. }
  874. }
  875. return callback(true);
  876. }
  877. private function getTopcardAmound($goods_id)
  878. {
  879. global $config;
  880. $spec_card = $config['vgoods_spec_card'];
  881. if(array_key_exists($goods_id,$spec_card)) {
  882. return $spec_card[$goods_id];
  883. }
  884. else {
  885. return 0;
  886. }
  887. }
  888. private function OnReserveOilCard($order)
  889. {
  890. Log::record(__FUNCTION__,Log::DEBUG);
  891. $amount = $this->getTopcardAmound($order['goods_id']);
  892. $member_id = $order['buyer_id'];
  893. $order_id = $order['order_id'];
  894. $extra_info = json_decode($order['extra_info'],true);
  895. $card_no = $extra_info['input']['card_no'];
  896. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  897. $ret = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper,$amount,$member_id,$card_no,$card_type,$order_id);
  898. return $ret;
  899. }
  900. private function OnReservePhoneCard($order)
  901. {
  902. Log::record(__FUNCTION__,Log::DEBUG);
  903. $amount = $this->getTopcardAmound($order['goods_id']);
  904. $member_id = $order['buyer_id'];
  905. $order_id = $order['order_id'];
  906. $extra_info = json_decode($order['extra_info'],true);
  907. $card_no = $extra_info['input']['card_no'];
  908. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  909. $ret = mtopcard\cards_helper::reserve(mtopcard\PhoneCardPaper,$amount,$member_id,$card_no,$card_type,$order_id);
  910. return $ret;
  911. }
  912. //虚拟订单取消回调事件.
  913. public function OnVrOrderCancel($params)
  914. {
  915. $order_sn = $params['order_sn'];
  916. $model_order = Model('vr_order');
  917. $order = $model_order->getOrderInfo(['order_sn' => $order_sn],'*',true);
  918. $goods_id = $order['goods_id'];
  919. global $config;
  920. $handlers = $config['vgoods_handlers'];
  921. if(array_key_exists($goods_id,$handlers))
  922. {
  923. $handler = $handlers[$goods_id];
  924. $method = $handler['cancel_method'];
  925. if(!empty($method)) {
  926. $this->$method($order);
  927. }
  928. }
  929. return callback(true);
  930. }
  931. private function OnCardKeyCancel($order)
  932. {
  933. $order_id = $order['order_id'];
  934. $mod_card = Model('card_key');
  935. $card = $mod_card->field('*')->where(['order_id' => $order_id])->select();
  936. if(empty($card)) {
  937. return callback(false,'订单取消,没找到对应的卡密.',['order_sn' => $order['order_sn']]);
  938. } else {
  939. CalcPrice::onCancelVrOrder($order);
  940. $card_id = $card[0]['card_id'];
  941. mtopcard\cards_helper::reuse($card_id);
  942. return callback(false,'订单取消,成功解除卡密.',['order_sn' => $order['order_sn']]);
  943. }
  944. }
  945. //虚拟订单支付成功回调事件.
  946. public function OnVrOrderPaidSuccess($params)
  947. {
  948. $order_sn = $params['order_sn'];
  949. $model_order = Model('vr_order');
  950. $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
  951. $goods_id = $order['goods_id'];
  952. global $config;
  953. $handlers = $config['vgoods_handlers'];
  954. if(array_key_exists($goods_id,$handlers))
  955. {
  956. $handler = $handlers[$goods_id];
  957. $method = $handler['paid_method'];
  958. if(!empty($method)) {
  959. $this->$method($order);
  960. }
  961. }
  962. return callback(true);
  963. }
  964. //支付成功完成会员卡操作.
  965. public function OnMCardPaidSuccess($order)
  966. {
  967. $order_sn = $order['order_sn'];
  968. if($order['order_state'] != ORDER_STATE_PAY) {
  969. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 状态错误",Log::ERR);
  970. return callback(false);
  971. }
  972. $extra_info = json_decode($order['extra_info'],true);
  973. $card_type = $extra_info['additional']['card_type'];
  974. if(empty($card_type)) {
  975. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 失败",Log::ERR);
  976. return callback(false);
  977. }
  978. else
  979. {
  980. $params = mcard\getConfig($card_type);
  981. if(empty($params)) {
  982. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} card_type = {$card_type} 失败",Log::ERR);
  983. return callback(false);
  984. }
  985. $member_id = intval($order['buyer_id']);
  986. $usercards = new mcard\user_mcards($member_id);
  987. $ret = $usercards->addCard($params);
  988. if($ret) {
  989. $vrLogic = Logic('vr_order');
  990. $vrLogic->changeOrderStateSuccess($order['order_id']);
  991. return callback(false);
  992. } else {
  993. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} addCard 失败",Log::ERR);
  994. return callback(false);
  995. }
  996. }
  997. }
  998. //虚拟商品完成回调事件....
  999. public function OnVrOrderComplete($params)
  1000. {
  1001. $order_sn = $params['order_sn'];
  1002. $model_order = Model('vr_order');
  1003. $order = $model_order->getOrderInfo(['order_sn' => $order_sn],'*',true);
  1004. $goods_id = $order['goods_id'];
  1005. global $config;
  1006. $handlers = $config['vgoods_handlers'];
  1007. if(array_key_exists($goods_id,$handlers))
  1008. {
  1009. $handler = $handlers[$goods_id];
  1010. $method = $handler['complete_method'];
  1011. if(!empty($method)) {
  1012. $ret = $this->$method($order);
  1013. if(!$ret) {
  1014. return callback(false);
  1015. }
  1016. }
  1017. }
  1018. return callback(true);
  1019. }
  1020. private function OnCardKeyComplete($order)
  1021. {
  1022. $order_id = $order['order_id'];
  1023. $mod_card = Model('card_key');
  1024. $card = $mod_card->field('*')->where(['order_id' => $order_id])->select();
  1025. if(empty($card)) {
  1026. return callback(false,'充值失败',['order_sn' => $order['order_sn']]);
  1027. } else {
  1028. $card_id = $card[0]['card_id'];
  1029. mtopcard\cards_helper::assign($card_id,'OnOilComplete');
  1030. return callback(true,'充值成功',['order_sn' => $order['order_sn']]);
  1031. }
  1032. }
  1033. }