queue.logic.php 51 KB

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