From 3c186cb310b35925a980b74f736239dc429e96d7 Mon Sep 17 00:00:00 2001 From: dengbw Date: Sat, 7 May 2022 15:15:44 +0800 Subject: [PATCH] live_507 --- admin/controllers/app/licheb/Sytlive.php | 423 +++++++++++++++ admin/controllers/app/licheb/Userslog.php | 10 +- admin/hooks/Auth.php | 20 +- admin/views/app/licheb/syt/live_edit.php | 555 ++++++++++++++++++++ admin/views/app/licheb/syt/live_lists.php | 78 +++ admin/views/app/licheb/userslog/lists.php | 18 +- api/controllers/plan/Licheb.php | 8 +- api/controllers/plan/Temp.php | 90 ++-- common/helpers/comm_helper.php | 6 +- common/models/app/licheb/Syt_live_model.php | 18 + home/controllers/h5/syt/Live.php | 237 ++++++--- home/views/h5/syt/live.php | 110 +++- 12 files changed, 1430 insertions(+), 143 deletions(-) create mode 100644 admin/controllers/app/licheb/Sytlive.php create mode 100644 admin/views/app/licheb/syt/live_edit.php create mode 100644 admin/views/app/licheb/syt/live_lists.php create mode 100644 common/models/app/licheb/Syt_live_model.php diff --git a/admin/controllers/app/licheb/Sytlive.php b/admin/controllers/app/licheb/Sytlive.php new file mode 100644 index 00000000..a1fc7384 --- /dev/null +++ b/admin/controllers/app/licheb/Sytlive.php @@ -0,0 +1,423 @@ + '已删除', 0 => '待审核', 1 => '已通过', 2 => '未通过'); + private $app_id = 2; + + public function __construct() + { + parent::__construct(); + $this->load->model('app/licheb/syt_live_model', 'mdSytLive'); + } + + public function index() + { + return $this->lists(); + } + + public function lists() + { + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 20; + $lists = array(); + $where = array('status>' => -1); + $count = $this->mdSytActivity->count($where); + if ($count) { + $this->load->library('MyEncryption'); + $res = $this->mdSytActivity->select($where, 'id desc', $params['page'], $params['size']); + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['title'] = $value['title']; + $z_title = ''; + if ($value['z_id']) { + $re_t = $this->mdTopics->get(array('id' => $value['z_id'])); + $re_t['title'] && $z_title = $re_t['title']; + } + $setValue['z_id'] = $value['z_id']; + $setValue['z_title'] = $z_title; + $setValue['s_time'] = $value['s_time']; + $setValue['e_time'] = $value['e_time']; + $setValue['c_time'] = date('Y-m-d H:i', $value['c_time']); + $setValue['status_name'] = $this->statusAry[$value['status']]; + + $url = http_host_com('home') . "/h5/syt/special?skey=" . $this->myencryption->base64url_encode("a_id=" . $value['id']); + $setValue['url'] = urlencode($url); + $lists[] = $setValue; + } + } + $this->data['_title'] = '私域通-直播列表'; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + $this->data['lists'] = $lists; + $this->data['params'] = $params; + return $this->show_view('/app/licheb/syt/live_lists', true); + } + + public function get() + { + $params = $this->input->get(); + $id = intval($params['id']); + $status_list = $kpi_list = array(); + $posters = array('imgs_url' => array(), 'imgs' => array()); + $share_title = $remark = $rule = $bg_color = $btn_color = ''; + if ($id > 0) { + $re = $this->mdSytActivity->get(array('id' => $id)); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '活动不存在!'); + } + $_title = '编辑私域通活动'; + $dataInfo['editType'] = 0; + $dataInfo['edit_url'] = '/app/licheb/sytactivity/edit'; + $dataInfo['brand_id'] = $re['brand_id'] ? explode(',', $re['brand_id']) : []; + $dataInfo['status'] = $re['status']; + $dataInfo['z_id'] = $re['z_id']; + if ($re['jsondata']) { + $jsondata = json_decode($re['jsondata'], true); + $share_title = $jsondata['share_title'] ? $jsondata['share_title'] : ''; + $remark = $jsondata['remark'] ? $jsondata['remark'] : ''; + $rule = $jsondata['rule'] ? $jsondata['rule'] : ''; + $bg_color = $jsondata['bg_color'] ? $jsondata['bg_color'] : ''; + $btn_color = $jsondata['btn_color'] ? $jsondata['btn_color'] : ''; + if ($jsondata['posters']) { + foreach ($jsondata['posters'] as $key => $value) { + $posters['imgs_url'][] = array("value" => $value['url'], "src" => build_qiniu_image_url($value['url'])); + $posters['imgs'][] = array("value" => $value['url'], "src" => build_qiniu_image_url($value['url']) + , "width" => $value['width'], "height" => $value['height']); + } + } + } + if ($re['z_id']) { + $re_t = $this->mdTopics->get(array('id' => $re['z_id'])); + $dataInfo['z_title'] = $re_t['title'] ? $re_t['title'] : ''; + } + $dataInfo['title'] = $re['title']; + $dataInfo['img'] = $re['img'] ? $re['img'] : ''; + $dataInfo['img_url'] = $re['img'] ? build_qiniu_image_url($re['img']) : ''; + $dataInfo['time'] = $re['s_time'] . " ~ " . $re['e_time']; + $jsonkpi = $re['jsonkpi'] ? json_decode($re['jsonkpi'], true) : ''; + foreach ($this->mdSytKpiData->kpiAry() as $key => $value) { + $kpi_list[$key] = array("num" => $jsonkpi[$key]['num'], "score" => $jsonkpi[$key]['score'] + , "title" => $value['title1'], "num_tag" => $value['num_tag'], "score_tag" => $value['score_tag']); + } + } else { + $_title = '新增私域通活动'; + $dataInfo['editType'] = 2; + $dataInfo['edit_url'] = '/app/licheb/sytactivity/add'; + $dataInfo['brand_id'] = []; + $dataInfo['status'] = 0; + $dataInfo['z_id'] = 0; + foreach ($this->mdSytKpiData->kpiAry() as $key => $value) { + $kpi_list[$key] = array("num" => 0, "score" => 0, "title" => $value['title1'], "num_tag" => $value['num_tag'] + , "score_tag" => $value['score_tag']); + } + } + foreach ($this->statusAry as $key => $value) { + $status_list[] = array("id" => $key, "name" => $value); + } + $dataInfo['kpi_list'] = $kpi_list; + $dataInfo['id'] = $id; + $dataInfo['share_title'] = $share_title; + $dataInfo['remark'] = $remark; + $dataInfo['rule'] = $rule; + $dataInfo['bg_color'] = $bg_color; + $dataInfo['btn_color'] = $btn_color; + $this->data['info'] = $dataInfo; + $this->data['status_list'] = $status_list; + $this->data['posters'] = $posters; + $this->data['_title'] = $_title; + return $this->show_view('/app/licheb/syt/activity_edit', true); + } + + public function add() + { + $info = $this->input->post('info'); + $checkData = $this->checkData($info); + if (!$checkData['code']) { + return $this->show_json($checkData['code'], $checkData['msg']); + } + $brand_id = $info['brand_id'] ? implode(',', $info['brand_id']) : 0; + $re = $this->mdSytActivity->get(array("z_id" => $info['z_id'], "brand_id" => $brand_id)); + if ($re) { + return $this->show_json(SYS_CODE_FAIL, '该活动已存在!'); + } + $jsonkpi = json_encode($info['kpi_list'], JSON_UNESCAPED_UNICODE); + $json_data['share_title'] = $info['share_title']; + $json_data['remark'] = $info['remark']; + $json_data['rule'] = $info['rule']; + $json_data['bg_color'] = $info['bg_color']; + $json_data['btn_color'] = $info['btn_color']; + //海报 + $posters = array(); + if ($info['posters']) { + foreach ($info['posters'] as $key => $value) { + $posters[] = array('url' => $value['value'], 'width' => $value['width'], 'height' => $value['height']); + } + } + $json_data['posters'] = $posters; + $jsondata = json_encode($json_data, JSON_UNESCAPED_UNICODE); + $addData = array("brand_id" => $brand_id, "title" => $info['title'], "z_id" => $info['z_id'], "img" => $info['img'] + , "jsonkpi" => $jsonkpi, "jsondata" => $jsondata, "status" => $info['status'], "c_time" => time()); + if ($info['time']) { + $time = explode(' ~ ', $info['time']); + $addData['s_time'] = $time[0]; + $addData['e_time'] = $time[1]; + } + $id = $this->mdSytActivity->add($addData); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '新增活动失败!'); + } + $this->data['type'] = 'add'; + $this->data['id'] = $id; + return $this->show_json(SYS_CODE_SUCCESS, '新增活动成功!'); + } + + public function edit() + { + $info = $this->input->post('info'); + $checkData = $this->checkData($info); + if (!$checkData['code']) { + return $this->show_json($checkData['code'], $checkData['msg']); + } + if (!$info['id']) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $jsonkpi = json_encode($info['kpi_list'], JSON_UNESCAPED_UNICODE); + $json_data['share_title'] = $info['share_title']; + $json_data['remark'] = $info['remark']; + $json_data['rule'] = $info['rule']; + $json_data['bg_color'] = $info['bg_color']; + $json_data['btn_color'] = $info['btn_color']; + //海报 + $posters = array(); + if ($info['posters']) { + foreach ($info['posters'] as $key => $value) { + $posters[] = array('url' => $value['value'], 'width' => $value['width'], 'height' => $value['height']); + } + } + $json_data['posters'] = $posters; + $jsondata = json_encode($json_data, JSON_UNESCAPED_UNICODE); + $brand_id = $info['brand_id'] ? implode(',', $info['brand_id']) : 0; + $updateData = array("brand_id" => $brand_id, "title" => $info['title'], "z_id" => $info['z_id'], "img" => $info['img'] + , "jsonkpi" => $jsonkpi, "jsondata" => $jsondata); + if ($info['time']) { + $time = explode(' ~ ', $info['time']); + $updateData['s_time'] = $time[0]; + $updateData['e_time'] = $time[1]; + } + $this->mdSytActivity->update($updateData, array('id' => $info['id'])); + $this->data['type'] = 'edit'; + return $this->show_json(SYS_CODE_SUCCESS, '修改活动成功!'); + } + + /** + * Notes:修改商家状态 + * Created on: 2020/8/24 11:12 + * Created by: dengbw + * @return bool|void + */ + public function edit_status() + { + $info = $this->input->post('info'); + if (!$info['id']) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $this->mdSytActivity->update(array("status" => intval($info['status'])), array('id' => $info['id'])); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功!'); + } + + + /** + * Notes:私域通-报名 + * Created on: 2020/12/23 14:54 + * Created by: dengbw + * @return bool + */ + public function get_enroll_lists() + { + $params = $this->input->get(); + if (!$params['a_id']) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $re = $this->mdSytActivity->get(array('id' => $params['a_id'])); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '活动不存在!'); + } + $res = $this->enrollSelect($params); + $lists = $res['lists']; + $count = $res['count']; + $params = $res['params']; + $this->data['_title'] = '私域通-[' . $re['title'] . ']报名'; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + $this->data['lists'] = $lists; + $this->data['params'] = $res['params']; + return $this->show_view('/app/hdy/syt/enroll_lists', true); + } + + public function enrollSelect($params) + { + $this->load->model('app/syt/syt_activity_enroll_model', 'mdSytActivityEnroll'); + $this->load->model('app/syt/syt_activity_team_model', 'mdSytActivityTeam'); + $this->load->model('app/hdy/app_hdy_users_model', 'mdHdyUsers'); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 20; + $params['a_id'] = intval($params['a_id']); + $lists = array(); + $where = array('status' => 1, 'a_id' => $params['a_id']); + if ($params['nickname']) { + $where['nickname LIKE "%' . $params['nickname'] . '%"'] = null; + } + if ($params['mobile']) { + $where['mobile LIKE "%' . $params['mobile'] . '%"'] = null; + } + $count = $this->mdSytActivityEnroll->count($where); + if ($count) { + $res = $this->mdSytActivityEnroll->select($where, 'id desc', $params['page'], $params['size']); + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['nickname'] = $value['nickname']; + $setValue['mobile'] = $value['mobile']; + $cf_name = '-'; + if ($value['cf_uid'] || $value['t_id']) { + if ($value['cf_uid']) { + $reUsers = $this->mdHdyUsers->get(array('id' => $value['cf_uid'])); + $reUsers['nickname'] && $cf_name = $reUsers['nickname']; + } else { + $re_t = $this->mdSytActivityTeam->get(array('id' => $value['t_id'])); + $re_t['name'] && $cf_name = $re_t['name']; + } + } + $setValue['cf_name'] = $cf_name; + $setValue['c_time'] = date('Y-m-d H:i', $value['c_time']); + $lists[] = $setValue; + } + } + $data['lists'] = $lists; + $data['count'] = $count; + $data['params'] = $params; + return $data; + } + + /** + * Notes:检查新增/修改数据 + * Created on: 2020/8/20 11:59 + * Created by: dengbw + * @param $info + * @return array + */ + private function checkData($info) + { + $msg = ''; + $code = SYS_CODE_FAIL; + if (!$info) { + $msg = '非法参数'; + } else if (!$info['brand_id']) { + $msg = '请选择活动品牌'; + } else if (!$info['z_id']) { + $msg = '请选择活动专题'; + } else if (!$info['title']) { + $msg = '请输入活动标题'; + } else if (!$info['time']) { + $msg = '请选择活动时间'; + } else { + $code = SYS_CODE_SUCCESS; + } + return array('code' => $code, 'msg' => $msg); + } + + public function del() + { + } + + public function batch() + { + // TODO: Implement batch() method. + } + + public function export() + { + $params = $this->input->get(); + $params['page'] = 1; + $params['size'] = 10000; + $data = $indexs = array(); + $res = $this->enrollSelect($params); + $fileName = '私域通报名'; + foreach ($res['lists'] as $key => $value) { + $temp['nickname'] = $value['nickname']; + $temp['mobile'] = $value['mobile']; + $temp['cf_name'] = $value['cf_name']; + $temp['c_time'] = $value['c_time']; + $data[] = $temp; + } + $indexs = [ + 'nickname' => '报名昵称', + 'mobile' => '手机号', + 'cf_name' => '来源', + 'c_time' => '创建时间' + ]; + array_unshift($data, $indexs); + $this->load->library('excel'); + $this->excel->out($data, $indexs, $fileName . "_" . date('YmdHis')); + } + + public function get_topics() + { + $page = $this->input->post('page') ? intval($this->input->post('page')) : 1; + $size = $this->input->post('size') ? intval($this->input->post('size')) : 10; + + $topicsList = array(); + $where = array('status >' => -1, 'app_id' => $this->app_id); + $title = $this->input->post('title'); + $title && $where['title like "%' . $title . '%"'] = null; + $count = $this->mdTopics->count($where); + if ($count) { + $res = $this->mdTopics->select($where, 'id desc', $page, $size); + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['title'] = $value['title']; + $topicsList[] = $setValue; + } + } + $this->data['topicsList'] = $topicsList; + $hasNext = ceil($count / $size) > $page ? 1 : 0; + $this->data['topicsPage'] = array('page' => $page, 'pageLimit' => $size, 'pageCount' => $count, 'hasNext' => $hasNext); + return $this->show_json(SYS_CODE_SUCCESS); + } + + private function get_biz_name($info) + { + $biz_name = ''; + if ($info['biz_id']) { + $reBiz = $this->mdBiz->get(array('id' => $info['biz_id']), 'biz_name'); + $biz_name = $reBiz['biz_name']; + } else if ($info['brand_id']) { + $reBrand = $this->mdBrand->get(array('id' => $info['brand_id']), 'brand_name'); + $biz_name = $reBrand['brand_name']; + } + return $biz_name; + } + + public function get_kpidata() + { + $this->load->model('app/syt/syt_activity_member_model', 'mdSytActivityMember'); + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 10; + $where = array('status' => 1); + $res = $this->mdSytActivityMember->select($where, 'id asc', $params['page'], $params['size']); + foreach ($res as $key => $value) { + $this->mdSytKpiData->update(array("t_id" => $value['t_id']), array("a_id" => $value['a_id'], 'cf_uid' => $value['uid'])); + } + print_r($res); + exit; + } + +} \ No newline at end of file diff --git a/admin/controllers/app/licheb/Userslog.php b/admin/controllers/app/licheb/Userslog.php index d6ab0a2a..89ee009e 100644 --- a/admin/controllers/app/licheb/Userslog.php +++ b/admin/controllers/app/licheb/Userslog.php @@ -95,8 +95,8 @@ class Userslog extends HD_Controller $map_biz[$v['biz_id']]['biz_name'] && $biz_name = $map_biz[$v['biz_id']]['biz_name']; $map_biz[$v['biz_id']]['type'] && $biz_type = $typeAry[$map_biz[$v['biz_id']]['type']]; $temp = ['uname' => $uname, 'biz_type' => $biz_type, 'biz_name' => $biz_name, 'defeats' => $v['defeats'] - , 'a_num' => $v['a_num'], 'orders' => $v['orders'], 'bills' => $v['bills'], 'follows' => $v['follows'] - , 'qy_adds' => $v['qy_adds'], 'qy_dels' => $v['qy_dels'], 'log_date' => $v['log_date']]; + , 'c_num' => $v['c_num'], 'a_num' => $v['a_num'], 'orders' => $v['orders'], 'bills' => $v['bills'] + , 'follows' => $v['follows'], 'qy_adds' => $v['qy_adds'], 'qy_dels' => $v['qy_dels'], 'log_date' => $v['log_date']]; $customer_json = $v['customer_json'] ? json_decode($v['customer_json'], true) : []; foreach ($offlineSources as $key1 => $value1) { $nums = intval($v['customer_' . $key1]); @@ -125,8 +125,9 @@ class Userslog extends HD_Controller if ($params['size'] != 10000) { $sum = $this->mdUsersLog->sum('customers', $where); $menus[] = ['title' => "客户数", 'value' => intval($sum['customers']), 'tag' => '人']; + $sum_c = $this->mdUsersLog->sum('c_num', $where); $sum = $this->mdUsersLog->sum('a_num', $where); - $menus[] = ['title' => "进店数", 'value' => intval($sum['a_num']), 'tag' => '人']; + $menus[] = ['title' => "进店人数/进店次数", 'value' => intval($sum_c['c_num']) . '/' . intval($sum['a_num']), 'tag' => '人']; $sum = $this->mdUsersLog->sum('follows', $where); $menus[] = ['title' => "跟进数", 'value' => intval($sum['follows']), 'tag' => '个']; $sum = $this->mdUsersLog->sum('orders', $where); @@ -188,7 +189,8 @@ class Userslog extends HD_Controller $indexs['customer_' . $key2] = $value2; } } - $indexs['a_num'] = '进店数'; + $indexs['c_num'] = '进店人数'; + $indexs['a_num'] = '进店次数'; $indexs['follows'] = '跟进数'; $indexs['orders'] = '订单数'; $indexs['defeats'] = '战败数'; diff --git a/admin/hooks/Auth.php b/admin/hooks/Auth.php index c9ef8caf..4b1897b8 100644 --- a/admin/hooks/Auth.php +++ b/admin/hooks/Auth.php @@ -58,16 +58,16 @@ class Auth { $ip_arr = array_merge($ip_arr, array_column($CI->sys_admin_model->select(array(),'','','','login_ip'), 'login_ip')); if(!in_array($ip, $ip_arr) && $dir) { - $admin_info = array( - 'id' => $admin_user['id'], - ); - - $domain = explode('.', $_SERVER['HTTP_HOST']); - array_shift($domain); - $domain = implode('.', $domain); - - $CI->input->set_cookie(LOGIN_COOKIE, $CI->encryption->encrypt(json_encode($admin_info)), time() + 86400, $domain); - $this->returnMsg('访问IP发生变化,请重新登录', '/login/check_view'); + if($admin_user['id'] > 10){//管理员id>10去掉验证码登录 + $admin_info = array( + 'id' => $admin_user['id'], + ); + $domain = explode('.', $_SERVER['HTTP_HOST']); + array_shift($domain); + $domain = implode('.', $domain); + $CI->input->set_cookie(LOGIN_COOKIE, $CI->encryption->encrypt(json_encode($admin_info)), time() + 86400, $domain); + $this->returnMsg('访问IP发生变化,请重新登录', '/login/check_view'); + } } } diff --git a/admin/views/app/licheb/syt/live_edit.php b/admin/views/app/licheb/syt/live_edit.php new file mode 100644 index 00000000..9e89ceae --- /dev/null +++ b/admin/views/app/licheb/syt/live_edit.php @@ -0,0 +1,555 @@ +
+
+
+
+
+
+
+ 状态 +
+
+ + +
+
+
+ +
+
+
+
+
+ 活动信息 + + +
+
+
+ +
+
+
+ +
+
+ 选择 +
+
+ 注:活动页面只能从现有的专题中选择 +
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+ +
+
+ + 建议尺寸宽度690 + + +
+
+
+
+ +
+

上传图片

+
+
+ + +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
{{v.title}}
+
+ +
+
{{v.num_tag}}
+
+ +
+
{{v.score_tag}}
+
+
+
+
+ + +
+
+
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/admin/views/app/licheb/syt/live_lists.php b/admin/views/app/licheb/syt/live_lists.php new file mode 100644 index 00000000..2ca003ba --- /dev/null +++ b/admin/views/app/licheb/syt/live_lists.php @@ -0,0 +1,78 @@ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID活动标题专题开始时间结束时间创建时间状态
+
+ 报名 + 门店 + 业绩报告 + 分享二维码 + 编辑 +
+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/admin/views/app/licheb/userslog/lists.php b/admin/views/app/licheb/userslog/lists.php index 0d35fc7b..0cf71c94 100644 --- a/admin/views/app/licheb/userslog/lists.php +++ b/admin/views/app/licheb/userslog/lists.php @@ -87,16 +87,16 @@ - + - - - - - - - + + + + + + + @@ -107,7 +107,7 @@ - + diff --git a/api/controllers/plan/Licheb.php b/api/controllers/plan/Licheb.php index a3c96b7b..30f19bd2 100644 --- a/api/controllers/plan/Licheb.php +++ b/api/controllers/plan/Licheb.php @@ -75,6 +75,8 @@ class Licheb extends HD_Controller $e_time = strtotime($log_date . ' 23:59:59'); $city_id = intval($map_biz[$biz_id]['city_id']); $type = intval($map_biz[$biz_id]['type']); + $c_num = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type' => 4, 'log' => '客户到店', 'c_time>=' => $s_time, 'c_time<=' => $e_time, + "customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null], 'distinct(customer_id)'); $a_num = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type' => 4, 'c_time>=' => $s_time, 'c_time<=' => $e_time, "customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null] ); @@ -97,9 +99,9 @@ class Licheb extends HD_Controller $qy_dels = $this->mdWechatqyLog->count(['userid' => $value['userid'], "change_type in('del_external_contact','del_follow_user')" => null , 'c_time>=' => $s_time, 'c_time<=' => $e_time]); } - $add_item = ['sale_id' => $sale_id, 'biz_id' => $biz_id, 'type' => $type, 'city_id' => $city_id, 'a_num' => $a_num - , 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'defeats' => $defeats, 'log_date' => $log_date - , 'qy_adds' => $qy_adds, 'qy_dels' => $qy_dels, 'c_time' => time()]; + $add_item = ['sale_id' => $sale_id, 'biz_id' => $biz_id, 'type' => $type, 'city_id' => $city_id, 'c_num' => $c_num + , 'a_num' => $a_num, 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'defeats' => $defeats + , 'log_date' => $log_date, 'qy_adds' => $qy_adds, 'qy_dels' => $qy_dels, 'c_time' => time()]; $customer_json = ''; foreach ($offlineSources as $key1 => $value1) { $customer_num1 = $this->mdCustomers->count(['of_id' => $key1, 'admin_id' => $sale_id diff --git a/api/controllers/plan/Temp.php b/api/controllers/plan/Temp.php index 74a5bd89..ebc11b50 100644 --- a/api/controllers/plan/Temp.php +++ b/api/controllers/plan/Temp.php @@ -16,6 +16,54 @@ class Temp extends HD_Controller $this->log_file = 'temp.log'; } + /** + * Notes:更新战败客户到店 + * Created on: 2022/3/09 11:58 + * Created by: dengbw + * https://liche-api-dev.xiaoyu.com/plan/temp/users_log_c_num + * https://api.liche.cn/plan/temp/users_log_c_num + */ + public function users_log_c_num() + { + $this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOplogs'); + $this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog'); + $param = $this->input->get(); + $param['page'] = intval($param['page']); + $param['size'] = intval($param['size']); + !$param['size'] && $param['size'] = 200; + !$param['page'] && $param['page'] = 1; + $counts = intval($param['counts']); + ob_start(); //打开缓冲区 + $where = ["a_num>" => 0]; + $res = $this->mdUsersLog->select($where, 'id ASC', $param['page'], $param['size'], 'id,sale_id,biz_id,log_date'); + if (!$res) { + echo '
本次更新完成了:'; + echo '

成功更新 ' . $counts . ' 条'; + echo '

点击将再次更新>>>'; + exit; + } + $log = array(); + foreach ($res as $key => $value) { + $sale_id = $value['sale_id']; + $biz_id = $value['biz_id']; + $s_time = strtotime($value['log_date'] . ' 00:00:00'); + $e_time = strtotime($value['log_date'] . ' 23:59:59'); + $c_num = $this->mdCustomerOplogs->count(['uid' => $sale_id, 'type' => 4, 'log' => '客户到店', 'c_time>=' => $s_time, 'c_time<=' => $e_time, + "customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null], 'distinct(customer_id)'); + if ($c_num) { + $this->mdUsersLog->update(['c_num' => $c_num], ['id' => $value['id']]); + $log[] = ['id' => $value['id'], 'c_num' => $c_num]; + $counts++; + } + } + echo '
成功更新:'; + $log && print_r($log); + echo '

数据库获取:'; + echo json_encode($res, JSON_UNESCAPED_UNICODE); + header('refresh:3;url=/plan/temp/users_log_c_num?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1)); + ob_end_flush();//输出全部内容到浏览器 + } + /** * Notes:更新顾问新增企微/删除企微 @@ -125,48 +173,6 @@ class Temp extends HD_Controller ob_end_flush();//输出全部内容到浏览器 } - /** - * Notes:更新战败客户到店 - * Created on: 2022/3/09 11:58 - * Created by: dengbw - * https://liche-api-dev.xiaoyu.com/plan/temp/receiver_customer_oplogs - * https://api.liche.cn/plan/temp/receiver_customer_oplogs - */ - public function receiver_customer_oplogs() - { - $this->load->model('receiver/receiver_customers_model', 'mdCustomers'); - $this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomersOplogs'); - $param = $this->input->get(); - $param['page'] = intval($param['page']); - $param['size'] = intval($param['size']); - !$param['size'] && $param['size'] = 50; - !$param['page'] && $param['page'] = 1; - $counts = intval($param['counts']); - ob_start(); //打开缓冲区 - $where = ["type" => 4]; - $res = $this->mdCustomersOplogs->select($where, 'id ASC', $param['page'], $param['size'], 'customer_id'); - if (!$res) { - echo '
本次更新完成了:'; - echo '

