665 lines
32 KiB
PHP
665 lines
32 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once 'Common.php';
|
|
require_once COMMPATH . 'third_party/phpqrcode/phpqrcode.php';
|
|
|
|
class Act extends Wx {
|
|
|
|
private $item_banner = ['https://qs.haodian.cn/web/images/project/H5-ShiYu/goods.jpg'];
|
|
private $template_id = 'DO0B9IYYub1d0oNvy9czzGbe6_1EU8PQmnLEoDOcmXA';
|
|
private $a_id,$skey;
|
|
|
|
public function __construct(){
|
|
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_order_model');
|
|
$this->load->model('market/market_sylive_customer_model');
|
|
$this->load->model('market/market_sylive_items_model');
|
|
$this->load->library('market/sylive_entity');
|
|
$this->load->library('market/sylive2_entity');
|
|
$this->load->library('qiniu');
|
|
$this->skey = $this->input->get('skey');
|
|
$param = $this->myencryption->base64url_decode($this->skey);
|
|
$this->a_id = intval($param['a_id']);//活动id
|
|
}
|
|
|
|
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);
|
|
}
|
|
$jsondata = json_decode($row['jsondata'],true);
|
|
$bottoms = [];
|
|
if($jsondata['bottoms']){
|
|
foreach ($jsondata['bottoms'] as $key=>$val) {
|
|
$temp = [
|
|
'title' => $val['title'],
|
|
'icon' => build_qiniu_image_url($val['icon'])
|
|
];
|
|
if($val['urlType']=='miniProgram'){
|
|
$temp['type'] = 2;
|
|
$temp['wechat_ghid'] = $val['miniProgramId'];
|
|
$temp['wechat_path'] = $val['url'];
|
|
}else{
|
|
$temp['type'] = 1;
|
|
$temp['url'] = $val['url'];
|
|
}
|
|
$bottoms[] = $temp;
|
|
}
|
|
}
|
|
$info['menu'] = $bottoms;
|
|
$user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg');
|
|
$timeStart = strtotime($row['timeStart']);
|
|
$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]);
|
|
//一次性订阅
|
|
$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']]);
|
|
$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{
|
|
$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
|
|
. '&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";
|
|
}
|
|
}
|
|
//浏览
|
|
$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]); //更新直播间状态
|
|
$live_status = 1; //直播中
|
|
}
|
|
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;
|
|
$info['live_status'] = $live_status;
|
|
$info['skey'] = $this->myencryption->base64url_encode($share_skey);
|
|
$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'];
|
|
$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{
|
|
$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['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']){
|
|
$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']) {
|
|
$auth_url = http_host_com('home') . "/h5/market/sylive2/act/userinfo?skey={$this->skey}&type=apt";
|
|
}
|
|
}
|
|
$info['auth_url'] = $auth_url;
|
|
$info['apt'] = $apt ? true : false; //是否弹窗报名
|
|
$info['ukey'] = $appoint ? md5($this->a_id.$appoint['mobile']) : ''; //是否弹窗报名
|
|
$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['btn_text'] = $jsondata['button']['title'] ? $jsondata['button']['title'] : '开播提醒';
|
|
$this->data['info'] = $info;
|
|
//微信分享
|
|
$wx_info = $this->share_info($row);
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->data['share'] = $wx_info['share'];
|
|
$this->data['_title'] = $row['title'];
|
|
$this->data['skey'] = $info['skey'];
|
|
$this->show_view('h5/market/sylive2/act/index');
|
|
}
|
|
|
|
//获取最新订阅用户
|
|
public function subscribemsg_lists(){
|
|
$map_kpi_name = [
|
|
'browse' => '进入了直播间', 'subscribe' => '订阅了直播通知'
|
|
];
|
|
$a_id = $this->input->get('a_id');
|
|
$live_status = $this->input->get('live_status');
|
|
$field = 'userId,createTime,kpi';
|
|
$lists = [];
|
|
$where = [
|
|
'activityId' => $a_id,
|
|
'kpi' => 'subscribe'
|
|
];
|
|
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);
|
|
$users = [];
|
|
$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');
|
|
}
|
|
foreach ($rows as $item) {
|
|
$nickname = $users[$item['userId']] ? $users[$item['userId']] : "用户{$item['userId']}";
|
|
//报名使用自定标题
|
|
if($jsondata['signBespeak']['status'] && !$live_status && $jsondata['barrage']['title']){
|
|
$tip = $jsondata['barrage']['title'];
|
|
}else{
|
|
$tip = $map_kpi_name[$item['kpi']];
|
|
}
|
|
$lists[] = [
|
|
'name' => $nickname,
|
|
'tip' => $tip,
|
|
];
|
|
}
|
|
}
|
|
$data['lists'] = $lists;
|
|
$this->show_json($data,200);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取授权发送一次性订阅接口
|
|
* Created on: 2020/11/26 17:11
|
|
* Created by: dengbw
|
|
*/
|
|
public function subscribemsg()
|
|
{
|
|
$skey = $this->input->get('skey');
|
|
$s_time = $this->input->get('s_time');//直播时间
|
|
$param = $this->myencryption->base64url_decode($skey);
|
|
$a_id = intval($param['a_id']);//活动id
|
|
$action = $this->input->get('action');
|
|
$show_code = 0;
|
|
if ($s_time && $action == "confirm") {
|
|
$add_data['activityId'] = $a_id;
|
|
$add_data['openId'] = $this->input->get('openid');
|
|
$add_data['scene'] = $this->input->get('scene');
|
|
$re_s = $this->mdSytSubscribemsg->get($add_data);
|
|
if (!$re_s) {
|
|
$add_data['userId'] = $this->uid;
|
|
$add_data['templateId'] = $this->input->get('template_id');
|
|
$add_data['url'] = http_host_com('home') . "/h5/market/sylive2/act?skey=" . $this->myencryption->base64url_encode("a_id=" . $a_id);;
|
|
$add_data['timeStart'] = $s_time;
|
|
$add_data['createTime'] = time();
|
|
$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]);
|
|
//订阅用户加统计
|
|
$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');
|
|
// $p_user = [];
|
|
// $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]);
|
|
// $p_user['teamId'] && $show_code = 1;
|
|
}
|
|
}
|
|
}
|
|
$url = http_host_com('home') . "/h5/market/sylive2/act?skey={$skey}&alert_code={$show_code}";
|
|
redirect($url);
|
|
}
|
|
|
|
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) : [];
|
|
$lists = [];
|
|
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_path = "temp/{$file_name}";
|
|
if (!file_exists(FCPATH.'temp/')) {
|
|
$oldumask = umask(0);
|
|
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);
|
|
$qr_code = build_qiniu_image_url($res['url']);
|
|
}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);
|
|
}
|
|
$lists[] = [
|
|
"img" => $img_url,
|
|
"code" => $qr_code,
|
|
'width' => $img_info['width'] ? $img_info['width'] : 750,
|
|
'height' => $img_info['height'] ? $img_info['height'] : 1130,
|
|
];
|
|
}
|
|
}
|
|
$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{
|
|
$this->data['posterTip'] = "{$user['nickname']}诚挚邀请您参与";
|
|
}
|
|
$this->data['lists'] = $lists;
|
|
$this->data['shareTitle'] = $shareTitle;
|
|
//微信分享
|
|
$wx_info = $this->share_info($row);
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->data['share'] = $wx_info['share'];
|
|
$this->show_view('h5/market/sylive2/act/share');
|
|
}
|
|
|
|
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);
|
|
}
|
|
$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']));
|
|
$validity = "有效期 {$useTimeStart} - {$useTimeEnd}";
|
|
}
|
|
$info = [
|
|
'title' => $item['title'] ? $item['title'] : '',
|
|
'e_time' => $e_time,
|
|
'price' => $item['price'] ? $item['price'] : '',
|
|
'content' => $item['introduction'] ? $item['introduction'] : '',
|
|
'banner' => $banner,
|
|
'stock' => $row['stock'],
|
|
'skey' => $skey,
|
|
'validity' => $validity,
|
|
'introTitle' => '权益说明',
|
|
];
|
|
$this->data['info'] = $info;
|
|
$this->data['_title'] = $row['title'];
|
|
//微信分享
|
|
$wx_info = $this->share_info($row);
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->data['share'] = $wx_info['share'];
|
|
$this->show_view('h5/market/sylive2/act/item');
|
|
}
|
|
|
|
//支付
|
|
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');
|
|
$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,'参数错误');
|
|
}
|
|
$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'] : [];
|
|
//判断是否已支付
|
|
$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($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){
|
|
$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));
|
|
}
|
|
try {
|
|
$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']]);
|
|
$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){
|
|
throw new Exception('限购一件');
|
|
}
|
|
$this->load->helper('order');
|
|
$unpay = [
|
|
'sid' => create_order_no('350200','market'),
|
|
'userId' => $this->uid,
|
|
'itemId' => $a_id,
|
|
'itemTitle' => $item['title'],
|
|
'totalPrice' => $pay_price,
|
|
'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)){
|
|
$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,$e->getMessage());
|
|
}
|
|
}
|
|
$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']);
|
|
}
|
|
$this->show_json($result['data'],200,'操作成功');
|
|
}
|
|
|
|
//获取微信用户信息
|
|
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;
|
|
}
|
|
$skey = $this->input->get('skey');
|
|
$type = $this->input->get('type');
|
|
if (!$skey) {
|
|
throw new Hd_exception("参数错误", 400);
|
|
}
|
|
$param = $this->myencryption->base64url_decode($skey);
|
|
$a_id = intval($param['a_id']);//活动id
|
|
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);
|
|
}
|
|
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}";
|
|
redirect($my_url);
|
|
}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";
|
|
redirect($my_url);
|
|
}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);
|
|
$live_url = "https://live.haodian.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}";
|
|
redirect($live_url);
|
|
}
|
|
}
|
|
//进入直播间统计
|
|
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,'参数错误');
|
|
}
|
|
}
|
|
|
|
//获取验证码
|
|
public function get_code(){
|
|
$mobile = $this->input->post('mobile');
|
|
if(!mobile_valid($mobile)){
|
|
$this->show_json('',400,'请输入正确的手机号码');
|
|
}
|
|
$redis = &load_cache('redis');
|
|
$key = "sylive_appointment_code_".$mobile;
|
|
$code = $redis->get($key);
|
|
if(!$code){
|
|
$this->load->helper('string');
|
|
$code = random_string('numeric', 4);
|
|
$redis->save($key, $code, 60*5);
|
|
}
|
|
$content = "【好店云】您的验证码为: {$code},五分钟之内有效,请勿泄露于他人,!";
|
|
b2m_send_sms($mobile,$content);
|
|
$this->show_json('',200, '验证码已发送');
|
|
}
|
|
//预约
|
|
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, '参数错误');
|
|
}
|
|
$redis = &load_cache('redis');
|
|
$key = "sylive_appointment_code_".$mobile;
|
|
$c_code = $redis->get($key);
|
|
if(!$code || $code!=$c_code){
|
|
$this->show_json('',400, '请输入正确的验证码');
|
|
}
|
|
$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 = [];
|
|
$act_user_row['channelId'] && $p_user = $this->act_user_model->get(['userId'=>$act_user_row['channelId'],'activityId'=>$a_id]);
|
|
$ukey = md5($a_id.$mobile);
|
|
$add_data = [
|
|
'activityId' => $a_id,
|
|
'userId' => $this->uid,
|
|
'ukey' => $ukey,
|
|
'ifAppointment' => 1,
|
|
'mobile' => $mobile,
|
|
'createTime' => date('Y-m-d H:i:s'),
|
|
'level' => 'H'
|
|
];
|
|
$act_user_row['channelId'] && $add_data['cfUserId'] = $act_user_row['channelId'];
|
|
$p_user['bizId'] && $add_data['bizId'] = $p_user['bizId'];
|
|
$p_user['levelId1'] && $add_data['levelId1'] = $p_user['levelId1'];
|
|
$p_user['levelId2'] && $add_data['levelId2'] = $p_user['levelId2'];
|
|
$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']){ //绑定新增商品订单
|
|
$itemId = $jsondata['signBespeak']['itemId'];
|
|
$item = $this->market_sylive_items_model->get(['itemId'=>$itemId]);
|
|
$this->load->helper('order');
|
|
$unpay = [
|
|
'sid' => create_order_no('350200','market'),
|
|
'activityId' => $a_id,
|
|
'userId' => $this->uid,
|
|
'itemId' => $itemId,
|
|
'itemTitle' => $item['title'],
|
|
'itemPrice' => 0,
|
|
'totalPrice' => 0,
|
|
'expireTime' => 0,//订单过sylive2_entity期时间
|
|
'status' => 1,
|
|
'payTime' => date('Y-m-d H:i:s'),
|
|
'createTime' => date('Y-m-d H:i:s')
|
|
];
|
|
$mobile && $unpay['mobile'] = $mobile;
|
|
$p_user['bizId'] && $unpay['bizId'] = $p_user['bizId'];
|
|
$p_user['levelId1'] && $unpay['levelId1'] = $p_user['levelId1'];
|
|
$p_user['levelId2'] && $unpay['levelId2'] = $p_user['levelId2'];
|
|
$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)){
|
|
//添加kpi
|
|
$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'] = [
|
|
'sid' => $unpay['sid'],
|
|
'order_id' => intval($order_id)
|
|
];
|
|
$this->sylive2_entity->kpi_log($params);
|
|
}
|
|
}
|
|
// if($a_id==27){
|
|
// //通知第三方
|
|
// require_once COMMPATH . 'third_party/SytApi.php';
|
|
// $syt = new SytApi();
|
|
// $dlrCode = "";
|
|
// $mediaCaName = "";
|
|
// $leadNo = $this->uid;
|
|
// //获取意向网点编码
|
|
// if($p_user){
|
|
// $user = $this->user_model->get(['userId'=>$act_user_row['channelId']]);
|
|
// $mediaCaName = $user['uname'];
|
|
// $group_user = $this->groups_user_model->get(['activityId' => $a_id, 'userId' => $act_user_row['channelId'], 'status' => 0]);
|
|
// $biz = $this->market_sylive_organization_model->get(['organizationId'=>$group_user['bizId']]);
|
|
// $dlrCode = $biz['comments'];
|
|
// }
|
|
// $syt->Tj($dlrCode,"活动客户",$mobile,$mediaCaName,$leadNo);
|
|
// }
|
|
|
|
// 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']]);
|
|
// }
|
|
//
|
|
// $data[] = array(
|
|
// 'cusSource3' => '023409',
|
|
// 'customerName' => "活动客户",
|
|
// 'dealerCode' => $biz['comments'],
|
|
// 'fromSystem' => "好店云",
|
|
// 'mobile' => $mobile,
|
|
// 'saMobile' => $user['mobile'],
|
|
// 'cusType' => '30111001',
|
|
// 'remark' => "2024新春",
|
|
// );
|
|
//
|
|
// $data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
//
|
|
// $ch = curl_init();
|
|
// curl_setopt($ch, CURLOPT_POST, 1);
|
|
// curl_setopt($ch, CURLOPT_URL, $url);
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
//
|
|
// //https
|
|
// if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
|
|
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
// }
|
|
//
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
// 'Content-Type: application/json; charset=utf-8',
|
|
// 'Content-Length: ' . strlen($data)
|
|
// )
|
|
// );
|
|
//
|
|
// $response = curl_exec($ch);
|
|
// curl_close($ch);
|
|
// debug_log("[info]# " . $data."\n".$response, 'neta.log','market/sylive');
|
|
// }
|
|
}
|
|
$redis->delete($key);
|
|
$this->show_json(array('ukey' => $ukey),200, '预约成功');
|
|
}
|
|
}
|