123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788 |
- <?php
- /**
- * 队列
- *
- * 方法名需要和 QueueClient::push中第一个参数一致,如:
- * QueueClient::push('editGroupbuySaleCount',$groupbuy_info);
- * public function editGroupbuySaleCount($groupbuy_info){...}
- *
- */
- use refill\chprice_helper;
- defined('InShopNC') or exit('Access Invalid!');
- require_once(BASE_HELPER_PATH . '/push_sender.php');
- require_once(BASE_HELPER_PATH . '/sms_helper.php');
- require_once(BASE_HELPER_PATH . '/kdn_helper.php');
- require_once(BASE_HELPER_PATH . '/statistics_helper.php');
- require_once(BASE_HELPER_PATH . '/member_helper.php');
- require_once(BASE_HELPER_PATH . '/account_helper.php');
- require_once(BASE_HELPER_PATH . '/fcode/generator.php');
- require_once(BASE_HELPER_PATH . '/memsg/message_sender.php');
- require_once(BASE_HELPER_PATH . '/login_helper.php');
- require_once(BASE_HELPER_PATH . '/fcode/mfcode.php');
- require_once(BASE_HELPER_PATH . '/fcode/operator.php');
- require_once(BASE_HELPER_PATH . '/user_session/fcode.php');
- require_once(BASE_HELPER_PATH . '/stat_helper.php');
- require_once(BASE_HELPER_PATH . '/message/publisher.php');
- require_once(BASE_HELPER_PATH . '/search/tcp_client.php');
- require_once(BASE_HELPER_PATH . '/ugc_helper.php');
- require_once(BASE_HELPER_PATH . '/room_helper.php');
- require_once(BASE_HELPER_PATH . '/mcard/mcard.php');
- require_once(BASE_HELPER_PATH . '/util_helper.php');
- require_once(BASE_HELPER_PATH . '/third_author/signaturer.php');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/refill/chprice_helper.php');
- class queueLogic
- {
- /**
- * 添加会员积分
- * @param unknown $member_info
- */
- public function addPoint($member_info)
- {
- $points_model = Model('points');
- $points_model->savePointsLog('login', array('pl_memberid' => $member_info['member_id'], 'pl_membername' => $member_info['member_name']), true);
- return callback(true);
- }
- /**
- * 添加会员经验值
- * @param unknown $member_info
- */
- public function addExppoint($member_info)
- {
- $exppoints_model = Model('exppoints');
- $exppoints_model->saveExppointsLog('login', array('exp_memberid' => $member_info['member_id'], 'exp_membername' => $member_info['member_name']), true);
- return callback(true);
- }
- /**
- * 更新抢购信息
- * @param unknown $groupbuy_info
- * @throws Exception
- */
- public function editGroupbuySaleCount($groupbuy_info)
- {
- $model_groupbuy = Model('groupbuy');
- $data = array();
- $data['buyer_count'] = array('exp', 'buyer_count+1');
- $data['buy_quantity'] = array('exp', 'buy_quantity+' . $groupbuy_info['quantity']);
- $update = $model_groupbuy->editGroupbuy($data, array('groupbuy_id' => $groupbuy_info['groupbuy_id']));
- if (!$update) {
- return callback(false, '更新抢购信息失败groupbuy_id:' . $groupbuy_info['groupbuy_id']);
- } else {
- return callback(true);
- }
- }
- public function makeMemberMiniQrCode($params)
- {
- $member_id = intval($params['member_id']);
- $resp = thrid_author\signaturer::instance()->minicode("/pages/index/index?relay_id={$member_id}&channel=0", 430);
- if (!empty($resp)) {
- $passwd = util::passwd;
- $name = md5("{$member_id}.{$passwd}") . ".png";
- $save_path = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
- $length = file_put_contents($save_path, $resp);
- if (!$length) {
- Log::record("Cannot write file: {$save_path}", Log::ERR);
- } else {
- $ret = $this->create_shareimage($member_id);
- }
- } else {
- Log::record("request mini code error when member_id = {$member_id}", Log::ERR);
- }
- if (empty($ret)) {
- return callback(false, '生成用户mini code 失败');
- } else {
- return callback(true);
- }
- }
- private function create_shareimage($uid)
- {
- $back_img = BASE_RESOURCE_PATH . '/mobile/member/images/share.jpg';
- $passwd = util::passwd;
- $name = md5("{$uid}.{$passwd}") . ".png";
- $mini_path = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
- $name = "share-{$name}";
- $dest_img = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
- $back = $this->create_image($back_img);
- $mini = $this->create_image($mini_path);
- if ($back == false || $mini == false) {
- Log::record("back or mini image load error", Log::ERR);
- return false;
- }
- $dest = imagecreatetruecolor(imagesx($back), imagesy($back));
- if ($dest == false) return false;
- imagecopy($dest, $back, 0, 0, 0, 0, imagesx($back), imagesy($back));
- imagecopyresized($dest, $mini, 30, 750, 0, 0, 168, 168, imagesx($mini), imagesy($mini));
- imagepng($dest, $dest_img);
- return true;
- }
- private function create_image($file)
- {
- $imagetype = exif_imagetype($file);
- if ($imagetype === false) {
- return false;
- }
- switch ($imagetype) {
- case IMAGETYPE_GIF:
- $image = @imagecreatefromgif($file);
- break;
- case IMAGETYPE_JPEG:
- case IMAGETYPE_JPEG2000:
- $image = @imagecreatefromjpeg($file);
- break;
- case IMAGETYPE_PNG:
- $image = @imagecreatefrompng($file);
- break;
- case IMAGETYPE_BMP:
- $image = @imagecreatefrombmp($file);
- break;
- default:
- return false;
- }
- return $image;
- }
- //邀请好友成功后向,邀请者发送微信push消息。
- public function sendInviterSubMsg($params)
- {
- $inviter_id = $params['inviter_id'];
- $invitee_id = $params['invitee_id'];
- $mod_member = Model('member');
- $items = $mod_member->field('member_id,member_wxopenid,member_nickname,member_time')
- ->where(['member_id' => ['in', [$inviter_id, $invitee_id]]])
- ->select();
- foreach ($items as $item) {
- if ($item['member_id'] == $inviter_id) {
- $inviter = $item;
- } else {
- $invitee = $item;
- }
- }
- if (empty($inviter) || empty($invitee) || empty($inviter['member_wxopenid'])) {
- return callback(false, '向邀请者发送微信push消息错误');
- }
- $tmpid = 'zBNktaey9EM2DcBzUNsjnAan2NvYpj_nKZDY__f9pGA'; //这个是
- $openid = $inviter['member_wxopenid'];
- $time = strftime('%Y年%m月%d日', $invitee['member_time']);
- $data = ['thing4' => ['value' => $invitee['member_nickname']], 'time3' => ['value' => "{$time}"]];
- $ret = thrid_author\signaturer::instance()->send_submsg($openid, $tmpid, 'pages/index/index', $data);
- if ($ret) {
- return callback(true, "向邀请者{$inviter_id}发送微信push消息成功");
- } else {
- return callback(false, "向邀请者{$inviter_id}发送微信push消息错误");
- }
- }
- /**
- * 更新使用的代金券状态
- * @param $input_voucher_list
- * @throws Exception
- */
- public function editVoucherState($voucher_list)
- {
- $model_voucher = Model('voucher');
- $send = new memsg\message_sender();
- foreach ($voucher_list as $store_id => $voucher_info) {
- $update = $model_voucher->editVoucher(['voucher_state' => 2], ['voucher_id' => $voucher_info['voucher_id']], $voucher_info['voucher_owner_id']);
- if ($update) {
- // 发送用户店铺消息
- $send->set('member_id', $voucher_info['voucher_owner_id']);
- $send->set('code', 'voucher_use');
- $param = array();
- $param['voucher_code'] = $voucher_info['voucher_code'];
- $param['voucher_url'] = urlShop('member_voucher', 'index');
- $send->send($param);
- } else {
- return callback(false, '更新代金券状态失败vcode:' . $voucher_info['voucher_code']);
- }
- }
- return callback(true);
- }
- /**
- * 下单变更库存销量
- * @param unknown $goods_buy_quantity
- */
- public function createOrderUpdateStorage($goods_buy_quantity)
- {
- $model_goods = Model('goods');
- foreach ($goods_buy_quantity as $goods_id => $quantity) {
- $data = array();
- $data['goods_storage'] = array('exp', 'goods_storage-' . $quantity);
- $data['goods_salenum'] = array('exp', 'goods_salenum+' . $quantity);
- $result = $model_goods->editGoodsById($data, $goods_id);
- }
- if (!$result) {
- return callback(false, '变更商品库存与销量失败');
- } else {
- return callback(true);
- }
- }
- /**
- * 取消订单变更库存销量
- * @param unknown $goods_buy_quantity
- */
- public function cancelOrderUpdateStorage($goods_buy_quantity)
- {
- $model_goods = Model('goods');
- foreach ($goods_buy_quantity as $goods_id => $quantity) {
- $data = array();
- $data['goods_storage'] = array('exp', 'goods_storage+' . $quantity);
- $data['goods_salenum'] = array('exp', 'goods_salenum-' . $quantity);
- $result = $model_goods->editGoodsById($data, $goods_id);
- }
- if (!$result) {
- return callback(false, '变更商品库存与销量失败');
- } else {
- return callback(true);
- }
- }
- /**
- * 更新F码为使用状态
- * @param int $fc_id
- */
- public function updateGoodsFCode($fc_ids)
- {
- $update = Model('goods_fcode')->editGoodsFCode(array('fc_state' => 1, 'consume_time' => time()), array('fc_id' => array('in', $fc_ids)));
- if (!$update) {
- return callback(false, '更新F码使用状态失败fc_ids:' . implode(',', $fc_ids));
- } else {
- return callback(true);
- }
- }
- /**
- * 删除购物车
- * @param unknown $cart
- */
- public function delCart($cart)
- {
- if (!is_array($cart['cart_ids']) || empty($cart['buyer_id'])) return callback(true);
- $del = Model('cart')->delCart('db', array('buyer_id' => $cart['buyer_id'], 'cart_id' => array('in', $cart['cart_ids'])));
- if (!$del) {
- return callback(false, '删除购物车数据失败');
- } else {
- return callback(true);
- }
- }
- /**
- * 根据商品id更新促销价格
- *
- * @param int /array $goods_commonid
- * @return boolean
- */
- public function updateGoodsPromotionPriceByGoodsId($goods_id)
- {
- $update = Model('goods')->editGoodsPromotionPrice(array('goods_id' => array('in', $goods_id)));
- if (!$update) {
- return callback(false, '根据商品ID更新促销价格失败');
- } else {
- return callback(true);
- }
- }
- /**
- * 根据商品公共id更新促销价格
- *
- * @param int /array $goods_commonid
- * @return boolean
- */
- public function updateGoodsPromotionPriceByGoodsCommonId($goods_commonid)
- {
- $update = Model('goods')->editGoodsPromotionPrice(array('goods_commonid' => array('in', $goods_commonid)));
- if (!$update) {
- return callback(false, '根据商品公共id更新促销价格失败');
- } else {
- return callback(true);
- }
- }
- /**
- * 发送店铺消息
- */
- public function sendStoreMsg($param)
- {
- $send = new sendStoreMsg();
- $send->set('code', $param['code']);
- $send->set('store_id', $param['store_id']);
- $send->send($param['param']);
- return callback(true);
- }
- /**
- * 发送会员消息
- */
- public function sendMemberMsg($param)
- {
- $send = new memsg\message_sender();
- $send->set('code', $param['code']);
- $send->set('member_id', $param['member_id']);
- $send->set('sms_param', $param['sms_param']);
- if (!empty($param['number']['mobile'])) $send->set('mobile', $param['number']['mobile']);
- if (!empty($param['number']['email'])) $send->set('email', $param['number']['email']);
- $send->send($param['param']);
- return callback(true);
- }
- /**
- * 生成商品F码
- */
- public function createGoodsFCode($param)
- {
- Log::record("createGoodsFCode {$param['goods_commonid']},{$param['fc_count']},{$param['fc_prefix']},{$param['fc_validate']}", Log::DEBUG);
- $gen = new fcode\generator($param['goods_commonid'], $param['fc_count'], $param['fc_prefix'], $param['fc_validate']);
- $url = $gen->make();
- Log::record("createGoodsFCode url={$url}", Log::DEBUG);
- return callback(true);
- }
- /**
- * 生成商品二维码
- */
- public function createGoodsQRCode($param)
- {
- if (empty($param['goodsid_array'])) {
- return callback(true);
- }
- // 生成商品二维码
- require_once(BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'index.php');
- $PhpQRCode = new PhpQRCode();
- $PhpQRCode->set('pngTempDir', BASE_UPLOAD_PATH . DS . ATTACH_STORE . DS . $param['store_id'] . DS);
- foreach ($param['goodsid_array'] as $goods_id) {
- // 生成商品二维码
- $PhpQRCode->set('date', urlShop('goods', 'index', array('goods_id' => $goods_id)));
- $PhpQRCode->set('pngTempName', $goods_id . '.png');
- $PhpQRCode->init();
- }
- return callback(true);
- }
- /**
- * 清理特殊商品促销信息
- */
- public function clearSpecialGoodsPromotion($param)
- {
- // 抢购
- Model('groupbuy')->delGroupbuy(array('goods_commonid' => $param['goods_commonid']));
- // 显示折扣
- Model('p_xianshi_goods')->delXianshiGoods(array('goods_id' => array('in', $param['goodsid_array'])));
- // 优惠套装
- Model('p_bundling')->delBundlingGoods(array('goods_id' => array('in', $param['goodsid_array'])));
- // 更新促销价格
- Model('goods')->editGoods(array('goods_promotion_price' => array('exp', 'goods_price'), 'goods_promotion_type' => 0), array('goods_commonid' => $param['goods_commonid']));
- return callback(true);
- }
- /**
- * 删除(买/卖家)订单全部数量缓存
- * @param array $data 订单信息
- * @return boolean
- */
- public function delOrderCountCache($order_info)
- {
- if (empty($order_info)) return callback(true);
- $model_order = Model('order');
- if ($order_info['order_id']) {
- $order_info = $model_order->getOrderInfo(array('order_id' => $order_info['order_id']), array(), 'buyer_id,store_id');
- }
- $model_order->delOrderCountCache('buyer', $order_info['buyer_id']);
- $model_order->delOrderCountCache('store', $order_info['store_id']);
- return callback(true);
- }
- /**
- * 发送兑换码
- * @param unknown $param
- * @return boolean
- */
- public function sendVrCode($param)
- {
- return callback(true);
- if (empty($param) && !is_array($param)) return callback(true);
- $condition = array();
- $condition['order_id'] = $param['order_id'];
- $condition['buyer_id'] = $param['buyer_id'];
- $condition['vr_state'] = 0;
- $condition['refund_lock'] = 0;
- $code_list = Model('vr_order')->getOrderCodeList($condition, 'vr_code,vr_indate');
- if (empty($code_list)) return callback(true);
- $content = '';
- foreach ($code_list as $v) {
- $content .= $v['vr_code'] . ',';
- }
- $tpl_info = Model('mail_templates')->getTplInfo(array('code' => 'send_vr_code'));
- $data = array();
- $data['site_name'] = C('site_name');
- $data['vr_code'] = rtrim($content, ',');
- $message = ncReplaceText($tpl_info['content'], $data);
- $sms = new Sms();
- $result = $sms->send($param["buyer_phone"], $message);
- if (!$result) {
- return callback(false, '兑换码发送失败order_id:' . $param['order_id']);
- } else {
- return callback(true);
- }
- }
- /**
- * 添加订单自提表内容
- */
- public function saveDeliveryOrder($param)
- {
- if (!is_array($param['order_sn_list'])) return callback(true);
- $data = array();
- $model_delivery_order = Model('delivery_order');
- foreach ($param['order_sn_list'] as $order_id => $v) {
- $data['order_id'] = $order_id;
- $data['order_sn'] = $v['order_sn'];
- $data['addtime'] = $v['add_time'];
- $data['dlyp_id'] = $param['dlyp_id'];
- $data['reciver_name'] = $param['reciver_name'];
- $data['reciver_telphone'] = $param['tel_phone'];
- $data['reciver_mobphone'] = $param['mob_phone'];
- $insert = $model_delivery_order->addDeliveryOrder($data);
- if (!$insert) {
- return callback(false, '保存自提站订单信息失败order_sn:' . $v['order_sn']);
- }
- }
- return callback(true);
- }
- /**
- * 发送提货码短信消息
- */
- public function sendPickupcode($param)
- {
- $dorder_info = Model('delivery_order')->getDeliveryOrderInfo(array('order_id' => $param['order_id']), 'reciver_mobphone');
- $tpl_info = Model('mail_templates')->getTplInfo(array('code' => 'send_pickup_code'));
- $data = array();
- $data['site_name'] = C('site_name');
- $data['pickup_code'] = $param['pickup_code'];
- $message = ncReplaceText($tpl_info['content'], $data);
- $sms = new Sms();
- $result = $sms->send($dorder_info['reciver_mobphone'], $message);
- if (!$result) {
- return callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']);
- } else {
- return callback(true);
- }
- }
- /**
- * 刷新搜索索引
- */
- public function flushIndexer()
- {
- require_once(BASE_DATA_PATH . '/api/xs/lib/XS.php');
- $obj_doc = new XSDocument();
- $obj_xs = new XS(C('fullindexer.appname'));
- $obj_xs->index->flushIndex();
- }
- /**
- * 推送服务
- * @param $param array
- * 共有三个key : member_id , text, go_type
- * @return bool
- */
- public function upushSendMsg($param)
- {
- if (empty($param) || empty($param['alias']) || empty($param['text'])) {
- Log::record("push info: 数据有误! param:" . json_encode($param) . "\t session:" . json_encode($_SESSION));
- return callback(false);
- }
- $push = new push_sender();
- $push->send($param);
- return callback(true);
- }
- public function sendPushMessage($param)
- {
- $push = new push_sender();
- $push->send_message($param);
- return callback(true);
- }
- /**
- * 发短信
- * @param $param
- *
- * @return bool
- */
- public function sendSMS($param)
- {
- if (empty($param) || empty($param['mobile']) || empty($param['type'])) {
- Log::record("sms info: 数据有误! param:" . json_encode($param), Log::ERR);
- return callback(false);
- }
- try {
- $sms = new Sms();
- $status = $sms->send($param['mobile'], $param);
- Log::record("sms info: status:" . json_encode($status) . "\t param:" . json_encode($param), Log::DEBUG);
- } catch (Exception $e) {
- Log::record("sms info: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param), Log::ERR);
- }
- return callback(true);
- }
- public function sendOperSMS($params)
- {
- if (empty($params) || empty($params['mobile']) || empty($params['type'])) {
- Log::record("sms info: 数据有误! param:" . json_encode($params), Log::ERR);
- return callback(false);
- }
- try {
- $datas = [];
- foreach ($params as $key => $val) {
- if ($key == 'mobile') {
- $mobile = $val;
- } elseif ($key == 'type') {
- $type = $val;
- } else {
- $datas[$key] = $val;
- }
- }
- $sms = new Sms();
- $status = $sms->send_oper($mobile, $type, $datas);
- Log::record("sms info: status:" . json_encode($status) . "\t param:" . json_encode($params), Log::DEBUG);
- } catch (Exception $e) {
- Log::record("sms info: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($params), Log::ERR);
- }
- return callback(true);
- }
- public function sendBonusAndSMS($params)
- {
- $input_type = $params['member']['input_type'];
- if ($input_type == 'mobiles') {
- $members = member_helper::from_mobiles($params['member']['data'], $error);
- } elseif ($input_type == 'sql') {
- $members = member_helper::from_sql($params['member']['data']);
- } else {
- return callback(false, 'sendBonusAndSMS 错误的人员输入类型.');
- }
- $fSendSms = $params['sms']['open'];
- $smscode = $params['sms']['template_id'];
- $rate = $params['bonus']['rate'];
- $bless = $params['bonus']['bless'];
- $amount = $params['bonus']['amount'];
- $can_share = intval($params['bonus']['can_share']);
- $chunks = array_chunk($members, 1000);
- foreach ($chunks as $chunk) {
- $chunk = member_helper::exmembers($chunk, $params['member']['ex_lrlz'], $params['member']['ex_brand']);
- $ids = [];
- foreach ($chunk as $member) {
- $ids[] = $member['member_id'];
- }
- $ret = account_helper::add_bonus($rate, $amount, $ids, $bless, $can_share);
- if ($ret == false) continue;
- if ($fSendSms) {
- $iconut = 0;
- $sms = new Sms();
- foreach ($chunk as $member) {
- $mobile = $member['member_mobile'];
- try {
- $status = $sms->send_oper($mobile, $smscode);
- Log::record("sms info: status:" . json_encode($status), Log::DEBUG);
- } catch (Exception $e) {
- Log::record("sms info: fall error\treturn:" . $e->getMessage(), Log::ERR);
- }
- ++$iconut;
- if ($iconut == 10) {
- sleep(2);
- $iconut = 0;
- }
- }
- }
- }
- return callback(true);
- }
- public function sendPushOrSMS($params)
- {
- $input_type = $params['member']['input_type'];
- if ($input_type == 'mobiles') {
- $members = member_helper::from_mobiles($params['member']['data'], $error);
- } elseif ($input_type == 'sql') {
- $members = member_helper::from_sql($params['member']['data']);
- } else {
- return callback(false, 'sendBonusAndSMS 错误的人员输入类型.');
- }
- $send_type = $params['send']['type'];
- $content = $params['send']['data'];
- $chunks = array_chunk($members, 1000);
- foreach ($chunks as $chunk) {
- $chunk = member_helper::exmembers($chunk, $params['member']['ex_lrlz'], $params['member']['ex_brand']);
- if ($send_type == 'sms') {
- $iconut = 0;
- $sms = new Sms();
- foreach ($chunk as $member) {
- try {
- $mobile = $member['member_mobile'];
- $status = $sms->send_oper($mobile, $content);
- Log::record("sms info: status:" . json_encode($status), Log::DEBUG);
- } catch (Exception $e) {
- Log::record("sms info: fall error\treturn:" . $e->getMessage(), Log::ERR);
- }
- ++$iconut;
- if ($iconut == 10) {
- sleep(2);
- $iconut = 0;
- }
- }
- } elseif ($send_type == 'push') {
- foreach ($chunk as $member) {
- push_helper::oper_push($member['member_id'], $content);
- }
- } else {
- }
- }
- return callback(true);
- }
- /**
- * 订阅快递鸟
- * @param $param
- *
- * @return bool
- */
- public function subscribeKDN($param)
- {
- if (empty($param) || empty($param['order_sn'])) {
- Log::record("kdn_helper: 数据有误! param:" . json_encode($param));
- return callback(false);
- }
- try {
- kdn_helper::subscribe($param['order_sn']);
- } catch (Exception $e) {
- Log::record("kdn_helper: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param));
- }
- return callback(true);
- }
- /**
- * 根据上传的通讯录生成好友关系
- */
- public function generateRelations($param)
- {
- if (empty($param["member_id"])) {
- return false;
- }
- try {
- Model("mobile_contacts")->genRelations($param["member_id"]);
- } catch (Exception $e) {
- Log::record("generateRelations: fall error\treturn:" . $e->getMessage());
- }
- return true;
- }
- public function savelog($param)
- {
- statistics_helper::instance()->add_logs($param);
- return callback(true);
- }
- public function click_goods($param)
- {
- $goods_id = intval($param['goods_id']);
- if ($goods_id > 0) {
- $mod_goods = Model('goods');
- $mod_goods->editGoodsById(array('goods_click' => array('exp', 'goods_click + 1')), $goods_id);
- return callback(true);
- } else {
- return callback(false, "click_goods 错误的goods_id");
- }
- }
- public function reset_fcode($param)
- {
- $pay_sn = $param['pay_sn'];
- if (empty($pay_sn)) {
- return callback(false);
- }
- $num = \fcode\operator::reset($pay_sn);
- if ($num > 0) {
- return callback(true);
- } else {
- return callback(false);
- }
- }
- public function onUseBonus($param)
- {
- stat_helper::onUseBonus($param);
- return callback(true);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function onAsyncRegister($param)
- {
- $user = $param['user'];
- $inviter = $param['inviter'];
- if ($user < 0) {
- return callback(false, "onRegisterFromBonus 错误的member_id");
- }
- account_helper::onAsyncRegister($user, $inviter);
- return callback(true);
- }
- public function onAsyncStatus($param)
- {
- Log::record(__METHOD__, Log::DEBUG);
- account_helper::onAsyncStatus($param['member_id']);
- return callback(true);
- }
- public function onAsyncTopup($param)
- {
- Log::record(__METHOD__, Log::DEBUG);
- account_helper::onAsyncTopup($param['member_id']);
- return callback(true);
- }
- public function onPredeposit($param)
- {
- Log::record('queue::onPredeposit', Log::DEBUG);
- account_helper::onPredeposit($param['change_type'], $param['buyer_id'], $param['order_sn']);
- return callback(true);
- }
- public function onBonusChange($param)
- {
- Log::record('queue::onPredeposit', Log::DEBUG);
- account_helper::onPredeposit($param['change_type'], $param['buyer_id'], $param['order_sn']);
- return callback(true);
- }
- public function onAsyncOrderPaied($param)
- {
- $pay_sn = $param['pay_sn'];
- account_helper::onAsyncOrderPaied($pay_sn);
- return callback(true);
- }
- public function onAsyncOrderSended($param)
- {
- $pay_sn = $param['pay_sn'];
- $logistics_no = $param['logistics_no'];
- $logistics_company = $param['logistics_company'];
- account_helper::onAsyncOrderSended($pay_sn, $logistics_no, $logistics_company);
- return callback(true);
- }
- public function onAsyncOrderComplete($param)
- {
- $pay_sn = $param['pay_sn'];
- if (!empty($pay_sn)) {
- account_helper::onAsyncOrderComplete($pay_sn);
- }
- return callback(true);
- }
- public function onAsyncOrderCancel($param)
- {
- $pay_sn = $param['pay_sn'];
- $order_sn = $param['order_sn'];
- if (!empty($pay_sn) && !empty($order_sn)) {
- account_helper::onAsyncOrderCancel($pay_sn, $order_sn);
- }
- return callback(true);
- }
- public function onAsyncOrderEvaluate($param)
- {
- $pay_sn = $param['pay_sn'];
- if (!empty($pay_sn)) {
- account_helper::onAsyncOrderEvaluate($pay_sn);
- }
- return callback(true);
- }
- public function onAsyncBroadcastOrder($param)
- {
- $pay_sn = $param['pay_sn'];
- $amount = $param['amount'];
- $days = $param['days'];
- if (!empty($pay_sn) && !empty($amount)) {
- account_helper::onAsyncBroadcastOrder($pay_sn, $amount, $days);
- }
- return callback(true);
- }
- public function onAsyncBroadcastNormal($param)
- {
- $filters = $param['filters'];
- $oper_param = $param['oper_param'];
- $send_params = $param['send_params'];
- if (!empty($oper_param) && !empty($filters) && !empty($send_params)) {
- account_helper::onAsyncBroadcastNormal($filters, $oper_param, $send_params);
- }
- return callback(true);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function onAsyncUgcPublish($param)
- {
- $spid = $param['special_id'];
- account_helper::onAsyncUgcPublish($spid);
- return callback(true);
- }
- public function onAsyncUgcDel($param)
- {
- $spid = $param['special_id'];
- account_helper::onAsyncUgcDel($spid);
- return callback(true);
- }
- public function onAsyncUgcSubmit($param)
- {
- $spid = $param['special_id'];
- $user = $param['user_id'];
- account_helper::onAsyncUgcSubmit($spid, $user);
- return callback(true);
- }
- public function onAsyncUgcSupport($param)
- {
- $spid = $param['special_id'];
- $user = $param['user_id'];
- $comment_id = $param['comment_id'];
- account_helper::onAsyncUgcSupport($spid, $comment_id, $user);
- return callback(true);
- }
- public static function onAsyncUgcAppreciate($param)
- {
- $spid = $param['special_id'];
- $user = $param['user_id'];
- $rate = $param['rate'];
- $amount = $param['amount'];
- account_helper::onAsyncUgcAppreciate($spid, $user, $rate, $amount);
- return callback(true);
- }
- public function onAsyncUgcComment($param)
- {
- $special_id = intval($param['special_id']);
- $comment_id = intval($param['comment_id']);
- $user_id = intval($param['user_id']);
- account_helper::onAsyncUgcComment($special_id, $comment_id, $user_id);
- return callback(true);
- }
- public function onClickSpecial($param)
- {
- $special_id = intval($param['special_id']);
- if ($special_id > 0) {
- Model()->table('mb_special')->where(['special_id' => $special_id])->update(['clicks' => ['exp', 'clicks + 1']]);
- }
- return callback(true);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function onAsyncBargain($param)
- {
- $type = $param['type'];
- $bargain_id = intval($param['bargain_id']);
- if (empty($type) || $bargain_id <= 0) {
- return callback(false);
- } else {
- account_helper::onAsyncBargain($type, $bargain_id);
- return callback(true);
- }
- }
- public function UpdateSotreLocation($param)
- {
- $store_id = intval($param['store_id']);
- if ($store_id <= 0) {
- return callback(false);
- } else {
- $ret = geo_helper::instance()->update_store($store_id);
- return callback($ret);
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function OnUpdateRoom($param)
- {
- $roomid = intval($param['room_id']);
- if ($roomid <= 0) {
- return callback(false);
- } else {
- Log::record("OnUpdateRoom Start", Log::DEBUG);
- $ret = room_helper::OnUpdateRoom($roomid);
- return callback($ret);
- }
- }
- public function OnGoodsConvert($params)
- {
- $appid = $params['appid'];
- $convert_sn = $params['convert_sn'];
- $return_url = $params['return_url'];
- $data['success'] = $params['success'] == true ? 1 : 0;
- $data['convert_sn'] = $params['convert_sn'];
- $data['appid'] = $params['appid'];
- if (empty($return_url) || empty($appid) || empty($convert_sn)) {
- return callback(false);
- } else {
- https_request($return_url, $data);
- return callback(true);
- }
- }
- //虚拟订单下单成功,回调事件.
- public function OnVrOrderSuccess($params)
- {
- $order_sn = $params['order_sn'];
- $model_order = Model('vr_order');
- $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
- $goods_id = $order['goods_id'];
- global $config;
- $handlers = $config['vgoods_handlers'];
- if (array_key_exists($goods_id, $handlers)) {
- $handler = $handlers[$goods_id];
- $method = $handler['order_method'];
- if (!empty($method)) {
- $ret = $this->$method($order);
- if (!$ret) {
- return callback(false);
- }
- }
- }
- return callback(true);
- }
- private function getTopcardAmound($goods_id)
- {
- global $config;
- $spec_card = $config['vgoods_spec_card'];
- if (array_key_exists($goods_id, $spec_card)) {
- return $spec_card[$goods_id];
- } else {
- return 0;
- }
- }
- public function OnPhoneCardCheck($params)
- {
- $extra_info = $params['extra_info'];
- $card_no = $extra_info['input']['card_no'];
- $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
- $goods_id = intval($params['goods_id']);
- $topcard = Model('topcard');
- if(empty($topcard->get_card($card_no)))
- {
- $topcard->add($card_no,$card_type,time());
- return callback(true);
- }
- else
- {
- $day_limit = 500;
- $month_limit = 1000;
- return $this->check_amount($goods_id,$card_no,$day_limit,$month_limit);
- }
- }
- private function check_amount($goods_id,$card_no,$day_limit,$month_limit)
- {
- global $config;
- $spec_card = $config['vgoods_spec_card'];
- if(!array_key_exists($goods_id,$spec_card)) {
- return callback(true);
- }
- else {
- $goods_spec = $spec_card[$goods_id];
- }
- [$start,$end] = $this->day_range(time());
- $day_total = $this->getOrderAmounts($card_no,$start,$end);
- if($day_total > $day_limit) {
- return callback(false,"本卡今日充值已经超过{$day_limit}元额度,请改日再充.");
- }
- elseif($day_total + $goods_spec > $day_limit)
- {
- $left = $day_limit - $day_total;
- if($left > 0) {
- return callback(false,"本卡今日还可以充值{$left}元,请重新选择充值面额.");
- } else {
- return callback(false,"本卡今日额度已经用完,请改日再充.");
- }
- }
- else {
- Log::record("满足充值条件",Log::DEBUG);
- }
- [$start,$end] = $this->month_range(time());
- $month_total = $this->getOrderAmounts($card_no,$start,$end);
- if($month_total > $month_limit) {
- return callback(false,"本卡本月充值已经超过{$day_limit}元额度,请下月再充.");
- }
- elseif ($month_total + $goods_spec > $month_limit)
- {
- $left = $month_limit - $month_total;
- if($left > 0) {
- return callback(false, "本卡本月还可以充值{$left}元,请重新选择充值面额.");
- } else {
- return callback(false,"本卡本月额度已经用完,请下月再充.");
- }
- }
- else {
- return callback(true);
- }
- }
- public function OnOilCardCheck($params)
- {
- $extra_info = $params['extra_info'];
- $card_no = $extra_info['input']['card_no'];
- $phone_no = $extra_info['input']['phone_no'];
- $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
- $goods_id = intval($params['goods_id']);
- $topcard = Model('topcard');
- $cards = $topcard->get_card($card_no);
- if(empty($cards))
- { //卡不存在
- //查询1000内是否有卡
- $items = $topcard->get_cards($card_no - 500,$card_no + 500);
- if(!empty($items)) {
- return callback(false,'此油卡充值,存在风险,请去运营商平台充值.');
- }
- else {
- $topcard->add($card_no,$card_type,time(),$phone_no);
- return callback(true);
- }
- }
- else
- {
- $day_limit = 1000;
- $month_limit = 2000;
- if(empty($cards[0]['bind_phone'])) {
- $topcard->table('topcard')->field('*')->where(['card_no' => $card_no])->update(['bind_phone' => $phone_no]);
- }
- return $this->check_amount($goods_id,$card_no,$day_limit,$month_limit);
- }
- }
- private function getOrderAmounts($card_no,$start,$end)
- {
- global $config;
- $spec_card = $config['vgoods_spec_card'];
- $vr_order = Model('vr_order');
- $cond = ['card_no' => $card_no,'add_time' =>['between',[$start,$end]]];
- $items = $vr_order->getOrderList($cond);
- $amount = 0;
- foreach ($items as $order) {
- $goods_id = intval($order['goods_id']);
- $order_state = intval($order['order_state']);
- if(array_key_exists($goods_id,$spec_card) && $order_state != ORDER_STATE_CANCEL) {
- $amount += $spec_card[$goods_id];
- }
- }
- return $amount;
- }
- private function day_range($time)
- {
- $x = strtotime(date('Y-m-d',$time));
- $y = strtotime('+1 day',$x);
- return [$x,$y];
- }
- private function month_range($time)
- {
- $x = strtotime(date('Y-m-d',$time));
- $x = strtotime(date('Y-m-01',$x));
- $y = strtotime('+1 month',$x);
- return [$x,$y];
- }
- public function OnChanageCard($params)
- {
- $order_sn = $params['order_sn'];
- $model_order = Model('vr_order');
- $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
- if (empty($order)) {
- return callback(false, '没找到订单');
- }
- if (($ret = $this->OnFreezeCard($order))['state'] == false) {
- return $ret;
- }
- $ret = $this->OnVrOrderSuccess(['order_sn' => $order_sn]);
- return $ret;
- }
- public function OnCancelorderFreezeCard($params)
- {
- $order_sn = $params['order_sn'];
- $model_order = Model('vr_order');
- $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
- if (empty($order)) {
- return callback(false, '没找到订单');
- }
- if (($ret = $this->OnFreezeCard($order))['state'] == false) {
- return $ret;
- } elseif (($ret = $this->OnVrOrderCancel($params))['state'] == false) {
- return $ret;
- } else {
- return callback();
- }
- }
- private function OnFreezeCard($order)
- {
- $order_id = $order['order_id'];
- if (mtopcard\cards_helper::freeze($order_id)) {
- return callback();
- } else {
- return callback(false, '解冻失败 ');
- }
- }
- private function OnReserveOilCard($order)
- {
- Log::record(__FUNCTION__, Log::DEBUG);
- $amount = $this->getTopcardAmound($order['goods_id']);
- $member_id = $order['buyer_id'];
- $order_id = $order['order_id'];
- $store_id = $order['store_id'];
- $extra_info = json_decode($order['extra_info'], true);
- $card_no = $extra_info['input']['card_no'];
- $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
- [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper, $amount, $member_id, $card_no, $card_type, $order_id,[$store_id]);
- $vr_order = Model();
- $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);
- return $ret;
- }
- private function OnReservePhoneCard($order)
- {
- Log::record(__FUNCTION__, Log::DEBUG);
- $amount = $this->getTopcardAmound($order['goods_id']);
- $member_id = $order['buyer_id'];
- $order_id = $order['order_id'];
- $store_id = $order['store_id'];
- $extra_info = json_decode($order['extra_info'], true);
- $card_no = $extra_info['input']['card_no'];
- $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
- [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\PhoneCardPaper, $amount, $member_id, $card_no, $card_type, $order_id, [$store_id]);
- $vr_order = Model();
- $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);
- return $ret;
- }
- //虚拟订单取消回调事件.
- public function OnVrOrderCancel($params)
- {
- $order_sn = $params['order_sn'];
- $model_order = Model('vr_order');
- $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
- $goods_id = $order['goods_id'];
- global $config;
- $handlers = $config['vgoods_handlers'];
- if (array_key_exists($goods_id, $handlers)) {
- $handler = $handlers[$goods_id];
- $method = $handler['cancel_method'];
- if (!empty($method)) {
- $this->$method($order);
- }
- }
- return callback(true);
- }
- private function OnCardKeyCancel($order)
- {
- $order_id = $order['order_id'];
- $mod_card = Model('card_key');
- $card = $mod_card->getCardByOrderId($order_id);
- if (empty($card)) {
- return callback(false, '订单取消,没找到对应的卡密.', ['order_sn' => $order['order_sn']]);
- } else {
- CalcPrice::onCancelVrOrder($order);
- mtopcard\cards_helper::reuse($order_id);
- return callback(false, '订单取消,成功解除卡密.', ['order_sn' => $order['order_sn']]);
- }
- }
- //虚拟订单支付成功回调事件.
- public function OnVrOrderPaidSuccess($params)
- {
- $order_sn = $params['order_sn'];
- $model_order = Model('vr_order');
- $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
- $goods_id = $order['goods_id'];
- global $config;
- $handlers = $config['vgoods_handlers'];
- if (array_key_exists($goods_id, $handlers)) {
- $handler = $handlers[$goods_id];
- $method = $handler['paid_method'];
- if (!empty($method)) {
- $this->$method($order);
- }
- }
- return callback(true);
- }
- //支付成功完成会员卡操作.
- public function OnMCardPaidSuccess($order)
- {
- $order_sn = $order['order_sn'];
- if ($order['order_state'] != ORDER_STATE_PAY) {
- Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 状态错误", Log::ERR);
- return callback(false);
- }
- $extra_info = json_decode($order['extra_info'], true);
- $card_type = $extra_info['additional']['card_type'];
- if (empty($card_type)) {
- Log::record("OnMCardOrderSuccess order_sn:{$order_sn} 失败", Log::ERR);
- return callback(false);
- } else {
- $params = mcard\getConfig($card_type);
- if (empty($params)) {
- Log::record("OnMCardOrderSuccess order_sn:{$order_sn} card_type = {$card_type} 失败", Log::ERR);
- return callback(false);
- }
- $member_id = intval($order['buyer_id']);
- $usercards = new mcard\user_mcards($member_id);
- $ret = $usercards->addCard($params);
- if ($ret) {
- $vrLogic = Logic('vr_order');
- $vrLogic->changeOrderStateSuccess($order['order_id']);
- return callback(false);
- } else {
- Log::record("OnMCardOrderSuccess order_sn:{$order_sn} addCard 失败", Log::ERR);
- return callback(false);
- }
- }
- }
- //虚拟商品完成回调事件....
- public function OnVrOrderComplete($params)
- {
- $order_sn = $params['order_sn'];
- $model_order = Model('vr_order');
- $order = $model_order->getOrderInfo(['order_sn' => $order_sn], '*', true);
- $goods_id = $order['goods_id'];
- global $config;
- $handlers = $config['vgoods_handlers'];
- if (array_key_exists($goods_id, $handlers)) {
- $handler = $handlers[$goods_id];
- $method = $handler['complete_method'];
- if (!empty($method)) {
- $ret = $this->$method($order);
- if (!$ret) {
- return callback(false);
- }
- }
- }
- return callback(true);
- }
- private function OnCardKeyComplete($order)
- {
- $order_id = $order['order_id'];
- $mod_card = Model('card_key');
- $card = $mod_card->getCardByOrderId($order_id);
- if (empty($card)) {
- return callback(false, '充值失败', ['order_sn' => $order['order_sn']]);
- } else {
- mtopcard\cards_helper::assign($order_id, 'OnOilComplete');
- return callback(true, '充值成功', ['order_sn' => $order['order_sn']]);
- }
- }
- public function NotifyMerchantComplete($params)
- {
- $order_id = intval($params['order_id']);
- $manual = $params['manual'] ?? false;
- if($order_id <= 0) {
- return callback(false, 'NotifyMerchantComplete 参数order_id错误');
- }
- else {
- refill\util::push_notify_merchant($order_id,$manual);
- return callback(true, '成功放入通知队列', ['order_id' => $order_id]);
- }
- }
- public function NotifyMerchantSuccess($params)
- {
- $mchid = intval($params['mchid']);
- $mch_order = $params['mch_order'] ?? false;
- if($mchid <= 0 || empty($mch_order)) {
- return callback(false, "NotifyMerchantSuccess 参数 $mchid : $mch_order 错误");
- }
- else {
- refill\util::push_notify_merchant_success($mchid, $mch_order);
- return callback(true, '成功放入通知队列', ['mchid' => $mchid, 'mch_order' => $mch_order]);
- }
- }
- public function QueryRefillState($params)
- {
- $order_id = intval($params['order_id']);
- if($order_id <= 0) {
- return callback(false, 'QueryRefillState 参数order_id错误');
- }
- else {
- refill\util::push_query($order_id);
- return callback(true, '成功放入通知队列', ['order_id' => $order_id]);
- }
- }
- public function QueryAutoRefillState($params)
- {
- $order_id = intval($params['order_id']);
- $query_times = intval($params['query_times']);
- if($order_id <= 0) {
- return callback(false, 'QueryAutoRefillState 参数order_id错误');
- }
- else {
- refill\util::push_auto_query($order_id,$query_times);
- return callback(true, '成功放入通知队列', ['order_id' => $order_id, 'query_times' => $query_times]);
- }
- }
- public function QueryOrderNeterr($params)
- {
- $order_id = intval($params['order_id']);
- if($order_id <= 0) {
- return callback(false, 'QueryOrderNeterr 参数order_id错误');
- }
- else {
- refill\util::push_query_net($order_id);
- return callback(true, '成功放入通知队列', ['order_id' => $order_id]);
- }
- }
- public function QueryMchOrderTimeout($params)
- {
- $mchid = intval($params['mchid']);
- $mch_order = $params['mch_order'];
- if($mchid <= 0 or empty($mch_order)) {
- return callback(false, "QueryMchOrderTimeout 参数错误 mchid=$mchid mch_order=$mch_order");
- }
- else {
- refill\util::push_query_timeout($mchid, $mch_order);
- return callback(true, '成功放入通知队列', ['mchid' => $mchid, 'mch_order' => $mch_order]);
- }
- }
- public function AysncAddDispatcher($params)
- {
- $method = $params['method'];
- $input = $params['params'];
- if(empty($method || empty($method))) {
- return callback(false, 'AysncAddDispatcher 参数为空');
- } else {
- $ret = queue\DispatcherClient::instance()->push($method,$input);
- return callback($ret, "放入通知队列 ret = {$ret}",$params);
- }
- }
- public function AysncChangePrice($params)
- {
- $price_id = intval($params['price_id']);
- if($price_id > 0) {
- $chprice_helper = new chprice_helper();
- $chprice_helper->effect($price_id);
- $publisher = new message\publisher();
- $publisher->modify_refill_channel();
- return callback(true, "成功更新价格",$params);
- } else {
- return callback(false, 'AysncChangePrice 参数为空');
- }
- }
- public function OnRiskSN($params)
- {
- $msg_adder = function ($order_id)
- {
- if($order_id <= 0) return false;
- $mod_order = Model('vr_order');
- $mod_refill = Model('refill_order');
- $mod_except = Model('refill_exception');
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
- $order_sn = $refill_info['order_sn'];
- if($mod_except->exist_order($order_sn)) {
- return false;
- }
- if(empty($refill_info) || empty($order_info)) {
- return false;
- }
- $sn = $refill_info['official_sn'];
- if(empty($sn)) {
- $desc = "渠道返回成功,但不含流水号。已经关闭通道,未给用户回调。";
- } else {
- $desc = "问题流水号:{$sn},有风险。已经关闭通道,未给用户回调。";
- }
- $params = ['title' => '风险号预警',
- 'order_id' => $refill_info['order_id'],
- 'order_sn' => $refill_info['order_sn'],
- 'mchid' => $refill_info['mchid'],
- 'store_id' => $order_info['store_id'],
- 'store_name' => $order_info['store_name'],
- 'except_desc' => $desc,
- 'except_type' => refill_exception_type::EOfficialSN,
- 'add_time' => time()];
- $mod_except->add_except($params);
- return [$order_info,$refill_info];
- };
- $in_exclude = function ($store_id)
- {
- $store_id = intval($store_id);
- if($store_id <= 0) {
- return false;
- }
- global $config;
- $risk_official_sn = $config['risk_official_sn'] ?? [];
- $exclude_stores = $risk_official_sn['exclude_stores'] ?? [];
- return in_array($store_id,$exclude_stores);
- };
- $store_id = intval($params['store_id']);
- $channel_name = $params['channel_name'];
- $order_id = intval($params['order_id']);
- if($in_exclude($store_id)) {
- return callback(true, '该通道不需要过滤');
- }
- $ret = $msg_adder($order_id);
- if($ret === false) {
- return callback(false, 'OnRiskSN:没找到订单');
- }
- [$order_info, $refill_info] = $ret;
- $quality = intval($refill_info['quality']);
- if($store_id <= 0 || empty($channel_name)) {
- return callback(false, 'OnRiskSN 参数有空');
- }
- $mod_provider = Model('refill_provider');
- $item = $mod_provider->getProviderInfo(['store_id' => $store_id,'name' => $channel_name]);
- if (empty($item)) {
- return callback(false, 'OnRiskSN:没找到通道');
- }
- elseif($quality === 2) {
- return callback(true, 'OnRiskSN:快充无需禁用通道.');
- }
- else
- {
- $provider_id = intval($item['provider_id']);
- $state = intval($item['opened']);
- if ($state == 1) {
- $mod_provider->editProvider(['opened' => 2,'oper_time' => time()], ['provider_id' => $provider_id]);
- $publisher = new message\publisher();
- $publisher->modify_refill_channel();
- }
- }
- return callback(true, "OnRiskSN 成功禁用通道");
- }
- public function OnRefillSuccess($params)
- {
- if (!defined('COMPANY_NAME') || COMPANY_NAME !== 'ZY_COMPANY') {
- return callback(true, "official_sn 流水号要支持索引.");
- }
- $official_sn = $params['official_sn'];
- $order_sn = $params['order_sn'];
- if(empty($order_sn) || empty($official_sn)) {
- return callback(true, "OnRefillSuccess official_sn or order_sn is empty.");
- }
- $mod_refill = Model('refill_order');
- $items = $mod_refill->table('refill_order')->field('order_id')->where(['official_sn' => $official_sn,'inner_status' => 0])->select();
- if(count($items) > 1)
- {
- $mod_order = Model('vr_order');
- $mod_except = Model('refill_exception');
- foreach ($items as $item)
- {
- $order_id = $item['order_id'];
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
- $desc = "流水号:$official_sn";
- $params = ['title' => "流水号相同",
- 'order_id' => $order_id,
- 'order_sn' => $order_sn,
- 'mchid' => $refill_info['mchid'],
- 'store_id' => $order_info['store_id'],
- 'store_name' => $order_info['store_name'],
- 'except_desc' => $desc,
- 'except_type' => refill_exception_type::EqualOfficialSN,
- 'add_time' => time()];
- $mod_except->add_except($params);
- }
- return callback(true, "OnRefillSuccess official_sn multi order.");
- }
- else {
- return callback(true, "OnRefillSuccess official_sn OK.");
- }
- }
- //检查统付返销.
- public function QueryRefund($params)
- {
- $getProvider = function ($name, $type = 'RefillPhone')
- {
- $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
- if (!file_exists($file)) {
- Log::record("provider api file=$file not exist.", Log::DEBUG);
- return false;
- } else {
- require_once($file);
- Log::record("file={$file} load success.", Log::DEBUG);
- }
- $class_name = "refill\\{$name}\\{$type}";
- if (class_exists($class_name, false)) {
- $caller = new $class_name([]);
- return $caller;
- }
- else {
- $error = "Base Error: class {$class_name} isn't exists!";
- Log::record($error, Log::ERR);
- return false;
- }
- };
- $order_id = intval($params['order_id'] ?? 0);
- if($order_id <= 0) {
- return callback(true, "Order id is nothing.");
- }
- $mod_refill = Model('refill_order');
- $mod_order = Model('vr_order');
- $mod_except = Model('refill_exception');
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
- if(empty($order_info) || empty($refill_info)) {
- return callback(false, "no order");
- }
- if($order_info['order_state'] != ORDER_STATE_SUCCESS) {
- return callback(false, "order state is not success.");
- }
- $chname = $refill_info['channel_name'];
- $provider = $getProvider($chname);
- if (empty($provider)) {
- return callback(false, "cannot create $chname provider.");
- }
- if (!method_exists($provider, 'need_refund')) {
- return callback(false, "$chname has not need_refund.");
- }
- [$need_refund,$neterr] = $provider->need_refund($refill_info);
- if($neterr) {
- QueueClient::async_push("QueryRefund", ['order_id' => $order_id], 300);
- return callback(false, "need_refund check neterror");
- }
- if($need_refund)
- {
- $desc = $refill_info['order_sn'];
- $params = ['title' => "统付返销",
- 'order_id' => $order_id,
- 'order_sn' => $refill_info['order_sn'],
- 'mchid' => $refill_info['mchid'],
- 'store_id' => $order_info['store_id'],
- 'store_name' => $order_info['store_name'],
- 'except_desc' => $desc,
- 'except_type' => refill_exception_type::ERefundOrder,
- 'add_time' => time()];
- $mod_except->add_except($params);
- return callback(true, "");
- }
- else {
- return callback(false, "$chname has not need_refund.");
- }
- }
- public function onHnydCbSuccess($params)
- {
- $getProvider = function ($name, $type = 'RefillPhone')
- {
- $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
- if (!file_exists($file)) {
- Log::record("provider api file=$file not exist.", Log::DEBUG);
- return false;
- } else {
- require_once($file);
- Log::record("file={$file} load success.", Log::DEBUG);
- }
- $class_name = "refill\\{$name}\\{$type}";
- if (class_exists($class_name, false)) {
- $caller = new $class_name([]);
- return $caller;
- }
- else {
- $error = "Base Error: class {$class_name} isn't exists!";
- Log::record($error, Log::ERR);
- return false;
- }
- };
- $order_id = intval($params['order_id'] ?? 0);
- if($order_id <= 0) {
- return callback(true, "Order id is nothing.");
- }
- $mod_refill = Model('refill_order');
- $mod_order = Model('vr_order');
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
- if(empty($order_info) || empty($refill_info)) {
- return callback(false, "no order");
- }
- $chname = $refill_info['channel_name'];
- $provider = $getProvider($chname);
- if (empty($provider)) {
- return callback(false, "cannot create $chname provider.");
- }
- [$succ, $msg, $offical_sn] = $provider->query($refill_info);
- Log::record("order_sn={$refill_info['order_sn']} offical_sn=$offical_sn", Log::DEBUG);
- return callback($succ, "$chname provider query $msg.");
- }
- }
|