queue.logic.php 49 KB

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