@@ -135,6 +137,8 @@
load_view("/topics/module_ad") ?>
load_view("/topics/module_enroll") ?>
+
+ load_view("/topics/module_button") ?>
+
\ No newline at end of file
diff --git a/admin/views/topics/module_enroll.php b/admin/views/topics/module_enroll.php
index 701bf063..60cbef87 100644
--- a/admin/views/topics/module_enroll.php
+++ b/admin/views/topics/module_enroll.php
@@ -150,7 +150,7 @@
查看报名列表
diff --git a/api/controllers/wxapp/liche/Aptinfo.php b/api/controllers/wxapp/liche/Aptinfo.php
index 5b76d8e5..39cbdaf6 100644
--- a/api/controllers/wxapp/liche/Aptinfo.php
+++ b/api/controllers/wxapp/liche/Aptinfo.php
@@ -124,6 +124,16 @@ class Aptinfo extends Wxapp{
$lng = $this->input_param('lng');
$recommend_id = intval($this->input_param('cf_uid')); //来源用户id
$cms_id = intval($this->input_param('cms_id')); //cmsid
+ $syt = intval($this->input_param('syt'));
+ if ($syt && $this->myuid) {//私域通报名
+ $this->load->library('entity/syt_entity');
+ $syt_entity = new Syt_entity(array('app_id' => $this->app_id));
+ $results = $syt_entity->kpi_enroll_log(['cf_platform' => 'wxapp', 'uid' => $this->myuid, 'nickname' => $this->session['nickname']
+ , 'mobile' => $this->session['mobile']]);
+ if ($results['code'] == 200) {
+ throw new Hd_exception($results['msg'], $results['code']);
+ }
+ }
$city_id && $city_row = $this->sys_area_model->get(['county_id' => $city_id],'id,county_id,city_id');
$cms_row = $this->cms_model->get(['id'=>$cms_id]);
diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php
index b53f96ea..12cb8bfd 100644
--- a/api/controllers/wxapp/licheb/Customers.php
+++ b/api/controllers/wxapp/licheb/Customers.php
@@ -120,7 +120,7 @@ class Customers extends Wxapp
}
$car_json = json_decode($row['car_json'], true);
$update = [];
- if($row['cf_title']!='平台分配'){
+ if ($row['cf_title'] != '平台分配') {
if ($mobile) {
if (!mobile_valid($mobile)) {
throw new Exception('手机号格式错误', ERR_PARAMS_ERROR);
@@ -314,7 +314,7 @@ class Customers extends Wxapp
$log = $log ? $log . ',' . $msg : $msg;
}
$visit = $status == 2 ? 1 : 0;//变成订单客户,更新客户已回访
- $this->customers_entity->add_log_visit($id, $uid, $this->session['uname'], $log,0,$visit);
+ $this->customers_entity->add_log_visit($id, $uid, $this->session['uname'], $log, 0, $visit);
}
}
if ($result) {
@@ -388,6 +388,7 @@ class Customers extends Wxapp
$cf_clues = $this->input_param('cf_clues');//线索来源
$admin_id = $this->input_param('admin_id');
$id = $this->input_param('cus_id');
+ $a_id = intval($this->input_param('a_id'));//私域通活动id
!$page && $page = 1;
!$size && $size = 10;
@@ -403,12 +404,16 @@ class Customers extends Wxapp
$orderby = 'c_time desc';
}
}
-
$where = [
'biz_id' => $biz_id,
'status>=' => 0
];
+ if ($a_id) {
+ $where["cf_id"] = 35;
+ $where["t_id"] = $a_id;
+ }
+
if ($group_id == 1 || $ismy) {
$where["admin_id"] = $uid;
}
@@ -697,7 +702,7 @@ class Customers extends Wxapp
if ($ret) {
$this->load->library('receiver/customers_entity');
$visit = $update['status'] == 3 ? 1 : 0;
- $this->customers_entity->add_log_visit($id, $this->session['uid'], $this->session['uname'], $log,0,$visit);
+ $this->customers_entity->add_log_visit($id, $this->session['uid'], $this->session['uname'], $log, 0, $visit);
throw new Exception('操作成功', API_CODE_SUCCESS);
}
throw new Exception('操作失败', ERR_PARAMS_ERROR);
diff --git a/api/controllers/wxapp/licheb/Sytactivity.php b/api/controllers/wxapp/licheb/Sytactivity.php
new file mode 100644
index 00000000..9834fc67
--- /dev/null
+++ b/api/controllers/wxapp/licheb/Sytactivity.php
@@ -0,0 +1,224 @@
+login_white = array();//登录白名单
+ $this->check_status = array();//用户状态校验
+ $this->majia_white = array('get');//超级管理员披上马甲权限控制
+ $this->load->model('app/licheb/syt_activity_model', 'mdSytActivity');
+ $this->load->model('app/licheb/syt_activity_kpidata_model', 'mdSytActivityKpiData');
+ $this->load->model('app/licheb/syt_biz_score_model', 'mdSytBizScore');
+ $this->load->model('app/app_weixin_users_model', 'mdWeixinUsers');
+ $this->load->model('app/licheb/app_licheb_users_model', 'mdLichebUsers');
+ $this->load->model("biz/biz_model", 'mdBiz');
+ $this->load->model('receiver/receiver_customers_model', 'mdCustomers');
+ $this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
+ }
+
+ /**
+ * Notes:顶部菜单
+ * Created on: 2022/1/14 9:40
+ * Created by: dengbw
+ * @return mixed
+ */
+ protected function get_tabs()
+ {
+ $data['title'] = '私域通';
+ $bm_count = $this->mdSytActivityKpiData->count(['kpi' => 'enroll']);
+ $dd_count = $this->mdCustomers->count(['status' => 1, 'cf_id' => $this->cf_id]);
+ $xd_count = $this->mdCustomers->count(['status' => 2, 'cf_id' => $this->cf_id]);
+ $data['bg_img'] = 'https://qs.haodian.cn/wechat_app/lichebao/siyutong/theme.jpg';
+ $data['menus'] = array(array('title' => '报名', 'value' => $bm_count), array('title' => '到店', 'value' => $dd_count),
+ array('title' => '下定', 'value' => $xd_count));
+ return $data;
+ }
+
+ /**
+ * Notes:推广活动列表
+ * Created on: 2022/1/14 9:40
+ * Created by: dengbw
+ * @return mixed
+ */
+ protected function get_list()
+ {
+ $page = $this->input_param('page');
+ $size = $this->input_param('size');
+ !$page && $page = 1;
+ !$size && $size = 3;
+ $where['status'] = 1;
+ $date = date('Y-m-d H:i:s');
+ $lists = array();
+ $total = $this->mdSytActivity->count($where);
+ if ($total) {
+ $res = $this->mdSytActivity->select($where, 'id DESC', $page, $size, 'id,title,s_time,e_time');
+ foreach ($res as $key => $value) {
+ $setValue = array();
+ $setValue['id'] = intval($value['id']);
+ $setValue['title'] = $value['title'];
+ $type_name = $color = '';
+ $type = 0;
+ $s_time = $value['s_time'];
+ $e_time = $value['e_time'];
+ if ($s_time > $date) {
+ $type = 1;
+ $type_name = '未开始';
+ $color = '#999';
+ } else if ($s_time <= $date && $e_time >= $date) {
+ $type = 2;
+ $type_name = '进行中';
+ $color = '#ff842d';
+ } else if ($e_time < $date) {
+ $type = 3;
+ $type_name = '已结束';
+ $color = '#996c6c';
+ }
+ $setValue['type'] = $type;
+ $setValue['type_name'] = $type_name;
+ $setValue['color'] = $color;
+ $lists[] = $setValue;
+ }
+ }
+ $data['list'] = $lists;
+ $data['total'] = $total;
+ return $data;
+ }
+
+ /**
+ * Notes:推广活动详情
+ * Created on: 2020/9/28 16:01
+ * Created by: dengbw
+ * @throws Hd_exception
+ */
+ protected function get_detail()
+ {
+ $id = intval($this->input_param('id'));
+ if (!$id) {
+ throw new Hd_exception('参数错误!', API_CODE_INVILD_PARAM);
+ }
+ $re = $this->mdSytActivity->get(array("id" => $id, "status" => 1));
+ if (!$re) {
+ throw new Hd_exception('未找到活动!', API_CODE_INVILD_PARAM);
+ }
+ $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : '';
+ $share_count = $this->mdSytActivityKpiData->count(['kpi' => 'share', 'a_id' => $id]);
+ $browse_count = $this->mdSytActivityKpiData->count(['kpi' => 'browse', 'a_id' => $id]);
+ $enroll_count = $this->mdSytActivityKpiData->count(['kpi' => 'enroll', 'a_id' => $id]);
+ $ranking = 0;
+ $re_biz_score = $this->mdSytBizScore->get(['a_id' => $id, 'biz_id' => $this->biz_id]);
+ if ($re_biz_score && $re_biz_score['score']) {
+ $ranking = $this->mdSytBizScore->count(['score >=' => $re_biz_score['score'], 'a_id' => $id]);
+ }
+ $data['id'] = intval($re['id']);
+ $data['img'] = $re['img'] ? build_qiniu_image_url($re['img']) : '';
+ $data['poster'] = $jsondata['posters'] ? build_qiniu_image_url($jsondata['posters'][0]['url']) : $data['img'];
+ $data['remark'] = $jsondata['remark'] ? $jsondata['remark'] : '';
+ $data['ranking'] = ['title' => '当前门店排名', 'value' => $ranking, 'url' => '/pages/siyutong/activityRanking/index?id=' . $id];
+ $data['menus'] = [['title' => '分享', 'value' => $share_count], ['title' => '浏览', 'value' => $browse_count]
+ , ['title' => '报名>', 'value' => $enroll_count, 'url' => '/pages/customer/filterList/index?a_id=' . $id]];
+ //生成分享连接
+ $this->load->library('MyEncryption');
+ $skey = $this->myencryption->base64url_encode("a_id={$id}&cf_uid={$this->myuid}&biz_id={$this->biz_id}&cf_share={$this->myencryption->random_string(6)}");
+ $myqrcode_url = http_host_com('home') . '/h5/syt/special?skey=' . $skey;
+ $share_url = http_host_com('home') . '/h5/syt/myqrcode/get?url=' . $myqrcode_url;
+ $data['btn'] = ['title' => '马上邀请', 'value' => 1, 'share_url' => $share_url];
+ return $data;
+ }
+
+ /**
+ * Notes:实时战报
+ * Created on: 2022/1/19 9:57
+ * Created by: dengbw
+ * @return mixed
+ * @throws Hd_exception
+ */
+ protected function get_log()
+ {
+ $page = $this->input_param('page');
+ $size = $this->input_param('size');
+ !$page && $page = 1;
+ !$size && $size = 10;
+ $id = intval($this->input_param('id'));
+ if (!$id) {
+ throw new Hd_exception('参数错误!', API_CODE_INVILD_PARAM);
+ }
+ $lists = array();
+ $where = array('a_id' => $id, 'kpi<>' => 'share');
+ $total = $this->mdSytActivityKpiData->count($where);
+ if ($total) {
+ $res = $this->mdSytActivityKpiData->select($where, 'id DESC', $page, $size, 'uid,cf_uid,kpi,biz_id,c_time');
+ $uids_arr = array_unique(array_column($res, 'uid'));
+ $cf_uids_arr = array_unique(array_column($res, 'cf_uid'));
+ $uids = $this->mdWeixinUsers->get_map_by_ids($uids_arr, 'id,nickname');
+ $cf_uids = $this->mdLichebUsers->get_map_by_ids($cf_uids_arr, 'id,uname');
+ foreach ($res as $key => $value) {
+ $setValue = array();
+ if ($value['kpi'] == 'enroll') {
+ $content = "{$uids[$value['uid']][0]['nickname']}通过{$cf_uids[$value['cf_uid']][0]['uname']}报名了活动";
+ } else {
+ $content = "{$cf_uids[$value['cf_uid']][0]['uname']}邀请{$uids[$value['uid']][0]['nickname']}进入活动页";
+ }
+ $setValue['content'] = $content;
+ $setValue['c_time'] = friendly_date($value['c_time'], 'mohu');
+ $lists[] = $setValue;
+ }
+ }
+ $data['list'] = $lists;
+ $data['total'] = $total;
+ return $data;
+ }
+
+ /**
+ * Notes:活动排名
+ * Created on: 2022/1/19 14:25
+ * Created by: dengbw
+ * @return mixed
+ * @throws Hd_exception
+ */
+ protected function get_ranking()
+ {
+ $id = intval($this->input_param('id'));
+ if (!$id) {
+ throw new Hd_exception('参数错误!', API_CODE_INVILD_PARAM);
+ }
+ $re = $this->mdSytActivity->get(array("id" => $id, "status" => 1));
+ if (!$re) {
+ throw new Hd_exception('未找到活动!', API_CODE_INVILD_PARAM);
+ }
+ $score = 0;
+ $ranking = [];
+ $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : '';
+ $re = $this->mdSytBizScore->get(array("biz_id" => $this->biz_id));
+ $re['score'] && $score = $re['score'];
+ $res = $this->mdSytBizScore->select(['a_id' => $id], 'score DESC,id ASC', 0, 7, 'biz_id,score');
+ if ($res) {
+ $str_biz_ids = implode(',', array_column($res, 'biz_id'));
+ $map_biz = $this->mdBiz->map('id', 'biz_name', ["id in ({$str_biz_ids})" => null]);
+ foreach ($res as $key => $value) {
+ $num = $key + 1;
+ $ranking[] = ['num' => $num, 'biz_name' => $map_biz[$value['biz_id']], 'score' => $value['score'] . '分'];
+ }
+ }
+ $data['title'] = '活动排名';
+ $data['biz'] = ['title' => '我的直营店', 'value' => $score . '分'];
+ $data['ranking'] = $ranking;
+ $data['rule'] = ['title' => '积分规则>', 'value' => $jsondata['rule'] ? $jsondata['rule'] : ''];
+ return $data;
+ }
+
+}
\ No newline at end of file
diff --git a/api/controllers/wxapp/material/Topic.php b/api/controllers/wxapp/material/Topic.php
index 6a21f146..5a89ba2d 100644
--- a/api/controllers/wxapp/material/Topic.php
+++ b/api/controllers/wxapp/material/Topic.php
@@ -131,6 +131,16 @@ class Topic extends Wxapp
$cf_id = 1;
$brand_id = 0;
$recommend_id && $cf_id = 8;
+ $syt = intval($this->input_param('syt'));
+ if ($syt && $this->myuid) {//私域通报名
+ $this->load->library('entity/syt_entity');
+ $syt_entity = new Syt_entity(array('app_id' => $this->app_id));
+ $results = $syt_entity->kpi_enroll_log(['cf_platform' => 'wxapp', 'uid' => $this->myuid, 'nickname' => $this->session['nickname']
+ , 'mobile' => $this->session['mobile']]);
+ if ($results['code'] == 200) {
+ throw new Hd_exception($results['msg'], $results['code']);
+ }
+ }
$city_id && $city_row = $this->sys_area_model->get(['county_id' => $city_id], 'id,county_id,city_id');
$re_t = $this->mdTemplate->get(['id' => $t_id]);
if ($re_t && $re_t['brand_ids']) {
diff --git a/common/helpers/comm_helper.php b/common/helpers/comm_helper.php
index d56450bc..427e0f45 100644
--- a/common/helpers/comm_helper.php
+++ b/common/helpers/comm_helper.php
@@ -33,6 +33,66 @@ if (!function_exists('load_cache')) {
}
}
+/**
+ * 接口加密
+ * @param $string
+ * @param string $operation
+ * @param string $key
+ * @param int $expiry
+ * @return string
+ */
+if (!function_exists('liche_authcode')) {
+ function liche_authcode($string, $operation = 'DECODE', $key = '123456', $expiry = 0)
+ {
+ $ckey_length = 4;
+ $key = md5($key ? $key : self::KEY);
+ $keya = md5(substr($key, 0, 16));
+ $keyb = md5(substr($key, 16, 16));
+ $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
+
+ $cryptkey = $keya . md5($keya . $keyc);
+ $key_length = strlen($cryptkey);
+
+ $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
+ $string_length = strlen($string);
+
+ $result = '';
+ $box = range(0, 255);
+
+ $rndkey = array();
+ for ($i = 0; $i <= 255; $i++) {
+ $rndkey[$i] = ord($cryptkey[$i % $key_length]);
+ }
+
+ for ($j = $i = 0; $i < 256; $i++) {
+ $j = ($j + $box[$i] + $rndkey[$i]) % 256;
+ $tmp = $box[$i];
+ $box[$i] = $box[$j];
+ $box[$j] = $tmp;
+ }
+
+ for ($a = $j = $i = 0; $i < $string_length; $i++) {
+ $a = ($a + 1) % 256;
+ $j = ($j + $box[$a]) % 256;
+ $tmp = $box[$a];
+ $box[$a] = $box[$j];
+ $box[$j] = $tmp;
+ $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
+ }
+
+ if ($operation == 'DECODE') {
+ if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
+ return substr($result, 26);
+ } else {
+ return '';
+ }
+ } else {
+ return $keyc . str_replace('=', '', base64_encode($result));
+ }
+
+ }
+}
+
/**
* sql日志
* @param $string
diff --git a/common/libraries/entity/Syt_entity.php b/common/libraries/entity/Syt_entity.php
new file mode 100644
index 00000000..de2507e8
--- /dev/null
+++ b/common/libraries/entity/Syt_entity.php
@@ -0,0 +1,249 @@
+ci = &get_instance();
+ $this->init($params);
+ $class_name = lcfirst(get_class($this));//调用类的名称,子类或者当前类名称
+ $this->log_file = "libraris_{$class_name}.log";
+ $this->load->model('app/licheb/syt_activity_model', 'mdSytActivity');
+ $this->load->model('app/licheb/syt_activity_kpidata_model', 'mdSytActivityKpiData');
+ $this->load->model('app/licheb/syt_biz_score_model', 'mdSytBizScore');
+ }
+
+ public function init($params)
+ {
+ if ($params['app_id']) {
+ $this->app_id = $params['app_id'];
+ $this->load->model('app/App_model', 'mdApp');
+ $this->app_config = $this->ci->mdApp->appConfig()[$this->app_id];
+ }
+ }
+
+ /**
+ * Notes:报名记录
+ * Created on: 2022/1/24 10:57
+ * Created by: dengbw
+ * @param $params
+ * @return array
+ */
+ public function kpi_enroll_log($params)
+ {
+ if ($params['cf_platform'] == 'wxapp') {
+ if (!$params['uid']) {
+ return array('code' => 400, 'msg' => '无狸车用户uid');
+ }
+ $this->load->model('app/liche/app_liche_users_model', 'mdLicheUsers');
+ $this->load->model('app/licheb/app_licheb_users_model', 'mdLichebUsers');
+ $this->load->model('app/app_weixin_users_model', 'mdWeixinUsers');
+ $re_lu = $this->ci->mdLicheUsers->get(array("id" => $params['uid']));
+ if (!$re_lu['unionid']) {
+ return array('code' => 400, 'msg' => '无狸车用户unionid');
+ }
+ $re_lw = $this->ci->mdWeixinUsers->get(array("unionid" => $re_lu['unionid']));
+ if (!$re_lw['unionid']) {
+ return array('code' => 400, 'msg' => '无狸车公众号unionid');
+ }
+ $jsondata = $re_lw['jsondata'] ? json_decode($re_lw['jsondata'], true) : '';
+ if (!$jsondata['syt']) {
+ return array('code' => 400, 'msg' => '无狸车公众号syt');
+ }
+ $syt = $jsondata['syt'];
+ $syt['nickname'] = $params['nickname'];
+ $syt['mobile'] = $params['mobile'];
+ $syt['uid'] = $re_lw['id'];
+ $syt['cf_id'] = 35;
+ $syt['if_driver'] = 1;
+ $params = $syt;
+ }
+ $this->load->model('receiver/receiver_customers_model', 'mdCustomers');
+ $this->load->model("biz/biz_model", 'mdBiz');
+ $re_a = $this->ci->mdSytActivity->get(array("id" => $params['a_id'], "status" => 1));
+ if (!$re_a) {
+ return array('code' => 400, 'msg' => '活动不存在');
+ }
+ $nickname = $params['nickname'];
+ $mobile = $params['mobile'];
+ $cf_id = intval($params['cf_id']);
+ $uid = intval($params['uid']);
+ $biz_id = intval($params['biz_id']);
+ $if_driver = intval($params['if_driver']);
+ if ($biz_id) {
+ $re_enroll = $this->ci->mdCustomers->get(array('cf_id' => $cf_id, 't_id' => $params['a_id'], 'mobile' => $mobile));
+ if ($re_enroll) {
+ return array('code' => 400, 'msg' => '你已经报名过啦,我们会在24时内与您取得联系,请耐心等待!');
+ }
+ }
+ $brand_id = 0;
+ if ($re_a['brand_id']) {
+ $brand_ids = implode(',', $re_a['brand_id']);
+ $brand_id = count($brand_ids) > 0 ? $brand_ids[0] : $re_a['brand_id'];
+ }
+ $c_id = 0;
+ $type = 'customers';
+ if ($biz_id) {//加入门店客户
+ $re_biz = $this->ci->mdBiz->get(['id' => $biz_id, 'status' => 1]);
+ if ($re_biz) {
+ $add_data = [
+ 'name' => $nickname,
+ 'mobile' => $mobile,
+ 'biz_id' => $biz_id,
+ 'brand_id' => $brand_id,
+ 'city_id' => $re_biz['city_id'],
+ 'county_id' => $re_biz['county_id'],
+ 'cf_title' => '私域活动',
+ 'cf_id' => $cf_id,
+ 't_id' => $params['a_id'],
+ 'p_time' => date('Y-m-d H:i:s'),
+ 'c_time' => time()
+ ];
+ $c_id = $this->ci->mdCustomers->add($add_data);
+ if (!$c_id) {
+ return array('code' => 400, 'msg' => '您报名该活动失败了');
+ }
+ }
+ }
+ if (!$c_id) {//未加到门店,加到线索池里
+ $this->load->model('receiver/receiver_clues_model', 'clues_model');
+ $this->load->library('receiver/clues_entity');
+ $row = $this->ci->clues_model->get(['mobile' => $mobile]);
+ if ($row) {
+ $update = ['en_time' => date('Y-m-d H:i:s')];
+ $this->ci->clues_model->update($update, ['id' => $row['id']]);
+ //增加日志
+ $cf_title = $this->ci->clues_entity->cf_title($cf_id);
+ $log_msg = '用户报名';
+ $cf_title && $log_msg = "用户通过【{$cf_title}】报名";
+ $this->ci->clues_entity->add_log($row['id'], $uid, $nickname, $log_msg);
+ return array('code' => 200, 'msg' => '报名成功了,我们会在24时内与您取得联系!');
+ }
+ $jsondata['info'] = ['biz_id' => $biz_id ? $biz_id : ''];
+ $params['a_id'] && $jsondata['info']['t_id'] = $params['a_id'];
+ $add_data = [
+ 'name' => $nickname,
+ 'mobile' => $mobile,
+ 'brand_id' => $brand_id,
+ 'cf_uid' => $uid,
+ 'cf_id' => $cf_id,
+ 'app_id' => $this->app_id,
+ 'if_driver' => $if_driver,
+ 'cf_platform' => $params['cf_platform'],
+ 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
+ 'en_time' => date('Y-m-d H:i:s'),
+ 'c_time' => time()
+ ];
+ $c_id = $this->ci->clues_model->add($add_data);
+ if (!$c_id) {
+ return array('code' => 400, 'msg' => '您报名该活动失败了');
+ }
+ $type = 'clues';
+ $cf_title = $this->ci->clues_entity->cf_title($cf_id);
+ $log_msg = '用户报名';
+ $cf_title && $log_msg = "用户通过【{$cf_title}】报名";
+ $this->ci->clues_entity->add_log($c_id, $uid, $nickname, $log_msg);
+ }
+ //增加报名分数
+ $this->kpi_log(array('a_id' => $params['a_id'], 'cf_uid' => $params['cf_uid'], 'biz_id' => $params['biz_id']
+ , 'kpi' => 'enroll', 'c_id' => $c_id, 'type' => $type, 'uid' => $uid));
+ return array('code' => 200, 'msg' => '报名成功,我们会在24时内与您取得联系!');
+ }
+
+ /**
+ * 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'] || $params['biz_id'])) {
+ $re_a = $this->ci->mdSytActivity->get(array("id" => $params['a_id'], "status" => 1));
+ $now_time = time();
+ if (!$re_a || $now_time < strtotime($re_a['s_time']) || $now_time > strtotime($re_a['e_time'])) {
+ return array('code' => 0, 'msg' => '无活动或未在活动时间内');
+ }
+ if ($params['kpi'] == 'share' && $params['cf_share']) {//检测分享码是否已使用
+ $where_share = array("a_id" => $params['a_id'], 'kpi' => $params['kpi'], "cf_share" => $params['cf_share']);
+ if ($params['cf_uid']) {
+ $where_share['cf_uid'] = $params['cf_uid'];
+ } else {
+ $where_share['biz_id'] = $params['biz_id'];
+ }
+ $re_share = $this->ci->mdSytActivityKpiData->get($where_share);
+ if ($re_share) {
+ 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'] . '记录');
+ }
+ $where_kpi = array("a_id" => $params['a_id'], "biz_id" => $params['biz_id'], 'kpi' => $params['kpi']);
+ //增加记录
+ $addData = array_merge($where_kpi, array('uid' => $params['uid'], 'cf_uid' => $params['cf_uid'], 'c_time' => time()));
+ $jsondata = array();
+ if ($params['kpi'] == 'enroll' && $params['c_id']) {//加报名id记录
+ $jsondata['enroll_type'] = $params['type'];
+ $jsondata['enroll_c_id'] = $params['c_id'];
+ }
+ if ($params['kpi'] == 'share' && $params['cf_share']) {//加分享码
+ $addData['cf_share'] = $params['cf_share'];
+ }
+ $jsondata && $addData['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
+ $id = $this->ci->mdSytActivityKpiData->add($addData);
+ if (!$id) {
+ return array('code' => 0, 'msg' => '添加记录失败');
+ }
+ if (!$params['biz_id']) {
+ return array('code' => 0, 'msg' => '无门店不加分数');
+ }
+ $jsonkpi = $re_a['jsonkpi'] ? json_decode($re_a['jsonkpi'], true) : array();
+ $kpi_count = $this->ci->mdSytActivityKpiData->count(array_merge($where_kpi, array('status' => 0)));
+ $kpi_num = intval($jsonkpi[$params['kpi']]['num']);
+ $kpi_score = intval($jsonkpi[$params['kpi']]['score']);
+ if ($kpi_num && $kpi_score && $kpi_count >= $kpi_num) {//大于等于次数加分
+ $re_biz_score = $this->ci->mdSytBizScore->get(array('a_id' => $params['a_id'], 'biz_id' => $params['biz_id']));
+ if (!$re_biz_score) {//未添加门店数据
+ $re_biz_score['id'] = $this->ci->mdSytBizScore->add(['a_id' => $params['a_id'], 'biz_id' => $params['biz_id'], 'c_time' => time()]);
+ if (!$re_biz_score['id']) {
+ return array('code' => 0, 'msg' => '添加门店分数记录');
+ }
+ $re_biz_score['score'] = 0;
+ }
+ $score_ms = $kpi_score + intval($re_biz_score['score']);
+ $this->ci->mdSytBizScore->update(array('score' => $score_ms), array('id' => $re_biz_score['id']));
+ $res_kpi = $this->ci->mdSytActivityKpiData->select(array_merge($where_kpi, array('status' => 0)), 'id asc', 0, $kpi_num, 'id');
+ if ($res_kpi) {
+ $kpi_ids = implode(',', array_column($res_kpi, "id"));
+ $this->ci->mdSytActivityKpiData->update(array('status' => 1), array("id in(" . $kpi_ids . ")" => null));//更新为已加分
+ }
+ return array('code' => 1, 'msg' => '添加记录成功');
+ }
+ } else {
+ return array('code' => 0, 'msg' => '参数错误');
+ }
+ }
+
+ public function __get($name)
+ {
+ if ('_model' === substr($name, -6)) {
+ return $this->ci->$name;
+ } elseif ('load' == $name) {
+ return $this->ci->load;
+ }
+ return null;
+ }
+}
diff --git a/common/models/app/App_weixin_users_model.php b/common/models/app/App_weixin_users_model.php
new file mode 100644
index 00000000..c914e4a2
--- /dev/null
+++ b/common/models/app/App_weixin_users_model.php
@@ -0,0 +1,39 @@
+table_name, 'default');
+ }
+
+ /**
+ * Notes:根据id获取数据
+ * Created on: 2022/1/17 11:06
+ * Created by: dengbw
+ * @param $ids
+ * @param string $fileds
+ * @return array
+ */
+ public function get_map_by_ids($ids, $fileds = '')
+ {
+ $rows = [];
+ $ids = array_filter($ids);
+ if ($ids) {
+ $cf_ids = implode(',', $ids);
+ $where = [
+ "id in ($cf_ids)" => null
+ ];
+ $rows = $this->map('id', '', $where, '', '', '', $fileds);
+ }
+ return $rows;
+ }
+}
diff --git a/common/models/app/licheb/Syt_activity_kpidata_model.php b/common/models/app/licheb/Syt_activity_kpidata_model.php
new file mode 100644
index 00000000..c6dd7dbc
--- /dev/null
+++ b/common/models/app/licheb/Syt_activity_kpidata_model.php
@@ -0,0 +1,34 @@
+table_name, 'default');
+ }
+
+ public function kpiAry($kpi = '', $title = '')
+ {
+ $url = 'https://qs.haodian.cn/wechat_app/haodianyun/siyutong';
+ $data['share'] = array('img' => $url . '/kpi2-1.png', 'title' => '分享', 'title1' => '分享次数', 'title2' => '分享次数', 'title3' => '分享人数'
+ , 'num_tag' => '次', 'score_tag' => '分数');
+ $data['browse'] = array('img' => $url . '/kpi2-2.png', 'title' => '浏览', 'title1' => '浏览用户', 'title2' => '浏览次数', 'title3' => '浏览人数'
+ , 'num_tag' => '人', 'score_tag' => '分数');
+ $data['enroll'] = array('img' => $url . '/kpi2-3.png', 'title' => '报名', 'title1' => '报名用户', 'title2' => '报名用户', 'title3' => '报名用户'
+ , 'num_tag' => '人', 'score_tag' => '分数');
+ if ($kpi) {
+ return $data[$kpi][$title];
+ } else {
+ return $data;
+ }
+ }
+}
diff --git a/common/models/app/licheb/Syt_activity_model.php b/common/models/app/licheb/Syt_activity_model.php
new file mode 100644
index 00000000..78a495d7
--- /dev/null
+++ b/common/models/app/licheb/Syt_activity_model.php
@@ -0,0 +1,18 @@
+table_name, 'default');
+ }
+}
diff --git a/common/models/app/licheb/Syt_biz_score_model.php b/common/models/app/licheb/Syt_biz_score_model.php
new file mode 100644
index 00000000..68b6d79c
--- /dev/null
+++ b/common/models/app/licheb/Syt_biz_score_model.php
@@ -0,0 +1,18 @@
+table_name, 'default');
+ }
+}
diff --git a/common/models/receiver/Receiver_customers_model.php b/common/models/receiver/Receiver_customers_model.php
index 7f3b7b86..602f74af 100644
--- a/common/models/receiver/Receiver_customers_model.php
+++ b/common/models/receiver/Receiver_customers_model.php
@@ -14,7 +14,7 @@ class Receiver_customers_model extends HD_Model
private $status_arr = [-1 => '删除', 0 => '未见客户', 1 => '到店客户', 2 => '订单客户', 3 => '战败客户'];
private $level = ['H', 'A', 'B', 'C', 'D'];
- private $cfrom_arr = ['自有资源', '平台分配', '素材推广'];
+ private $cfrom_arr = ['自有资源', '平台分配', '素材推广', '私域活动'];
private $cfrom_clues_arr = ['自然进店', '外展', 'DM', '转介绍', '其它','网站','外展外拓','垂直媒体','自媒体'];
private $buy_time = [3, 7, 15, 30];
diff --git a/common/models/topics/Topic_module_button_model.php b/common/models/topics/Topic_module_button_model.php
new file mode 100644
index 00000000..c921d4b6
--- /dev/null
+++ b/common/models/topics/Topic_module_button_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}
\ No newline at end of file
diff --git a/home/config/app.php b/home/config/app.php
new file mode 100644
index 00000000..ac3eaca9
--- /dev/null
+++ b/home/config/app.php
@@ -0,0 +1,12 @@
+input_param();
+
+ //app_id是必需的
+ $this->app_id = $app_id = $set_app_id ? $set_app_id : $this->input_param('app_id');
+ $this->data['app_id'] = $app_id;
+
+ $this->get_env();
+
+ $r = &load_cache('redis');
+ $this->lc_redis = $r;
+
+ //日志文件
+ $class_name = lcfirst(get_class($this));//调用类的名称,子类或者当前类名称
+
+ $this->log_file = "h5_wxapp{$app_id}_{$class_name}.log";
+ $this->log_dir = "h5_wxapp{$app_id}_{$class_name}";
+ $this->redis_mcode = "wxapp_{$app_id}_mcode_";
+ $this->white_mobile = array('18063762579');
+
+ $this->load->helper('cookie');
+
+ //根据app_id重载model
+ $this->load->rebuild_model($this->app_id);
+
+ $this->load->library('hd_exception');
+ }
+
+ /**
+ * 所有方法请求入口
+ * @param $method
+ * @return mixed
+ */
+ function _remap($method){
+ try{
+
+ if('index' == $method){
+ $method = $this->request;
+ } else {
+ $method = $this->request.'_'. $method;
+ }
+
+ if(!in_array($method, $this->white_appid) && !$this->app_id){
+ debug_log("[error] ". __FUNCTION__ . "# not app_id", $this->log_file);
+ throw new Hd_exception('请求超时', 403);
+ }
+
+ $data = $this->$method();
+
+ if($data['view']){//返回视图
+ $this->data = array_merge($this->data, $data);
+ return $this->show_view($data['view'], $data['alone']);
+ } else {//返回json数据
+ return $this->show_json($data);
+ }
+ } catch(Hd_exception $e){//处理异常
+ $code = $e->getCode();
+ $msg = $e->getMessage();
+
+ if($this->input->is_ajax_request()){
+ return $this->show_json(array(), $code, $msg);
+ } else {
+ $this->data = array('heading' => 'Warning', 'message' => $msg);
+ return $this->show_view('errors/html/error_404');
+ }
+ }
+ }
+
+ /**
+ * 获取参数(只支持application/json格式)
+ * @param string $key
+ * @return array|mixed
+ */
+ protected function input_param($key = ''){
+ if($key){
+ return $this->inputs[$key];
+ }
+
+ $request = $this->input->method();
+
+ switch($request){
+ case 'post':
+ case 'put':
+ case 'delete':
+ $input = json_decode(file_get_contents('php://input'), true);
+ break;
+ default:
+ $input = $this->input->get();
+ }
+
+ $this->request = $request;
+ $this->inputs = $input;
+ return $this->inputs;
+ }
+
+ /**
+ * @param $view
+ * @param $alone "独立页面"
+ */
+ protected function show_view($view, $alone = false){
+ if($alone){
+ $this->load->view($view, $this->data);
+ } else{
+ $this->load->view('h5/header',$this->data);
+ $this->load->view($view);
+ $this->load->view('h5/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 $ukey
+ * @return array|mixed
+ */
+ protected function api_session($ukey){
+ $redis = &load_cache('redis');
+
+ $app_key = "";
+ switch($this->app_id){
+ case 1:
+ $app_key = "sbcard";
+ break;
+ case 2:
+ $app_key= "xcard";
+ }
+
+ if(!$app_key){
+ return array();
+ }
+
+ $redis_login = "wxapp_{$app_key}_login_";
+ //data:{"uid":"用户ID", "session_key":"微信session_key"}
+ $data = $redis->get($redis_login.$ukey);
+
+ $session = array();
+ if($data){
+ $session = json_decode($data, true);
+ }
+
+ return $session;
+ }
+
+ /**
+ * 获取环境
+ */
+ private function get_env(){
+ if (false !== strpos($_SERVER['HTTP_HOST'], 'dev')) { //dev 测试
+ $this->env = 'd';
+ $this->host = "https://hd-wxdev.xiaoyu.com";
+ $this->api_host = "https://hd-api-dev.xiaoyu.com";
+ } elseif (false !== strpos($_SERVER['HTTP_HOST'], 'test')) {//test 测试
+ $this->env = 't';
+ $this->host = "https://www-test.haodian.cn";
+ $this->api_host = "https://api.test.haodian.cn";
+ } else { // 正式
+ $this->env = 'p';
+ $this->host = "https://www.haodian.cn";
+ $this->api_host = "https://api.haodian.cn";
+ }
+ }
+}
diff --git a/home/controllers/h5/syt/Myqrcode.php b/home/controllers/h5/syt/Myqrcode.php
new file mode 100644
index 00000000..2a169efe
--- /dev/null
+++ b/home/controllers/h5/syt/Myqrcode.php
@@ -0,0 +1,51 @@
+input->get('url');
+ if ($url) {
+ $errorCorrectionLevel = 'L'; //容错级别
+ $matrixPointSize = 5; //生成图片大小
+ //生成二维码图片
+ QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize, 1);
+ }
+ }
+
+ function save()
+ {
+ $basedir = '';
+ $saveDir = '要保存的目录地址';
+ if (!is_dir($saveDir)) {
+ mkdir($basedir);
+ chmod($basedir, 0777);
+ }
+ if (is_dir($saveDir)) {
+ $filename = $saveDir . '/qrcode.png';
+ $qrcode_content = 'hello qrcode';//二维码的内容
+ ob_clean();
+ QRcode::png($qrcode_content, $filename);
+ echo $filename;
+ } else {
+ exit('目录创建失败');
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/home/controllers/h5/syt/Special.php b/home/controllers/h5/syt/Special.php
new file mode 100644
index 00000000..06f03b70
--- /dev/null
+++ b/home/controllers/h5/syt/Special.php
@@ -0,0 +1,652 @@
+secret = "2021_syt_h5_1119";
+ //$this->load->helper('cookie');
+ $this->load->model('app/licheb/syt_activity_model', 'mdSytActivity');
+ $this->load->model('app/licheb/syt_activity_kpidata_model', 'mdSytActivityKpiData');
+ $this->load->model('app/app_weixin_users_model', 'mdWeixinUsers');
+ $this->load->model('receiver/receiver_customers_model', 'mdCustomers');
+ $this->load->model("biz/biz_model", 'mdBiz');
+ $ukey = get_cookie('ukey');
+ if ($ukey) {
+ $this->session = json_decode(liche_authcode($ukey, 'DECODE', $this->secret), true);
+ $this->uid = $this->session['uid'];
+ }
+ //重置cookie
+ $reset = $this->input_param('reset');
+ if ($reset) {
+ set_cookie("ukey", "", 86400 * 30);
+ $this->session = array();
+ $this->uid = 0;
+ }
+ }
+
+ /**
+ * Notes:
+ * https://liche-dev.xiaoyu.com/h5/syt/special
+ * https://liche-dev.xiaoyu.com/h5/syt/special?skey=YV9pZD03JmNmX3VpZD0yMSZiaXpfaWQ9MiZjZl9zaGFyZT1SNU5JS1c
+ * https://www.liche.cn/h5/syt/special
+ * Created on: 2021/8/26 11:19
+ * Created by: dengbw
+ */
+ function get()
+ {
+ $skey = $this->input->get('skey');
+ //$skey = "YV9pZD03JmNmX3VpZD0yMSZiaXpfaWQ9MiZjZl9zaGFyZT1SNU5JS1c";
+ if (!$skey) {
+ throw new Hd_exception("参数错误", 400);
+ }
+ $this->load->library('MyEncryption');
+ $param = $this->myencryption->base64url_decode($skey);
+ //$skey = "a_id=7&cf_uid=24&biz_id=2&cf_share=" . $this->myencryption->random_string(6);
+ //echo $this->myencryption->base64url_encode($skey);
+ //print_r($param);
+ //exit;
+ $a_id = intval($param['a_id']);//活动id
+ $cf_uid = intval($param['cf_uid']);//来源用户id
+ $biz_id = intval($param['biz_id']);//门店id
+ $cf_share = $param['cf_share'];//分享
+ $re_a = $this->mdSytActivity->get(array("id" => $a_id, "status" => 1));
+ if (!$re_a) {
+ throw new Hd_exception("活动不存在", 400);
+ }
+ $url = http_host_com('home') . "/h5/syt/special?skey={$skey}";
+ $this->set_auth($url);
+ $topic_ary = array('id' => $re_a['z_id'], 'a_id' => $a_id, '_title' => $re_a['title']);
+ $topic = $this->get_topic($topic_ary);
+ if (!$topic) {
+ throw new Hd_exception("专题不存在", 400);
+ }
+ if ($this->uid) {
+ $re_wu = $this->mdWeixinUsers->get(['id' => $this->uid]);
+ if ($re_wu) {//更新参数
+ $jsondata = $re_wu['jsondata'] ? json_decode($re_wu['jsondata'], true) : '';
+ $jsondata['syt'] = $param;
+ $this->mdWeixinUsers->update(['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)], ['id' => $this->uid]);
+ }
+ }
+ //一次性订阅
+// $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/syt/special/subscribemsg?skey=' . $skey
+// . '&s_time=' . $topic['mCountdown']['b_s_time']);
+// $subscribemsg = "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid={$config['appid']}&scene=0}&template_id=DO0B9IYYub1d0oNvy9czzGbe6_1EU8PQmnLEoDOcmXA&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect";
+// }
+// $topic['subscribemsg'] = $subscribemsg;
+ $topic['subscribemsg'] = '';
+ $a_img = $re_a['img'] ? build_qiniu_image_url($re_a['img']) : '';
+ $a_title = $re_a['title'] ? $re_a['title'] : '';
+ //微信分享
+ $this->load->library('Jssdk');
+ $jssdk = new Jssdk('liche');
+ $sign_package = $jssdk->getSignPackage();
+ $t_skey = $c_skey = '';
+ if ($biz_id) {//门店
+ $skey = "a_id=" . $a_id . "&cf_uid=" . $cf_uid . "&biz_id=" . $biz_id . "&cf_share=" . $this->myencryption->random_string(6);
+ $c_skey = "a_id=" . $a_id . "&cf_uid=" . $cf_uid . '&biz_id=' . $biz_id;
+ } else {
+ $skey = "a_id=" . $a_id . "&cf_uid=" . $cf_uid . "&cf_share=" . $this->myencryption->random_string(6);
+ $c_skey = "a_id=" . $a_id . '&cf_uid=' . $cf_uid;
+ }
+ //浏览
+ $this->set_kpi_score(array('a_id' => $a_id, 'cf_uid' => $cf_uid, 'biz_id' => $biz_id, 'kpi' => 'browse'));
+ //分享
+ $cf_share && $this->set_kpi_score(array('a_id' => $a_id, 'cf_uid' => $cf_uid, 'biz_id' => $biz_id, 'cf_share' => $cf_share, 'kpi' => 'share'));
+ $share_url = http_host_com('home') . "/h5/syt/special?skey=" . $this->myencryption->base64url_encode($skey);
+ $jsondata = $re_a['jsondata'] ? json_decode($re_a['jsondata'], true) : '';
+ $share_title = $jsondata['share_title'] ? $jsondata['share_title'] : '';
+ $posters = $jsondata['posters'] ? $jsondata['posters'] : '';
+ $share = array(
+ 'title' => $a_title,
+ "img" => $a_img,
+ "desc" => $share_title,
+ "url" => $share_url
+ );
+ //渠道获取统计代码
+ $stat_code = "";
+// if ($t_id) {
+// $where = array('id' => $t_id);
+// $row = $this->mdSytActivityTeam->get($where);
+// $row['declaration'] && $stat_code = $row['declaration'];
+// }
+ $topic['a_skey'] = $this->myencryption->base64url_encode("a_id=" . $a_id);
+ $topic['c_skey'] = $this->myencryption->base64url_encode($c_skey);
+ $topic['t_skey'] = $t_skey;
+ $topic['a_id'] = $a_id;
+ $topic['cf_uid'] = $cf_uid;
+ $topic['biz_id'] = $biz_id;
+ $topic['uid'] = $this->uid;
+ $topic['posters'] = $posters;
+ $topic['stat_code'] = $stat_code;
+ $data = array(
+ '_title' => $a_title,
+ 'view' => 'h5/syt/special',
+ 'topic' => $topic,
+ "sign_package" => $sign_package,
+ "share" => $share,
+ );
+ return $data;
+ }
+
+ private function get_topic($param = array())
+ {
+ $data = $list = $mButton = array();
+ $mCountdown = array('b_e_time' => 0, 'b_s_time' => 0);
+ $this->load->model('app/App_model', 'mdApp');
+ $this->load->model('topics/topics_model', 'mdTopics');
+ $this->load->model('topics/topic_modules_model', 'mdTopicModules');
+ $this->load->model('topics/topic_module_text_model', 'mdModuleText');
+ $this->load->model('topics/topic_module_ad_model', 'mdModuleAd');
+ $this->load->model('topics/topic_module_enroll_model', 'mdModuleEnroll');
+ $this->load->model('topics/topic_module_button_model', 'mdModuleButton');
+// $this->load->model('topics/topic_module_countdown_model', 'mdModuleCountdown');
+ $re = $this->mdTopics->get(array('id' => $param['id'], 'app_id' => $this->app_id));
+ if (!$re) {
+ return $data;
+ }
+ $appConfig = array();
+ $mp_app_id = $mp_app_name = '';
+ $ebiz = 0;
+ if ($re['jsondata']) {
+ $topics_jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : array();
+ if ($topics_jsondata['mp_app_id']) {
+ $appConfig = $this->mdApp->appConfig()[$topics_jsondata['mp_app_id']];
+ $mp_app_id = $topics_jsondata['mp_app_id'];
+ $mp_app_name = $appConfig['wx_kzh']['appname'] ? $appConfig['wx_kzh']['appname'] : '星师傅';
+ }
+ $ebiz = intval($topics_jsondata['ebiz']);
+ }
+ $nickname = $mobile = $msgisReg = '';
+ $module_ids = $re['module_ids'];
+ if ($module_ids) {
+ $where = is_numeric($module_ids) ? array('id' => $module_ids) : array("id in ({$module_ids})" => null);
+ $where['status'] = 1;
+ $total = $this->mdTopicModules->count($where);
+ if ($total) {
+ $select = 'id, type,jsondata';
+ $rows = $this->mdTopicModules->select($where, 'sort DESC', 0, 0, $select);
+ foreach ($rows as $row_topic) {
+ $mid = $row_topic['id'];
+ $type = $row_topic['type'];
+ $json_topic = json_decode($row_topic['jsondata'], true);
+ $title_img = "";
+ $title_icon = "";
+ if ($json_topic['title_img']) {
+ $title_img = build_qiniu_image_url($json_topic['title_img']);
+ } else {
+ $title_icon = "https://qs.haodian.cn/wechat_app/xingxuanka/special/tt-tip2.png";
+ }
+ switch ($type) {
+ case "countdown"://倒计时
+ $module = $this->mdModuleCountdown->get(array('module_id' => $mid));
+ $jsondata = $module['jsondata'] ? json_decode($module['jsondata'], true) : array();
+ $b_s_time = $jsondata['time'] ? $jsondata['time'] : 0;
+ $b_e_time = strtotime($b_s_time) - time();
+ $b_e_time < 0 && $b_e_time = 0;
+ $mCountdown = array(
+ 'title' => $module['title'] ? $module['title'] : '',
+ 'b_title' => $jsondata['title'] ? $jsondata['title'] : '',
+ 'b_mp_title' => $jsondata['mp_title'] ? $jsondata['mp_title'] : '',
+ 'b_ghid' => $appConfig['ghid'] ? $appConfig['ghid'] : '',
+ 'b_s_time' => $b_s_time,
+ 'b_e_time' => $b_e_time,
+ );
+ break;
+ case "button"://按钮类型
+ $module = $this->mdModuleButton->get(array('module_id' => $mid));
+ $jsondata = $module['jsondata'] ? json_decode($module['jsondata'], true) : array();
+ $ghid = $url = '';
+ $url = $jsondata['url'] ? $jsondata['url'] : '';
+ $url_mini = $jsondata['url_mini'] ? $jsondata['url_mini'] : '';//在小程序里连接
+ if ($appConfig['ghid'] && (strstr($url, 'pages'))) {//跳转小程序
+ $ghid = $appConfig['ghid'];
+ }
+ $mButton = array(
+ 'title' => $module['title'] ? $module['title'] : '',
+ 'type' => $module['type'],
+ 'b_url' => $url,
+ 'b_url_mini' => $url_mini,
+ 'b_title' => $jsondata['title'] ? $jsondata['title'] : '',
+ 'b_img' => $jsondata['img'] ? build_qiniu_image_url($jsondata['img']) : '',
+ 'b_color' => $jsondata['color'] ? $jsondata['color'] : '',
+ 'b_ghid' => $ghid,
+ );
+ break;
+ case "text"://文本类型
+ $module = $this->mdModuleText->get(array('module_id' => $mid));
+ $list[] = array(
+ "type" => "text",
+ 'id' => $mid,
+ 'title' => $module['title'] ? $module['title'] : '',
+ "title_img" => $title_img,
+ "title_icon" => $title_icon,
+ "title_color" => $json_topic["title_color"] ? $json_topic["title_color"] : "#fff",//背景色,
+ "title_bgcolor" => $json_topic["title_bgcolor"] ? $json_topic["title_bgcolor"] : "#ee5b15",//背景色
+ 'bg_img' => $json_topic['bg_img'] ? build_qiniu_image_url($json_topic['bg_img']) : "",
+ 'bg_color' => $json_topic["bg_color"] ? $json_topic["bg_color"] : '#ff0',
+ "border_color" => strval($json_topic['border_color']),
+ 'descrip' => $module['descrip'] ? $module['descrip'] : '',
+ 'content' => $module['content'] ? $module['content'] : '',
+ 'style' => 0,
+ 'ads' => array(),
+ );
+ break;
+ case 'ad'://广告
+ $module = $this->mdModuleAd->get(array('module_id' => $mid));
+ $module_json = $module['img_json'] ? json_decode($module['img_json'], true) : array();
+ $ads = array();
+ foreach ($module_json as $ad) {
+ $url = strval($ad['link']);
+ $miniProgram = '';
+ $img = $ad['img'] ? build_qiniu_image_url($ad['img']) : '';
+ if ($appConfig['ghid'] && strstr($url, 'pages')) {//跳转小程序
+ $img_class = $module['style'] == 2 ? 'wp100 block bds-f3' : 'wp100 block';
+ $miniProgram = '
+
+
+
+
';
+ }
+ $is_item = false;
+ if (strpos($url, "wxapp/syt/item") !== false) {
+ $url .= "&__skey=" . $this->input_param('skey');
+ $is_item = true;
+ }
+ $ads[] = array(
+ 'type' => 'ad',
+ 'img' => $img,
+ 'url' => $url ? $url : '',
+ 'miniProgram' => $miniProgram,
+ 'jump_type' => intval($ad['jump_type']),
+ 'is_item' => $is_item,
+ 'title' => $ad['title']
+ );
+ }
+ $title_img = "";
+ $title_icon = "";
+ if ($json_topic['title_img']) {
+ $title_img = build_qiniu_image_url($json_topic['title_img']);
+ } else {
+ $title_icon = "https://qs.haodian.cn/wechat_app/xingxuanka/special/tt-tip2.png";
+ }
+ $list[] = array(
+ "type" => "ad",
+ 'id' => $mid,
+ 'title' => $module['title'] ? $module['title'] : '',
+ "title_img" => $title_img,
+ "title_icon" => $title_icon,
+ "title_color" => $json_topic["title_color"] ? $json_topic["title_color"] : "#fff",//背景色,
+ "title_bgcolor" => $json_topic["title_bgcolor"] ? $json_topic["title_bgcolor"] : "#fe7c35",//背景色
+ 'bg_img' => $json_topic['bg_img'] ? build_qiniu_image_url($json_topic['bg_img']) : "",
+ 'bg_color' => $json_topic["bg_color"] ? $json_topic["bg_color"] : (2 == $module['style'] ? '#FFF' : ''),
+ "border_color" => strval($json_topic['border_color']),
+ 'descrip' => $module['descrip'] ? $module['descrip'] : '',
+ 'content' => '',
+ 'style' => $module['style'],
+ 'ads' => $ads,
+ );
+ break;
+ case 'enroll'://报名活动
+ $module = $this->mdModuleEnroll->get(array('module_id' => $mid));
+ //处理状态字段
+ $status = array("title" => "我要报名", "value" => 0);
+ //是否开始
+ if (1 == $module['type']) {
+ $s_time = strtotime($module['as_time']);
+ $e_time = strtotime($module['ae_time']);
+ } else {
+ $s_time = strtotime($module['es_time']);
+ $e_time = strtotime($module['ee_time']);
+ }
+ if ($s_time > time()) {
+ $status = array("title" => "报名尚未开始", "value" => 2);
+ } elseif ($e_time < time()) {
+ $status = array("title" => "报名已截止", "value" => -2);
+ }
+ //判断是否还能参加报名
+ if (0 == $status['value'] && $module['limit_num'] > 0) {
+ $where = array('a_id' => $param['a_id']);
+ $count = $this->mdSytActivityEnroll->count($where);
+ if ($count >= $module['limit_num']) {
+ $status = array("title" => "报名人数已满", "value" => 3);
+ }
+ }
+ if ($this->uid) {//是否报名
+ $re_enroll = [];
+ $this->session['mobile'] && $re_enroll = $this->mdCustomers->get(array('cf_id' => $this->cf_id, 't_id' => $param['a_id'], 'mobile' => $this->session['mobile']));
+ if ($re_enroll) {
+ $status = array("title" => "已报名", "value" => 1);
+ } else {
+ $reUsers = $this->mdWeixinUsers->get(array('id' => $this->uid));
+ $nickname = $reUsers['nickname'] ? $reUsers['nickname'] : '';
+ $mobile = $reUsers['mobile'] ? $reUsers['mobile'] : '';
+ }
+ }
+ $jsondata = $module['jsondata'] ? json_decode($module['jsondata'], true) : array();
+ $if_code = intval($jsondata['if_code']);//是否验证手机
+ if ($jsondata["show_type"] == 1) {
+ $msgisReg = array(
+ 'title' => $module['title'] ? $module['title'] : '报名',
+ 'if_code' => $if_code,
+ 'status' => $status);
+ break;
+ }
+
+ $info = array(
+// array("title" => "姓名", "field" => "input", "key" => "uname"),
+// array("title" => "手机号", "field" => "mobile", "key" => "mobile"),
+// array("title" => "备注", "field" => "input", "key" => "remark"),
+ );
+ $record = array();
+ $date_arr = array(
+ date('Y.m.d'),
+ date('Y.m.d', strtotime("-1 day")),
+ date('Y.m.d', strtotime("-2 day")),
+ date('Y.m.d', strtotime("-3 day"))
+ );
+ $num = 10;
+ $res = $this->mdCustomers->select(array('cf_id' => $this->cf_id, 't_id' => $param['a_id']), 'c_time desc', 1, $num);
+ if ($res) {
+ foreach ($res as $key2 => $val2) {
+ $nick_name = $val2['nickname'];
+ $len = mb_strlen($nick_name, 'UTF-8');
+ if ($len >= 3) {
+ $nick_name = mb_substr($nick_name, 0, 1, 'UTF-8') . '*' . mb_substr($nick_name, -1, 1, 'UTF-8');
+ } else {
+ $nick_name = mb_substr($nick_name, 0, 1, 'UTF-8') . '*';
+ }
+ $record[] = date('Y.m.d', $val2['c_time']) . ' ' . $nick_name . ' 报名了 ' . $param['_title'];
+ }
+ }
+ $num = $num - count($record);
+ if ($num) {
+ for ($i = 0; $i < $num; $i++) {
+ $record[] = $date_arr[array_rand($date_arr)] . ' ' . rand_name() . ' 报名了 ' . $param['_title'];
+ }
+ }
+ $list[] = array(
+ "type" => "enroll",
+ 'id' => $mid,
+ 'title' => $module['title'] ? $module['title'] : '',
+ "title_img" => $title_img,
+ "title_icon" => $title_icon,
+ "title_color" => $json_topic["title_color"] ? $json_topic["title_color"] : "#fff",//背景色,
+ "title_bgcolor" => $json_topic["title_bgcolor"] ? $json_topic["title_bgcolor"] : "#ee5b15",//背景色
+ 'bg_img' => $json_topic['bg_img'] ? build_qiniu_image_url($json_topic['bg_img']) : "",
+ 'bg_color' => $json_topic["bg_color"] ? $json_topic["bg_color"] : '#fff',
+ "border_color" => strval($json_topic['border_color']),
+ 'descrip' => $module['descrip'] ? $module['descrip'] : '',
+ 'content' => $module['content'] ? $module['content'] : '',
+ 'style' => 0,
+ 'if_code' => $if_code,
+ 'ads' => array(),
+ 'status' => $status,
+ 'info' => $info,
+ 'record' => $record
+ );
+ break;
+ default:
+ }
+ }
+ }
+ }
+
+ $data = array(
+ 'id' => $param['id'],
+ 'title' => $re['title'],
+ 'bg_img' => build_qiniu_image_url($re['bg_img']),
+ 'bg_color' => $re['bg_color'],
+ 'ebiz' => $ebiz,
+ 'list' => $list,
+ 'name' => $nickname,
+ 'telPhone' => $mobile,
+ 'vCode' => '',
+ 'codeState' => true,
+ 'codeTx' => '获取验证码',
+ 'isSubmiting' => false,
+ 'mButton' => $mButton,
+ 'mCountdown' => $mCountdown,
+ "bundleIntervalEvent" => '',
+ 'msgisShowCode' => false,
+ 'msgisRegShow' => false,
+ "qrcode" => '',
+ "logintelPhone" => '',
+ "loginvCode" => '',
+ "logincodeState" => true,
+ "logincodeTx" => '获取验证码',
+ "loginBundleIntervalEvent" => '',
+ 'loginBackurl' => '',
+ "msgisLoginShowCode" => false,
+ "needLogin" => $reUsers['mobile'] ? false : true,
+ 'mp_app_id' => $mp_app_id,
+ 'mp_app_name' => $mp_app_name,
+ 'msgisReg' => $msgisReg,
+ );
+ return $data;
+ }
+
+ /**
+ * Notes:生成海报
+ * Created on: 2022/1/20 16:35
+ * Created by: dengbw
+ * @return array
+ * @throws Hd_exception
+ */
+ protected function get_poster()
+ {
+ $skey = $this->input_param('skey');
+ if (!$skey) {
+ throw new Hd_exception("参数错误", 400);
+ }
+ $this->load->library('MyEncryption');
+ $param = $this->myencryption->base64url_decode($skey);
+ $a_id = intval($param['a_id']);//活动id
+ $cf_uid = intval($param['cf_uid']);
+ $biz_id = intval($param['biz_id']);//门店id
+ $re_a = $this->mdSytActivity->get(array("id" => $a_id, "status" => 1));
+ if (!$re_a) {
+ throw new Hd_exception("活动不存在", 400);
+ }
+ $url = http_host_com('home') . "/h5/wxapp/syt/special/poster?skey={$skey}";
+ $this->set_auth($url);
+ if ($biz_id) {//门店
+ $skey = "a_id=" . $a_id . "&cf_uid=" . $cf_uid . "&biz_id=" . $biz_id . "&cf_share=" . $this->myencryption->random_string(6);
+ } else {
+ $skey = "a_id=" . $a_id . "&cf_uid=" . $cf_uid . "&cf_share=" . $this->myencryption->random_string(6);
+ }
+ $share_url = http_host_com('home') . "/h5/syt/special?skey=" . $this->myencryption->base64url_encode($skey);
+ $qr_cod = '/h5/syt/myqrcode/get?url=' . $share_url;
+ $posters = array();
+ if ($re_a['jsondata']) {
+ $jsondata = json_decode($re_a['jsondata'], true);
+ if ($jsondata['posters']) {//海报
+ foreach ($jsondata['posters'] as $key => $value) {
+ $posters[] = array("img" => build_qiniu_image_url($value['url']), "code" => $qr_cod,
+ "width" => $value['width'], "height" => $value['height']);
+ }
+ }
+ }
+ $this->load->library('Jssdk');
+ $jssdk = new Jssdk('liche');
+ $sign_package = $jssdk->getSignPackage();
+ $data = array(
+ '_title' => '生成海报',
+ 'posters' => $posters,
+ 'sign_package' => $sign_package,
+ 'view' => 'h5/syt/special_poster',
+ );
+ return $data;
+ }
+
+ /**
+ * Notes:活动报名
+ * Created on: 2020/11/3 14:36
+ * Created by: dengbw
+ * @throws Hd_exception
+ */
+ function post_enroll()
+ {
+ $params = $this->input->post();
+ $mobile = $params['mobile'];
+ $code = $params['code'];
+ $nickname = $params['nickname'];
+ $if_code = $params['if_code'];
+ if (!$nickname) {
+ throw new Hd_exception('请输入昵称', 400);
+ }
+ if (!mobile_valid($mobile)) {
+ throw new Hd_exception('手机号码不正确', 400);
+ }
+ $key = '';
+ if (!$if_code) {//0开启,1关闭
+ if (!$code) {
+ throw new Hd_exception('请输入验证码', 400);
+ }
+ $key = $this->redis_mcode . $mobile;
+ if (!in_array($mobile, $this->white_mobile)) {//校验手机号
+ $code_check = $this->lc_redis->get($key);
+ if (!$code || $code != $code_check) {
+ throw new Hd_exception("验证码不正确", 400);
+ }
+ }
+ }
+ $params['cf_platform'] = 'h5';
+ $params['mobile'] = $mobile;
+ $params['nickname'] = $nickname;
+ $params['uid'] = $this->uid;
+ $params['cf_id'] = $this->cf_id;
+ $this->load->library('entity/syt_entity');
+ $syt_entity = new Syt_entity(array('app_id' => $this->app_id));
+ $results = $syt_entity->kpi_enroll_log($params);
+ if ($results['code'] == 400) {
+ throw new Hd_exception($results['msg'], $results['code']);
+ }
+ $key && $this->lc_redis->delete($key);
+ throw new Hd_exception($results['msg'], $results['code']);
+ }
+
+ /**
+ * Notes:获取短信验证码
+ * Created on: 2020/10/14 22:10
+ * Created by: dengbw
+ * @throws Hd_exception
+ */
+ protected function get_mcode()
+ {
+ $mobile = $this->input_param('mobile');
+ $title = $this->input_param('title');
+ if (!mobile_valid($mobile)) {
+ throw new Hd_exception('手机号码不正确', 400);
+ }
+ $key = $this->redis_mcode . $mobile;
+ $code = $this->lc_redis->get($key);
+ if (!$code) {
+ $this->load->helper('string');
+ $code = random_string('numeric', 6);
+ $this->lc_redis->save($key, $code, 600);
+ }
+ $content = "【狸车】您正在参与{$title}报名,验证码 {$code}";
+ b2m_send_sms($mobile, $content);
+ throw new Hd_exception('发送成功', 200);
+ }
+
+ /**
+ * Notes:设置kpi加分
+ * Created on: 2020/10/15 10:09
+ * Created by: dengbw
+ * @param array $param
+ */
+ private function set_kpi_score($param = array())
+ {
+ $param['uid'] = $this->uid;
+ if ($param['a_id'] && $param['uid'] && ($param['cf_uid'] || $param['biz_id'])) {
+ $this->load->library('entity/syt_entity');
+ $syt_entity = new Syt_entity(array('app_id' => $this->app_id));
+ $syt_entity->kpi_log($param);
+ }
+ }
+
+ /**
+ * Notes:未登录授权登录
+ * Created on: 2020/10/28 21:07
+ * Created by: dengbw
+ * @param $url
+ */
+ protected function set_auth($url)
+ {
+ if ("wx" == checkua() && !$this->uid) {
+ $this->load->helper('url');
+ $config['appid'] = 'wxe66f905683582780';//小红榜授权
+ $config['appSecret'] = '9546cd4de877be13ce203f3e6140633f';
+ $this->load->config('wechat');
+ $config = $this->config->item('liche');
+ $code = $this->input->get('code');
+ $auth = 1;//是否信息授权
+ $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);
+ $openid = $ret['openid'];
+ $unionid = $ret['unionid'];
+ $mobile = '';
+ if ($openid) {
+ $row_wechat = $this->mdWeixinUsers->get(array('openid' => $openid));
+ if (!$row_wechat) {//用户授权信息未记录到wechat
+ $info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$ret['access_token']}&openid={$openid}&lang=zh_CN";
+ $res = file_get_contents($info_url);
+ $ret = json_decode($res, true);
+ $unionid = $ret['unionid'];
+ $add = array(
+ 'nickname' => strval($ret['nickname']),
+ "headimg" => strval($ret['headimgurl']),
+ "unionid" => $unionid,
+ "openid" => $openid,
+ "app_id" => $this->app_id,
+ "c_time" => time()
+ );
+ $this->uid = $this->mdWeixinUsers->add($add);
+ if (!$this->uid) {
+ debug_log("[error]# " . $this->mdWeixinUsers->db->last_query(), __FUNCTION__, $this->log_dir);
+ }
+ } else {
+ !$unionid && $unionid = $row_wechat['unionid'];
+ $this->uid = $row_wechat['id'];
+ $mobile = $row_wechat['mobile'];
+ }
+ }
+ if ($this->uid) {
+ $session = array('uid' => $this->uid, "unionid" => $unionid, "mobile" => $mobile);
+ $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret);
+ set_cookie("ukey", $ukey, 86400 * 30);
+ }
+ } 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";
+ 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);
+ }
+ }
+ }
+
+}
diff --git a/home/libraries/Hdwechat.php b/home/libraries/Hdwechat.php
new file mode 100644
index 00000000..63c16cf9
--- /dev/null
+++ b/home/libraries/Hdwechat.php
@@ -0,0 +1,215 @@
+init($config);
+ }
+
+ /**
+ * @param $config ('appid', 'secret')
+ */
+ function init($config){
+ $this->appid = $config['appid'];
+ $this->secret = $config['secret'];
+ $this->token_url = $config['token_url'];
+
+ $CI = & get_instance();
+ $CI->load->library("hd_wechat", $config);
+ /*这里用new的方式,因为load如果对象已经存在,会去取旧的,不会生成新配置的对象*/
+ $this->hd_wechat = new Hd_wechat($config);
+ }
+
+ /**
+ * 获取或者重置access_token
+ * @param $reset (是否重置)
+ * @return mixed
+ */
+ function access_token($reset = false){
+
+ $this->access_token = $this->hd_wechat->access_token($reset);
+
+ return $this->access_token;
+ }
+
+
+ /**
+ * 生成二维码
+ * @param $filename (文件名称)
+ * @param $scene (最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
+ * @param $page (必须是已经发布的小程序存在的页面(否则报错),例如 pages/index/index, 根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面)
+ * @param $width (二维码的宽度,单位 px,最小 280px,最大 1280px,默认430px)
+ * @return array {'file':'文件路径', 'url':'访问相对路径'}
+ */
+ function wxacode($filename, $scene, $page, $width){
+ $file = APPPATH . '../www/home/wx/wxacode/' . $filename . '.png';
+ $dir = substr($file, 0, strrpos($file, '/'));
+ if(!is_dir($dir)){
+ $ret = mkdir($dir, 0777, true);// 如果文件夹不存在,将以递归方式创建该文件夹
+ if(!$ret){
+ debug_log("[error] ". __FUNCTION__ . ": mkdir {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
+ return array();
+ }
+ }
+
+ if(file_exists($file)){
+ return array('file' => $file, 'url' => 'wx/wxacode/' . $filename . '.png');
+ }
+
+ $pre_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
+ $url = $pre_url . $this->access_token();
+ $data = array(
+ 'scene' => $scene,
+ 'page' => $page,
+ 'width' => $width ? $width : 430,
+ );
+
+ list($code, $res) = $this->curl_post($url, $data);
+ $ret = json_decode($res, true);
+
+ if(isset($ret['errcode']) && 40001 == $ret['errcode']){//token过期,重置后请求
+ $url = $pre_url . $this->access_token(true);
+ list($code, $res) = $this->curl_post($url, $data);
+ $ret = json_decode($res, true);
+ }
+
+ if(isset($ret['errcode'])){
+ debug_log("[error] ". __FUNCTION__ . ": httpcode:{$code}, response:{$res}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
+ return array();
+ }
+
+ $ret = file_put_contents($file, $res);
+ if(false === $ret){
+ debug_log("[error] ". __FUNCTION__ . ": file_put_contents {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
+ return array();
+ }
+
+ return array('file' => $file, 'url' => 'wx/' . $filename . '.png');
+ }
+
+ function qrcode($filename, $scene, $type = 0, $expire = 0){
+ $file = APPPATH . '../www/home/wx/qrcode/' . $filename . '.png';
+ $file_url = 'wx/qrcode/' . $filename . '.png';
+ $dir = substr($file, 0, strrpos($file, '/'));
+ if(!is_dir($dir)){
+ $ret = mkdir($dir, 0777, true);// 如果文件夹不存在,将以递归方式创建该文件夹
+ if(!$ret){
+ debug_log("[error] ". __FUNCTION__ . ": mkdir {$ret}, filename:{$filename}, scene:{$scene}", $this->log_file);
+ return array();
+ }
+ }
+
+ if(file_exists($file)){
+ return array('file' => $file, 'url' => $file_url);
+ }
+
+ if(is_numeric($scene)){
+ $action_info = array(
+ 'scene' => array('scene_id' => $scene)
+ );
+ $action_name = $type ? 'QR_LIMIT_SCENE' : 'QR_SCENE';
+ } else {
+ $action_info = array(
+ 'scene' => array('scene_str' => $scene)
+ );
+ $action_name = $type ? 'QR_LIMIT_STR_SCENE' : 'QR_STR_SCENE';
+ }
+
+ $data = array(
+ 'action_name' => $action_name,
+ 'action_info' => $action_info
+ );
+ $expire && $data['expire_seconds'] = $expire;
+
+ $qr_url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=';
+ $url = $qr_url . $this->access_token();
+
+ //请求获取二维码的ticket
+ list($code, $res) = $this->curl_post($url, $data);
+ $ret = json_decode($res, true);
+
+ if(isset($ret['errcode']) && 40001 == $ret['errcode']){//token过期,重置后请求
+ $url = $qr_url . $this->access_token(true);
+ list($code, $res) = $this->curl_post($url, $data);
+ $ret = json_decode($res, true);
+ }
+
+ if(isset($ret['errcode'])){
+ debug_log("[error] ". __FUNCTION__ . ": httpcode:{$code}, response:{$res}, filename:{$filename}, scene:{$scene}", $this->log_file);
+ return array();
+ }
+
+ if(!$ret['ticket']){
+ debug_log("[error] ". __FUNCTION__ . ": not ticket, filename:{$filename}, scene:{$scene}", $this->log_file);
+ return array();
+ }
+
+ //根据ticket获取
+ $ticket_url='https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.$ret['ticket'];
+
+ debug_log("[info] ". __FUNCTION__ . ": ticket_url=$ticket_url", $this->log_file);
+
+ $ret = file_put_contents($file, $this->url_get($ticket_url));
+ if(false === $ret){
+ debug_log("[error] ". __FUNCTION__ . ": file_put_contents {$ret}, filename:{$filename}, scene:{$scene}", $this->log_file);
+ return array();
+ }
+
+ return array('file' => $file, 'url' => $file_url);
+ }
+
+ /**
+ * @param $url
+ * @param $data
+ * @return array
+ */
+ private function curl_post($url, $data){
+ debug_log("[info] ". __FUNCTION__ . ":url={$url}, data=".json_encode($data), $this->log_file);
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+ $res = curl_exec($ch);
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+
+ $size = strlen($res);
+ if($size > 5000){
+ debug_log("[info] ". __FUNCTION__ . ":httpcode={$code}, response is big only show size={$size}", $this->log_file);
+ } else {
+ debug_log("[info] ". __FUNCTION__ . ":httpcode={$code}, response={$res}", $this->log_file);
+ }
+
+ return array($code, $res);
+ }
+
+ /**
+ * @param $url
+ * @return string
+ */
+ private function url_get($url){
+ $res = file_get_contents($url);
+ debug_log("[info] ". __FUNCTION__ . ":url={$url}, res={$res}", $this->log_file);
+ return $res;
+ }
+}
\ No newline at end of file
diff --git a/home/libraries/Jssdk.php b/home/libraries/Jssdk.php
new file mode 100644
index 00000000..4fa21937
--- /dev/null
+++ b/home/libraries/Jssdk.php
@@ -0,0 +1,85 @@
+appId = $group['appid'];
+ $this->appSecret = $group['appSecret'];
+ } else {
+ $CI->load->config('wechat');
+ $config =$CI->config->item($group);
+
+ $this->appId = $config['appid'];
+ $this->appSecret = $config['appSecret'];
+ }
+
+ $r = &load_cache('redis');
+ $this->redis = $r->redis();
+
+ $param = array('appid' => $this->appId, "secret" => $this->appSecret);
+ $CI->load->library("hd_wechat", $param);
+ $this->hd_wechat = $CI->hd_wechat;
+ $this->hd_wechat->init($param);
+ }
+
+ public function getSignPackage()
+ {
+ $jsapiTicket = $this->getJsApiTicket();
+ $url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
+
+ if($_SERVER['QUERY_STRING'])
+ {
+ //$url .= '?'.$_SERVER['QUERY_STRING'];
+ }
+
+ $timestamp = time();
+ $nonceStr = $this->createNonceStr();
+
+ // 这里参数的顺序要按照 key 值 ASCII 码升序排序
+ $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
+ $signature = sha1($string);
+
+ $signPackage = array(
+ "appId" => $this->appId,
+ "nonceStr" => $nonceStr,
+ "timestamp" => $timestamp,
+ "url" => $url,
+ "signature" => $signature,
+ "rawString" => $string,
+ 'jsapi_ticket' => $jsapiTicket
+ );
+
+ return $signPackage;
+ }
+
+ private function createNonceStr($length = 16)
+ {
+ $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ $str = "";
+ for ($i = 0; $i < $length; $i++)
+ {
+ $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
+ }
+
+ return $str;
+ }
+
+ private function getJsApiTicket()
+ {
+ $ticket = $this->hd_wechat->api_ticket();
+ return $ticket;
+ }
+}
diff --git a/home/views/h5/footer.php b/home/views/h5/footer.php
new file mode 100644
index 00000000..98709269
--- /dev/null
+++ b/home/views/h5/footer.php
@@ -0,0 +1,3 @@
+