queue.logic.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  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. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  980. $goods_id = intval($params['goods_id']);
  981. $topcard = Model('topcard');
  982. if(empty($topcard->get_card($card_no)))
  983. {//卡不存在
  984. //查询1000内是否有卡
  985. $items = $topcard->get_cards($card_no - 500,$card_no + 500);
  986. if(!empty($items)) {
  987. return callback(false,'此油卡充值,存在风险,请去运营商平台充值.');
  988. }
  989. else {
  990. $topcard->add($card_no,$card_type,time());
  991. return callback(true);
  992. }
  993. }
  994. else
  995. {
  996. $day_limit = 1000;
  997. $month_limit = 2000;
  998. return $this->check_amount($goods_id,$card_no,$day_limit,$month_limit);
  999. }
  1000. }
  1001. private function getOrderAmounts($card_no,$start,$end)
  1002. {
  1003. global $config;
  1004. $spec_card = $config['vgoods_spec_card'];
  1005. $vr_order = Model('vr_order');
  1006. $cond = ['card_no' => $card_no,'add_time' =>['between',[$start,$end]]];
  1007. $items = $vr_order->getOrderList($cond);
  1008. $amount = 0;
  1009. foreach ($items as $order) {
  1010. $goods_id = intval($order['goods_id']);
  1011. $order_state = intval($order['order_state']);
  1012. if(array_key_exists($goods_id,$spec_card) && $order_state != ORDER_STATE_CANCEL) {
  1013. $amount += $spec_card[$goods_id];
  1014. }
  1015. }
  1016. return $amount;
  1017. }
  1018. private function day_range($time)
  1019. {
  1020. $x = strtotime(date('Y-m-d',$time));
  1021. $y = strtotime('+1 day',$x);
  1022. return [$x,$y];
  1023. }
  1024. private function month_range($time)
  1025. {
  1026. $x = strtotime(date('Y-m-d',$time));
  1027. $x = strtotime(date('Y-m-01',$x));
  1028. $y = strtotime('+1 month',$x);
  1029. return [$x,$y];
  1030. }
  1031. public function OnChanageCard($params)
  1032. {
  1033. $order_sn = $params['order_sn'];
  1034. $model_order = Model('vr_order');
  1035. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1036. if (empty($order)) {
  1037. return callback(false, '没找到订单');
  1038. }
  1039. if (($ret = $this->OnFreezeCard($order))['state'] == false) {
  1040. return $ret;
  1041. }
  1042. $ret = $this->OnVrOrderSuccess(['order_sn' => $order_sn]);
  1043. return $ret;
  1044. }
  1045. public function OnCancelorderFreezeCard($params)
  1046. {
  1047. $order_sn = $params['order_sn'];
  1048. $model_order = Model('vr_order');
  1049. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1050. if (empty($order)) {
  1051. return callback(false, '没找到订单');
  1052. }
  1053. if (($ret = $this->OnFreezeCard($order))['state'] == false) {
  1054. return $ret;
  1055. } elseif (($ret = $this->OnVrOrderCancel($params))['state'] == false) {
  1056. return $ret;
  1057. } else {
  1058. return callback();
  1059. }
  1060. }
  1061. private function OnFreezeCard($order)
  1062. {
  1063. $order_id = $order['order_id'];
  1064. $cards = Model('card_key')->getCardByOrderId($order_id);
  1065. foreach ($cards as $card) {
  1066. $card_id = $card['card_id'];
  1067. if (mtopcard\cards_helper::freeze($card_id)) {
  1068. return callback();
  1069. } else {
  1070. return callback(false, '解冻失败 ');
  1071. }
  1072. }
  1073. return callback(false, '没找到卡');
  1074. }
  1075. private function OnReserveOilCard($order)
  1076. {
  1077. Log::record(__FUNCTION__, Log::DEBUG);
  1078. $amount = $this->getTopcardAmound($order['goods_id']);
  1079. $member_id = $order['buyer_id'];
  1080. $order_id = $order['order_id'];
  1081. $extra_info = json_decode($order['extra_info'], true);
  1082. $card_no = $extra_info['input']['card_no'];
  1083. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  1084. $ret = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper, $amount, $member_id, $card_no, $card_type, $order_id);
  1085. $vr_order = Model();
  1086. $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);
  1087. return $ret;
  1088. }
  1089. private function OnReservePhoneCard($order)
  1090. {
  1091. Log::record(__FUNCTION__, Log::DEBUG);
  1092. $amount = $this->getTopcardAmound($order['goods_id']);
  1093. $member_id = $order['buyer_id'];
  1094. $order_id = $order['order_id'];
  1095. $extra_info = json_decode($order['extra_info'], true);
  1096. $card_no = $extra_info['input']['card_no'];
  1097. $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
  1098. $ret = mtopcard\cards_helper::reserve(mtopcard\PhoneCardPaper, $amount, $member_id, $card_no, $card_type, $order_id);
  1099. $vr_order = Model();
  1100. $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);
  1101. return $ret;
  1102. }
  1103. //虚拟订单取消回调事件.
  1104. public function OnVrOrderCancel($params)
  1105. {
  1106. $order_sn = $params['order_sn'];
  1107. $model_order = Model('vr_order');
  1108. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1109. $goods_id = $order['goods_id'];
  1110. global $config;
  1111. $handlers = $config['vgoods_handlers'];
  1112. if (array_key_exists($goods_id, $handlers)) {
  1113. $handler = $handlers[$goods_id];
  1114. $method = $handler['cancel_method'];
  1115. if (!empty($method)) {
  1116. $this->$method($order);
  1117. }
  1118. }
  1119. return callback(true);
  1120. }
  1121. private function OnCardKeyCancel($order)
  1122. {
  1123. $order_id = $order['order_id'];
  1124. $mod_card = Model('card_key');
  1125. $card = $mod_card->getCardByOrderId($order_id);
  1126. if (empty($card)) {
  1127. return callback(false, '订单取消,没找到对应的卡密.', ['order_sn' => $order['order_sn']]);
  1128. } else {
  1129. CalcPrice::onCancelVrOrder($order);
  1130. $card_id = $card[0]['card_id'];
  1131. mtopcard\cards_helper::reuse($card_id);
  1132. return callback(false, '订单取消,成功解除卡密.', ['order_sn' => $order['order_sn']]);
  1133. }
  1134. }
  1135. //虚拟订单支付成功回调事件.
  1136. public function OnVrOrderPaidSuccess($params)
  1137. {
  1138. $order_sn = $params['order_sn'];
  1139. $model_order = Model('vr_order');
  1140. $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
  1141. $goods_id = $order['goods_id'];
  1142. global $config;
  1143. $handlers = $config['vgoods_handlers'];
  1144. if (array_key_exists($goods_id, $handlers)) {
  1145. $handler = $handlers[$goods_id];
  1146. $method = $handler['paid_method'];
  1147. if (!empty($method)) {
  1148. $this->$method($order);
  1149. }
  1150. }
  1151. return callback(true);
  1152. }
  1153. //支付成功完成会员卡操作.
  1154. public function OnMCardPaidSuccess($order)
  1155. {
  1156. $order_sn = $order['order_sn'];
  1157. if ($order['order_state'] != ORDER_STATE_PAY) {
  1158. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 状态错误", Log::ERR);
  1159. return callback(false);
  1160. }
  1161. $extra_info = json_decode($order['extra_info'], true);
  1162. $card_type = $extra_info['additional']['card_type'];
  1163. if (empty($card_type)) {
  1164. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 失败", Log::ERR);
  1165. return callback(false);
  1166. } else {
  1167. $params = mcard\getConfig($card_type);
  1168. if (empty($params)) {
  1169. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} card_type = {$card_type} 失败", Log::ERR);
  1170. return callback(false);
  1171. }
  1172. $member_id = intval($order['buyer_id']);
  1173. $usercards = new mcard\user_mcards($member_id);
  1174. $ret = $usercards->addCard($params);
  1175. if ($ret) {
  1176. $vrLogic = Logic('vr_order');
  1177. $vrLogic->changeOrderStateSuccess($order['order_id']);
  1178. return callback(false);
  1179. } else {
  1180. Log::record("OnMCardOrderSuccess order_sn:{$order_sn} addCard 失败", Log::ERR);
  1181. return callback(false);
  1182. }
  1183. }
  1184. }
  1185. //虚拟商品完成回调事件....
  1186. public function OnVrOrderComplete($params)
  1187. {
  1188. $order_sn = $params['order_sn'];
  1189. $model_order = Model('vr_order');
  1190. $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
  1191. $goods_id = $order['goods_id'];
  1192. global $config;
  1193. $handlers = $config['vgoods_handlers'];
  1194. if (array_key_exists($goods_id, $handlers)) {
  1195. $handler = $handlers[$goods_id];
  1196. $method = $handler['complete_method'];
  1197. if (!empty($method)) {
  1198. $ret = $this->$method($order);
  1199. if (!$ret) {
  1200. return callback(false);
  1201. }
  1202. }
  1203. }
  1204. return callback(true);
  1205. }
  1206. private function OnCardKeyComplete($order)
  1207. {
  1208. $order_id = $order['order_id'];
  1209. $mod_card = Model('card_key');
  1210. $card = $mod_card->getCardByOrderId($order_id);
  1211. if (empty($card)) {
  1212. return callback(false, '充值失败', ['order_sn' => $order['order_sn']]);
  1213. } else {
  1214. $card_id = $card[0]['card_id'];
  1215. mtopcard\cards_helper::assign($card_id, 'OnOilComplete');
  1216. return callback(true, '充值成功', ['order_sn' => $order['order_sn']]);
  1217. }
  1218. }
  1219. }