queue.logic.php 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  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 NotifyMerchantSuccess($params)
  1236. {
  1237. $mchid = intval($params['mchid']);
  1238. $mch_order = $params['mch_order'] ?? false;
  1239. if($mchid <= 0 || empty($mch_order)) {
  1240. return callback(false, "NotifyMerchantSuccess 参数 $mchid : $mch_order 错误");
  1241. }
  1242. else {
  1243. refill\util::push_notify_merchant_success($mchid, $mch_order);
  1244. return callback(true, '成功放入通知队列', ['mchid' => $mchid, 'mch_order' => $mch_order]);
  1245. }
  1246. }
  1247. public function QueryRefillState($params)
  1248. {
  1249. $order_id = intval($params['order_id']);
  1250. if($order_id <= 0) {
  1251. return callback(false, 'QueryRefillState 参数order_id错误');
  1252. }
  1253. else {
  1254. refill\util::push_query($order_id);
  1255. return callback(true, '成功放入通知队列', ['order_id' => $order_id]);
  1256. }
  1257. }
  1258. public function QueryAutoRefillState($params)
  1259. {
  1260. $order_id = intval($params['order_id']);
  1261. $query_times = intval($params['query_times']);
  1262. if($order_id <= 0) {
  1263. return callback(false, 'QueryAutoRefillState 参数order_id错误');
  1264. }
  1265. else {
  1266. refill\util::push_auto_query($order_id,$query_times);
  1267. return callback(true, '成功放入通知队列', ['order_id' => $order_id, 'query_times' => $query_times]);
  1268. }
  1269. }
  1270. public function QueryOrderNeterr($params)
  1271. {
  1272. $order_id = intval($params['order_id']);
  1273. if($order_id <= 0) {
  1274. return callback(false, 'QueryOrderNeterr 参数order_id错误');
  1275. }
  1276. else {
  1277. refill\util::push_query_net($order_id);
  1278. return callback(true, '成功放入通知队列', ['order_id' => $order_id]);
  1279. }
  1280. }
  1281. public function QueryMchOrderTimeout($params)
  1282. {
  1283. $mchid = intval($params['mchid']);
  1284. $mch_order = $params['mch_order'];
  1285. if($mchid <= 0 or empty($mch_order)) {
  1286. return callback(false, "QueryMchOrderTimeout 参数错误 mchid=$mchid mch_order=$mch_order");
  1287. }
  1288. else {
  1289. refill\util::push_query_timeout($mchid, $mch_order);
  1290. return callback(true, '成功放入通知队列', ['mchid' => $mchid, 'mch_order' => $mch_order]);
  1291. }
  1292. }
  1293. public function AysncAddDispatcher($params)
  1294. {
  1295. $method = $params['method'];
  1296. $input = $params['params'];
  1297. if(empty($method || empty($method))) {
  1298. return callback(false, 'AysncAddDispatcher 参数为空');
  1299. } else {
  1300. $ret = queue\DispatcherClient::instance()->push($method,$input);
  1301. return callback($ret, "放入通知队列 ret = {$ret}",$params);
  1302. }
  1303. }
  1304. public function AysncChangePrice($params)
  1305. {
  1306. $price_id = intval($params['price_id']);
  1307. if($price_id > 0) {
  1308. $chprice_helper = new chprice_helper();
  1309. $chprice_helper->effect($price_id);
  1310. $publisher = new message\publisher();
  1311. $publisher->modify_refill_channel();
  1312. return callback(true, "成功更新价格",$params);
  1313. } else {
  1314. return callback(false, 'AysncChangePrice 参数为空');
  1315. }
  1316. }
  1317. public function OnRiskSN($params)
  1318. {
  1319. $msg_adder = function ($order_id)
  1320. {
  1321. if($order_id <= 0) return false;
  1322. $mod_order = Model('vr_order');
  1323. $mod_refill = Model('refill_order');
  1324. $mod_except = Model('refill_exception');
  1325. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  1326. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
  1327. $order_sn = $refill_info['order_sn'];
  1328. if($mod_except->exist_order($order_sn)) {
  1329. return false;
  1330. }
  1331. if(empty($refill_info) || empty($order_info)) {
  1332. return false;
  1333. }
  1334. $sn = $refill_info['official_sn'];
  1335. if(empty($sn)) {
  1336. $desc = "渠道返回成功,但不含流水号。已经关闭通道,未给用户回调。";
  1337. } else {
  1338. $desc = "问题流水号:{$sn},有风险。已经关闭通道,未给用户回调。";
  1339. }
  1340. $params = ['title' => '风险号预警',
  1341. 'order_id' => $refill_info['order_id'],
  1342. 'order_sn' => $refill_info['order_sn'],
  1343. 'mchid' => $refill_info['mchid'],
  1344. 'store_id' => $order_info['store_id'],
  1345. 'store_name' => $order_info['store_name'],
  1346. 'except_desc' => $desc,
  1347. 'except_type' => refill_exception_type::EOfficialSN,
  1348. 'add_time' => time()];
  1349. $mod_except->add_except($params);
  1350. return [$order_info,$refill_info];
  1351. };
  1352. $in_exclude = function ($store_id)
  1353. {
  1354. $store_id = intval($store_id);
  1355. if($store_id <= 0) {
  1356. return false;
  1357. }
  1358. global $config;
  1359. $risk_official_sn = $config['risk_official_sn'] ?? [];
  1360. $exclude_stores = $risk_official_sn['exclude_stores'] ?? [];
  1361. return in_array($store_id,$exclude_stores);
  1362. };
  1363. $store_id = intval($params['store_id']);
  1364. $channel_name = $params['channel_name'];
  1365. $order_id = intval($params['order_id']);
  1366. if($in_exclude($store_id)) {
  1367. return callback(true, '该通道不需要过滤');
  1368. }
  1369. $ret = $msg_adder($order_id);
  1370. if($ret === false) {
  1371. return callback(false, 'OnRiskSN:没找到订单');
  1372. }
  1373. [$order_info, $refill_info] = $ret;
  1374. $quality = intval($refill_info['quality']);
  1375. if($store_id <= 0 || empty($channel_name)) {
  1376. return callback(false, 'OnRiskSN 参数有空');
  1377. }
  1378. $mod_provider = Model('refill_provider');
  1379. $item = $mod_provider->getProviderInfo(['store_id' => $store_id,'name' => $channel_name]);
  1380. if (empty($item)) {
  1381. return callback(false, 'OnRiskSN:没找到通道');
  1382. }
  1383. elseif($quality === 2) {
  1384. return callback(true, 'OnRiskSN:快充无需禁用通道.');
  1385. }
  1386. else
  1387. {
  1388. $provider_id = intval($item['provider_id']);
  1389. $state = intval($item['opened']);
  1390. if ($state == 1) {
  1391. $mod_provider->editProvider(['opened' => 2,'oper_time' => time()], ['provider_id' => $provider_id]);
  1392. $publisher = new message\publisher();
  1393. $publisher->modify_refill_channel();
  1394. }
  1395. }
  1396. return callback(true, "OnRiskSN 成功禁用通道");
  1397. }
  1398. public function OnRefillSuccess($params)
  1399. {
  1400. if (!defined('COMPANY_NAME') || COMPANY_NAME !== 'ZY_COMPANY') {
  1401. return callback(true, "official_sn 流水号要支持索引.");
  1402. }
  1403. $official_sn = $params['official_sn'];
  1404. $order_sn = $params['order_sn'];
  1405. if(empty($order_sn) || empty($official_sn)) {
  1406. return callback(true, "OnRefillSuccess official_sn or order_sn is empty.");
  1407. }
  1408. $mod_refill = Model('refill_order');
  1409. $items = $mod_refill->table('refill_order')->field('order_id')->where(['official_sn' => $official_sn,'inner_status' => 0])->select();
  1410. if(count($items) > 1)
  1411. {
  1412. $mod_order = Model('vr_order');
  1413. $mod_except = Model('refill_exception');
  1414. foreach ($items as $item)
  1415. {
  1416. $order_id = $item['order_id'];
  1417. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  1418. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
  1419. $desc = "流水号:$official_sn";
  1420. $params = ['title' => "流水号相同",
  1421. 'order_id' => $order_id,
  1422. 'order_sn' => $order_sn,
  1423. 'mchid' => $refill_info['mchid'],
  1424. 'store_id' => $order_info['store_id'],
  1425. 'store_name' => $order_info['store_name'],
  1426. 'except_desc' => $desc,
  1427. 'except_type' => refill_exception_type::EqualOfficialSN,
  1428. 'add_time' => time()];
  1429. $mod_except->add_except($params);
  1430. }
  1431. return callback(true, "OnRefillSuccess official_sn multi order.");
  1432. }
  1433. else {
  1434. return callback(true, "OnRefillSuccess official_sn OK.");
  1435. }
  1436. }
  1437. //检查统付返销.
  1438. public function QueryRefund($params)
  1439. {
  1440. $getProvider = function ($name, $type = 'RefillPhone')
  1441. {
  1442. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  1443. if (!file_exists($file)) {
  1444. Log::record("provider api file=$file not exist.", Log::DEBUG);
  1445. return false;
  1446. } else {
  1447. require_once($file);
  1448. Log::record("file={$file} load success.", Log::DEBUG);
  1449. }
  1450. $class_name = "refill\\{$name}\\{$type}";
  1451. if (class_exists($class_name, false)) {
  1452. $caller = new $class_name([]);
  1453. return $caller;
  1454. }
  1455. else {
  1456. $error = "Base Error: class {$class_name} isn't exists!";
  1457. Log::record($error, Log::ERR);
  1458. return false;
  1459. }
  1460. };
  1461. $order_id = intval($params['order_id'] ?? 0);
  1462. if($order_id <= 0) {
  1463. return callback(true, "Order id is nothing.");
  1464. }
  1465. $mod_refill = Model('refill_order');
  1466. $mod_order = Model('vr_order');
  1467. $mod_except = Model('refill_exception');
  1468. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  1469. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
  1470. if(empty($order_info) || empty($refill_info)) {
  1471. return callback(false, "no order");
  1472. }
  1473. if($order_info['order_state'] != ORDER_STATE_SUCCESS) {
  1474. return callback(false, "order state is not success.");
  1475. }
  1476. $chname = $refill_info['channel_name'];
  1477. $provider = $getProvider($chname);
  1478. if (empty($provider)) {
  1479. return callback(false, "cannot create $chname provider.");
  1480. }
  1481. if (!method_exists($provider, 'need_refund')) {
  1482. return callback(false, "$chname has not need_refund.");
  1483. }
  1484. [$need_refund,$neterr] = $provider->need_refund($refill_info);
  1485. if($neterr) {
  1486. QueueClient::async_push("QueryRefund", ['order_id' => $order_id], 300);
  1487. return callback(false, "need_refund check neterror");
  1488. }
  1489. if($need_refund)
  1490. {
  1491. $desc = $refill_info['order_sn'];
  1492. $params = ['title' => "统付返销",
  1493. 'order_id' => $order_id,
  1494. 'order_sn' => $refill_info['order_sn'],
  1495. 'mchid' => $refill_info['mchid'],
  1496. 'store_id' => $order_info['store_id'],
  1497. 'store_name' => $order_info['store_name'],
  1498. 'except_desc' => $desc,
  1499. 'except_type' => refill_exception_type::ERefundOrder,
  1500. 'add_time' => time()];
  1501. $mod_except->add_except($params);
  1502. return callback(true, "");
  1503. }
  1504. else {
  1505. return callback(false, "$chname has not need_refund.");
  1506. }
  1507. }
  1508. public function onHnydCbSuccess($params)
  1509. {
  1510. $getProvider = function ($name, $type = 'RefillPhone')
  1511. {
  1512. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  1513. if (!file_exists($file)) {
  1514. Log::record("provider api file=$file not exist.", Log::DEBUG);
  1515. return false;
  1516. } else {
  1517. require_once($file);
  1518. Log::record("file={$file} load success.", Log::DEBUG);
  1519. }
  1520. $class_name = "refill\\{$name}\\{$type}";
  1521. if (class_exists($class_name, false)) {
  1522. $caller = new $class_name([]);
  1523. return $caller;
  1524. }
  1525. else {
  1526. $error = "Base Error: class {$class_name} isn't exists!";
  1527. Log::record($error, Log::ERR);
  1528. return false;
  1529. }
  1530. };
  1531. $order_id = intval($params['order_id'] ?? 0);
  1532. if($order_id <= 0) {
  1533. return callback(true, "Order id is nothing.");
  1534. }
  1535. $mod_refill = Model('refill_order');
  1536. $mod_order = Model('vr_order');
  1537. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  1538. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
  1539. if(empty($order_info) || empty($refill_info)) {
  1540. return callback(false, "no order");
  1541. }
  1542. $chname = $refill_info['channel_name'];
  1543. $provider = $getProvider($chname);
  1544. if (empty($provider)) {
  1545. return callback(false, "cannot create $chname provider.");
  1546. }
  1547. [$succ, $msg, $offical_sn] = $provider->query($refill_info);
  1548. Log::record("order_sn={$refill_info['order_sn']} offical_sn=$offical_sn", Log::DEBUG);
  1549. return callback($succ, "$chname provider query $msg.");
  1550. }
  1551. }