queue.logic.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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 send_sms($param)
  505. {
  506. if (empty($param) || empty($param['mobile']) || empty($param['type'])) {
  507. Log::record("sms info: 数据有误! param:" . json_encode($param), Log::ERR);
  508. return callback(false);
  509. }
  510. try {
  511. $sms = new Sms();
  512. $status = $sms->send($param['mobile'], $param);
  513. Log::record("sms info: status:" . json_encode($status) . "\t param:" . json_encode($param), Log::DEBUG);
  514. } catch (Exception $e) {
  515. Log::record("sms info: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param), Log::ERR);
  516. }
  517. return callback(true);
  518. }
  519. public function sendOperSMS($params)
  520. {
  521. if (empty($params) || empty($params['mobile']) || empty($params['type'])) {
  522. Log::record("sms info: 数据有误! param:" . json_encode($params), Log::ERR);
  523. return callback(false);
  524. }
  525. try {
  526. $datas = [];
  527. foreach ($params as $key => $val) {
  528. if ($key == 'mobile') {
  529. $mobile = $val;
  530. } elseif ($key == 'type') {
  531. $type = $val;
  532. } else {
  533. $datas[$key] = $val;
  534. }
  535. }
  536. $sms = new Sms();
  537. $status = $sms->send_oper($mobile, $type, $datas);
  538. Log::record("sms info: status:" . json_encode($status) . "\t param:" . json_encode($params), Log::DEBUG);
  539. } catch (Exception $e) {
  540. Log::record("sms info: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($params), Log::ERR);
  541. }
  542. return callback(true);
  543. }
  544. public function sendBonusAndSMS($params)
  545. {
  546. $input_type = $params['member']['input_type'];
  547. if ($input_type == 'mobiles') {
  548. $members = member_helper::from_mobiles($params['member']['data'], $error);
  549. } elseif ($input_type == 'sql') {
  550. $members = member_helper::from_sql($params['member']['data']);
  551. } else {
  552. return callback(false, 'sendBonusAndSMS 错误的人员输入类型.');
  553. }
  554. $fSendSms = $params['sms']['open'];
  555. $smscode = $params['sms']['template_id'];
  556. $rate = $params['bonus']['rate'];
  557. $bless = $params['bonus']['bless'];
  558. $amount = $params['bonus']['amount'];
  559. $can_share = intval($params['bonus']['can_share']);
  560. $chunks = array_chunk($members, 1000);
  561. foreach ($chunks as $chunk) {
  562. $chunk = member_helper::exmembers($chunk, $params['member']['ex_lrlz'], $params['member']['ex_brand']);
  563. $ids = [];
  564. foreach ($chunk as $member) {
  565. $ids[] = $member['member_id'];
  566. }
  567. $ret = account_helper::add_bonus($rate, $amount, $ids, $bless, $can_share);
  568. if ($ret == false) continue;
  569. if ($fSendSms) {
  570. $iconut = 0;
  571. $sms = new Sms();
  572. foreach ($chunk as $member) {
  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. } elseif ($input_type == 'sql') {
  596. $members = member_helper::from_sql($params['member']['data']);
  597. } else {
  598. return callback(false, 'sendBonusAndSMS 错误的人员输入类型.');
  599. }
  600. $send_type = $params['send']['type'];
  601. $content = $params['send']['data'];
  602. $chunks = array_chunk($members, 1000);
  603. foreach ($chunks as $chunk) {
  604. $chunk = member_helper::exmembers($chunk, $params['member']['ex_lrlz'], $params['member']['ex_brand']);
  605. if ($send_type == 'sms') {
  606. $iconut = 0;
  607. $sms = new Sms();
  608. foreach ($chunk as $member) {
  609. try {
  610. $mobile = $member['member_mobile'];
  611. $status = $sms->send_oper($mobile, $content);
  612. Log::record("sms info: status:" . json_encode($status), Log::DEBUG);
  613. } catch (Exception $e) {
  614. Log::record("sms info: fall error\treturn:" . $e->getMessage(), Log::ERR);
  615. }
  616. ++$iconut;
  617. if ($iconut == 10) {
  618. sleep(2);
  619. $iconut = 0;
  620. }
  621. }
  622. } elseif ($send_type == 'push') {
  623. foreach ($chunk as $member) {
  624. push_helper::oper_push($member['member_id'], $content);
  625. }
  626. } else {
  627. }
  628. }
  629. return callback(true);
  630. }
  631. /**
  632. * 订阅快递鸟
  633. * @param $param
  634. *
  635. * @return bool
  636. */
  637. public function subscribeKDN($param)
  638. {
  639. if (empty($param) || empty($param['order_sn'])) {
  640. Log::record("kdn_helper: 数据有误! param:" . json_encode($param));
  641. return callback(false);
  642. }
  643. try {
  644. kdn_helper::subscribe($param['order_sn']);
  645. } catch (Exception $e) {
  646. Log::record("kdn_helper: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param));
  647. }
  648. return callback(true);
  649. }
  650. /**
  651. * 根据上传的通讯录生成好友关系
  652. */
  653. public function generateRelations($param)
  654. {
  655. if (empty($param["member_id"])) {
  656. return false;
  657. }
  658. try {
  659. Model("mobile_contacts")->genRelations($param["member_id"]);
  660. } catch (Exception $e) {
  661. Log::record("generateRelations: fall error\treturn:" . $e->getMessage());
  662. }
  663. return true;
  664. }
  665. public function savelog($param)
  666. {
  667. statistics_helper::instance()->add_logs($param);
  668. return callback(true);
  669. }
  670. public function click_goods($param)
  671. {
  672. $goods_id = intval($param['goods_id']);
  673. if ($goods_id > 0) {
  674. $mod_goods = Model('goods');
  675. $mod_goods->editGoodsById(array('goods_click' => array('exp', 'goods_click + 1')), $goods_id);
  676. return callback(true);
  677. } else {
  678. return callback(false, "click_goods 错误的goods_id");
  679. }
  680. }
  681. public function reset_fcode($param)
  682. {
  683. $pay_sn = $param['pay_sn'];
  684. if (empty($pay_sn)) {
  685. return callback(false);
  686. }
  687. $num = \fcode\operator::reset($pay_sn);
  688. if ($num > 0) {
  689. return callback(true);
  690. } else {
  691. return callback(false);
  692. }
  693. }
  694. public function onUseBonus($param)
  695. {
  696. stat_helper::onUseBonus($param);
  697. return callback(true);
  698. }
  699. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  700. public function onAsyncRegister($param)
  701. {
  702. $user = $param['user'];
  703. $inviter = $param['inviter'];
  704. if ($user < 0) {
  705. return callback(false, "onRegisterFromBonus 错误的member_id");
  706. }
  707. account_helper::onAsyncRegister($user, $inviter);
  708. return callback(true);
  709. }
  710. public function onAsyncStatus($param)
  711. {
  712. Log::record(__METHOD__, Log::DEBUG);
  713. account_helper::onAsyncStatus($param['member_id']);
  714. return callback(true);
  715. }
  716. public function onAsyncTopup($param)
  717. {
  718. Log::record(__METHOD__, Log::DEBUG);
  719. account_helper::onAsyncTopup($param['member_id']);
  720. return callback(true);
  721. }
  722. public function onPredeposit($param)
  723. {
  724. Log::record('queue::onPredeposit', Log::DEBUG);
  725. account_helper::onPredeposit($param['change_type'], $param['buyer_id'], $param['order_sn']);
  726. return callback(true);
  727. }
  728. public function onBonusChange($param)
  729. {
  730. Log::record('queue::onPredeposit', Log::DEBUG);
  731. account_helper::onPredeposit($param['change_type'], $param['buyer_id'], $param['order_sn']);
  732. return callback(true);
  733. }
  734. public function onAsyncOrderPaied($param)
  735. {
  736. $pay_sn = $param['pay_sn'];
  737. account_helper::onAsyncOrderPaied($pay_sn);
  738. return callback(true);
  739. }
  740. public function onAsyncOrderSended($param)
  741. {
  742. $pay_sn = $param['pay_sn'];
  743. $logistics_no = $param['logistics_no'];
  744. $logistics_company = $param['logistics_company'];
  745. account_helper::onAsyncOrderSended($pay_sn, $logistics_no, $logistics_company);
  746. return callback(true);
  747. }
  748. public function onAsyncOrderComplete($param)
  749. {
  750. $pay_sn = $param['pay_sn'];
  751. if (!empty($pay_sn)) {
  752. account_helper::onAsyncOrderComplete($pay_sn);
  753. }
  754. return callback(true);
  755. }
  756. public function onAsyncOrderCancel($param)
  757. {
  758. $pay_sn = $param['pay_sn'];
  759. $order_sn = $param['order_sn'];
  760. if (!empty($pay_sn) && !empty($order_sn)) {
  761. account_helper::onAsyncOrderCancel($pay_sn, $order_sn);
  762. }
  763. return callback(true);
  764. }
  765. public function onAsyncOrderEvaluate($param)
  766. {
  767. $pay_sn = $param['pay_sn'];
  768. if (!empty($pay_sn)) {
  769. account_helper::onAsyncOrderEvaluate($pay_sn);
  770. }
  771. return callback(true);
  772. }
  773. public function onAsyncBroadcastOrder($param)
  774. {
  775. $pay_sn = $param['pay_sn'];
  776. $amount = $param['amount'];
  777. $days = $param['days'];
  778. if (!empty($pay_sn) && !empty($amount)) {
  779. account_helper::onAsyncBroadcastOrder($pay_sn, $amount, $days);
  780. }
  781. return callback(true);
  782. }
  783. public function onAsyncBroadcastNormal($param)
  784. {
  785. $filters = $param['filters'];
  786. $oper_param = $param['oper_param'];
  787. $send_params = $param['send_params'];
  788. if (!empty($oper_param) && !empty($filters) && !empty($send_params)) {
  789. account_helper::onAsyncBroadcastNormal($filters, $oper_param, $send_params);
  790. }
  791. return callback(true);
  792. }
  793. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  794. public function onAsyncUgcPublish($param)
  795. {
  796. $spid = $param['special_id'];
  797. account_helper::onAsyncUgcPublish($spid);
  798. return callback(true);
  799. }
  800. public function onAsyncUgcDel($param)
  801. {
  802. $spid = $param['special_id'];
  803. account_helper::onAsyncUgcDel($spid);
  804. return callback(true);
  805. }
  806. public function onAsyncUgcSubmit($param)
  807. {
  808. $spid = $param['special_id'];
  809. $user = $param['user_id'];
  810. account_helper::onAsyncUgcSubmit($spid, $user);
  811. return callback(true);
  812. }
  813. public function onAsyncUgcSupport($param)
  814. {
  815. $spid = $param['special_id'];
  816. $user = $param['user_id'];
  817. $comment_id = $param['comment_id'];
  818. account_helper::onAsyncUgcSupport($spid, $comment_id, $user);
  819. return callback(true);
  820. }
  821. public static function onAsyncUgcAppreciate($param)
  822. {
  823. $spid = $param['special_id'];
  824. $user = $param['user_id'];
  825. $rate = $param['rate'];
  826. $amount = $param['amount'];
  827. account_helper::onAsyncUgcAppreciate($spid, $user, $rate, $amount);
  828. return callback(true);
  829. }
  830. public function onAsyncUgcComment($param)
  831. {
  832. $special_id = intval($param['special_id']);
  833. $comment_id = intval($param['comment_id']);
  834. $user_id = intval($param['user_id']);
  835. account_helper::onAsyncUgcComment($special_id, $comment_id, $user_id);
  836. return callback(true);
  837. }
  838. public function onClickSpecial($param)
  839. {
  840. $special_id = intval($param['special_id']);
  841. if ($special_id > 0) {
  842. Model()->table('mb_special')->where(['special_id' => $special_id])->update(['clicks' => ['exp', 'clicks + 1']]);
  843. }
  844. return callback(true);
  845. }
  846. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  847. public function onAsyncBargain($param)
  848. {
  849. $type = $param['type'];
  850. $bargain_id = intval($param['bargain_id']);
  851. if (empty($type) || $bargain_id <= 0) {
  852. return callback(false);
  853. } else {
  854. account_helper::onAsyncBargain($type, $bargain_id);
  855. return callback(true);
  856. }
  857. }
  858. public function UpdateSotreLocation($param)
  859. {
  860. $store_id = intval($param['store_id']);
  861. if ($store_id <= 0) {
  862. return callback(false);
  863. } else {
  864. $ret = geo_helper::instance()->update_store($store_id);
  865. return callback($ret);
  866. }
  867. }
  868. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  869. public function OnUpdateRoom($param)
  870. {
  871. $roomid = intval($param['room_id']);
  872. if ($roomid <= 0) {
  873. return callback(false);
  874. } else {
  875. Log::record("OnUpdateRoom Start", Log::DEBUG);
  876. $ret = room_helper::OnUpdateRoom($roomid);
  877. return callback($ret);
  878. }
  879. }
  880. public function OnGoodsConvert($params)
  881. {
  882. $appid = $params['appid'];
  883. $convert_sn = $params['convert_sn'];
  884. $return_url = $params['return_url'];
  885. $data['success'] = $params['success'] == true ? 1 : 0;
  886. $data['convert_sn'] = $params['convert_sn'];
  887. $data['appid'] = $params['appid'];
  888. if (empty($return_url) || empty($appid) || empty($convert_sn)) {
  889. return callback(false);
  890. } else {
  891. https_request($return_url, $data);
  892. return callback(true);
  893. }
  894. }
  895. //虚拟订单下单成功,回调事件.
  896. public function OnVrOrderSuccess($params)
  897. {
  898. $order_sn = $params['order_sn'];
  899. $model_order = Model('vr_order');
  900. $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
  901. $goods_id = $order['goods_id'];
  902. global $config;
  903. $handlers = $config['vgoods_handlers'];
  904. if (array_key_exists($goods_id, $handlers)) {
  905. $handler = $handlers[$goods_id];
  906. $method = $handler['order_method'];
  907. if (!empty($method)) {
  908. $ret = $this->$method($order);
  909. if (!$ret) {
  910. return callback(false);
  911. }
  912. }
  913. }
  914. return callback(true);
  915. }
  916. private function getTopcardAmound($goods_id)
  917. {
  918. global $config;
  919. $spec_card = $config['vgoods_spec_card'];
  920. if (array_key_exists($goods_id, $spec_card)) {
  921. return $spec_card[$goods_id];
  922. } else {
  923. return 0;
  924. }
  925. }
  926. public function OnPhoneCardCheck($params)
  927. {
  928. $extra_info = $params['extra_info'];
  929. $card_no = $extra_info['input']['card_no'];
  930. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  931. $goods_id = intval($params['goods_id']);
  932. $topcard = Model('topcard');
  933. if(empty($topcard->get_card($card_no)))
  934. {
  935. $topcard->add($card_no,$card_type,time());
  936. return callback(true);
  937. }
  938. else
  939. {
  940. $day_limit = 500;
  941. $month_limit = 1000;
  942. return $this->check_amount($goods_id,$card_no,$day_limit,$month_limit);
  943. }
  944. }
  945. private function check_amount($goods_id,$card_no,$day_limit,$month_limit)
  946. {
  947. global $config;
  948. $spec_card = $config['vgoods_spec_card'];
  949. if(!array_key_exists($goods_id,$spec_card)) {
  950. return callback(true);
  951. }
  952. else {
  953. $goods_spec = $spec_card[$goods_id];
  954. }
  955. [$start,$end] = $this->day_range(time());
  956. $day_total = $this->getOrderAmounts($card_no,$start,$end);
  957. if($day_total > $day_limit) {
  958. return callback(false,"本卡今日充值已经超过{$day_limit}元额度,请改日再充.");
  959. }
  960. elseif($day_total + $goods_spec > $day_limit)
  961. {
  962. $left = $day_limit - $day_total;
  963. if($left > 0) {
  964. return callback(false,"本卡今日还可以充值{$left}元,请重新选择充值面额.");
  965. } else {
  966. return callback(false,"本卡今日额度已经用完,请改日再充.");
  967. }
  968. }
  969. else {
  970. Log::record("满足充值条件",Log::DEBUG);
  971. }
  972. [$start,$end] = $this->month_range(time());
  973. $month_total = $this->getOrderAmounts($card_no,$start,$end);
  974. if($month_total > $month_limit) {
  975. return callback(false,"本卡本月充值已经超过{$day_limit}元额度,请下月再充.");
  976. }
  977. elseif ($month_total + $goods_spec > $month_limit)
  978. {
  979. $left = $month_limit - $month_total;
  980. if($left > 0) {
  981. return callback(false, "本卡本月还可以充值{$left}元,请重新选择充值面额.");
  982. } else {
  983. return callback(false,"本卡本月额度已经用完,请下月再充.");
  984. }
  985. }
  986. else {
  987. return callback(true);
  988. }
  989. }
  990. public function OnOilCardCheck($params)
  991. {
  992. $extra_info = $params['extra_info'];
  993. $card_no = $extra_info['input']['card_no'];
  994. $phone_no = $extra_info['input']['phone_no'];
  995. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  996. $goods_id = intval($params['goods_id']);
  997. $topcard = Model('topcard');
  998. $cards = $topcard->get_card($card_no);
  999. if(empty($cards))
  1000. { //卡不存在
  1001. //查询1000内是否有卡
  1002. $items = $topcard->get_cards($card_no - 500,$card_no + 500);
  1003. if(!empty($items)) {
  1004. return callback(false,'此油卡充值,存在风险,请去运营商平台充值.');
  1005. }
  1006. else {
  1007. $topcard->add($card_no,$card_type,time(),$phone_no);
  1008. return callback(true);
  1009. }
  1010. }
  1011. else
  1012. {
  1013. $day_limit = 1000;
  1014. $month_limit = 2000;
  1015. if(empty($cards[0]['bind_phone'])) {
  1016. $topcard->table('topcard')->field('*')->where(['card_no' => $card_no])->update(['bind_phone' => $phone_no]);
  1017. }
  1018. return $this->check_amount($goods_id,$card_no,$day_limit,$month_limit);
  1019. }
  1020. }
  1021. private function getOrderAmounts($card_no,$start,$end)
  1022. {
  1023. global $config;
  1024. $spec_card = $config['vgoods_spec_card'];
  1025. $vr_order = Model('vr_order');
  1026. $cond = ['card_no' => $card_no,'add_time' =>['between',[$start,$end]]];
  1027. $items = $vr_order->getOrderList($cond);
  1028. $amount = 0;
  1029. foreach ($items as $order) {
  1030. $goods_id = intval($order['goods_id']);
  1031. $order_state = intval($order['order_state']);
  1032. if(array_key_exists($goods_id,$spec_card) && $order_state != ORDER_STATE_CANCEL) {
  1033. $amount += $spec_card[$goods_id];
  1034. }
  1035. }
  1036. return $amount;
  1037. }
  1038. private function day_range($time)
  1039. {
  1040. $x = strtotime(date('Y-m-d',$time));
  1041. $y = strtotime('+1 day',$x);
  1042. return [$x,$y];
  1043. }
  1044. private function month_range($time)
  1045. {
  1046. $x = strtotime(date('Y-m-d',$time));
  1047. $x = strtotime(date('Y-m-01',$x));
  1048. $y = strtotime('+1 month',$x);
  1049. return [$x,$y];
  1050. }
  1051. public function OnChanageCard($params)
  1052. {
  1053. $order_sn = $params['order_sn'];
  1054. $model_order = Model('vr_order');
  1055. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1056. if (empty($order)) {
  1057. return callback(false, '没找到订单');
  1058. }
  1059. if (($ret = $this->OnFreezeCard($order))['state'] == false) {
  1060. return $ret;
  1061. }
  1062. $ret = $this->OnVrOrderSuccess(['order_sn' => $order_sn]);
  1063. return $ret;
  1064. }
  1065. public function OnCancelorderFreezeCard($params)
  1066. {
  1067. $order_sn = $params['order_sn'];
  1068. $model_order = Model('vr_order');
  1069. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1070. if (empty($order)) {
  1071. return callback(false, '没找到订单');
  1072. }
  1073. if (($ret = $this->OnFreezeCard($order))['state'] == false) {
  1074. return $ret;
  1075. } elseif (($ret = $this->OnVrOrderCancel($params))['state'] == false) {
  1076. return $ret;
  1077. } else {
  1078. return callback();
  1079. }
  1080. }
  1081. private function OnFreezeCard($order)
  1082. {
  1083. $order_id = $order['order_id'];
  1084. $cards = Model('card_key')->getCardByOrderId($order_id);
  1085. foreach ($cards as $card) {
  1086. $card_id = $card['card_id'];
  1087. if (mtopcard\cards_helper::freeze($card_id)) {
  1088. return callback();
  1089. } else {
  1090. return callback(false, '解冻失败 ');
  1091. }
  1092. }
  1093. return callback(false, '没找到卡');
  1094. }
  1095. private function OnReserveOilCard($order)
  1096. {
  1097. Log::record(__FUNCTION__, Log::DEBUG);
  1098. $amount = $this->getTopcardAmound($order['goods_id']);
  1099. $member_id = $order['buyer_id'];
  1100. $order_id = $order['order_id'];
  1101. $extra_info = json_decode($order['extra_info'], true);
  1102. $card_no = $extra_info['input']['card_no'];
  1103. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  1104. $ret = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper, $amount, $member_id, $card_no, $card_type, $order_id);
  1105. $vr_order = Model();
  1106. $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);
  1107. return $ret;
  1108. }
  1109. private function OnReservePhoneCard($order)
  1110. {
  1111. Log::record(__FUNCTION__, Log::DEBUG);
  1112. $amount = $this->getTopcardAmound($order['goods_id']);
  1113. $member_id = $order['buyer_id'];
  1114. $order_id = $order['order_id'];
  1115. $extra_info = json_decode($order['extra_info'], true);
  1116. $card_no = $extra_info['input']['card_no'];
  1117. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  1118. $ret = mtopcard\cards_helper::reserve(mtopcard\PhoneCardPaper, $amount, $member_id, $card_no, $card_type, $order_id);
  1119. $vr_order = Model();
  1120. $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);
  1121. return $ret;
  1122. }
  1123. //虚拟订单取消回调事件.
  1124. public function OnVrOrderCancel($params)
  1125. {
  1126. $order_sn = $params['order_sn'];
  1127. $model_order = Model('vr_order');
  1128. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1129. $goods_id = $order['goods_id'];
  1130. global $config;
  1131. $handlers = $config['vgoods_handlers'];
  1132. if (array_key_exists($goods_id, $handlers)) {
  1133. $handler = $handlers[$goods_id];
  1134. $method = $handler['cancel_method'];
  1135. if (!empty($method)) {
  1136. $this->$method($order);
  1137. }
  1138. }
  1139. return callback(true);
  1140. }
  1141. private function OnCardKeyCancel($order)
  1142. {
  1143. $order_id = $order['order_id'];
  1144. $mod_card = Model('card_key');
  1145. $card = $mod_card->getCardByOrderId($order_id);
  1146. if (empty($card)) {
  1147. return callback(false, '订单取消,没找到对应的卡密.', ['order_sn' => $order['order_sn']]);
  1148. } else {
  1149. CalcPrice::onCancelVrOrder($order);
  1150. $card_id = $card[0]['card_id'];
  1151. mtopcard\cards_helper::reuse($card_id);
  1152. return callback(false, '订单取消,成功解除卡密.', ['order_sn' => $order['order_sn']]);
  1153. }
  1154. }
  1155. //虚拟订单支付成功回调事件.
  1156. public function OnVrOrderPaidSuccess($params)
  1157. {
  1158. $order_sn = $params['order_sn'];
  1159. $model_order = Model('vr_order');
  1160. $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
  1161. $goods_id = $order['goods_id'];
  1162. global $config;
  1163. $handlers = $config['vgoods_handlers'];
  1164. if (array_key_exists($goods_id, $handlers)) {
  1165. $handler = $handlers[$goods_id];
  1166. $method = $handler['paid_method'];
  1167. if (!empty($method)) {
  1168. $this->$method($order);
  1169. }
  1170. }
  1171. return callback(true);
  1172. }
  1173. //支付成功完成会员卡操作.
  1174. public function OnMCardPaidSuccess($order)
  1175. {
  1176. $order_sn = $order['order_sn'];
  1177. if ($order['order_state'] != ORDER_STATE_PAY) {
  1178. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 状态错误", Log::ERR);
  1179. return callback(false);
  1180. }
  1181. $extra_info = json_decode($order['extra_info'], true);
  1182. $card_type = $extra_info['additional']['card_type'];
  1183. if (empty($card_type)) {
  1184. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 失败", Log::ERR);
  1185. return callback(false);
  1186. } else {
  1187. $params = mcard\getConfig($card_type);
  1188. if (empty($params)) {
  1189. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} card_type = {$card_type} 失败", Log::ERR);
  1190. return callback(false);
  1191. }
  1192. $member_id = intval($order['buyer_id']);
  1193. $usercards = new mcard\user_mcards($member_id);
  1194. $ret = $usercards->addCard($params);
  1195. if ($ret) {
  1196. $vrLogic = Logic('vr_order');
  1197. $vrLogic->changeOrderStateSuccess($order['order_id']);
  1198. return callback(false);
  1199. } else {
  1200. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} addCard 失败", Log::ERR);
  1201. return callback(false);
  1202. }
  1203. }
  1204. }
  1205. //虚拟商品完成回调事件....
  1206. public function OnVrOrderComplete($params)
  1207. {
  1208. $order_sn = $params['order_sn'];
  1209. $model_order = Model('vr_order');
  1210. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1211. $goods_id = $order['goods_id'];
  1212. global $config;
  1213. $handlers = $config['vgoods_handlers'];
  1214. if (array_key_exists($goods_id, $handlers)) {
  1215. $handler = $handlers[$goods_id];
  1216. $method = $handler['complete_method'];
  1217. if (!empty($method)) {
  1218. $ret = $this->$method($order);
  1219. if (!$ret) {
  1220. return callback(false);
  1221. }
  1222. }
  1223. }
  1224. return callback(true);
  1225. }
  1226. private function OnCardKeyComplete($order)
  1227. {
  1228. $order_id = $order['order_id'];
  1229. $mod_card = Model('card_key');
  1230. $card = $mod_card->getCardByOrderId($order_id);
  1231. if (empty($card)) {
  1232. return callback(false, '充值失败', ['order_sn' => $order['order_sn']]);
  1233. } else {
  1234. $card_id = $card[0]['card_id'];
  1235. mtopcard\cards_helper::assign($card_id, 'OnOilComplete');
  1236. return callback(true, '充值成功', ['order_sn' => $order['order_sn']]);
  1237. }
  1238. }
  1239. }