queue.logic.php 41 KB

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