From 2706cae481e666a74374b8456ad64ec2ff5fb739 Mon Sep 17 00:00:00 2001 From: dengbw Date: Thu, 14 Oct 2021 15:41:15 +0800 Subject: [PATCH] material_1014 --- admin/controllers/app/licheb/Main.php | 21 +- admin/controllers/app/material/Template.php | 288 +++++ admin/controllers/auto/Brand.php | 2 + admin/views/app/material/template/edit.php | 999 ++++++++++++++++++ admin/views/app/material/template/lists.php | 81 ++ api/controllers/Hd.php | 59 ++ api/controllers/wxapp/licheb/User.php | 1 + api/controllers/wxapp/material/Biz.php | 135 +++ api/controllers/wxapp/material/Home.php | 202 ++++ api/controllers/wxapp/material/Statistics.php | 160 +++ api/controllers/wxapp/material/Topic.php | 88 ++ .../app/material/Material_biz_model.php | 17 + .../Material_biz_statistics_model.php | 49 + .../app/material/Material_template_model.php | 39 + 14 files changed, 2136 insertions(+), 5 deletions(-) create mode 100644 admin/controllers/app/material/Template.php create mode 100644 admin/views/app/material/template/edit.php create mode 100644 admin/views/app/material/template/lists.php create mode 100644 api/controllers/wxapp/material/Biz.php create mode 100644 api/controllers/wxapp/material/Home.php create mode 100644 api/controllers/wxapp/material/Statistics.php create mode 100644 api/controllers/wxapp/material/Topic.php create mode 100644 common/models/app/material/Material_biz_model.php create mode 100644 common/models/app/material/Material_biz_statistics_model.php create mode 100644 common/models/app/material/Material_template_model.php diff --git a/admin/controllers/app/licheb/Main.php b/admin/controllers/app/licheb/Main.php index bb0afa64..0b88749a 100644 --- a/admin/controllers/app/licheb/Main.php +++ b/admin/controllers/app/licheb/Main.php @@ -1,22 +1,25 @@ app_id = 2; parent::__construct(); $this->load->model('app/licheb/App_licheb_users_model', 'userM'); - + $this->load->model('app/material/Material_template_model', 'mdTemplate'); } - public function index(){ + public function index() + { /*应用状况*/ $conditions = array(); @@ -31,6 +34,14 @@ class Main extends HD_Controller{ array('name' => '查看详情', 'url' => '/app/licheb/member/index'), ), ); + $value = $this->mdTemplate->count(); + $list[] = array( + 'title' => '素材模版(个)', + 'value' => $value, + 'btns' => array( + array('name' => '查看详情', 'url' => '/app/material/template/index?app_id=' . $this->app_id), + ), + ); $conditions[] = array('icon' => 'am-icon-home', 'list' => $list); /*小程序设置 end*/ diff --git a/admin/controllers/app/material/Template.php b/admin/controllers/app/material/Template.php new file mode 100644 index 00000000..1cde9458 --- /dev/null +++ b/admin/controllers/app/material/Template.php @@ -0,0 +1,288 @@ +load->model('app/material/Material_template_model', 'mdTemplate'); + $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); + } + + //首页信息 + public function index() + { + $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 = $users = array(); + $where = array('app_id' => $params['app_id']); + if ($params['type']) { + $where['type'] = $params['type']; + } + if (strlen($params['status'])) { + $where['status'] = $params['status']; + } + $count = $this->mdTemplate->count($where); + if ($count) { + $fileds = "id,title,type,status,brand_ids,c_time"; + $res = $this->mdTemplate->select($where, "id desc", $params['page'], $params['size'], $fileds); + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['title'] = $value['title']; + $setValue['type_name'] = $this->mdTemplate->typeAry()[$value['type']]; + $setValue['status_name'] = $this->mdTemplate->statusAry()[$value['status']]; + $brands = ''; + if ($value['brand_ids']) { + $res_b = $this->mdAutoBrand->select(array("id in ({$value['brand_ids']})" => null, 'status' => 1), "id desc", 0, 0, 'name'); + if ($res_b) { + $brands = array_column($res_b, 'name'); + $brands = implode(',', $brands); + } + } + $setValue['brands'] = $brands; + $setValue['c_time'] = date('Y-m-d H:i:s', $value["c_time"]); + $lists[] = $setValue; + } + } + $this->data['lists'] = $lists; + $this->data['params'] = $params; + $this->data['typeAry'] = $this->mdTemplate->typeAry(); + $this->data['statusAry'] = $this->mdTemplate->statusAry(); + $this->data['_title'] = '素材模板列表'; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + return $this->show_view('/app/material/template/lists', true); + } + + //展示单条数据 + public function get() + { + $id = $this->input->get('id'); + $info['app_id'] = intval($this->input->get('app_id')); + $info['status'] = 1; + $info['type'] = 1; + $info['cover'] = array('value' => '', 'src' => ''); + $brands = $tgsp_list = $lbhb_list = $pyqwa_list = array(); + if ($id) { + $re = $this->mdTemplate->get(array('id' => $id)); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '模板不存在!'); + } + if ($re['json_data']) { + $json_data = json_decode($re['json_data'], true); + $lists = array(); + foreach ($json_data['lists'] as $key => $value) { + if ($re['type'] == 1) { + if ($value['video_type'] == 1) { + $value['video_file_url'] = $value['video']; + $value['video_url'] = build_qiniu_image_url($value['video'], 0, 0, 'video'); + $value['video_cover'] = $value['video_url'] . '?vframe/jpg/offset/1'; + $value['img'] = $value['img_url'] = ''; + } else { + $value['img_url'] = $value['img'] ? build_qiniu_image_url($value['img']) : ''; + $value['video_file_url'] = $value['video_url'] = $value['video_cover'] = ''; + } + } else if ($re['type'] == 2) { + $value['img_url'] = $value['img'] ? build_qiniu_image_url($value['img']) : ''; + } else if ($re['type'] == 3) { + if ($value['brands']) { + $value['brands'] = $this->mdAutoBrand->select(array("id in ({$value['brands']})" => null, 'status' => 1), "id desc", 0, 0, 'id,name'); + } else { + $value['brands'] = array(); + } + } + $lists[] = $value; + } + if ($re['type'] == 1) { + $tgsp_list = $lists; + } else if ($re['type'] == 2) { + $lbhb_list = $lists; + } else if ($re['type'] == 3) { + $pyqwa_list = $lists; + } + unset($re['json_data']); + } + $info = $re; + $info['cover'] = $info['cover'] ? array('value' => $info['cover'], 'src' => build_qiniu_image_url($info['cover'])) + : array('value' => '', 'src' => ''); + if ($info['brand_ids']) { + $brand_ids = str_replace(",0", "", $info['brand_ids']); + $brands = $this->mdAutoBrand->select(array("id in ({$brand_ids})" => null, 'status' => 1), "id desc", 0, 0, 'id,name'); + } + $_title = '编辑素材模板'; + $edit_url = '/app/material/template/edit'; + } else { + $_title = '新增素材模板'; + $edit_url = '/app/material/template/add'; + } + $showInfo['statusAry'] = $this->mdTemplate->statusAry(); + $showInfo['typeAry'] = $this->mdTemplate->typeAry(); + $showInfo['brands'] = $brands; + $showInfo['tgsp_list'] = $tgsp_list; + $showInfo['lbhb_list'] = $lbhb_list; + $showInfo['pyqwa_list'] = $pyqwa_list; + $this->data['info'] = $info; + $this->data['showInfo'] = $showInfo; + $this->data['edit_url'] = $edit_url; + $this->data['_title'] = $_title; + return $this->show_view('/app/material/template/edit', true); + } + + private function checkInfo($info) + { + $msg = ''; + $code = SYS_CODE_FAIL; + if (!$info) { + $msg = '非法参数'; + } else if (!$info['title']) { + $msg = '请输入模版名称'; + } else if (!$info['cover']['value']) { + $msg = '请上传封面图'; + } else if (!$info['brand_ids'] && $info['type'] != 3) { + $msg = '请选择适用品牌'; + } else { + $code = SYS_CODE_SUCCESS; + } + return array('code' => $code, 'msg' => $msg); + } + + //添加单条数据 + public function add() + { + $info = $this->input->post('info'); + $checkInfo = $this->checkInfo($info); + if (!$checkInfo['code']) { + return $this->show_json($checkInfo['code'], $checkInfo['msg']); + } + $brand_ids = ''; + if ($info['brand_ids']) { + $brand_ids = implode(',', $info['brand_ids']); + if (!strstr($brand_ids, ',0')) { + $brand_ids .= ',0'; + } + } + if ($info['lists']) { + $json_data = $info['json_data']; + $lists = array(); + foreach ($info['lists'] as $key => $value) { + if ($info['type'] == 1) { + if ($value['video_type'] == 1) { + $value['video'] = $value['video_file_url']; + unset($value['img']); + } + unset($value['video_file_url']); + unset($value['video_url']); + unset($value['video_cover']); + unset($value['img_url']); + } else if ($info['type'] == 2) { + unset($value['img_url']); + } else if ($info['type'] == 3) { + $brands = ''; + if ($value['brands']) { + $brands = array_column($value['brands'], 'id'); + $brands = implode(',', $brands); + } + $value['brands'] = $brands; + } + $lists[] = $value; + } + $json_data['lists'] = $lists; + $editData['json_data'] = json_encode($json_data, JSON_UNESCAPED_UNICODE); + } + $editData['app_id'] = $info['app_id']; + $editData['title'] = $info['title']; + $editData['cover'] = $info['cover']['value']; + $editData['type'] = $info['type']; + $editData['brand_ids'] = $info['type'] == 3 ? '' : $brand_ids; + $editData['status'] = $info['status']; + $editData['c_time'] = time(); + $id = $this->mdTemplate->add($editData); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '新增失败!'); + } + return $this->show_json(SYS_CODE_SUCCESS, '新增成功!', '/app/material/template/index?app_id=' . $info['app_id']); + } + + //编辑单条数据 + public function edit() + { + $info = $this->input->post('info'); + $checkInfo = $this->checkInfo($info); + if (!$checkInfo['code']) { + return $this->show_json($checkInfo['code'], $checkInfo['msg']); + } + $brand_ids = ''; + if ($info['brand_ids']) { + $brand_ids = implode(',', $info['brand_ids']); + if (!strstr($brand_ids, ',0')) { + $brand_ids .= ',0'; + } + } + if ($info['lists']) { + $json_data = $info['json_data']; + $lists = array(); + foreach ($info['lists'] as $key => $value) { + if ($info['type'] == 1) { + $value['video'] = $value['video_file_url']; + unset($value['video_file_url']); + unset($value['video_url']); + unset($value['video_cover']); + } else if ($info['type'] == 2) { + unset($value['img_url']); + } else if ($info['type'] == 3) { + $brands = ''; + if ($value['brands']) { + $brands = array_column($value['brands'], 'id'); + $brands = implode(',', $brands); + } + $value['brands'] = $brands; + } + $lists[] = $value; + } + $json_data['lists'] = $lists; + $editData['json_data'] = json_encode($json_data, JSON_UNESCAPED_UNICODE); + } + $editData['title'] = $info['title']; + $editData['cover'] = $info['cover']['value']; + $editData['type'] = $info['type']; + $editData['brand_ids'] = $info['type'] == 3 ? '' : $brand_ids; + $editData['status'] = $info['status']; + $ret = $this->mdTemplate->update($editData, array('id' => $info['id'])); + if (!$ret) { + return $this->show_json(SYS_CODE_FAIL, '修改失败!'); + } + return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); + } + + //删除单条数据 + public function del() + { + + } + + //批量操作(默认修改状态) + public function batch() + { + + } + + //导出数据列表 + public function export() + { + + } +} \ No newline at end of file diff --git a/admin/controllers/auto/Brand.php b/admin/controllers/auto/Brand.php index 91d4f3a0..373c7bb8 100644 --- a/admin/controllers/auto/Brand.php +++ b/admin/controllers/auto/Brand.php @@ -146,9 +146,11 @@ class Brand extends HD_Controller{ $status = $this->input->post('status'); $page = $this->input->post('page'); $size = $this->input->post('size'); + $title = trim($this->input->post('title')); $where = array(); $keyword && $where['keyword'] = $keyword; + $title && $where["name like '%{$title}%'"] = null; if(strlen($status) > 0){ $where['status'] = $status; } else { diff --git a/admin/views/app/material/template/edit.php b/admin/views/app/material/template/edit.php new file mode 100644 index 00000000..2bd83ce7 --- /dev/null +++ b/admin/views/app/material/template/edit.php @@ -0,0 +1,999 @@ +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ 模版封面图 +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+ {{v.name}} + +
+
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
图片标题类型排序链接 + 添加 +
+ +
+ +
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + +
图片标题排序链接 + 添加 +
+ +
+ +
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + +
文案内容适用品牌排序 + 添加 +
+ +
+
+ +
+
+
+
+
+ 保存 +
+ +
+ + + + \ No newline at end of file diff --git a/admin/views/app/material/template/lists.php b/admin/views/app/material/template/lists.php new file mode 100644 index 00000000..98c1e211 --- /dev/null +++ b/admin/views/app/material/template/lists.php @@ -0,0 +1,81 @@ +
+ +
+
共有条数据
+ + + + + + + + + + + + + + + + + + + + + + + + + +
id模板名称模板分类适用品牌状态创建时间操作
修改
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/api/controllers/Hd.php b/api/controllers/Hd.php index 838d4ad3..194feaab 100755 --- a/api/controllers/Hd.php +++ b/api/controllers/Hd.php @@ -327,6 +327,65 @@ class Hd extends CI_Controller { } } + /** + * 推广素材入口 + */ + public function material() + { + define('WXAPP_ITEMS', 1); + //加载输入参数 + $this->input_param(); + $app_id = $this->input_param('app_id'); + !$app_id && $app_id = $this->input_param('vipcard_id'); + $version = $this->input_param('version'); + $sversion = $this->input_param('sversion'); + + $this->log_file = get_class($this) . "_{$app_id}.log"; + + //应用ID为空 + if (!$app_id) { + debug_log("[fail]" . __FUNCTION__ . ":app_id is null; uri_string:" . $this->uri->uri_string(), $this->log_file); + return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '请求丢失')); + } + //签名不正确 + if (!$this->vaild_sign()) { + debug_log("[fail]" . __FUNCTION__ . ":sign check fail; uri_string:" . $this->uri->uri_string() . "; param:" . json_encode($this->inputs), $this->log_file); + return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '非法请求')); + } + $app = self::$apps[$app_id]; + $class_name = ucfirst($this->uri->segment(3)); + if ($this->uri->segment(4)) { + $method = $this->request . "_" . $this->uri->segment(4); + } else { + $method = $this->request; + } + //app定制ct + $file_name = APPPATH . "controllers/wxapp/material/{$app}/{$class_name}.php"; + //ct不存在 + if (file_exists($file_name)) { + require_once $file_name; + } else { + //app定制ct不存在,使用公共ct + $file_name = APPPATH . "controllers/wxapp/material/{$class_name}.php"; + if (file_exists($file_name)) { + require_once $file_name; + } else { + debug_log("[fail]" . __FUNCTION__ . ": file '{$file_name}' not exist; method:{$method}, app_id:" . $app_id, $this->log_file); + return $this->print_return($this->return_error(API_CODE_NONE, '非法请求')); + } + } + try { + $class = new $class_name($this->inputs, $app); + $result = $class->$method($version, $sversion); + if (!$result) { + throw new Exception('', ERR_SYS_FAIL); + } + return $this->print_return($result); + } catch (Exception $e) { + return $this->print_return($this->return_error($e->getCode(), $e->getMessage())); + } + } + /** * 测试签名(开发环境) */ diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php index 518c3231..a3cdfc73 100644 --- a/api/controllers/wxapp/licheb/User.php +++ b/api/controllers/wxapp/licheb/User.php @@ -119,6 +119,7 @@ class User extends Wxapp{ 'tel' => $tel, 'group_id' => $user['group_id'], 'group_name' => $group_name, + 'biz_id' => $biz_id, 'biz_name' => $biz['biz_name'] ? $biz['biz_name'] : '' ); diff --git a/api/controllers/wxapp/material/Biz.php b/api/controllers/wxapp/material/Biz.php new file mode 100644 index 00000000..83b55633 --- /dev/null +++ b/api/controllers/wxapp/material/Biz.php @@ -0,0 +1,135 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + $this->load->model('app/material/Material_template_model', 'mdTemplate'); + $this->load->model('app/material/Material_biz_model', 'mdMaterialBiz'); + $this->load->model('app/material/Material_biz_statistics_model', 'mdBizStatistics'); + $this->load->model('receiver/receiver_customers_model', 'mdCustomers'); + $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); + $this->load->model("biz/biz_model", 'mdBiz'); + $this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据 + } + + /** + * Notes:店铺首页 + * Created on: 2021/10/12 11:47 + * Created by: dengbw + * @return array + * @throws Exception + */ + protected function get() + { + $biz_id = intval($this->input_param('biz_id')); + $re = $this->mdBiz->get(array('id' => $biz_id, 'status' => 1)); + if (!$re || empty($re)) { + throw new Hd_exception('门店不存在', API_CODE_FAIL); + } + //加店铺浏览 + $where_s = ['app_id' => $this->app_id, 'biz_id' => $biz_id, 't_id' => 0, 'day' => date('Y-m-d')]; + $re_s = $this->mdBizStatistics->get($where_s); + if ($re_s) { + $this->mdBizStatistics->update(['browse_num = browse_num+1' => null], $where_s); + } else { + $where_s['browse_num'] = 1; + $this->mdBizStatistics->add($where_s); + } + $auto_brands = $list = array(); + if ($re['jsondata']) { + $jsondata = json_decode($re['jsondata'], true); + if ($jsondata['auto_brands']) { + $brand_ids = implode(',', $jsondata['auto_brands']); + $res_b = $this->mdAutoBrand->select(array("id in ({$brand_ids})" => null, 'status' => 1), "id desc", 0, 0, 'name'); + $res_b && $auto_brands = array_column($res_b, 'name'); + } + } + $where = ['a.status' => 1, 'b.app_id' => $this->app_id, 'b.biz_id' => $biz_id]; + $this->mdTemplate->db->from('lc_material_template as a'); + $this->mdTemplate->db->join('lc_material_biz as b', "b.t_id=a.id", 'left'); + $this->mdTemplate->db->select('a.id, a.cover,b.biz_id,b.app_id'); + $this->mdTemplate->db->where($where); + $this->mdTemplate->db->order_by('a.id Desc'); + $this->mdTemplate->db->limit(50); + $res = $this->mdTemplate->db->get()->result_array(); + foreach ($res as $key => $value) { + $list[] = array( + 'id' => $value['id'], + 'cover' => $value['cover'] ? build_qiniu_image_url($value['cover']) : ''); + } + //统计浏览数 + $re_s = $this->mdBizStatistics->sum('browse_num', ['app_id' => $this->app_id, 'biz_id' => $biz_id]); + $orders = $this->mdBizStatistics->count_order(array('c.biz_id' => $biz_id, 'c.cf_id' => $this->cf_id, 'c.status >=' => 0)); + $this->data['title'] = '店铺'; + $this->data['biz_name'] = $re['biz_name']; + $this->data['address'] = $re['address']; + $this->data['lat'] = $re['lat']; + $this->data['lng'] = $re['lng']; + $this->data['auto_brands'] = $auto_brands; + $this->data['statistics'] = $re_s['browse_num'] . '人浏览 | ' . $orders . '笔成交'; + $this->data['topics'] = array('title' => '热门', 'list' => $list); + return $this->data; + } + + /** + * Notes:预约报名 + * Created on: 2021/10/12 17:51 + * Created by: dengbw + * @throws Hd_exception + */ + protected function put() + { + $biz_id = intval($this->input_param('biz_id')); + $t_id = intval($this->input_param('t_id')); + if (!$biz_id || !$this->session['mobile']) { + throw new Hd_exception('参数错误', API_CODE_FAIL); + } + $re_biz = $this->mdBiz->get(['id' => $biz_id, 'status' => 1]); + if (!$re_biz) { + return $this->Hd_exception(SYS_CODE_FAIL, '预约的门店不存在!'); + } + $add_data = [ + 'name' => $this->session['uname'] ? $this->session['uname'] : '', + 'mobile' => $this->session['mobile'], + 'biz_id' => $biz_id, + 'city_id' => $re_biz['city_id'], + 'county_id' => $re_biz['county_id'], + 'cf_title' => '自有资源', + 'cf_id' => $this->cf_id, + 't_id' => $t_id, + 'p_time' => date('Y-m-d H:i:s'), + 'c_time' => time() + ]; + $where = ['biz_id' => $biz_id, 'mobile' => $add_data['mobile'], 'cf_id' => $this->cf_id]; + $t_id && $where['t_id'] = $t_id; + $re_cus = $this->mdCustomers->get($where); + if ($re_cus) { + throw new Hd_exception('您已经预约报名了', API_CODE_FAIL); + } + $id = $this->mdCustomers->add($add_data); + if (!$id) { + throw new Hd_exception('预约报名失败!', API_CODE_FAIL); + } + throw new Hd_exception('预约报名成功!', API_CODE_SUCCESS); + } + +} diff --git a/api/controllers/wxapp/material/Home.php b/api/controllers/wxapp/material/Home.php new file mode 100644 index 00000000..8ef1c383 --- /dev/null +++ b/api/controllers/wxapp/material/Home.php @@ -0,0 +1,202 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + $this->load->model('app/material/Material_template_model', 'mdTemplate'); + $this->load->model('app/material/Material_biz_model', 'mdMaterialBiz'); + $this->load->model("biz/biz_model", 'mdBiz'); + $this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据 + } + + /** + * Notes:推广素材_tab + * Created on: 2021/10/13 11:42 + * Created by: dengbw + * @return array + */ + protected function get_tabs() + { + $list = array(); + foreach ($this->mdTemplate->typeAry() as $key => $value) { + $list[] = array('id' => $key, 'name' => $value); + } + $this->data['title'] = '推广素材'; + $this->data['list'] = $list; + return $list; + } + + /** + * Notes:推广素材_list + * Created on: 2021/10/11 11:47 + * Created by: dengbw + * @return array + * @throws Exception + */ + protected function get_lists() + { + $page = $this->input_param('page'); + $size = $this->input_param('size'); + $type = intval($this->input_param('type')); + !$page && $page = 1; + !$size && $size = 10; + !$type && $type = 1; + $brand_ids = array(); + if ($this->biz_id) {//查找门店授权品牌 + $re_b = $this->mdBiz->get(array('id' => $this->biz_id, 'status' => 1)); + if ($re_b['jsondata']) { + $jsondata = json_decode($re_b['jsondata'], true); + $jsondata['auto_brands'] && $brand_ids = $jsondata['auto_brands']; + } + } + $lists = array(); + $total = 0; + $show = 'image'; + if ($brand_ids) { + $where = array('app_id' => $this->app_id, 'type' => $type, 'status' => 1); + if ($type == 3) { + $show = 'text'; + $res = $this->mdTemplate->select($where, "id desc", 1, 1, 'json_data'); + if ($res[0]['json_data']) { + $json_data = json_decode($res[0]['json_data'], true); + $total = count($json_data['lists']); + foreach ($json_data['lists'] as $key2 => $value2) { + if ($value2['brands']) { + $brands = $value2['brands'] . ','; + foreach ($brand_ids as $key3 => $value3) { + if (strstr($brands, $value3 . ',')) { + $lists[] = array('content' => $value2['content']); + break; + } + } + } + } + } + } else { + $or_str = ''; + foreach ($brand_ids as $key3 => $value3) { + $brand_id = $value3 . ','; + $or_str = $or_str ? $or_str . " OR brand_ids like '%{$brand_id}%'" : "brand_ids like '%{$brand_id}%'"; + } + $where[' (' . $or_str . ') '] = null; + $total = $this->mdTemplate->count($where); + $fileds = 'id,title,cover'; + $res = $this->mdTemplate->select($where, "id desc", $page, $size, $fileds); + foreach ($res as $key2 => $value2) { + $value2['cover'] = $value2['cover'] ? build_qiniu_image_url($value2['cover']) : ''; + $re_biz = $this->mdMaterialBiz->get(array('app_id' => $this->app_id, 't_id' => $value2['id'], 'biz_id' => $this->biz_id)); + $value2['if_add'] = $re_biz ? 1 : 0; + $lists[] = $value2; + } + } + } + $this->data['show'] = $show; + $this->data['list'] = $lists; + $this->data['total'] = $total; + return $this->data; + } + + /** + * Notes:生成专题 + * Created on: 2021/10/11 16:14 + * Created by: dengbw + * @throws Hd_exception + */ + protected function put_topic() + { + $t_id = intval($this->input_param('t_id')); + if (!$t_id || !$this->biz_id) { + throw new Hd_exception('参数错误', API_CODE_FAIL); + } + $where = array('app_id' => $this->app_id, 't_id' => $t_id, 'biz_id' => $this->biz_id); + $re = $this->mdMaterialBiz->get($where); + if ($re) { + throw new Hd_exception('该专题已经生成过了~', API_CODE_FAIL); + } + $where['c_time'] = time(); + $id = $this->mdMaterialBiz->add($where); + if ($id) { + throw new Exception('专题生成成功', API_CODE_SUCCESS); + } else { + throw new Exception('专题生成失败', API_CODE_FAIL); + } + } + + /** + * Notes:获取二维码 + * Created on: 2021/8/27 16:34 + * Created by: dengbw + * @return array + * @throws Hd_Exception + */ + protected function get_qrcode() + { + $scene = $this->input_param('scene'); + $page = $this->input_param('page'); + $width = $this->input_param('width'); + if (0 == strlen($scene)) { + throw new Hd_Exception('二维码参数必填', API_CODE_INVILD_PARAM); + } + return $this->qrcode($scene, $page, $width); + } + + /** + * Notes:获取图片二维码 + * Created on: 2021/8/27 16:33 + * Created by: dengbw + * @param $scene + * @param string $page + * @param int $width + * @param string $fig + * @return array + * @throws Hd_Exception + */ + private function qrcode($scene, $page = '', $width = 0, $fig = 'liche') + { + $path = "{$page}?{$scene}"; + $width && $path .= "{$width}"; + if ($fig) { + $this->config->load('app', true, true); + $configs = $this->config->item('app'); + $config = $configs[$fig]; + if (!$config) { + debug_log("[error] " . __FUNCTION__ . ": config not exist;fig={$fig}", $this->log_file); + throw new Hd_Exception('请求的小程序不存在', API_CODE_INVILD_PARAM); + } + $wxconfig = $config['wx']; + } else { + $wxconfig = $this->wx_config; + $fig = $this->app_key; + } + $filename = "{$fig}/" . substr(md5($path), 8, 16); + $this->load->library('Hdwechat'); + $hdwechat = new Hdwechat($wxconfig); + $ret = $hdwechat->qrcode($filename, $scene, $page, $width); + if (!$ret) { + throw new Hd_Exception('生成失败,稍后重试', API_CODE_FAIL); + } + $data = array('url' => $ret['url']); + return $data; + } + +} diff --git a/api/controllers/wxapp/material/Statistics.php b/api/controllers/wxapp/material/Statistics.php new file mode 100644 index 00000000..fb5a3a6a --- /dev/null +++ b/api/controllers/wxapp/material/Statistics.php @@ -0,0 +1,160 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + $this->load->model('app/material/Material_biz_statistics_model', 'mdBizStatistics'); + $this->load->model('app/material/Material_template_model', 'mdTemplate'); + $this->load->model('receiver/receiver_customers_model', 'mdCustomers'); + $this->load->model("biz/biz_model", 'mdBiz'); + $this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据 + } + + /** + * Notes:数据分析首页 + * Created on: 2021/10/12 11:47 + * Created by: dengbw + * @return array + * @throws Exception + */ + protected function get() + { + if (!$this->biz_id) { + throw new Hd_exception('门店不存在!', API_CODE_FAIL); + } + $re_biz = $this->mdBiz->get(['id' => $this->biz_id, 'status' => 1]); + if (!$re_biz) { + return $this->show_json(SYS_CODE_FAIL, '门店不存在!'); + } + $topic_list = array(); + $where = ['a.status' => 1, 'b.app_id' => $this->app_id, 'b.biz_id' => $this->biz_id]; + $this->mdTemplate->db->from('lc_material_template as a'); + $this->mdTemplate->db->join('lc_material_biz as b', "b.t_id=a.id", 'left'); + $this->mdTemplate->db->select('a.id, a.title,b.biz_id,b.app_id'); + $this->mdTemplate->db->where($where); + $this->mdTemplate->db->order_by('a.id Desc'); + $this->mdTemplate->db->limit(50); + $res = $this->mdTemplate->db->get()->result_array(); + foreach ($res as $key => $value) { + $topic_list[] = array('id' => $value['id'], 'title' => $value['title']); + } + $this->data['title'] = '数据分析'; + $this->data['biz_name'] = $re_biz['biz_name']; + $this->data['topic_list'] = $topic_list; + return $this->data; + } + + /** + * Notes:累计数据 + * Created on: 2021/10/13 14:51 + * Created by: dengbw + * @return array + */ + protected function get_cal() + { + $day = $this->input_param('day'); + $t_id = intval($this->input_param('t_id')); + $where_s = array('app_id' => $this->app_id, 'biz_id' => $this->biz_id); + $where_c = array('biz_id' => $this->biz_id, 'cf_id' => $this->cf_id, 'status >=' => 0); + $where_o = array('c.biz_id' => $this->biz_id, 'c.cf_id' => $this->cf_id, 'c.status >=' => 0); + if ($day) { + $where_s['day'] = $day; + $where_c['c_time>='] = strtotime($day . ' 00:00:00'); + $where_c['c_time<='] = strtotime($day . ' 23:59:59'); + $where_o['o.c_time>='] = strtotime($day . ' 00:00:00'); + $where_o['o.c_time<='] = strtotime($day . ' 23:59:59'); + } + if ($t_id) { + $where_s['t_id'] = $t_id; + $where_c['t_id '] = $t_id; + $where_o['c.t_id'] = $t_id; + } + $re_s = $this->mdBizStatistics->sum('browse_num', $where_s); + $count_c = $this->mdCustomers->count($where_c); + $count_o = $this->mdBizStatistics->count_order($where_o); + $data = [ + ['icon' => 'icon-liulan', 'name' => '浏览次数', 'value' => intval($re_s['browse_num'])], + ['icon' => 'icon-baoming', 'name' => '报名客户', 'value' => $count_c], + ['icon' => 'icon-dingdan', 'name' => '订单客户', 'value' => $count_o] + ]; + return $data; + } + + /** + * Notes:图表 + * Created on: 2021/10/13 10:59 + * Created by: dengbw + * @return array + */ + protected function get_chart() + { + $xAxis = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; + $year = date('Y'); + $browse_data = $enroll_data = $orders_data = []; + $where_s = array('app_id' => $this->app_id, 'biz_id' => $this->biz_id); + $where_c = array('biz_id' => $this->biz_id, 'cf_id' => $this->cf_id, 'status >=' => 0); + $where_o = array('c.biz_id' => $this->biz_id, 'c.cf_id' => $this->cf_id, 'c.status >=' => 0); + foreach ($xAxis as $key => $value) { + $value < 10 && $value = '0' . $value; + $s_day = $year . '-' . $value . '-01';//第一天 + $e_day = date('Y-m-d', strtotime("$s_day +1 month -1 day"));//最后一天 + //浏览 + $re_s = $this->mdBizStatistics->sum('browse_num', array_merge($where_s, array('day>=' => $s_day, 'day<=' => $e_day))); + $s_time = strtotime($s_day . ' 00:00:00'); + $e_time = strtotime($e_day . ' 23:59:59'); + //客户 + $count_c = $this->mdCustomers->count(array_merge($where_c, array('c_time>=' => $s_time, 'c_time<=' => $e_time))); + //订单 + $count_o = $this->mdBizStatistics->count_order(array_merge($where_o, array('o.c_time>=' => $s_time, 'o.c_time<=' => $e_time))); + $browse_data[] = intval($re_s['browse_num']); + $enroll_data[] = $count_c; + $orders_data[] = $count_o; + } + $data = [ + 'legend' => ["浏览", "客户", "订单"], + 'xAxis' => $xAxis, + 'series' => [ + [ + 'name' => '浏览', + 'type' => 'line', + 'smooth' => true, + 'data' => $browse_data, + ], + [ + 'name' => '客户', + 'type' => 'line', + 'smooth' => true, + 'data' => $enroll_data, + ], + [ + 'name' => '订单', + 'type' => 'line', + 'smooth' => true, + 'data' => $orders_data, + ] + ] + ]; + return $data; + } +} \ No newline at end of file diff --git a/api/controllers/wxapp/material/Topic.php b/api/controllers/wxapp/material/Topic.php new file mode 100644 index 00000000..45d5ffe7 --- /dev/null +++ b/api/controllers/wxapp/material/Topic.php @@ -0,0 +1,88 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + $this->load->model('app/material/Material_template_model', 'mdTemplate'); + $this->load->model('app/material/Material_biz_model', 'mdMaterialBiz'); + $this->load->model('app/material/Material_biz_statistics_model', 'mdBizStatistics'); + $this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据 + } + + /** + * Notes:专题首页 + * Created on: 2021/10/12 11:47 + * Created by: dengbw + * @return array + * @throws Exception + */ + protected function get() + { + $id = intval($this->input_param('id')); + $biz_id = intval($this->input_param('biz_id')); + $re = $this->mdTemplate->get(array('id' => $id, 'status' => 1)); + if (!$re || empty($re)) { + throw new Hd_exception('专题不存在', API_CODE_FAIL); + } + if ($biz_id) { + $re_biz = $this->mdMaterialBiz->get(array('app_id' => $this->app_id, 't_id' => $id, 'biz_id' => $biz_id)); + if (!$re_biz || empty($re_biz)) { + throw new Hd_exception('门店还未创建专题', API_CODE_FAIL); + } + //加店铺专题浏览 + $where_s = ['app_id' => $this->app_id, 'biz_id' => $biz_id, 't_id' => $id, 'day' => date('Y-m-d')]; + $re_s = $this->mdBizStatistics->get($where_s); + if ($re_s) { + $this->mdBizStatistics->update(['browse_num = browse_num+1' => null], $where_s); + } else { + $where_s['browse_num'] = 1; + $this->mdBizStatistics->add($where_s); + } + } + $lists = array(); + if ($re['json_data']) { + $json_data = json_decode($re['json_data'], true); + foreach ($json_data['lists'] as $key => $value) { + $setValue = array(); + $setValue['title'] = $value['title']; + if ($re['type'] == 1) { + $setValue['video_type'] = intval($value['video_type']); + if ($value['video_type'] == 1) { + $setValue['video'] = $value['video'] ? build_qiniu_image_url($value['video'], 0, 0, 'video') : ''; + $setValue['video_cover'] = $value['video'] ? $value['video'] . '?vframe/jpg/offset/1' : ''; + } else { + $setValue['img'] = $value['img'] ? build_qiniu_image_url($value['img']) : ''; + $setValue['link'] = $value['link']; + } + } else if ($re['type'] == 2) { + $setValue['img'] = $value['img'] ? build_qiniu_image_url($value['img']) : ''; + $setValue['link'] = $value['link']; + } + $lists[] = $setValue; + } + } + $this->data['id'] = $id; + $this->data['type'] = $re['type']; + $this->data['sign_up'] = 1; + $this->data['lists'] = $lists; + return $this->data; + } +} diff --git a/common/models/app/material/Material_biz_model.php b/common/models/app/material/Material_biz_model.php new file mode 100644 index 00000000..d81b1a32 --- /dev/null +++ b/common/models/app/material/Material_biz_model.php @@ -0,0 +1,17 @@ +table_name, 'default'); + } +} diff --git a/common/models/app/material/Material_biz_statistics_model.php b/common/models/app/material/Material_biz_statistics_model.php new file mode 100644 index 00000000..c543096f --- /dev/null +++ b/common/models/app/material/Material_biz_statistics_model.php @@ -0,0 +1,49 @@ +table_name, 'default'); + } + + //关联订单 + public function count_order($where) + { + return $this->select_order($where, 'o.rid', '', '', '', 1); + } + + public function select_order($where = array(), $order = '', $page = 0, $page_size = 20, $fileds = '', $count = 0) + { + !$fileds && $fileds = 'o.*'; + $this->db->select($fileds); + $this->db->from('lc_receiver_orders as o'); + $this->db->join('lc_receiver_customers as c', 'c.id = o.rid', 'left'); + if ($where) { + $this->db->where($where); + } + if ($count) { + return $this->db->count_all_results(); + } + if ($order) { + $this->db->order_by($order); + } + if ($page) { + $offset = ($page - 1) * $page_size; + $limit = $page_size; + } else { + $offset = null; + $limit = null; + } + $this->db->limit($limit, $offset); + return $this->db->get()->result_array(); + } +} diff --git a/common/models/app/material/Material_template_model.php b/common/models/app/material/Material_template_model.php new file mode 100644 index 00000000..3c99618e --- /dev/null +++ b/common/models/app/material/Material_template_model.php @@ -0,0 +1,39 @@ +table_name, 'default'); + } + + /** + * Notes:素材分类 + * Created on: 2021/9/15 10:25 + * Created by: dengbw + * @return array + */ + public function typeAry() + { + return array(1 => '推广视频', 2 => '轮播海报', 3 => '朋友圈文案'); + } + + /** + * Notes:状态 + * Created on: 2021/9/15 10:25 + * Created by: dengbw + * @return array + */ + public function statusAry() + { + return array(1 => '正常', 0 => '下架', -1 => '删除'); + } +}