From 412798a32e6d78da3ecc67acedca9c345f0392f3 Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Fri, 28 Oct 2022 17:42:23 +0800 Subject: [PATCH] edit-sylive-under_order --- common/libraries/market/Sylive_entity.php | 2 +- home/controllers/h5/market/sylive/Act.php | 74 +++++++++++++------- home/controllers/h5/market/sylive/Notify.php | 9 ++- home/controllers/h5/market/sylive/Stic.php | 43 ++++++++---- home/views/h5/market/sylive/act/index.php | 2 +- home/views/h5/market/sylive/act/item.php | 3 + home/views/h5/market/sylive/stic/users.php | 30 ++++++-- 7 files changed, 114 insertions(+), 49 deletions(-) diff --git a/common/libraries/market/Sylive_entity.php b/common/libraries/market/Sylive_entity.php index 5a359a34..f0b1de66 100644 --- a/common/libraries/market/Sylive_entity.php +++ b/common/libraries/market/Sylive_entity.php @@ -201,7 +201,7 @@ class Sylive_entity{ ]; $area_id && $addData['area_id'] = $area_id; $biz_id && $addData['biz_id'] = $biz_id; - $jsondata = array(); + $jsondata = $params['jsondata'] ? $params['jsondata'] : []; $jsondata && $addData['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); $id = $this->ci->mdSytActivityKpiData->add($addData); if (!$id) { diff --git a/home/controllers/h5/market/sylive/Act.php b/home/controllers/h5/market/sylive/Act.php index 19929240..ae765dc8 100644 --- a/home/controllers/h5/market/sylive/Act.php +++ b/home/controllers/h5/market/sylive/Act.php @@ -328,6 +328,8 @@ class Act extends Wx { //支付 public function post_pay(){ + $redis = load_cache('redis'); + $redis_obj = $redis->redis(); $skey = $this->input->post('skey'); $name = $this->input->post('name'); $mobile = $this->input->post('telPhone'); @@ -337,6 +339,7 @@ class Act extends Wx { if(!$row){ $this->show_json('',400,'参数错误'); } + $mb_key = 'SYLIVE_ITEM_AID_'.$a_id; if(!mobile_valid($mobile)){ $this->show_json('',400,'请输入正确手机号'); } @@ -351,37 +354,56 @@ class Act extends Wx { if($pay_price<=0){ $this->show_json('',400,'无需支付'); } + if($row['stock']<=0){ + $this->show_json('',400,'已售罄'); + } $unpay = $this->market_sylive_order_model->get(['item_id'=>$a_id,'status'=>0,'uid'=>$this->uid,'expire_time>'=>time()]); if(!$unpay){ - $this->market_sylive_order_model->db->trans_begin(); - $this->load->helper('order'); - $unpay = [ - 'sid' => create_order_no('350200','market'), - 'uid' => $this->uid, - 'item_id' => $a_id, - 'item_title' => $item['title'], - 'total_price' => $pay_price, - 'expire_time' => time()+30*60,//订单过期时间 - 'createTime' => date('Y-m-d H:i:s') - ]; - $name && $unpay['uname'] = $name; - $mobile && $unpay['mobile'] = $mobile; - $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); - $p_user = []; - $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]); - $p_user['teamId'] && $unpay['cfrom'] = 1; - $oid = $this->market_sylive_order_model->add($unpay); - if(!is_numeric($oid)){ - $this->market_sylive_order_model->db->trans_rollback(); - $this->show_json('',400,'创建订单失败'); + $mb_count = $redis_obj->sCard($mb_key); //获取集合中用户数量 + if($mb_count && $mb_count>$row['stock']+10){ + $mb = $redis_obj->sMembers($mb_key); + $this->show_json('',400,'已售罄:'.json_encode($mb,JSON_UNESCAPED_UNICODE)); } - $this->market_sylive_activity_model->update(['stock = stock-1' =>null],['activityId'=>$a_id]); - $res = $this->market_sylive_activity_model->db->affected_rows(); - if(!$res){ + try { + $this->market_sylive_order_model->db->trans_begin(); + //限购一件 + $u_row = $this->market_sylive_order_model->get(['item_id'=>$a_id,'status>='=>0,'uid'=>$this->uid]); + if($u_row){ + throw new Exception('限购一件'); + } + $this->load->helper('order'); + $unpay = [ + 'sid' => create_order_no('350200','market'), + 'uid' => $this->uid, + 'item_id' => $a_id, + 'item_title' => $item['title'], + 'total_price' => $pay_price, + 'expire_time' => time()+5*60,//订单过期时间 + 'createTime' => date('Y-m-d H:i:s') + ]; + $name && $unpay['uname'] = $name; + $mobile && $unpay['mobile'] = $mobile; + $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); + $p_user = []; + $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]); + $p_user['teamId'] && $unpay['cfrom'] = 1; + $oid = $this->market_sylive_order_model->add($unpay); + if(!is_numeric($oid)){ + $this->market_sylive_order_model->db->trans_rollback(); + throw new Exception('创建订单失败'); + } + $this->market_sylive_activity_model->update(['stock = stock-1' =>null],['activityId'=>$a_id,'stock>'=>0]); + $res = $this->market_sylive_activity_model->db->affected_rows(); + if(!$res){ + throw new Exception('已售罄'); + } + $this->market_sylive_order_model->db->trans_commit(); + $redis_obj->sRem($mb_key,$this->uid); //删除集合 + }catch (Exception $e){ + $redis_obj->sRem($mb_key,$this->uid); //删除集合 $this->market_sylive_order_model->db->trans_rollback(); - $this->show_json('',400,'已售罄'); + $this->show_json('',400,$e->getMessage()); } - $this->market_sylive_order_model->db->trans_commit(); } $user = $this->user_model->get(['userId'=>$this->uid]); $notify_url = http_host_com('home').'/h5/market/sylive/notify'; diff --git a/home/controllers/h5/market/sylive/Notify.php b/home/controllers/h5/market/sylive/Notify.php index 0c8b2fb6..3c1cd8c9 100644 --- a/home/controllers/h5/market/sylive/Notify.php +++ b/home/controllers/h5/market/sylive/Notify.php @@ -55,7 +55,14 @@ class Notify extends CI_Controller { $res = $this->order_model->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')],['id'=>$order['id']]); if($res){ $act_user = $this->act_user_model->get(['userId'=>$order['uid'],'activityId'=>$order['item_id']]); - $sy_res = $this->sylive_entity->kpi_log(['a_id' => $order['item_id'], 'uid' => $order['uid'],'cf_uid' => $act_user['channelId'], 'kpi' => 'order']); + $params = [ + 'a_id' => $order['item_id'], + 'uid' => $order['uid'], + 'cf_uid' => $act_user['channelId'], + 'kpi' => 'order', + 'jsondata'=> ['order_id'=>$order['id'],'sid'=>$sid] + ]; + $sy_res = $this->sylive_entity->kpi_log($params); debug_log("[info] ". __FUNCTION__ . ":私域通增加记录-".json_encode($sy_res,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir); debug_log("[success] ". __FUNCTION__ . ":操作成功", $this->log_file,$this->log_dir); } diff --git a/home/controllers/h5/market/sylive/Stic.php b/home/controllers/h5/market/sylive/Stic.php index 7f1b6e5f..4b551a6a 100644 --- a/home/controllers/h5/market/sylive/Stic.php +++ b/home/controllers/h5/market/sylive/Stic.php @@ -11,7 +11,7 @@ class Stic extends Admin{ $this->load->model('market/market_sylive_activity_model'); $this->load->model('market/market_sylive_activity_biz_model','mdSytActivityBiz'); $this->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData'); - + $this->load->model('market/market_sylive_order_model'); $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); $this->load->library('market/sylive_entity'); $this->group_id = $this->sylive_entity->get_level($this->session['org_id']); @@ -108,8 +108,8 @@ class Stic extends Admin{ $where['kpi'] = 'subscribe'; $all_subscribe_count = $this->mdSytActivityKpiData->count($where); //订阅数据 $all = [ - ['title' => '访问用户', 'num' => "{$all_browse_count}人",'url'=>"/h5/market/sylive/stic/users?type=all&kpi=browse&a_id={$a_id}"], - ['title' => '预约用户', 'num' => "{$all_subscribe_count}人",'url'=>"/h5/market/sylive/stic/users?type=all&kpi=subscribe&a_id={$a_id}"], + ['title' => '访问用户', 'num' => "{$all_browse_count}人",'url'=>""], + ['title' => '预约用户', 'num' => "{$all_subscribe_count}人",'url'=>""], ['title' => '预约率', 'num' => $all_browse_count ? round($all_subscribe_count/$all_browse_count*100,2)."%" : 0], ]; }else{ @@ -126,8 +126,8 @@ class Stic extends Admin{ $where['kpi'] = 'subscribe'; $a_subscribe_count = $this->mdSytActivityKpiData->count($where); //订阅数据 $area = [ - ['title' => '访问用户', 'num' => "{$a_browse_count}人",'url'=>"/h5/market/sylive/stic/users?type=area&type_id={$area_id}&kpi=browse&a_id={$a_id}"], - ['title' => '预约用户', 'num' => "{$a_subscribe_count}人",'url'=>"/h5/market/sylive/stic/users?type=area&type_id={$area_id}&kpi=subscribe&a_id={$a_id}"], + ['title' => '访问用户', 'num' => "{$a_browse_count}人",'url'=>""], + ['title' => '预约用户', 'num' => "{$a_subscribe_count}人",'url'=>""], ['title' => '预约率', 'num' => $a_browse_count ? round($a_subscribe_count/$a_browse_count*100,2)."%" : 0], ]; } @@ -230,8 +230,8 @@ class Stic extends Admin{ $where['kpi'] = 'order'; $all_order_count = $this->mdSytActivityKpiData->count($where); //下单数据 $all = [ - ['title' => '观看用户', 'num' => "{$all_view_count}人",'url'=>'/h5/market/sylive/stic/users?type=all&kpi=watch&a_id='.$a_id], - ['title' => '下单用户', 'num' => "{$all_order_count}人",'url'=>'/h5/market/sylive/stic/users?type=all&kpi=order&a_id='.$a_id], + ['title' => '观看用户', 'num' => "{$all_view_count}人",'url'=>''], + ['title' => '下单用户', 'num' => "{$all_order_count}人",'url'=>''], ['title' => '转化率', 'num' => $all_view_count ? round($all_order_count/$all_view_count*100,2)."%" : 0], ]; }else{ @@ -248,8 +248,8 @@ class Stic extends Admin{ $where['kpi'] = 'order'; $a_order_count = $this->mdSytActivityKpiData->count($where); //下单数据 $area = [ - ['title' => '观看用户', 'num' => "{$a_view_count}人",'url'=>"/h5/market/sylive/stic/users?type=area&type_id={$area_id}&kpi=watch&a_id={$a_id}"], - ['title' => '下单用户', 'num' => "{$a_order_count}人",'url'=>"/h5/market/sylive/stic/users?type=area&type_id={$area_id}&kpi=order&a_id={$a_id}"], + ['title' => '观看用户', 'num' => "{$a_view_count}人",'url'=>""], + ['title' => '下单用户', 'num' => "{$a_order_count}人",'url'=>""], ['title' => '转化率', 'num' => $a_view_count ? round($a_order_count/$a_view_count*100,2)."%" : 0], ]; } @@ -471,7 +471,7 @@ class Stic extends Admin{ $tab = [ ['id'=>1,'title'=>'客户列表'] ]; - if($this->group_id==2){ //店长 + if($this->group_id==2 || ($params['type']=='biz'&&$params['type_id'])){ //店长 $tab[] = ['id'=>2,'title'=>'顾问数据']; } $this->data['title'] = $title; @@ -507,7 +507,7 @@ class Stic extends Admin{ $total = $this->mdSytActivityKpiData->count($where); $lists = []; if($total){ - $rows = $this->mdSytActivityKpiData->select($where,'id desc',$page,20,'uid,cf_uid,c_time'); + $rows = $this->mdSytActivityKpiData->select($where,'id desc',$page,20,'uid,cf_uid,c_time,jsondata'); $uids_arr = array_column($rows,'uid'); if($this->group_id==2){ $gw_uids_arr = array_column($rows,'cf_uid'); @@ -522,18 +522,28 @@ class Stic extends Admin{ $users = $this->user_model->map('userId','',$where,'','','','userId,uname,nickname,headimg'); } foreach ($rows as $key => $item) { + $jsondata = json_decode($item['jsondata'],true); $user = $users[$item['uid']] ? $users[$item['uid']][0] : []; $nickname = $user['nickname'] ? $user['nickname'] : '用户'.$user['userId']; $headimg = $user['headimg'] ? $user['headimg'] : 'https://thirdwx.qlogo.cn/mmopen/vi_32/Q3auHgzwzM483tlYWFg5RWQ1Xat94ib82prnDSicm2GHuxI49swU08N2I1aHb7B1gmicyxXF8R1BsVWahU9SiaPEzA/132'; $cf_uname = ''; if($this->group_id==2){ //店长 $cf_user = $users[$item['cf_uid']] ? $users[$item['cf_uid']][0] : []; - $cf_uname = $cf_user['uname'] ? "({$cf_user['uname']})" : ""; + $cf_uname = $cf_user['uname'] ? $cf_user['uname'] : ""; + } + $mobile = $name = ''; + if($params['kpi']=='order' && $jsondata['order_id']){ + $order = $this->market_sylive_order_model->get(['id'=>$jsondata['order_id']],'uname,mobile'); + $name = $order['uname'] ? $order['uname'] : ''; + $mobile = $order['mobile'] ? $order['mobile'] : ''; } $lists[] = [ 'nickname' => $nickname, + 'name' => $name, + 'mobile' => $mobile, 'headimg' => $headimg, - 'time' => $cf_uname.friendly_date($item['c_time'],'normal',1) + 'cf_uname' => $cf_uname, + 'time' => friendly_date($item['c_time'],'normal',1) ]; } } @@ -546,7 +556,12 @@ class Stic extends Admin{ public function gw_lists(){ $params = $this->input->get(); - $res = $this->sylive_entity->top_biz_user($params['a_id'],$this->session['org_id'],$this->uid,$params['kpi']); + if($params['type']=='biz'&&$params['type_id']){ + $biz_id = $params['type_id']; + }else{ + $biz_id = $this->session['org_id']; + } + $res = $this->sylive_entity->top_biz_user($params['a_id'],$biz_id,$this->uid,$params['kpi']); $lists = []; if($res['lists']){ foreach ($res['lists'] as $item) { diff --git a/home/views/h5/market/sylive/act/index.php b/home/views/h5/market/sylive/act/index.php index 465bdb82..16fba697 100644 --- a/home/views/h5/market/sylive/act/index.php +++ b/home/views/h5/market/sylive/act/index.php @@ -16,7 +16,7 @@ 点击这里预约直播 diff --git a/home/views/h5/market/sylive/act/item.php b/home/views/h5/market/sylive/act/item.php index 59c21921..66f46d8e 100644 --- a/home/views/h5/market/sylive/act/item.php +++ b/home/views/h5/market/sylive/act/item.php @@ -173,6 +173,9 @@ content: "请输入正确手机号" }); }else{ + if(that.isSubmit){ + return '' + } that.isSubmiting = true $.post('/h5/market/sylive/act/post_pay',{'skey':'','name':that.name,'telPhone':that.telPhone},function (res){ that.isSubmiting = false diff --git a/home/views/h5/market/sylive/stic/users.php b/home/views/h5/market/sylive/stic/users.php index 03362275..2af02bb5 100644 --- a/home/views/h5/market/sylive/stic/users.php +++ b/home/views/h5/market/sylive/stic/users.php @@ -21,13 +21,31 @@ -
-
- # - {{item.nickname}} + +
+
+
+ # + {{item.nickname}} +
+
{{item.cf_uname}}
+
+
+
+ {{item.name}} {{item.mobile}} +
+
{{item.time}}
+
-
{{item.time}}
-
+ +
+
+ # + {{item.nickname}} +
+
{{item.cf_uname}} {{item.time}}
+
+
暂无数据
请稍等...