diff --git a/common/helpers/comm_helper.php b/common/helpers/comm_helper.php index 27097f7b..f8f29b46 100644 --- a/common/helpers/comm_helper.php +++ b/common/helpers/comm_helper.php @@ -950,11 +950,11 @@ if (!function_exists('http_host_com')) { } else if ($type == 'admin') { $url = "http://liche-admin.dev.xiaoyu.com"; } - } elseif (false !== strpos($_SERVER['HTTP_HOST'], 'test')) {//test 测试 + } elseif (false !== strpos($_SERVER['HTTP_HOST'], 'lc')) {//test 测试 if ($type == 'api') { $url = 'api.lc.haodian.cn'; } else if ($type == 'home') { - $url = "https://www-test.liche.cn"; + $url = "http://www.lc.haodian.cn"; } else if ($type == 'admin') { $url = "https://admin.test.liche.cn"; } diff --git a/home/controllers/h5/market/sylive2/Act.php b/home/controllers/h5/market/sylive2/Act.php index 5932d28b..77125b11 100644 --- a/home/controllers/h5/market/sylive2/Act.php +++ b/home/controllers/h5/market/sylive2/Act.php @@ -1,22 +1,24 @@ 大家都太热情了,先稍等片刻再访问吧~";exit; parent::__construct(); $this->load->model('market/market_sylive_organization_model'); $this->load->model('market/market_sylive_activity_model'); - $this->load->model('market/market_sylive_activity_biz_model','mdSytActivityBiz'); - $this->load->model('market/market_sylive_subscribemsg_model','mdSytSubscribemsg'); - $this->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData'); + $this->load->model('market/market_sylive_activity_biz_model', 'mdSytActivityBiz'); + $this->load->model('market/market_sylive_subscribemsg_model', 'mdSytSubscribemsg'); + $this->load->model('market/market_sylive_activity_kpidata_model', 'mdSytActivityKpiData'); $this->load->model('market/market_sylive_order_model'); $this->load->model('market/market_sylive_customer_model'); $this->load->model('market/market_sylive_items_model'); @@ -28,29 +30,34 @@ class Act extends Wx { $this->a_id = intval($param['a_id']);//活动id } - public function index(){ + public function index() + { $alert_code = $this->input->get('alert_code'); $apt = $this->input->get('apt'); if (!$this->a_id) { throw new Hd_exception("参数错误", 400); } - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } - $jsondata = json_decode($row['jsondata'],true); + $jsondata = json_decode($row['jsondata'], true); $bottoms = []; - if($jsondata['bottoms']){ - foreach ($jsondata['bottoms'] as $key=>$val) { + if ($jsondata['bottoms']) { + foreach ($jsondata['bottoms'] as $key => $val) { $temp = [ 'title' => $val['title'], 'icon' => build_qiniu_image_url($val['icon']) ]; - if($val['urlType']=='miniProgram'){ + if ($val['urlType'] == 'miniProgram') { $temp['type'] = 2; $temp['wechat_ghid'] = $val['miniProgramId']; $temp['wechat_path'] = $val['url']; - }else{ + } else if ($val['urlType'] == 'enroll') { //报名 + $temp['type'] = 3; + } else if ($val['urlType'] == 'appoint') { //订阅 + $temp['type'] = 4; + } else { $temp['type'] = 1; $temp['url'] = $val['url']; } @@ -58,24 +65,24 @@ class Act extends Wx { } } $info['menu'] = $bottoms; - $user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg'); + $user = $this->user_model->get(['userId' => $this->uid], 'unionid,nickname,headimg'); $timeStart = strtotime($row['timeStart']); - $info['s_time'] = time() < $timeStart ? $timeStart-time() : 0; + $info['s_time'] = time() < $timeStart ? $timeStart - time() : 0; $info['bg'] = $row['bgImg'] ? build_qiniu_image_url($row['bgImg']) : ''; $info['content'] = $row['introduction']; - $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$this->a_id]); + $act_user = $this->act_user_model->get(['userId' => $this->uid, 'activityId' => $this->a_id]); //一次性订阅 $re_s = $this->mdSytSubscribemsg->get(array('activityId' => $this->a_id, 'userId' => $this->uid)); $is_show_code = false; //是否显示二维码 if ($re_s) { $subscribemsg = '已订阅直播'; $p_user = []; - $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]); + $act_user['channelId'] && $p_user = $this->user_model->get(['userId' => $act_user['channelId']]); $p_user['teamId'] && $is_show_code = true; } else { - if(!$user['nickname'] && !$user['headimg']){ - $subscribemsg = http_host_com('home')."/h5/market/sylive2/act/userinfo?skey={$this->skey}&type=sub"; - }else{ + if (!$user['nickname'] && !$user['headimg']) { + $subscribemsg = http_host_com('home') . "/h5/market/sylive2/act/userinfo?skey={$this->skey}&type=sub"; + } else { $this->load->config('wechat'); $config = $this->config->item('hdy'); $sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive2/act/subscribemsg?skey=' . $this->skey @@ -84,15 +91,15 @@ class Act extends Wx { } } //浏览 - $params = array('a_id' => $this->a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'browse'); + $params = array('a_id' => $this->a_id, 'uid' => $this->uid, 'cf_uid' => $act_user['channelId'], 'kpi' => 'browse'); $this->sylive2_entity->kpi_log($params); $live_status = 0; //直播未开始 - if(time()>strtotime($row['timeStart']) && time()<=strtotime($row['timeEnd'])){ //直播期间人数 - $row['liveStatus']!=1 && $this->market_sylive_activity_model->update(['liveStatus'=>1],['activityId'=>$this->a_id]); //更新直播间状态 + if (time() > strtotime($row['timeStart']) && time() <= strtotime($row['timeEnd'])) { //直播期间人数 + $row['liveStatus'] != 1 && $this->market_sylive_activity_model->update(['liveStatus' => 1], ['activityId' => $this->a_id]); //更新直播间状态 $live_status = 1; //直播中 } - if(time()>strtotime($row['timeEnd'])){ //直播结束 - $row['liveStatus']!=2 && $this->market_sylive_activity_model->update(['liveStatus'=>2],['activityId'=>$this->a_id]); //更新直播间状态 + if (time() > strtotime($row['timeEnd'])) { //直播结束 + $row['liveStatus'] != 2 && $this->market_sylive_activity_model->update(['liveStatus' => 2], ['activityId' => $this->a_id]); //更新直播间状态 $live_status = 2; //直播结束 } $share_skey = "a_id=" . $this->a_id . "&cf_uid=" . $this->uid; @@ -101,44 +108,47 @@ class Act extends Wx { $info['a_id'] = $this->a_id; $info['subscribemsg'] = $subscribemsg; $info['statisticsurl'] = $info['shareurl'] = $info['code'] = ''; - if($act_user['groupsId']){ - $info['shareurl'] = '/h5/market/sylive2/act/share?skey='.$info['skey']; + if ($act_user['groupsId']) { + $info['shareurl'] = '/h5/market/sylive2/act/share?skey=' . $info['skey']; $info['statisticsurl'] = "/h5/market/sylive2/stic?a_id={$this->a_id}"; $info['rankingurl'] = "/h5/market/sylive2/stic/ranking?a_id={$this->a_id}"; } $info['channelImg'] = build_qiniu_image_url($row['channelImg']); $userid = $user['unionid'] ? $user['unionid'] : $this->uid; - $ts = time()*1000; - $sign = md5($this->secretkey.$userid.$this->secretkey.$ts); - if(!$user['nickname'] && !$user['headimg']){ - $info['live_url'] = http_host_com('home').'/h5/market/sylive2/act/userinfo?skey='.$this->skey; - }else{ + $ts = time() * 1000; + $sign = md5($this->secretkey . $userid . $this->secretkey . $ts); + if (!$user['nickname'] && !$user['headimg']) { + $info['live_url'] = http_host_com('home') . '/h5/market/sylive2/act/userinfo?skey=' . $this->skey; + } else { $info['live_url'] = "https://live.haodian.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}"; } - $info['my_url'] = http_host_com('home')."/h5/market/sylive2/act/userinfo?skey={$this->skey}&type=my"; + $info['my_url'] = http_host_com('home') . "/h5/market/sylive2/act/userinfo?skey={$this->skey}&type=my"; $info['show_code'] = $is_show_code ? 1 : 0; $info['alert_code'] = $alert_code ? 1 : 0; $info['appoint_mobile'] = false; $info['is_appoint'] = false; $auth_url = ''; - if($jsondata['signBespeak']['status']){ + //判断是否已报名 + $where = ['activityId' => $this->a_id, 'userId' => $this->uid]; + $appoint = $this->market_sylive_customer_model->get($where); + $info['is_appoint'] = $appoint ? true : false; + if ($jsondata['signBespeak']['status']) { $info['appoint_mobile'] = true; - //判断是否已报名 - $where = ['activityId'=>$this->a_id,'userId'=>$this->uid]; - $appoint = $this->market_sylive_customer_model->get($where); - $info['is_appoint'] = $appoint ? true : false; - if(!$user['nickname'] && !$user['headimg']) { + if (!$user['nickname'] && !$user['headimg']) { $auth_url = http_host_com('home') . "/h5/market/sylive2/act/userinfo?skey={$this->skey}&type=apt"; } } + $pay_item_id = intval($jsondata['signBespeak']['payItemId']); + $pay_skey = $this->myencryption->base64url_encode("a_id={$this->a_id}&itemId={$pay_item_id}"); $info['auth_url'] = $auth_url; $info['apt'] = $apt ? true : false; //是否弹窗报名 $info['ukey'] = $appoint ? $appoint['ukey'] : ''; //是否弹窗报名 $info['appoint_title'] = $jsondata['signBespeak']['title'] ? $jsondata['signBespeak']['title'] : ''; $info['appoint_msg'] = $jsondata['signBespeak']['content'] ? $jsondata['signBespeak']['content'] : ''; - $info['notice_color'] = $jsondata['barrage']['color'] ? '#fff' : '#333'; + $info['notice_color'] = $jsondata['barrage']['color'] ? '#fff' : '#333'; $info['btn_text'] = $jsondata['button']['title'] ? $jsondata['button']['title'] : '开播提醒'; + $info['pay_item_url'] = $pay_item_id ? http_host_com('home') . "/h5/market/sylive2/item/detail?skey={$pay_skey}" : ''; $this->data['info'] = $info; //微信分享 $wx_info = $this->share_info($row); @@ -150,7 +160,8 @@ class Act extends Wx { } //获取最新订阅用户 - public function subscribemsg_lists(){ + public function subscribemsg_lists() + { $map_kpi_name = [ 'browse' => '进入了直播间', 'subscribe' => '订阅了直播通知' ]; @@ -162,27 +173,27 @@ class Act extends Wx { 'activityId' => $a_id, 'kpi' => 'subscribe' ]; - if($live_status){ + if ($live_status) { $where['kpi'] = 'browse'; } - $rows = $this->mdSytActivityKpiData->select($where,'id desc',1,30,$field); - if($rows){ - $act_row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); - $jsondata = json_decode($act_row['jsondata'],true); + $rows = $this->mdSytActivityKpiData->select($where, 'id desc', 1, 30, $field); + if ($rows) { + $act_row = $this->market_sylive_activity_model->get(['activityId' => $a_id]); + $jsondata = json_decode($act_row['jsondata'], true); $users = []; - $uids = implode(',',array_unique(array_column($rows,'userId'))); - if($uids){ + $uids = implode(',', array_unique(array_column($rows, 'userId'))); + if ($uids) { $where = [ "userId in ($uids)" => null, ]; - $users = $this->user_model->map('userId','nickname',$where,'','','','userId,nickname'); + $users = $this->user_model->map('userId', 'nickname', $where, '', '', '', 'userId,nickname'); } foreach ($rows as $item) { $nickname = $users[$item['userId']] ? $users[$item['userId']] : "用户{$item['userId']}"; //报名使用自定标题 - if($jsondata['signBespeak']['status'] && !$live_status && $jsondata['barrage']['title']){ + if ($jsondata['signBespeak']['status'] && !$live_status && $jsondata['barrage']['title']) { $tip = $jsondata['barrage']['title']; - }else{ + } else { $tip = $map_kpi_name[$item['kpi']]; } $lists[] = [ @@ -192,7 +203,7 @@ class Act extends Wx { } } $data['lists'] = $lists; - $this->show_json($data,200); + $this->show_json($data, 200); } /** @@ -222,11 +233,11 @@ class Act extends Wx { $add_data['status'] = 0; $id = $this->mdSytSubscribemsg->add($add_data); if ($id) { - $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); + $act_user = $this->act_user_model->get(['userId' => $this->uid, 'activityId' => $a_id]); //订阅用户加统计 - $params = array('a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'subscribe'); + $params = array('a_id' => $a_id, 'uid' => $this->uid, 'cf_uid' => $act_user['channelId'], 'kpi' => 'subscribe'); $req = $this->sylive2_entity->kpi_log($params); - debug_log("[info]# " . json_encode($req,JSON_UNESCAPED_UNICODE), 'market/sylive','subscribemsg.log'); + debug_log("[info]# " . json_encode($req, JSON_UNESCAPED_UNICODE), 'market/sylive', 'subscribemsg.log'); // $p_user = []; // $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]); // $p_user['teamId'] && $show_code = 1; @@ -237,40 +248,41 @@ class Act extends Wx { redirect($url); } - public function share(){ - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + public function share() + { + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } - $shareImg = json_decode($row['shareImg'],true); - $shareTitle = $row['shareTitle'] ? json_decode($row['shareTitle'],true) : []; + $shareImg = json_decode($row['shareImg'], true); + $shareTitle = $row['shareTitle'] ? json_decode($row['shareTitle'], true) : []; $lists = []; - if($shareImg){ + if ($shareImg) { $share_skey = "a_id=" . $this->a_id . "&cf_uid=" . $this->uid; $share_url = http_host_com('home') . "/h5/market/sylive2/act?skey=" . $this->myencryption->base64url_encode($share_skey); $errorCorrectionLevel = 'L'; //容错级别 $matrixPointSize = 5; //生成图片大小 //生成二维码图片 - $file_name = md5($share_url).'.png'; + $file_name = md5($share_url) . '.png'; $file_path = "temp/{$file_name}"; - if (!file_exists(FCPATH.'temp/')) { + if (!file_exists(FCPATH . 'temp/')) { $oldumask = umask(0); - mkdir(FCPATH.'temp/', 0777, true); + mkdir(FCPATH . 'temp/', 0777, true); umask($oldumask); } - QRcode::png($share_url, FCPATH.$file_path, $errorCorrectionLevel, $matrixPointSize, 1); - $res = $this->qiniu->save($file_name, file_get_contents(FCPATH.$file_path)); - if($res['url']){ - @unlink(FCPATH.$file_path); + QRcode::png($share_url, FCPATH . $file_path, $errorCorrectionLevel, $matrixPointSize, 1); + $res = $this->qiniu->save($file_name, file_get_contents(FCPATH . $file_path)); + if ($res['url']) { + @unlink(FCPATH . $file_path); $qr_code = build_qiniu_image_url($res['url']); - }else{ + } else { $qr_code = '/h5/market/sylive2/myqrcode/get?url=' . $share_url; } foreach ($shareImg as $item) { $img_url = build_qiniu_image_url($item); - $img_info = file_get_contents($img_url.'?imageInfo'); - if($img_info){ - $img_info = json_decode($img_info,true); + $img_info = file_get_contents($img_url . '?imageInfo'); + if ($img_info) { + $img_info = json_decode($img_info, true); } $lists[] = [ "img" => $img_url, @@ -280,17 +292,17 @@ class Act extends Wx { ]; } } - $user = $this->user_model->get(['userId'=>$this->uid],'uname,nickname'); - $act_row = $this->act_user_model->get(['id'=>$this->act_uid],'groupsId'); - if($act_row['groupsId']){ - $group_lists = $this->sylive2_entity->get_group_lists($act_row['groupsId'],$this->a_id); + $user = $this->user_model->get(['userId' => $this->uid], 'uname,nickname'); + $act_row = $this->act_user_model->get(['id' => $this->act_uid], 'groupsId'); + if ($act_row['groupsId']) { + $group_lists = $this->sylive2_entity->get_group_lists($act_row['groupsId'], $this->a_id); $this->data['posterTip'] = "{$group_lists[0]['groupsName']}{$user['uname']}诚挚邀请您参与"; - }else{ + } else { $this->data['posterTip'] = "{$user['nickname']}诚挚邀请您参与"; } $jsondata = json_decode($row['jsondata'], true); - $this->data['fillStyle'] = $jsondata['barrage']['color'] ? '#fff' : '#333';; + $this->data['fillStyle'] = $jsondata['barrage']['color'] ? '#fff' : '#333'; $this->data['lists'] = $lists; $this->data['shareTitle'] = $shareTitle; //微信分享 @@ -300,27 +312,29 @@ class Act extends Wx { $this->show_view('h5/market/sylive2/act/share'); } - public function item(){ + public function item() + { $skey = $this->input->get('skey'); $param = $this->myencryption->base64url_decode($skey); $a_id = intval($param['a_id']);//活动id - $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + $row = $this->market_sylive_activity_model->get(['activityId' => $a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } - $jsondata = json_decode($row['jsondata'],true); - $item = $jsondata['item'] ? $jsondata['item'] : []; - $is_pay = $this->market_sylive_order_model->count(['itemId'=>$a_id,'status'=>1,'userId'=>$this->uid,'type'=>0]); - if($is_pay){ - $url = http_host_com('home').'/h5/market/sylive2/ucenter/mygift?skey='.$skey; - redirect($url);exit; + $jsondata = json_decode($row['jsondata'], true); + $item = $jsondata['item'] ? $jsondata['item'] : []; + $is_pay = $this->market_sylive_order_model->count(['itemId' => $a_id, 'status' => 1, 'userId' => $this->uid, 'type' => 0]); + if ($is_pay) { + $url = http_host_com('home') . '/h5/market/sylive2/ucenter/mygift?skey=' . $skey; + redirect($url); + exit; } $e_time = time() < strtotime($row['timeEnd']) ? strtotime($row['timeEnd']) - time() : 0; $banner = $this->item_banner; $validity = ''; - if($item['useTimeStart'] || $item['useTimeEnd']){ - $useTimeStart = date('Y-m-d',strtotime($item['useTimeStart'])); - $useTimeEnd = date('Y-m-d',strtotime($item['useTimeEnd'])); + if ($item['useTimeStart'] || $item['useTimeEnd']) { + $useTimeStart = date('Y-m-d', strtotime($item['useTimeStart'])); + $useTimeEnd = date('Y-m-d', strtotime($item['useTimeEnd'])); $validity = "有效期 {$useTimeStart} - {$useTimeEnd}"; } $info = [ @@ -344,7 +358,8 @@ class Act extends Wx { } //支付 - public function post_pay(){ + public function post_pay() + { $redis = load_cache('redis'); $redis_obj = $redis->redis(); $skey = $this->input->post('skey'); @@ -352,100 +367,101 @@ class Act extends Wx { $mobile = $this->input->post('telPhone'); $param = $this->myencryption->base64url_decode($skey); $a_id = intval($param['a_id']);//活动id - $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); - if(!$row){ - $this->show_json('',400,'参数错误'); + $row = $this->market_sylive_activity_model->get(['activityId' => $a_id]); + if (!$row) { + $this->show_json('', 400, '参数错误'); } - $mb_key = 'SYLIVE_ITEM_AID_'.$a_id; - if(!mobile_valid($mobile)){ - $this->show_json('',400,'请输入正确手机号'); + $mb_key = 'SYLIVE_ITEM_AID_' . $a_id; + if (!mobile_valid($mobile)) { + $this->show_json('', 400, '请输入正确手机号'); } - $jsondata = json_decode($row['jsondata'],true); - $item = $jsondata['item'] ? $jsondata['item'] : []; + $jsondata = json_decode($row['jsondata'], true); + $item = $jsondata['item'] ? $jsondata['item'] : []; //判断是否已支付 - $o_row = $this->market_sylive_order_model->get(['itemId'=>$a_id,'status'=>1,'userId'=>$this->uid,'type'=>0]); - if($o_row){ - $this->show_json('',400,'已支付,请勿重复支付'); + $o_row = $this->market_sylive_order_model->get(['itemId' => $a_id, 'status' => 1, 'userId' => $this->uid, 'type' => 0]); + if ($o_row) { + $this->show_json('', 400, '已支付,请勿重复支付'); } $pay_price = $item['price']; - if($pay_price<=0){ - $this->show_json('',400,'无需支付'); + if ($pay_price <= 0) { + $this->show_json('', 400, '无需支付'); } - if($row['stock']<=0){ - $this->show_json('',400,'已售罄'); + if ($row['stock'] <= 0) { + $this->show_json('', 400, '已售罄'); } - $unpay = $this->market_sylive_order_model->get(['itemId'=>$a_id,'status'=>0,'userId'=>$this->uid,'expireTime>'=>time(),'type'=>0]); - if(!$unpay){ + $unpay = $this->market_sylive_order_model->get(['itemId' => $a_id, 'status' => 0, 'userId' => $this->uid, 'expireTime>' => time(), 'type' => 0]); + if (!$unpay) { $mb_count = $redis_obj->sCard($mb_key); //获取集合中用户数量 - if($mb_count && $mb_count>$row['stock']+10){ + 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->show_json('', 400, '已售罄:' . json_encode($mb, JSON_UNESCAPED_UNICODE)); } try { - $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); + $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']]); + $act_user['channelId'] && $p_user = $this->user_model->get(['userId' => $act_user['channelId']]); $this->market_sylive_order_model->db->trans_begin(); //限购一件 - $u_row = $this->market_sylive_order_model->get(['itemId'=>$a_id,'status>='=>0,'userId'=>$this->uid]); - if($u_row){ + $u_row = $this->market_sylive_order_model->get(['itemId' => $a_id, 'status>=' => 0, 'userId' => $this->uid]); + if ($u_row) { throw new Exception('限购一件'); } $this->load->helper('order'); $unpay = [ - 'sid' => create_order_no('350200','market'), + 'sid' => create_order_no('350200', 'market'), 'userId' => $this->uid, 'itemId' => $a_id, 'itemTitle' => $item['title'], 'totalPrice' => $pay_price, - 'expireTime' => time()+5*60,//订单过期时间 + 'expireTime' => time() + 5 * 60,//订单过期时间 'createTime' => date('Y-m-d H:i:s') ]; $name && $unpay['uname'] = $name; $mobile && $unpay['mobile'] = $mobile; $p_user['teamId'] && $unpay['cfrom'] = 1; $oid = $this->market_sylive_order_model->add($unpay); - if(!is_numeric($oid)){ + 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]); + $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){ + 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); //删除集合 + $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,$e->getMessage()); + $this->show_json('', 400, $e->getMessage()); } } - $user = $this->user_model->get(['userId'=>$this->uid]); - $notify_url = http_host_com('home').'/h5/market/sylive2/notify'; + $user = $this->user_model->get(['userId' => $this->uid]); + $notify_url = http_host_com('home') . '/h5/market/sylive2/notify'; $other_data = []; $pay_config = $this->market_sylive_activity_model->pay_config($row['mchId']); $pay_config && $other_data['pay_config'] = $pay_config; - $result = $this->unorder($unpay['sid'],$unpay['totalPrice'],$user['openid'],$unpay['itemTitle'],$notify_url,$unpay['expireTime'],$other_data); - if(!$result['code']){ - $this->show_json('',400,$result['msg']); + $result = $this->unorder($unpay['sid'], $unpay['totalPrice'], $user['openid'], $unpay['itemTitle'], $notify_url, $unpay['expireTime'], $other_data); + if (!$result['code']) { + $this->show_json('', 400, $result['msg']); } - $this->show_json($result['data'],200,'操作成功'); + $this->show_json($result['data'], 200, '操作成功'); } //获取微信用户信息 - public function userinfo(){ - $ret = $this->set_auth('',1); - if($ret){ + public function userinfo() + { + $ret = $this->set_auth('', 1); + if ($ret) { $update = [ "sex" => $ret['sex'] ? 1 : 0, ]; $ret['nickname'] && $update['nickname'] = strval($ret['nickname']); $ret['headimgurl'] && $update['headimg'] = strval($ret['headimgurl']); $ret['unionid'] && $update['unionid'] = $ret['unionid']; - $this->user_model->update($update,['userId'=>$this->uid,'openid'=>$ret['openid']]); - $_SESSION[self::SESSION_KEY]['all_info'] =1; + $this->user_model->update($update, ['userId' => $this->uid, 'openid' => $ret['openid']]); + $_SESSION[self::SESSION_KEY]['all_info'] = 1; } $skey = $this->input->get('skey'); $type = $this->input->get('type'); @@ -457,95 +473,100 @@ class Act extends Wx { if (!$a_id) { throw new Hd_exception("参数错误", 400); } - $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + $row = $this->market_sylive_activity_model->get(['activityId' => $a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } - if($type=='sub'){ //订阅跳转 + if ($type == 'sub') { //订阅跳转 $this->load->config('wechat'); $config = $this->config->item('hdy'); $sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive2/act/subscribemsg?skey=' . $skey . '&s_time=' . $row['timeStart']); $subscribemsg = "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid={$config['appid']}&scene=0&template_id={$this->template_id}&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect"; redirect($subscribemsg); - }elseif($type=='my'){ //跳转我的 - $my_url = http_host_com('home')."/h5/market/sylive2/ucenter?skey={$skey}"; + } elseif ($type == 'my') { //跳转我的 + $my_url = http_host_com('home') . "/h5/market/sylive2/ucenter?skey={$skey}"; redirect($my_url); - }elseif($type=='item'){ - $my_url = http_host_com('home')."/h5/market/sylive2/item/detail?skey={$skey}&click=1"; + } elseif ($type == 'item') { + $my_url = http_host_com('home') . "/h5/market/sylive2/item/detail?skey={$skey}&click=1"; redirect($my_url); - }elseif ($type=='apt'){ - $my_url = http_host_com('home')."/h5/market/sylive2/act?skey={$skey}&apt=1"; + } elseif ($type == 'apt') { + $my_url = http_host_com('home') . "/h5/market/sylive2/act?skey={$skey}&apt=1"; redirect($my_url); - }else{ - $user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg'); + } else { + $user = $this->user_model->get(['userId' => $this->uid], 'unionid,nickname,headimg'); $userid = $user['unionid'] ? $user['unionid'] : $this->uid; - $ts = time()*1000; - $sign = md5($this->secretkey.$userid.$this->secretkey.$ts); + $ts = time() * 1000; + $sign = md5($this->secretkey . $userid . $this->secretkey . $ts); $live_url = "https://live.haodian.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}"; redirect($live_url); } } + //进入直播间统计 - public function golive(){ + public function golive() + { $params = $this->input->get(); $a_id = $params['a_id']; - $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); - if($row && time()>strtotime($row['timeStart']) && time()<=strtotime($row['timeEnd'])){ - $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); - $this->sylive2_entity->kpi_log(['a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'watch']); - $this->show_json([],200,'操作成功'); - }else{ - $this->show_json([],400,'参数错误'); + $row = $this->market_sylive_activity_model->get(['activityId' => $a_id]); + if ($row && time() > strtotime($row['timeStart']) && time() <= strtotime($row['timeEnd'])) { + $act_user = $this->act_user_model->get(['userId' => $this->uid, 'activityId' => $a_id]); + $this->sylive2_entity->kpi_log(['a_id' => $a_id, 'uid' => $this->uid, 'cf_uid' => $act_user['channelId'], 'kpi' => 'watch']); + $this->show_json([], 200, '操作成功'); + } else { + $this->show_json([], 400, '参数错误'); } } //获取验证码 - public function get_code(){ + public function get_code() + { $mobile = $this->input->post('mobile'); - if(!mobile_valid($mobile)){ - $this->show_json('',400,'请输入正确的手机号码'); + if (!mobile_valid($mobile)) { + $this->show_json('', 400, '请输入正确的手机号码'); } $redis = &load_cache('redis'); - $key = "sylive_appointment_code_".$mobile; + $key = "sylive_appointment_code_" . $mobile; $code = $redis->get($key); - if(!$code){ + if (!$code) { $this->load->helper('string'); $code = random_string('numeric', 4); - $redis->save($key, $code, 60*5); + $redis->save($key, $code, 60 * 5); } $content = "【好店云】您的验证码为: {$code},五分钟之内有效,请勿泄露于他人,!"; - b2m_send_sms($mobile,$content); - $this->show_json('',200, '验证码已发送'); + b2m_send_sms($mobile, $content); + $this->show_json('', 200, '验证码已发送'); } + //预约 - public function appointment(){ + public function appointment() + { $mobile = $this->input->post('mobile'); $code = $this->input->post('code'); $a_id = $this->input->post('a_id'); - if(!$a_id){ - $this->show_json('',400, '参数错误'); + if (!$a_id) { + $this->show_json('', 400, '参数错误'); } $redis = &load_cache('redis'); - $key = "sylive_appointment_code_".$mobile; + $key = "sylive_appointment_code_" . $mobile; $c_code = $redis->get($key); - if(!$code || $code!=$c_code){ - $this->show_json('',400, '请输入正确的验证码'); + if (!$code || $code != $c_code) { + $this->show_json('', 400, '请输入正确的验证码'); } - $row = $this->market_sylive_customer_model->get(['activityId'=>$this->a_id,'mobile'=>$mobile]); - if($row){ + $row = $this->market_sylive_customer_model->get(['activityId' => $this->a_id, 'mobile' => $mobile]); + if ($row) { $update = [ 'ifAppointment' => 1 ]; !$row['userId'] && $update['userId'] = $this->uid; - $this->market_sylive_customer_model->update($update,['customerId'=>$row['customerId']]); - }else{ - $ac_row = $this->market_sylive_activity_model->get(['activityId'=>$a_id],'jsondata'); - $jsondata = json_decode($ac_row['jsondata'],true); - $act_user_row = $this->act_user_model->get(['id'=>$this->act_uid]); - $p_user = $this->act_user_model->get(['userId'=>$act_user_row['channelId'],'activityId' => $a_id]); + $this->market_sylive_customer_model->update($update, ['customerId' => $row['customerId']]); + } else { + $ac_row = $this->market_sylive_activity_model->get(['activityId' => $a_id], 'jsondata'); + $jsondata = json_decode($ac_row['jsondata'], true); + $act_user_row = $this->act_user_model->get(['id' => $this->act_uid]); + $p_user = $this->act_user_model->get(['userId' => $act_user_row['channelId'], 'activityId' => $a_id]); - $ukey = md5($a_id.$mobile); + $ukey = md5($a_id . $mobile); $add_data = [ 'activityId' => $a_id, 'userId' => $this->uid, @@ -563,12 +584,12 @@ class Act extends Wx { $p_user['levelId3'] && $add_data['levelId3'] = $p_user['levelId3']; $add_data['cfUserId'] && $add_data['status'] = 1; $this->market_sylive_customer_model->add($add_data); - if($jsondata['signBespeak']['status'] && $jsondata['signBespeak']['itemId']){ //绑定新增商品订单 + if ($jsondata['signBespeak']['status'] && $jsondata['signBespeak']['itemId']) { //绑定新增商品订单 $itemId = $jsondata['signBespeak']['itemId']; - $item = $this->market_sylive_items_model->get(['itemId'=>$itemId]); + $item = $this->market_sylive_items_model->get(['itemId' => $itemId]); $this->load->helper('order'); $unpay = [ - 'sid' => create_order_no('350200','market'), + 'sid' => create_order_no('350200', 'market'), 'activityId' => $a_id, 'userId' => $this->uid, 'itemId' => $itemId, @@ -587,9 +608,9 @@ class Act extends Wx { $p_user['levelId3'] && $unpay['levelId3'] = $p_user['levelId3']; $p_user['userId'] && $unpay['cfUserId'] = $p_user['userId']; $order_id = $this->market_sylive_order_model->add($unpay); - if(is_numeric($order_id)){ + if (is_numeric($order_id)) { //添加kpi - $params = ['a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user_row['channelId'], 'kpi' => 'beforeOrder']; + $params = ['a_id' => $a_id, 'uid' => $this->uid, 'cf_uid' => $act_user_row['channelId'], 'kpi' => 'beforeOrder']; $order_id && $params['tagId'] = intval($order_id); $params['itemId'] = $itemId; $params['jsondata'] = [ @@ -617,17 +638,17 @@ class Act extends Wx { // $syt->Tj($dlrCode,"活动客户",$mobile,$mediaCaName,$leadNo); // } - if($a_id == 27){ + if ($a_id == 27) { //生产地址 $url = 'https://salesapp.hozonauto.com/appservice/app/if/salesclue/createSalesclue'; //获取意向网点编码 - if($p_user){ - $user = $this->user_model->get(['userId'=>$act_user_row['channelId']]); - $biz = $this->market_sylive_organization_model->get(['organizationId'=>$user['bizId']]); + if ($p_user) { + $user = $this->user_model->get(['userId' => $act_user_row['channelId']]); + $biz = $this->market_sylive_organization_model->get(['organizationId' => $user['bizId']]); } - if($biz['comments']){ + if ($biz['comments']) { $data[] = array( 'cusSource3' => '023410', 'customerName' => "活动客户", @@ -661,11 +682,11 @@ class Act extends Wx { $response = curl_exec($ch); curl_close($ch); - debug_log("[info]# " . $data."\n".$response, 'neta.log','market/sylive'); + debug_log("[info]# " . $data . "\n" . $response, 'neta.log', 'market/sylive'); } } } $redis->delete($key); - $this->show_json(array('ukey' => $ukey),200, '预约成功'); + $this->show_json(array('ukey' => $ukey), 200, '预约成功'); } } diff --git a/home/views/h5/market/sylive2/act/index.php b/home/views/h5/market/sylive2/act/index.php index c1724dc6..5f6ec434 100644 --- a/home/views/h5/market/sylive2/act/index.php +++ b/home/views/h5/market/sylive2/act/index.php @@ -45,24 +45,40 @@ +
+
+
+
+