queue.logic.php 47 KB

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