diff --git a/api/controllers/plan/Syt.php b/api/controllers/plan/Syt.php
new file mode 100644
index 00000000..00aa8bb4
--- /dev/null
+++ b/api/controllers/plan/Syt.php
@@ -0,0 +1,104 @@
+ options = [
+ 'token' => '',
+ 'appid' => 'wxe66f905683582780',
+ 'appsecret' => '9546cd4de877be13ce203f3e6140633f',
+ 'encodingaeskey' => '',
+ 'debug' => false
+ ];
+ }
+
+ /**
+ * Notes:发送一次性订阅
+ * Created on: 2020/11/30 17:02
+ * Created by: dengbw
+ * https://hd-api-dev.xiaoyu.com/plan/syt/subscribemsg
+ * https://api.test.haodian.cn/plan/syt/subscribemsg
+ * https://api.haodian.cn/plan/syt/subscribemsg
+ */
+ public function subscribemsg()
+ {
+ $this->load->model('market/market_sylive_subscribemsg_model','mdSytSubscribemsg');
+ $date = date('Y-m-d H:i:s', strtotime('+2 minute'));//提前2分钟发送
+ $where['s_time<='] = $date;
+ $where['status'] = 0;
+ $res = $this->mdSytSubscribemsg->select($where, 'id asc', 1, 200);
+ $log = array();
+ if ($res) {
+ $this->load->model('market/market_sylive_activity_model','mdSytActivity');
+ $wechatS = new WechatServer($this->options);
+ $wechatS->checkAuth();
+ foreach ($res as $key => $value) {
+ $re_a = $this->mdSytActivity->get(array("activityId" => $value['a_id'], "status" => 0));
+ if ($re_a) {
+ $content = '您预约“' . $re_a['title'] . '”直播已经开始啦!赶紧进入直播间观看直播领取福利吧~';
+ $temp_arr = array(
+ 'touser' => $value['openid'],
+ 'template_id' => $value['template_id'],
+ 'url' => $value['url'],
+ 'scene' => $value['scene'],
+ 'title' => '开播提醒',
+ 'data' => array(
+ 'content' => array('value' => $content)
+ )
+ );
+ $re = $wechatS->subscribeTemplateMessage($temp_arr);
+ if ($re) {//errcode 0(发送成功) 43101(已发送过)
+ $this->mdSytSubscribemsg->update(['status' => 1], ['id' => $value['id']]);
+ if ($re['errcode'] == 0) {
+ $log[] = $value['a_id'] . '=' . $value['openid'];
+ }
+ }
+ }
+ }
+ }
+ echo '
数据库获取:';
+ echo json_encode($res, JSON_UNESCAPED_UNICODE);
+ echo '
成功发送:';
+ $log && print_r($log);
+ $total = count($res);
+ $do = count($log);
+ debug_log("[info] " . __FUNCTION__ . "# date:{$date}; total:{$total}; do:{$do};", $this->log_file);
+ }
+
+ public function test(){
+ require_once(COMMPATH . "/third_party/WeChat/WechatServer.php");
+ $options = [
+ 'token' => '',
+ 'appid' => 'wxe66f905683582780',
+ 'appsecret' => '9546cd4de877be13ce203f3e6140633f',
+ 'encodingaeskey' => '',
+ 'debug' => false
+ ];
+ $wechatS = new WechatServer($options);
+ $token = $wechatS->checkAuth();
+ $content = '您预约直播已经开始啦!赶紧进入直播间观看直播领取福利吧~';
+ $temp_arr = array(
+ 'touser' => 'ospBg6AXMlXNdgv_rzbFvBXAD4TU',
+ 'template_id' => '4eHuGYK69_GTjOlzkp8HK8iJNFuKboTpO7Igc1CC_fQ',
+ 'url' => 'https://liche-dev.xiaoyu.com/h5/market/sylive/act?skey=aWQ9MQ',
+ 'scene' => 0,
+ 'title' => '开播提醒',
+ 'data' => array(
+ 'content' => array('value' => $content)
+ )
+ );
+ $re = $wechatS->subscribeTemplateMessage($temp_arr);
+ }
+
+}
\ No newline at end of file
diff --git a/api/third_party/WXconfig/liche_home_WxPay.Config.php b/api/third_party/WXconfig/liche_home_WxPay.Config.php
new file mode 100755
index 00000000..1883e2ee
--- /dev/null
+++ b/api/third_party/WXconfig/liche_home_WxPay.Config.php
@@ -0,0 +1,29 @@
+ 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch'
+ ];
+
+ public function __construct(){
+ $this->ci = &get_instance();
+ $this->ci->load->model('market/market_sylive_user_model', 'user_model');
+ $this->ci->load->model('market/market_sylive_activity_model');
+ $this->ci->load->model('market/market_sylive_activity_biz_model','mdSytActivityBiz');
+ $this->ci->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData');
+ $this->ci->load->model('market/market_sylive_organization_model');
+ }
+
+ /**
+ * @param $organizationId 机构id
+ * @param $level 0品牌-管理大区 1 督导-权限范围内所有门店 2 店长-门店所有权限 3 顾问-个人权限 4普通用户-没有权限
+ * @return int|mixed
+ */
+ public function get_level($organizationId,$level=0){
+ if(!$organizationId){
+ return 4;
+ }
+ $row = $this->ci->market_sylive_organization_model->get(['organizationId'=>$organizationId],'organizationId,parentId');
+ if(!$row){
+ return 4;
+ }
+ if($row['parentId']){
+ $temp = $level+1;
+ return $this->get_level($row['parentId'],$temp);
+ }
+ return $level;
+ }
+
+ /**
+ * 获取等级数据
+ * @param $organizationId
+ * @param $data
+ * @return int
+ */
+ public function get_level_lists($organizationId,$data=[]){
+ $this->ci->load->model('market/market_sylive_organization_model');
+ $row = $this->ci->market_sylive_organization_model->get(['organizationId'=>$organizationId],'organizationId,parentId,organizationName');
+ if(!$row){
+ return $data;
+ }else{
+ array_unshift($data,$row);
+ if($row['parentId']){
+ return $this->get_level_lists($row['parentId'],$data);
+ }else{
+ return $data;
+ }
+ }
+ }
+
+ /**
+ * Notes:添加kpi记录
+ * Created on: 2021/1/13 11:20
+ * Created by: dengbw
+ * @param $params
+ * @return array
+ */
+ public function kpi_log($params)
+ {
+ if ($params['a_id'] && $params['uid'] && $params['cf_uid']) {
+ $user = $this->user_model->get(['userId'=>$params['cf_uid']]);
+ if(!$user){
+ return array('code' => 0, 'msg' => '顾问不存在');
+ }
+ $re_a = $this->ci->market_sylive_activity_model->get(array("activityId" => $params['a_id'], "status" => 0));
+ $now_time = time();
+ if(!in_array($params['kpi'],['subscribe','browse'])){ //无需活动开始
+ if ((!$re_a || $now_time < strtotime($re_a['timeStart']) || $now_time > strtotime($re_a['timeEnd']))) {
+ return array('code' => 0, 'msg' => '无活动或未在活动时间内');
+ }
+ }
+ $re_kpi = $this->ci->mdSytActivityKpiData->get(array("a_id" => $params['a_id'], 'uid' => $params['uid'], 'kpi' => $params['kpi']));
+ if ($re_kpi) {//已添加过活动kpi(访活动只记录一次用户kpi记录)
+ return array('code' => 0, 'msg' => '已添加过' . $params['kpi'] . '记录');
+ }
+ $level_lists = $this->get_level_lists($user['organizationId']);
+ if($level_lists){
+ //获取大区id
+ $area_id = $level_lists[1]['organizationId'];
+ //获取店铺id
+ $biz_id = $level_lists[2]['organizationId'];
+ }
+ //增加记录
+ $addData = [
+ 'a_id' => $params['a_id'],
+ 'uid' => $params['uid'],
+ 'cf_uid' => $params['cf_uid'],
+ 'kpi' => $params['kpi'],
+ 'c_time' => time()
+ ];
+ $area_id && $addData['area_id'] = $area_id;
+ $biz_id && $addData['biz_id'] = $biz_id;
+ $jsondata = array();
+ $jsondata && $addData['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
+ $id = $this->ci->mdSytActivityKpiData->add($addData);
+ if (!$id) {
+ return array('code' => 0, 'msg' => '添加记录失败');
+ }
+ if($this->map_kpi_biz[$params['kpi']] && $biz_id){//更新门店统计数据
+ $up_key = $this->map_kpi_biz[$params['kpi']];
+ $update[$up_key] = $this->ci->mdSytActivityKpiData->count(['a_id'=>$params['a_id'],'biz_id'=>$biz_id,'kpi'=>$params['kpi']]);
+ $this->ci->mdSytActivityBiz->update($update,['activityId'=>$params['a_id'],'bizId'=>$biz_id]);
+ }
+ return array('code' => 1, 'msg' => '添加记录成功');
+ } else {
+ return array('code' => 0, 'msg' => '参数错误');
+ }
+ }
+
+ //排行数据
+ public function top_lists($aid,$type='browse',$page=1,$size=10,$biz_id=0){
+ $lists = [];
+ $where = [
+ 'activityId' => $aid,
+ 'status' => 0
+ ];
+ $total = $this->ci->mdSytActivityBiz->count($where);
+ $field = $this->map_kpi_biz[$type];
+ if($total && $field){
+ $rows = $this->ci->mdSytActivityBiz->select($where,"{$field} desc",$page,$size);
+ $biz_ids = implode(',',array_column($rows,'bizId'));
+ $org_rows = [];
+ if($biz_ids){
+ $org_rows = $this->ci->market_sylive_organization_model->map('organizationId','organizationName',["organizationId in ($biz_ids)"],'','','','organizationId,organizationName');
+ }
+ foreach ($rows as $key=>$val) {
+ $lists[] = [
+ 'ranking' => $key+1,
+ 'name' => $org_rows[$val['bizId']] ? $org_rows[$val['bizId']] : '',
+ 'num' => $val[$this->map_kpi_biz[$type]].'人',
+ 'tip' => $biz_id==$val['bizId'] ? '本店' : '',
+ ];
+ }
+ }
+ $data = [
+ 'total' => $total,
+ 'lists' => $lists
+ ];
+ return $data;
+ }
+
+ public function __get($name)
+ {
+ if ('_model' === substr($name, -6)) {
+ return $this->ci->$name;
+ } elseif ('load' == $name) {
+ return $this->ci->load;
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_activity_biz_model.php b/common/models/market/Market_sylive_activity_biz_model.php
new file mode 100644
index 00000000..e578ea3c
--- /dev/null
+++ b/common/models/market/Market_sylive_activity_biz_model.php
@@ -0,0 +1,11 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_activity_kpidata_model.php b/common/models/market/Market_sylive_activity_kpidata_model.php
new file mode 100644
index 00000000..7d8bf35b
--- /dev/null
+++ b/common/models/market/Market_sylive_activity_kpidata_model.php
@@ -0,0 +1,12 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_activity_model.php b/common/models/market/Market_sylive_activity_model.php
new file mode 100644
index 00000000..108babe3
--- /dev/null
+++ b/common/models/market/Market_sylive_activity_model.php
@@ -0,0 +1,18 @@
+table_name, 'default');
+ }
+
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_activity_user_model.php b/common/models/market/Market_sylive_activity_user_model.php
new file mode 100644
index 00000000..056d2740
--- /dev/null
+++ b/common/models/market/Market_sylive_activity_user_model.php
@@ -0,0 +1,11 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_order_model.php b/common/models/market/Market_sylive_order_model.php
new file mode 100644
index 00000000..881b15f3
--- /dev/null
+++ b/common/models/market/Market_sylive_order_model.php
@@ -0,0 +1,35 @@
+table_name, 'default');
+ }
+
+ /**
+ * Notes:支付状态
+ * Created on: 2022/9/26 14:46
+ * Created by: dengbw
+ * @param string $status
+ * @return array|mixed
+ */
+ public function statusAry($status = '')
+ {
+ $arr = [0 => '未支付', 1 => '已支付'];
+ if (strlen($status)) {
+ return $arr[$status];
+ } else {
+ return $arr;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_organization_model.php b/common/models/market/Market_sylive_organization_model.php
new file mode 100644
index 00000000..4ea875b5
--- /dev/null
+++ b/common/models/market/Market_sylive_organization_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_subscribemsg_model.php b/common/models/market/Market_sylive_subscribemsg_model.php
new file mode 100644
index 00000000..177a97d8
--- /dev/null
+++ b/common/models/market/Market_sylive_subscribemsg_model.php
@@ -0,0 +1,12 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sylive_user_model.php b/common/models/market/Market_sylive_user_model.php
new file mode 100644
index 00000000..cdfb3c40
--- /dev/null
+++ b/common/models/market/Market_sylive_user_model.php
@@ -0,0 +1,52 @@
+table_name, 'default');
+ }
+
+ /**
+ * Notes:用户角色
+ * Created on: 2022/9/20 11:04
+ * Created by: dengbw
+ * @param string $roleId
+ * @return array|mixed
+ */
+ public function roleAry($roleId = '')
+ {
+ $arr = [1 => '品牌', 2 => '区域', 3 => '店长', 4 => '顾问'];
+ if (strlen($roleId)) {
+ return $arr[$roleId];
+ } else {
+ return $arr;
+ }
+ }
+
+ /**
+ * Notes:性别
+ * Created on: 2022/9/21 14:34
+ * Created by: dengbw
+ * @param string $sex
+ * @return array|mixed
+ */
+ public function sexAry($sex = '')
+ {
+ $arr = [0 => '未知', 1 => '男', 2 => '女'];
+ if (strlen($sex)) {
+ return $arr[$sex];
+ } else {
+ return $arr;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sys_admin_model.php b/common/models/market/Market_sys_admin_model.php
new file mode 100644
index 00000000..a5253a86
--- /dev/null
+++ b/common/models/market/Market_sys_admin_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sys_dictionary_data_model.php b/common/models/market/Market_sys_dictionary_data_model.php
new file mode 100644
index 00000000..c23ae56e
--- /dev/null
+++ b/common/models/market/Market_sys_dictionary_data_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sys_dictionary_model.php b/common/models/market/Market_sys_dictionary_model.php
new file mode 100644
index 00000000..068d0a57
--- /dev/null
+++ b/common/models/market/Market_sys_dictionary_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sys_login_record_model.php b/common/models/market/Market_sys_login_record_model.php
new file mode 100644
index 00000000..586157df
--- /dev/null
+++ b/common/models/market/Market_sys_login_record_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sys_menu_model.php b/common/models/market/Market_sys_menu_model.php
new file mode 100644
index 00000000..33db7958
--- /dev/null
+++ b/common/models/market/Market_sys_menu_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sys_operation_record_model.php b/common/models/market/Market_sys_operation_record_model.php
new file mode 100644
index 00000000..e8aecea2
--- /dev/null
+++ b/common/models/market/Market_sys_operation_record_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/common/models/market/Market_sys_role_model.php b/common/models/market/Market_sys_role_model.php
new file mode 100644
index 00000000..67bfdec4
--- /dev/null
+++ b/common/models/market/Market_sys_role_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/home/config/wechat.php b/home/config/wechat.php
index cbe89dd2..b67009a0 100755
--- a/home/config/wechat.php
+++ b/home/config/wechat.php
@@ -9,4 +9,6 @@ if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//狸车-服务号
$config['liche']['appid'] = 'wxe66f905683582780';
-$config['liche']['appSecret'] = '9546cd4de877be13ce203f3e6140633f';
\ No newline at end of file
+$config['liche']['appSecret'] = '9546cd4de877be13ce203f3e6140633f';
+$config['liche']['token'] = 'iuvkjhz457854';
+$config['liche']['appsecret'] = 'Ay2qHzlKEpPxdMzUSy5bjJcyL5lZxotOf7JThlDKQdQ';
\ No newline at end of file
diff --git a/home/controllers/h5/market/sylive/Act.php b/home/controllers/h5/market/sylive/Act.php
new file mode 100644
index 00000000..47cf414d
--- /dev/null
+++ b/home/controllers/h5/market/sylive/Act.php
@@ -0,0 +1,336 @@
+load->model('market/market_sylive_organization_model');
+ $this->load->model('market/market_sylive_activity_model');
+ $this->load->model('market/market_sylive_subscribemsg_model','mdSytSubscribemsg');
+ $this->load->model('market/market_sylive_order_model');
+ $this->load->library('market/sylive_entity');
+ $this->group_id = $this->sylive_entity->get_level($this->session['org_id']);
+ }
+
+ public function index(){
+ $skey = $this->input->get('skey');
+ 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);
+ }
+ $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'=>$a_id]);
+ //一次性订阅
+ $re_s = $this->mdSytSubscribemsg->get(array('a_id' => $a_id, 'uid' => $this->uid));
+ if ($re_s) {
+ $subscribemsg = '已订阅直播';
+ } else {
+ $this->load->config('wechat');
+ $config = $this->config->item('liche');
+ $sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive/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=sdJ4eXXA3OdMZVkJdOrzusYLGr0Jpz9I7WiZurgGLBs&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect";
+ }
+ //浏览
+ $params = array('a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'browse');
+ $this->sylive_entity->kpi_log($params);
+ $live_status = 0;
+ if(time()>strtotime($row['timeStart']) && time()<=strtotime($row['timeEnd'])){ //直播期间人数
+ $this->sylive_entity->kpi_log(['a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'watch']);
+ $row['liveStatus']!=1 && $this->market_sylive_activity_model->update(['liveStatus'=>1],['activityId'=>$a_id]); //更新直播间状态
+ $live_status = 1;
+ }
+ if(time()>strtotime($row['timeEnd'])){ //直播结束
+ $row['liveStatus']!=2 && $this->market_sylive_activity_model->update(['liveStatus'=>2],['activityId'=>$a_id]); //更新直播间状态
+ $live_status = 2;
+ }
+ $share_skey = "a_id=" . $a_id . "&cf_uid=" . $this->uid . "&cf_share=" . $this->myencryption->random_string(6);
+ //微信分享
+ $share_url = http_host_com('home') . "/h5/market/sylive/act?skey=" . $this->myencryption->base64url_encode($share_skey);
+ $this->load->library('Jssdk');
+ $jssdk = new Jssdk('liche');
+ $sign_package = $jssdk->getSignPackage();
+ $share = array(
+ 'title' => $row['title'],
+ "img" => $row['bgImg'] ? build_qiniu_image_url($row['bgImg']) : '',
+ "desc" => '分享描述',
+ "url" => $share_url
+ );
+ //直播参数
+ $live_user = ['userId' => 888888888, 'userName' => '私域直播', 'pic' => '//livestatic.videocc.net/assets/wimages/missing_face.png'];
+ $this->load->library('PolyvApi');
+ $polyv = new PolyvApi();
+ $liveSdk = $polyv->getLiveSdk();
+ $liveSdk['user'] = $live_user;
+ $info['live_status'] = $live_status;
+ $info['liveSdk'] = $liveSdk;
+ $info['skey'] = $this->myencryption->base64url_encode($share_skey);
+ $info['a_id'] = $a_id;
+ $info['org_id'] = $this->session['org_id'];
+ $info['subscribemsg'] = $subscribemsg;
+ $info['shareurl'] = $info['code'] = '';
+ if($this->group_id==3||$this->group_id==2){
+ $info['shareurl'] = '/h5/market/sylive/act/share?skey='.$info['skey'];
+ }
+ $info['statisticsurl'] = '/h5/market/sylive/stic?skey='.$info['skey'];
+ $info['channelImg'] = build_qiniu_image_url($row['channelImg']);
+ $this->data['info'] = $info;
+ $this->data['sign_package'] = $sign_package;
+ $this->data['share'] = $share;
+ $this->show_view('h5/market/sylive/act/index');
+ }
+
+ //获取最新订阅用户
+ public function subscribemsg_lists(){
+ $a_id = $this->input->get('a_id');
+ $field = '';
+ $lists = [];
+ $where = [
+ 'a_id' => $a_id
+ ];
+ $rows = $this->mdSytSubscribemsg->select($where,'id desc',0,30,$field);
+ if($rows){
+ foreach ($rows as $item) {
+ $lists[] = [
+ 'name' => substr($item['openid'], 0, 3) . "****" . substr($item['openid'], 7, 4),
+ 'tip' => friendly_date($item['c_time']).'订阅了直播提醒',
+ ];
+ }
+ }
+ $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');
+ if ($s_time && $action == "confirm") {
+ $add_data['a_id'] = $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['uid'] = $this->uid;
+ $add_data['template_id'] = $this->input->get('template_id');
+ $add_data['url'] = http_host_com('home') . "/h5/market/sylive/act?skey=" . $this->myencryption->base64url_encode("a_id=" . $a_id);;
+ $add_data['s_time'] = $s_time;
+ $add_data['c_time'] = 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');
+ $this->sylive_entity->kpi_log($params);
+ }
+ }
+ }
+ $url = http_host_com('home') . "/h5/market/sylive/act?skey={$skey}";
+ redirect($url);
+ }
+
+ public function share(){
+ if($this->group_id!=2 && $this->group_id!=3){
+ throw new Hd_exception("页面不存在", 400);
+ }
+ $skey = $this->input->get('skey');
+ if (!$skey) {
+ throw new Hd_exception("参数错误", 400);
+ }
+ $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);
+ }
+ $shareImg = json_decode($row['shareImg'],true);
+ $shareTitle = $row['shareTitle'] ? json_decode($row['shareTitle'],true) : [];
+ $lists = [];
+ if($shareImg){
+ $share_skey = "a_id=" . $a_id . "&cf_uid=" . $this->uid . "&cf_share=" . $this->myencryption->random_string(6);
+ $share_url = http_host_com('home') . "/h5/market/sylive/act?skey=" . $this->myencryption->base64url_encode($share_skey);
+ $qr_code = '/h5/market/sylive/myqrcode/get?url=' . $share_url;
+ foreach ($shareImg as $item) {
+ $lists[] = [
+ "img" => build_qiniu_image_url($item),
+ "code" => $qr_code,
+ 'width' => 750,
+ 'height' => 1130,
+ ];
+ }
+ }
+ $user = $this->user_model->get(['userId'=>$this->uid]);
+ $this->data['posterTip'] = '狸车集美店李菲菲诚挚邀请您参与';
+ $this->data['lists'] = $lists;
+ $this->data['shareTitle'] = $shareTitle;
+ $this->show_view('h5/market/sylive/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(['item_id'=>$a_id,'status'=>1,'uid'=>$this->uid]);
+ $e_time = time() < strtotime($row['timeEnd']) ? strtotime($row['timeEnd']) - time() : 0;
+ $banner = [];
+ if($item['itemImg']){
+ foreach ($item['itemImg'] as $value) {
+ $banner[] = build_qiniu_image_url($value);
+ }
+ }
+ $info = [
+ 'title' => $item['title'] ? $item['title'] : '',
+ 'e_time' => $e_time,
+ 'price' => $item['price'] ? $item['price'] : '',
+ 'content' => $item['introduction'] ? $item['introduction'] : '',
+ 'banner' => $banner,
+ 'skey' => $skey,
+ 'is_pay' => $is_pay
+ ];
+ $this->data['info'] = $info;
+ $this->show_view('h5/market/sylive/act/item');
+ }
+
+ //支付
+ public function post_pay(){
+ $skey = $this->input->post('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){
+ $this->show_json('',400,'参数错误');
+ }
+ $jsondata = json_decode($row['jsondata'],true);
+ $item = $jsondata['item'] ? $jsondata['item'] : [];
+ //判断是否已支付
+ $o_row = $this->market_sylive_order_model->get(['item_id'=>$a_id,'status'=>1,'uid'=>$this->uid]);
+ if($o_row){
+ $this->show_json('',400,'已支付,请勿重复支付');
+ }
+ $pay_price = $item['price'];
+ if($pay_price<=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->load->helper('order');
+ $unpay = [
+ 'sid' => create_order_no(),
+ 'uid' => $this->uid,
+ 'item_id' => $a_id,
+ 'item_title' => $item['title'],
+ 'total_price' => $pay_price,
+ 'expire_time' => time()+24*60*60,//订单过期时间
+ 'createTime' => date('Y-m-d H:i:s')
+ ];
+ $oid = $this->market_sylive_order_model->add($unpay);
+ if(!is_numeric($oid)){
+ $this->show_json('',400,'创建订单失败');
+ }
+ }
+ $user = $this->user_model->get(['userId'=>$this->uid]);
+ $notify_url = http_host_com('home').'//h5/market/sylive/notify';
+ $result = $this->pay($unpay['sid'],$unpay['total_price'],$user['openid'],$unpay['item_title'],$notify_url,$unpay['expire_time']);
+ if(!$result['code']){
+ $this->show_json('',400,$result['msg']);
+ }
+ $this->show_json($result['data'],200,'操作成功');
+ }
+ public function ucenter(){
+ $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'] : [];
+ $banner = [];
+ if($item['itemImg']){
+ foreach ($item['itemImg'] as $value) {
+ $banner[] = build_qiniu_image_url($value);
+ }
+ }
+ $order = $this->market_sylive_order_model->get(['uid'=>$this->uid,'status'=>1,'item_id'=>$a_id]);
+ $pay_text = $order ? '(已支付)' : '(未支付)';
+ $info = [
+ 'title' => $item['title'].$pay_text,
+ 'content' => $item['introduction'],
+ 'banner' => $banner,
+ ];
+ $this->data['info'] = $info;
+ $this->show_view('h5/market/sylive/act/ucenter');
+ }
+
+ /**
+ * 支付
+ * @param $trade_no
+ * @param $price
+ * @param $openid
+ * @param $body
+ * @param $notify_url 异步通知
+ * @param $expire_time 过期时间
+ * @param $attach
+ * @return bool|json数据,可直接填入js函数作为参数|mixed
+ * @throws WxPayException
+ */
+ private function pay($trade_no,$price,$openid,$body,$notify_url,$expire_time,$attach=''){
+
+ if(!$body){return false;}
+ require_once APPPATH."../api/third_party/WXconfig/liche_home_WxPay.Config.php";
+ require_once APPPATH."../api/third_party/WXpay/WxPay.Api.php";
+ $config = new WxPayConfig();
+ $wxpay = new WxPayUnifiedOrder();
+ $wxpay->SetVersion('1.0');
+ $wxpay->SetBody($body); //简单描述
+ $attach && $wxpay->SetAttach($attach); //附加信息
+ $wxpay->SetNotify_url($notify_url);
+ $wxpay->SetOut_trade_no($trade_no); //订单号
+ $wxpay->SetTotal_fee($price * 100); //支付价格
+ $wxpay->SetTime_start(date("YmdHis")); //交易起始时间
+ $wxpay->SetTime_expire(date('YmdHis',$expire_time)); //交易结束时间
+ $wxpay->SetTrade_type("JSAPI"); //设置交易类型
+ $wxpay->SetOpenid($openid); //openid
+ $return = WxPayApi::unifiedOrder($config, $wxpay); //统一支付
+ if($return['result_code'] == 'SUCCESS') {
+ $wxpay_api = new WxPayJsApiPay();
+ $jsApiParameters = WxPayApi::GetJsApiParameters($return, $config, $wxpay_api);
+ $jsApiParameters = json_decode($jsApiParameters, true);
+ return ['code'=>1,'data'=>$jsApiParameters,'msg'=>'下单成功'];
+ }else{
+ $msg = $return['return_msg'] ? $return['return_msg'].$return['err_code_des'] : $return['return_msg'];
+ return ['code'=>0,'data'=>[],'msg'=>$msg];
+ }
+ }
+}
diff --git a/home/controllers/h5/market/sylive/Biz.php b/home/controllers/h5/market/sylive/Biz.php
new file mode 100644
index 00000000..afcbaa70
--- /dev/null
+++ b/home/controllers/h5/market/sylive/Biz.php
@@ -0,0 +1,266 @@
+load->model('market/market_sylive_organization_model');
+ $this->load->model('market/market_sylive_activity_model');
+ $this->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData');
+ $this->load->library('market/sylive_entity');
+ $this->load->library('MyEncryption');
+ $this->group_id = $this->sylive_entity->get_level($this->session['org_id']);
+ }
+
+ public function index(){
+ if($this->group_id>3){
+ throw new Hd_exception('权限不足',400);
+ }
+ $this->data['area_id'] = $this->input->get('area_id');
+ $this->data['biz_id'] = $biz_id = $this->input->get('biz_id');
+ $this->data['group_id'] = $this->group_id;
+ $row = $this->market_sylive_organization_model->get(['organizationId'=>$biz_id]);
+ $this->data['headimg'] = $this->liche_img;
+ $this->data['biz_name'] = $row['organizationName'];
+ $this->show_view('h5/market/sylive/biz/index');
+ }
+
+ //店铺列表
+ public function lists(){
+ if($this->group_id>1){
+ throw new Hd_exception('权限不足',400);
+ }
+ $area_id = $this->input->get('area_id');
+ $this->data['area_id'] = $area_id;
+ $this->data['group_id'] = $this->group_id;
+ $this->show_view('h5/market/sylive/biz/lists');
+ }
+ //大区列表
+ public function brands(){
+ if($this->group_id!=0){
+ throw new Hd_exception('权限不足',400);
+ }
+ $this->show_view('h5/market/sylive/biz/brands');
+ }
+ //顾问
+ public function detail(){
+ if($this->group_id!=3){
+ throw new Hd_exception('权限不足',400);
+ }
+ $this->show_view('h5/market/sylive/biz/detail');
+ }
+ public function nav(){
+ if($this->group_id>1){
+ $this->show_json([],200);
+ }
+ $area_id = $this->input->get('area_id');
+ $user = $this->user_model->get(['userId'=>$this->uid]);
+ $data = [
+ 'nickname' => $user['nickname'],
+ 'headimg' => $this->liche_img
+ ];
+ if($this->group_id==1 || $area_id){ //所有店铺
+ !$area_id && $area_id = $this->session['org_id'];
+ $where = [
+ 'status' => 0,
+ "parentId" => $area_id
+ ];
+ $count_biz = $this->market_sylive_organization_model->count($where); //门店
+ $where = [
+ 'status' => 0,
+ "organizationId in (select organizationId from lc_market_sylive_organization where
+ parentId in (select organizationId from lc_market_sylive_organization where parentId={$area_id} and status=0)
+ )" => null
+ ];
+ $count_gw = $this->user_model->count($where); //顾问
+ $where = [
+ 'status' => 0,
+ "activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$area_id})" => null
+ ];
+ $count_live = $this->market_sylive_activity_model->count($where);
+ $where = [
+ 'kpi' => 'order',
+ "area_id" => $area_id
+ ];
+ $count_order = $this->mdSytActivityKpiData->count($where);
+ $count = [
+ ['title' => '门店','num' => $count_biz,'icon' => 'icon-quyu'],
+ ['title' => '顾问','num' => $count_gw,'icon' => 'icon-mendian'],
+ ['title' => '活动','num' => $count_live,'icon' => 'icon-zhibo'],
+ ['title' => '订单','num' => $count_order,'icon' => 'icon-dingdan'],
+ ];
+ $tab = [
+ ['id' => 1, 'title' => '门店',],
+ ['id' => 2, 'title' => '活动',],
+ ];
+ }else{ //所有大区
+ $count_dq = $this->market_sylive_organization_model->count(['parentId'=>$this->session['org_id'],'status'=>0]);
+ $where = [
+ 'status' => 0,
+ "parentId in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0) and status=0" => null
+ ];
+ $count_biz = $this->market_sylive_organization_model->count($where);
+ $where = [
+ 'status' => 0,
+ "activityId in (select activityId from lc_market_sylive_activity_biz where
+ areaId in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0)
+ )" => null
+ ];
+ $count_live = $this->market_sylive_activity_model->count($where);
+ $where = [
+ 'kpi' => 'order',
+ " area_id in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0)" => null
+ ];
+ $count_order = $this->mdSytActivityKpiData->count($where);
+ $count = [
+ ['title' => '区域','num' => $count_dq],
+ ['title' => '门店','num' => $count_biz],
+ ['title' => '活动','num' => $count_live],
+ ['title' => '订单','num' => $count_order],
+ ];
+ $tab = [
+ ['id' => 1, 'title' => '区域',],
+ ['id' => 2, 'title' => '活动',],
+ ];
+ }
+ $data['count'] = $count;
+ $data['tab'] = $tab;
+ $this->show_json($data,200);
+ }
+
+ //大区列表
+ public function area_lists(){
+ $page = $this->input->get('page');
+ !$page && $page = 1;
+ $size = 10;
+ $where = [
+ 'parentId' => $this->session['org_id'],
+ 'status' => 0,
+ ];
+ $total = $this->market_sylive_organization_model->count($where);
+ $lists = [];
+ if($total){
+ $rows = $this->market_sylive_organization_model->select($where,'sortNumber desc',$page,$size,'organizationId,parentId,organizationName');
+ foreach ($rows as $val) {
+ $where = [
+ 'status' => 0,
+ "activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$val['organizationId']})" => null
+ ];
+ $activitynum = $this->market_sylive_activity_model->count($where);
+ $temp = [
+ 'title' => $val['organizationName'],
+ 'storenum' => $this->market_sylive_organization_model->count(['parentId'=>$val['organizationId'],'status'=>0]),
+ 'activitynum' => $activitynum,
+ 'url' => '/h5/market/sylive/biz/lists?area_id='.$val['organizationId'],
+ 'state' => [],
+ ];
+ $lists[] = $temp;
+ }
+ }
+ $data['list'] = $lists;
+ $data['total'] = $total;
+ $this->show_json($data,200);
+ }
+ //门店列表
+ public function biz_lists(){
+ $area_id = $this->input->get('area_id');
+ !$area_id && $area_id = 0;
+ $page = $this->input->get('page');
+ !$page && $page = 1;
+ $size = 10;
+ $where = [
+ 'status' => 0,
+ ];
+ if($this->group_id==1){
+ $where['parentId'] = $this->session['org_id'];
+ }else{
+ $where['parentId'] = $area_id;
+ }
+ $total = $this->market_sylive_organization_model->count($where);
+ $lists = [];
+ if($total){
+ $rows = $this->market_sylive_organization_model->select($where,'sortNumber desc',$page,$size,'organizationId,parentId,organizationName');
+ foreach ($rows as $val) {
+ $where = [
+ 'status' => 0,
+ "activityId in (select activityId from lc_market_sylive_activity_biz where bizId={$val['organizationId']})" => null
+ ];
+ $activitynum = $this->market_sylive_activity_model->count($where);
+ $temp = [
+ 'title' => $val['organizationName'],
+ 'storenum' => $this->user_model->count(['organizationId'=>$val['organizationId'],'status'=>0]), //顾问
+ 'activitynum' => $activitynum,
+ 'url' => '/h5/market/sylive/biz?biz_id='.$val['organizationId'].'&area_id='.$area_id,
+ 'state' => [],
+ ];
+ $lists[] = $temp;
+ }
+ }
+ $data['list'] = $lists;
+ $data['total'] = $total;
+ $this->show_json($data,200);
+ }
+ //活动列表
+ public function act_list(){
+ $area_id = $this->input->get('area_id');
+ $biz_id = $this->input->get('biz_id');
+ $page = $this->input->get('page');
+ !$page && $page = 1;
+ $size = 10;
+ $where = [
+ 'status' => 0,
+ ];
+ if($this->group_id==3){ //顾问
+ $where["activityId in (select activityId from lc_market_sylive_activity_biz where
+ bizId in (select parentId from lc_market_sylive_organization where organizationId={$this->session['org_id']} and status=0)
+ )"] = null;
+ }elseif($this->group_id==2){ //当前店铺
+ $where["activityId in (select activityId from lc_market_sylive_activity_biz where bizId={$this->session['org_id']})"] = null;
+ }elseif($this->group_id==1) { //所有店铺
+ $where["activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$this->session['org_id']})"] = null;
+ }elseif(!$this->group_id && $biz_id){
+ $where["activityId in (select activityId from lc_market_sylive_activity_biz where bizId={$biz_id})"] = null;
+ }elseif (!$this->group_id && $area_id) {
+ $where["activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$area_id} and status=0)"] = null;
+ }else{ //所有大区
+ $where["activityId in (select activityId from lc_market_sylive_activity_biz where
+ areaId in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0)
+ )"] = null;
+ }
+ $total = $this->market_sylive_activity_model->count($where);
+ $lists = [];
+ if($total){
+ $rows = $this->market_sylive_activity_model->select($where,'timeStart desc',$page,$size,'activityId,title,timeStart,timeEnd');
+ foreach ($rows as $val) {
+ $s_time = strtotime($val['timeStart']);
+ $e_time = strtotime($val['timeEnd']);
+ $n_time = time();
+ if($n_time>=$s_time&&$n_time<=$e_time){
+ $state = ['title'=>'活动进行中','class'=>'bg-fe9538'];
+ }elseif($n_time<$s_time){
+ $state = ['title'=>'活动预热中','class'=>'bg-ff5a5a'];
+ }else{
+ $state = ['title'=>'活动已结束','class'=>'bg-fccba0'];
+ }
+ $skey = $this->myencryption->base64url_encode("a_id=" . $val['activityId']);
+ $temp = [
+ 'title' => $val['title'],
+ 'time' => date('Y-m-d',$s_time).'~'.date('Y-m-d',$e_time),
+ 'url' => '/h5/market/sylive/act?skey='.$skey,
+ 'state' => $state,
+ ];
+ $lists[] = $temp;
+ }
+ }
+ $data['list'] = $lists;
+ $data['total'] = $total;
+ $this->show_json($data,200);
+ }
+
+
+}
\ No newline at end of file
diff --git a/home/controllers/h5/market/sylive/Common.php b/home/controllers/h5/market/sylive/Common.php
new file mode 100644
index 00000000..7e1cf64c
--- /dev/null
+++ b/home/controllers/h5/market/sylive/Common.php
@@ -0,0 +1,198 @@
+load->helper('cookie');
+ $this->load->model('market/market_sylive_user_model', 'user_model');
+ $this->load->model('market/market_sylive_activity_user_model', 'act_user_model');
+
+ $this->load->library('hd_exception');
+ $this->load->library('MyEncryption');
+ $ukey = get_cookie('ukey');
+ if ($ukey) {
+ $this->session = json_decode(liche_authcode($ukey, 'DECODE', $this->secret), true);
+ $this->uid = $this->session['uid'];
+ }
+ }
+
+ /**
+ * @param $view
+ */
+ protected function show_view($view){
+ $this->load->view('h5/market/sylive/header',$this->data);
+ $this->load->view($view);
+ $this->load->view('h5/market/sylive/footer');
+ }
+
+ /**
+ * @param $data
+ * @param int $code
+ * @param string $msg
+ * @param string $url
+ */
+ protected function show_json($data, $code = 200, $msg = 'success', $url = '')
+ {
+ if(!isset($data['code'])){
+ $data = array('data' => $data, 'code' => $code, 'msg' => $msg, 'url' => $url);
+ }
+
+ exit(json_encode($data));
+ }
+
+ /**
+ * @param $url 回调url地址
+ * @param $auth 是否信息授权
+ * @return void
+ * @throws Hd_exception
+ */
+ protected function set_auth($url='',$auth=0){
+ $this->load->helper('url');
+ $this->load->config('wechat');
+ $config = $this->config->item('liche');
+ $code = $this->input->get('code');
+ !$url && $url = http_host_com('home').$_SERVER['REQUEST_URI'];
+ $auth && $url = $_SERVER['QUERY_STRING'] ? $url."&auth={$auth}" : $url."?auth={$auth}";
+ if ($code) {//授权码获取微信信息
+ $auth_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$config['appid']}&secret={$config['appSecret']}&code={$code}&grant_type=authorization_code";
+ $res = file_get_contents($auth_url);
+ $ret = json_decode($res, true);
+ $access_token = $ret['access_token'];
+ $openid = $ret['openid'];
+ $unionid = $ret['unionid'];
+ if($this->input->get('auth') && $access_token){
+ $u_info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN";
+ $u_ret = file_get_contents($u_info_url);
+ $ret = json_decode($u_ret,true);
+ }
+ if(!$openid){
+ debug_log("[error]# " . $res, __FUNCTION__, $this->log_dir);
+ throw new Hd_exception('获取用户信息失败', 400);
+ }
+ return $ret;
+ } elseif ($auth) {//信息授权获取用户微信昵称/头像
+ $redirect_uri = urlencode($url);
+ $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect&forcePopup=true";
+ redirect($auth_url);
+ } elseif (!$this->session) {//静默授权获取用户openid
+ $redirect_uri = urlencode($url);
+ $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
+ redirect($auth_url);
+ }
+ }
+}
+
+class Admin extends Common{
+ const WX_SESSION = "market_wx_info";
+ public function __construct(){
+ parent::__construct();
+ session_start();
+ }
+
+ public function _remap($method){
+ try{
+ if(!in_array($method,$this->white_login_method) && !$this->uid){
+ $ret = $this->set_auth('',1);
+ $openid = $ret['openid'];
+ $row_wechat = $this->user_model->get(['openid' => $openid,'organizationId>'=>0,'status>='=>0]);
+ if(!$row_wechat){
+ $_SESSION[self::WX_SESSION] = $ret;
+ header('Location:/h5/market/sylive/login');exit;
+ }
+ if($row_wechat['status']){
+ throw new Hd_exception('该账户禁用', 400);
+ }
+ $this->uid = $row_wechat['userId'];
+ $session = ['uid' => $this->uid,'org_id'=>$row_wechat['organizationId']];
+ $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret);
+ set_cookie("ukey", $ukey, 86400 * 30);
+ $this->session = $session;
+ }
+ return $this->$method();
+ } catch(Hd_exception $e){//处理异常
+// $code = $e->getCode();
+ $msg = $e->getMessage();
+ $data = array('heading' => 'Warning', 'message' => $msg);
+ return $this->load->view('errors/html/error_404',$data);
+ }
+ }
+
+}
+
+class Wx extends Common{
+ public function __construct(){
+ parent::__construct();
+ }
+
+ public function _remap($method){
+ try{
+ if(!in_array($method,$this->white_login_method) && !$this->uid){
+ $ret = $this->set_auth('',1);
+ $openid = $ret['openid'];
+ $row_wechat = $this->user_model->get(['openid' => $openid,'status>='=>0]);
+ if($row_wechat['status']){
+ throw new Hd_exception('该账户禁用', 400);
+ }
+ if(!$row_wechat){ //创建用户
+ $add = array(
+ "openid" => $openid,
+ "sex" => $ret['sex'] ? 1 : 0,
+ "createTime" => date('Y-m-d H:i:s')
+ );
+ $ret['nickname'] && $add['nickname'] = strval($ret['nickname']);
+ $ret['headimgurl'] && $add['headimg'] = strval($ret['headimgurl']);
+ $ret['unionid'] && $add['unionid'] = $ret['unionid'];
+ $this->uid = $this->user_model->add($add);
+ $row_wechat['organizationId'] = 0;
+ if (!$this->uid) {
+ debug_log("[error]# " . $this->mdWeixinUsers->db->last_query(), __FUNCTION__, $this->log_dir);
+ }
+ }else{
+ $this->uid = $row_wechat['userId'];
+ }
+ $skey = $this->input->get('skey');
+ $param = $this->myencryption->base64url_decode($skey);
+ $act_user = $this->act_user_model->get(['activityId'=>$param['a_id'],'userId'=>$this->uid]);
+ if(!$act_user && $param['a_id']){
+ $act_data = [
+ 'activityId' => $param['a_id'],
+ 'userId' => $this->uid,
+ "createTime" => date('Y-m-d H:i:s')
+ ];
+ if($param['cf_uid']){
+ $p_user = $this->user_model->get(['userId'=>$param['cf_uid']],'userId,organizationId');
+ $p_act_user = $this->act_user_model->get(['userId'=>$param['cf_uid']],'userId,channelId');
+ $p_act_user['channelId'] && $act_data['channelId'] = $p_act_user['channelId'];
+ if(!$p_user['channelId'] && $p_user['organizationId']>0){
+ $act_data['channelId'] = $p_user['userId'];
+ }
+ $act_data['pid'] = $p_user['userId'];
+ }
+ $this->act_user_model->add($act_data);
+ }
+ $session = ['uid' => $this->uid,'org_id'=>$row_wechat['organizationId']];
+ $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret);
+ set_cookie("ukey", $ukey, 86400 * 30);
+ $this->session = $session;
+ }
+ return $this->$method();
+ } catch(Hd_exception $e){//处理异常
+// $code = $e->getCode();
+ $msg = $e->getMessage();
+ $data = array('heading' => 'Warning', 'message' => $msg);
+ return $this->load->view('errors/html/error_404',$data);
+ }
+ }
+}
diff --git a/home/controllers/h5/market/sylive/Login.php b/home/controllers/h5/market/sylive/Login.php
new file mode 100644
index 00000000..26e502c2
--- /dev/null
+++ b/home/controllers/h5/market/sylive/Login.php
@@ -0,0 +1,99 @@
+load->helper('cookie');
+ $this->load->model('market/market_sylive_user_model', 'user_model');
+ }
+
+ public function index(){
+ if($this->input->is_ajax_request()){
+ $redis = &load_cache('redis');
+ $code = $this->input->post('code');
+ $mobile = $this->input->post('mobile');
+ $key = "sylive_login_code_".$mobile;
+ if(!$code || $code!=$redis->get($key)){
+ $this->show_json('',400,'请输入正确的验证码');
+ }
+ $user=$this->user_model->get(array('mobile' => $mobile,'organizationId>'=>0));
+ if($user['status']){
+ $this->show_json('',400,'用户已禁用');
+ }
+ $this->bind_openid($user);
+ $session = ['uid' => $user['userId'],'org_id'=>$user['organizationId']];
+ $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret);
+ set_cookie("ukey", $ukey, 86400 * 30);
+ $this->show_json('',200,'登录成功');
+ }else{
+ $this->load->view('h5/market/sylive/login');
+ }
+ }
+ //绑定微信openid
+ private function bind_openid($user){
+ $wx_info = $_SESSION[self::WX_SESSION];
+ if(!$wx_info['openid']){
+ return ['code' => 0,'msg' => '不存在公众号信息,无需绑定'];
+ }
+ if($user['openid']){
+ return ['code' => 0,'msg' => '该用户已绑定公众号'];
+ }
+ $is_bind = $this->user_model->count(['openid'=>$wx_info['openid'],'organizationId>'=>0,'status>='=>0]); //是否绑定
+ if($is_bind){
+ return ['code' => 0,'msg' => '该公众号已存在绑定账号'];
+ }
+ $update = [
+ 'openid' => $wx_info['openid']
+ ];
+ $wx_info['nickname'] && $update['nickname'] = strval($wx_info['nickname']);
+ $wx_info['headimgurl'] && $update['headimg'] = strval($wx_info['headimgurl']);
+ $wx_info['unionid'] && $update['unionid'] = $wx_info['unionid'];
+ $this->user_model->update($update,['userId'=>$user['userId']]);
+ //删除普通账户
+ $this->user_model->update(['status'=>-1],['openid'=>$wx_info['openid'],'organizationId'=>0,'status>='=>0]);
+ return ['code' => 1,'msg' => '绑定成功'];
+ }
+ //获取验证码
+ public function get_code(){
+ $mobile = $this->input->post('mobile');
+ if(!mobile_valid($mobile)){
+ $this->show_json('',400,'请输入正确的手机号码');
+ }
+ $user=$this->user_model->get(array('mobile' => $mobile, 'status' => 0,'organizationId>'=>0));
+ if(!$user){
+ $this->show_json('',400,'用户不存在');
+ }
+ if($user['status']){
+ $this->show_json('',400,'用户已禁用');
+ }
+ $redis = &load_cache('redis');
+ $key = "sylive_login_code_".$mobile;
+ if(!$code = $redis->get($key)){
+ $this->load->helper('string');
+ $code = random_string('numeric', 4);
+ $redis->save($key, $code, 60*5);
+ }
+ send_sms($mobile, $code);
+ $this->show_json('',200, '验证码已发送');
+ }
+
+ private function show_json($data, $code = 200, $msg = 'success', $url = ''){
+ if(!isset($data['code'])){
+ $data = array('data' => $data, 'code' => $code, 'msg' => $msg, 'url' => $url);
+ }
+
+ exit(json_encode($data));
+ }
+
+ public function test(){
+ $this->load->library('market/sylive_entity');
+ $oid = 1;
+ $req = $this->sylive_entity->get_level($oid);
+ print_r($req);
+ }
+}
\ No newline at end of file
diff --git a/home/controllers/h5/market/sylive/Myqrcode.php b/home/controllers/h5/market/sylive/Myqrcode.php
new file mode 100644
index 00000000..133b97b2
--- /dev/null
+++ b/home/controllers/h5/market/sylive/Myqrcode.php
@@ -0,0 +1,33 @@
+input->get('url');
+ if ($url) {
+ $errorCorrectionLevel = 'L'; //容错级别
+ $matrixPointSize = 5; //生成图片大小
+ //生成二维码图片
+ QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize, 1);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/home/controllers/h5/market/sylive/Notify.php b/home/controllers/h5/market/sylive/Notify.php
new file mode 100644
index 00000000..a91ea90a
--- /dev/null
+++ b/home/controllers/h5/market/sylive/Notify.php
@@ -0,0 +1,67 @@
+load->model('market/market_sylive_activity_user_model', 'act_user_model');
+ $this->load->model('market/market_sylive_order_model','order_model');
+ $this->load->library('market/sylive_entity');
+ try{
+ //如果返回成功则验证签名
+ $config = new WxPayConfig();
+ $input = file_get_contents("php://input");
+ $result = WxPayNotifyResults::Init($config, $input);
+ $this->notify = $result->GetValues();
+ debug_log("[info] ". __FUNCTION__ . "# notify:" . json_encode($this->notify,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir);
+ }catch (WxPayException $e){
+ debug_log("[error] ". __FUNCTION__ . ":".$e->getMessage(), $this->log_file,$this->log_dir);
+ exit();
+ }
+ }
+
+ //微信支付异步通知
+ public function index(){
+ try{
+ $sid = $this->notify['out_trade_no'];
+ if($sid){
+ debug_log("[start] ". __FUNCTION__ . ": out_trade_no:".$this->notify['out_trade_no'], $this->log_file,$this->log_dir);
+ $order = $this->order_model->get(array('sid'=>$sid));
+ if(!$order){
+ throw new Exception("{$sid}_订单不存在");
+ }
+ if($order['status']){
+ throw new Exception("{$sid}_订单已支付");
+ }
+ if($this->notify['result_code'] != 'SUCCESS'){ //支付失败
+ throw new Exception("支付失败,sid={$sid}");
+ }else{ //支付成功
+ $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']);
+ 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);
+ }
+ }
+ }
+ }catch (Exception $e){
+ $msg = $e->getMessage();
+ debug_log("[error] ". __FUNCTION__ . ":{$msg}", $this->log_file,$this->log_dir);
+ }
+ if($sid){
+ debug_log("[finish] ". __FUNCTION__ . ": out_trade_no-".$this->notify['out_trade_no'], $this->log_file,$this->log_dir);
+ }else{
+ debug_log("[finish] ". __FUNCTION__ . ": 参数错误-".json_encode($this->notify,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir);
+ }
+ echo '