成功更新 ' . $counts . ' 条'; - echo '

点击将再次更新>>>'; - exit; - } - $log = array(); - foreach ($res as $key => $value) { - $re = $this->mdCustomers->get(['id' => $value['customer_id']], 'id,a_num,name'); - if ($re && $re['a_num'] == 0) { - $this->mdCustomers->update(['a_num' => 1], ['id' => $re['id']]); - $log[] = ['id' => $re['id'], 'name' => $re['name']]; - $counts++; - } - } - echo '
成功更新:'; - $log && print_r($log); - echo '

数据库获取:'; - echo json_encode($res, JSON_UNESCAPED_UNICODE); - header('refresh:3;url=/plan/temp/receiver_customer_oplogs?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1)); - ob_end_flush();//输出全部内容到浏览器 - } /** * Notes:更新车辆调拨状态 diff --git a/common/helpers/comm_helper.php b/common/helpers/comm_helper.php index 6279cba7..40693a9f 100644 --- a/common/helpers/comm_helper.php +++ b/common/helpers/comm_helper.php @@ -220,8 +220,10 @@ if (!function_exists('checkua')) { function checkua() { if (is_mobile()) { - if (strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { - return 'wx'; + if (strstr($_SERVER['HTTP_USER_AGENT'], 'wxwork')) { + return 'wxwork';//企业微信 + } else if (strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { + return 'wx';//微信 } else if (strstr($_SERVER['HTTP_USER_AGENT'], 'microfish')) { return 'xy'; } else { diff --git a/common/models/app/licheb/Syt_live_model.php b/common/models/app/licheb/Syt_live_model.php new file mode 100644 index 00000000..fc48bab8 --- /dev/null +++ b/common/models/app/licheb/Syt_live_model.php @@ -0,0 +1,18 @@ +table_name, 'default'); + } +} diff --git a/home/controllers/h5/syt/Live.php b/home/controllers/h5/syt/Live.php index 14704271..bff8ee93 100644 --- a/home/controllers/h5/syt/Live.php +++ b/home/controllers/h5/syt/Live.php @@ -22,7 +22,6 @@ class Live extends Wxapp } //重置cookie $reset = $this->input_param('reset'); - $reset = 1; if ($reset) { set_cookie("ukey", "", 86400 * 30); $this->session = array(); @@ -39,92 +38,190 @@ class Live extends Wxapp */ function get() { - $skey = 1111; + $skey = $this->input->get('skey'); + $this->load->library('MyEncryption'); + if (!$skey) {//测试专用 + $skey = "id=1"; + $skey = $this->myencryption->base64url_encode($skey); + } + if (!$skey) { + throw new Hd_exception("参数错误", 400); + } + $params = $this->myencryption->base64url_decode($skey); + $id = intval($params['id']);//活动id + if (!$id) { + throw new Hd_exception("参数错误", 400); + } + $cf_uid = intval($params['cf_uid']);//来源狸车宝用户id + $biz_id = intval($params['biz_id']);//门店id + echo json_encode($params, JSON_UNESCAPED_UNICODE); +// $re = $this->mdSytActivity->get(array("id" => $id, "status" => 1)); +// if (!$re) { +// throw new Hd_exception("活动不存在", 400); +// } + $checkua = checkua(); + $sign_package = []; $url = http_host_com('home') . "/h5/syt/live?skey={$skey}"; - $this->set_auth($url); - if ($this->uid && $this->session['biz_id']) {//门店人员 - echo '门店人员
'; + if ($checkua == 'wxwork') {//企业微信 + $this->load->library('wx_qyapi_agent', ['app' => 'liche_1000024']); + $this->load->library('wx_qyapi', ['app' => 'liche']); + $this->set_auth_wxwork($url); + $sign_package = $this->wx_qyapi->getSignPackage(); + } else if ($checkua == 'wx') {//微信 + $this->set_auth($url); + $this->load->library('Jssdk'); + $jssdk = new Jssdk('liche'); + $sign_package = $jssdk->getSignPackage(); } - if ($this->session) { - echo json_encode($this->session, JSON_UNESCAPED_UNICODE); + 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['live'] = $params; + $this->mdWeixinUsers->update(['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)], ['id' => $this->uid]); + } + if ($this->session['biz_id']) {//门店人员 + $biz_id = $this->session['biz_id']; + $cf_uid = $this->session['biz_uid']; + } } - $data = array( - '_title' => '盲盒抽奖', + $share_skey = "id=" . $id . "&cf_uid=" . $cf_uid . '&biz_id=' . $biz_id; + echo '
share_skey:' . $share_skey; + $share_url = http_host_com('home') . "/h5/syt/live?skey=" . $this->myencryption->base64url_encode($share_skey); + echo '
share_url:' . $share_url; + $title = '盲盒抽奖'; + $share = [ + 'title' => $title, + "img" => 'http://bbs.xmfish.com/attachment/2022_05/097c021b16d9ed4c11e7cb6f97818350.jpg', + "desc" => '五一说走就走的旅行!下了两天雨,终于要大晴天了', + "url" => $share_url + ]; + $data = [ + '_title' => $title, + "sign_package" => $sign_package, + "share" => $share, 'view' => 'h5/syt/live', - ); + "checkua" => $checkua, + ]; return $data; } /** - * Notes:未登录授权登录 + * 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'); - $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) { + return; + } + $this->load->helper('url'); + $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) { - $biz_id = $biz_uid = 0; - if ($unionid) { - $re_licheb_users = $this->mdLichebUsers->get(array('unionid' => $unionid)); - if ($re_licheb_users) { - $biz_id = intval($re_licheb_users['biz_id']); - $biz_uid = $re_licheb_users['id']; - } - } - $session = ['uid' => $this->uid, "unionid" => $unionid, "mobile" => $mobile, "biz_id" => $biz_id, "biz_uid" => $biz_uid]; - $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret); - set_cookie("ukey", $ukey, 86400 * 30); - $this->session = $session; - } - } 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); } + if ($this->uid) { + $biz_id = $biz_uid = 0; + if ($unionid) { + $re_licheb_users = $this->mdLichebUsers->get(array('unionid' => $unionid)); + if ($re_licheb_users) { + $biz_id = intval($re_licheb_users['biz_id']); + $biz_uid = $re_licheb_users['id']; + } + } + $session = ['uid' => $this->uid, "unionid" => $unionid, "mobile" => $mobile, "biz_id" => $biz_id, "biz_uid" => $biz_uid]; + $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret); + set_cookie("ukey", $ukey, 86400 * 30); + $this->session = $session; + } + } 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); } } + + /** + * Notes:授权获取企业员工UserId + * Created on: 2022/3/29 17:03 + * Created by: dengbw + * @param string $url + * @return mixed + */ + private function set_auth_wxwork($url = '') + { +// if ($this->uid) { +// return; +// } + $config = $this->wx_qyapi_agent->getConfig(); + $code = $this->input->get('code'); + if ($code) {//授权码获取微信信息 + $this->load->library('mycurl'); + $access_token = $this->wx_qyapi_agent->access_token(); + $auth_url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={$access_token}&code={$code}"; + $result = $this->mycurl->httpGet($auth_url); + $result = json_decode($result, true); + if ($result['errcode'] == 0 && $result['UserId']) { + $re_wx = $this->wx_qyapi->get_external_contact(['url' => 'user_get', 'userid' => $result['UserId']]); + if ($re_wx['errcode'] == 0 && $re_wx['mobile']) { + $re_u = $this->mdLichebUsers->get(array('mobile' => $re_wx['mobile'])); + if ($re_u) { + $this->uid = $biz_uid = $re_u['id']; + $biz_id = intval($re_u['biz_id']); + $mobile = $re_u['mobile']; + $unionid = ''; + $session = ['uid' => $this->uid, "unionid" => $unionid, "mobile" => $mobile, "biz_id" => $biz_id, "biz_uid" => $biz_uid]; + $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret); + set_cookie("ukey", $ukey, 86400 * 30); + $this->session = $session; + } + } + } + } else {//静默授权获取用户openid + $this->load->helper('url'); + $redirect_uri = urlencode($url); + $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['corpid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; + redirect($auth_url); + } + } + } diff --git a/home/views/h5/syt/live.php b/home/views/h5/syt/live.php index 21ea3010..e2ea10b0 100644 --- a/home/views/h5/syt/live.php +++ b/home/views/h5/syt/live.php @@ -15,8 +15,11 @@ + + + + -
- + + + + + - \ No newline at end of file
门店门店 顾问 客户数进店数跟进数订单数战败数开票数新增企微删除企微进店人数/进店次数跟进数订单数战败数开票数新增企微删除企微 日期
/