123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660 |
- <?php
- /**
- * 队列
- *
- * 方法名需要和 QueueClient::push中第一个参数一致,如:
- * QueueClient::push('editGroupbuySaleCount',$groupbuy_info);
- * public function editGroupbuySaleCount($groupbuy_info){...}
- *
- */
- defined('InShopNC') or exit('Access Invalid!');
- require_once (BASE_ROOT_PATH . '/helper/push_sender.php');
- require_once (BASE_ROOT_PATH . '/helper/sms_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/kdn_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/statistics_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/member_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/account_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/fcode/generator.php');
- require_once (BASE_ROOT_PATH . '/helper/memsg/message_sender.php');
- require_once (BASE_ROOT_PATH . '/helper/login_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/fcode/mfcode.php');
- require_once (BASE_ROOT_PATH . '/helper/fcode/operator.php');
- require_once (BASE_ROOT_PATH . '/helper/user_session/fcode.php');
- require_once (BASE_ROOT_PATH . '/helper/stat_helper.php');
- class queueLogic
- {
- /**
- * push app内容跳转类型
- * @var array
- */
- protected $go_type = array(
- '',//跳转到app首页
- 'bonus',//红包页
- );
- /**
- * 添加会员积分
- * @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);
- }
- }
- /**
- * 更新使用的代金券状态
- * @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(array('voucher_state' => 2), array('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), 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)
- {
- 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['member_id']) || empty($param['text'])) {
- Log::record("push info: 数据有误! param:" . json_encode($param) . "\t session:" . json_encode($_SESSION));
- return callback(false);
- }
- if (!isset($param['go_type'])) {
- $param['go_type'] = '';
- }
- if (!in_array($param['go_type'], $this->go_type)) {
- Log::record("push info: go_type参数有误! param:" . json_encode($param) . "\t session:" . json_encode($_SESSION));
- return callback(false);
- }
- $push = new push_sender();
- $push->send($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 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'];
- $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);
- 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 invite_user_register($param)
- {
- $member_id = $param['member_id'];
- $relay_id = $param['relay_id'];
- $password = $param['password'];
- if($member_id < 0) {
- return callback(false,"invite_user_register 错误的member_id");
- }
- login_helper::onInvite($member_id,$relay_id,$password);
- 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 onPaySuccess($param)
- {
- $pay_sn = $param['pay_sn'];
- account_helper::onPaySuccess($pay_sn);
- return callback(true);
- }
- 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);
- }
- }
|