From 9f090795fa05b390d4ec346c7a8d1ff091021de5 Mon Sep 17 00:00:00 2001 From: dengbw Date: Wed, 3 Nov 2021 11:43:54 +0800 Subject: [PATCH] api_biz_1103 --- .../wxapp/content/liche/Sub_cms.php | 73 +++++++---- api/controllers/wxapp/material/Biz.php | 121 ++++++++++++++++-- common/models/biz/Biz_statistics_model.php | 19 +++ 3 files changed, 175 insertions(+), 38 deletions(-) create mode 100644 common/models/biz/Biz_statistics_model.php diff --git a/api/controllers/wxapp/content/liche/Sub_cms.php b/api/controllers/wxapp/content/liche/Sub_cms.php index 8ff083b0..53c8e618 100644 --- a/api/controllers/wxapp/content/liche/Sub_cms.php +++ b/api/controllers/wxapp/content/liche/Sub_cms.php @@ -7,9 +7,12 @@ defined('WXAPP_CONTENT') OR exit('No direct script access allowed'); * Date: 2021/6/28 * Time: 10:54 */ -require_once APPPATH.'controllers/wxapp/Wxapp.php'; -class Sub_cms extends Wxapp{ - function __construct($inputs, $app_key){ +require_once APPPATH . 'controllers/wxapp/Wxapp.php'; + +class Sub_cms extends Wxapp +{ + function __construct($inputs, $app_key) + { parent::__construct($inputs, $app_key); $this->login_white = 'all';//登录白名单 @@ -17,17 +20,18 @@ class Sub_cms extends Wxapp{ $this->load->model('app/liche/app_liche_cms_model', 'cms_model'); } - protected function get(){ + protected function get() + { $id = $this->input_param('id'); - if($id){ - return $this->detail($id); + if ($id) { + return $this->detail($this->input_param()); } $page = $this->input_param('page'); $size = $this->input_param('size'); $position = $this->input_param('position'); $type = $this->input_param('type'); - if(0 == strlen($position)){ + if (0 == strlen($position)) { throw new Exception('请求超时', API_CODE_INVILD_PARAM); } @@ -38,32 +42,32 @@ class Sub_cms extends Wxapp{ $where = array( 'status' => self::STATUS_NOR, ); - if(is_numeric($position)){ + if (is_numeric($position)) { $where['position'] = $position; } else { $where["position in ({$position})"] = null; } - if($type == 1){ - $where['e_time <= '] = time(); + if ($type == 1) { + $where['e_time <= '] = time(); } else { - $where['e_time >= '] = time(); + $where['e_time >= '] = time(); } $total = $this->cms_model->count($where); $lists = array(); - if($total){ + if ($total) { $select = 'id, title, cover, url, position,e_time,target_id,jsondata'; $rows = $this->cms_model->select($where, 'sort DESC', $page, $size, $select); - foreach($rows as $item){ - $jsondata =json_decode($item['jsondata'],true); + foreach ($rows as $item) { + $jsondata = json_decode($item['jsondata'], true); $lists[] = array( 'id' => $item['id'], 'title' => $item['title'], 'img' => $item['cover'] ? build_qiniu_image_url($item['cover']) : '', 'url' => build_app_url($item['url']), - 'e_time' => date('Y-m-d H:i:s',$item['e_time']), + 'e_time' => date('Y-m-d H:i:s', $item['e_time']), 'target_id' => $item['target_id'], - 'status' => $item['e_time'] $item['e_time'] < time() ? 0 : 1, 'btn_type' => $jsondata['btn_type'] ? $jsondata['btn_type'] : 1, ); } @@ -76,33 +80,48 @@ class Sub_cms extends Wxapp{ return $data; } - - private function detail($id){ - $row = $this->cms_model->get(['id'=>$id]); - if(!$row){ + + private function detail($params) + { + $id = $params['id']; + $row = $this->cms_model->get(['id' => $id]); + if (!$row) { throw new Exception('数据不存在', API_CODE_INVILD_PARAM); } - $jsondata =json_decode($row['jsondata'],true); + if ($params['type'] == 'biz' && $params['biz_id']) {//加店铺浏览 + $this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据 + $this->load->model("biz/biz_statistics_model", 'mdBizStatistics'); + $where_s = ['app_id' => $this->app_id, 'biz_id' => $params['biz_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); + } + } + $jsondata = json_decode($row['jsondata'], true); $data = array( 'id' => $row['id'], 'title' => $row['title'], 'img' => $row['cover'] ? build_qiniu_image_url($row['cover']) : '', 'url' => build_app_url($row['url']), 'content' => $row['content'], - 'e_time' => date('Y-m-d H:i:s',$row['e_time']), + 'e_time' => date('Y-m-d H:i:s', $row['e_time']), 'target_id' => $row['target_id'], - 'status' => $row['e_time'] $row['e_time'] < time() ? 0 : 1, 'qrcode' => $jsondata['qrcode'] ? build_qiniu_image_url($jsondata['qrcode']) : '', ); return $data; } - + //获取cms tab - protected function get_tabs(){ + protected function get_tabs() + { $posion_arr = $this->cms_model->get_position(); $data = []; - foreach($posion_arr as $key => $val){ - if($key>2 && $key<8){ + foreach ($posion_arr as $key => $val) { + if ($key > 2 && $key < 8) { $data[] = [ 'id' => $key, 'name' => $val diff --git a/api/controllers/wxapp/material/Biz.php b/api/controllers/wxapp/material/Biz.php index 09d4f09f..5492f0ec 100644 --- a/api/controllers/wxapp/material/Biz.php +++ b/api/controllers/wxapp/material/Biz.php @@ -22,12 +22,13 @@ class Biz extends Wxapp $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('app/liche/App_liche_cms_model', 'mdLicheCms'); $this->load->model('receiver/receiver_customers_model', 'mdCustomers'); $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); + $this->load->model('auto/auto_series_model', 'mdAutoSeries'); + $this->load->model('auto/auto_attr_model', 'mdAutoAttr'); $this->load->model("biz/biz_model", 'mdBiz'); + $this->load->model('items/items_model', 'mdItems'); $this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据 } @@ -40,6 +41,95 @@ class Biz extends Wxapp */ protected function get() { + $this->load->model("biz/biz_statistics_model", 'mdBizStatistics'); + $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, '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 = []; + $sql = "SELECT id,brand_id,s_id,v_id,cor_id,ori_price FROM lc_items WHERE biz_id={$biz_id} +AND bill_time='0000-00-00 00:00:00' GROUP BY cor_id ORDER BY in_time DESC"; + $res = $this->mdItems->db->query($sql)->result_array(); + $brand_ids = $s_ids = $attr_vids = $attr_corids = $ids = array(); + foreach ($res as $v) { + $v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_id']; + $v['s_id'] && !in_array($v['s_id'], $s_ids) && $s_ids[] = $v['s_id']; + $v['v_id'] && !in_array($v['v_id'], $attr_vids) && $attr_vids[] = $v['v_id']; + $v['cor_id'] && !in_array($v['cor_id'], $attr_corids) && $attr_corids[] = $v['cor_id']; + } + $map_brand = $map_sery = $map_vid = $map_corid = array(); + if ($brand_ids) { + $str_ids = implode(',', $brand_ids); + $where = array("id in ({$str_ids})" => null); + $map_brand = $this->mdAutoBrand->map('id', 'name', $where); + } + if ($s_ids) { + $str_ids = implode(',', $s_ids); + $where = array("id in ({$str_ids})" => null); + $map_sery = $this->mdAutoSeries->map('id', 'name', $where); + } + if ($attr_vids) { + $str_ids = implode(',', $attr_vids); + $where = array("id in ({$str_ids})" => null); + $map_vid = $this->mdAutoAttr->map('id', 'title', $where); + } + if ($attr_corids) { + $str_ids = implode(',', $attr_corids); + $where = array("id in ({$str_ids})" => null); + $map_corid = $this->mdAutoAttr->map('id', 'title', $where); + } + foreach ($res as $key => $val) { + $id = $img = ''; + $re_attr = $this->mdAutoAttr->get(['id' => $val['cor_id']], 'jsondata'); + if ($re_attr['jsondata']) { + $jsondata = json_decode($re_attr['jsondata'], true); + $jsondata['img'] && $img = build_qiniu_image_url($jsondata['img']); + } + $title = $map_brand[$val['brand_id']]; + $map_sery[$val['s_id']] && $title .= '-' . $map_sery[$val['s_id']]; + $map_vid[$val['v_id']] && $title .= '-' . $map_vid[$val['v_id']]; + $map_corid[$val['cor_id']] && $title .= '-' . $map_corid[$val['cor_id']]; + $where_l = ['target_id' => $val['brand_id'], 'position' => 2, 'status' => 1, 'e_time>=' => time()]; + $re_l = $this->mdLicheCms->max('id', $where_l); + $re_l['id'] && $id = $re_l['id']; + $lists[] = [ + 'cms_id' => $id, + 'title' => $title, + 'img' => $img, + 'ori_price' => ['title' => '厂商指导价¥', 'value' => $val['ori_price']], + ]; + } + $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['lists'] = $lists; + return $this->data; + } + + /** + * Notes:店铺素材库首页 + * Created on: 2021/11/3 9:44 + * Created by: dengbw + * @return array + * @throws Hd_exception + */ + protected function get_material() + { + $this->load->model('app/material/Material_biz_statistics_model', 'mdMaterialBizStatistics'); + $this->load->model('app/material/Material_template_model', 'mdTemplate'); + $this->load->model('app/material/Material_biz_model', 'mdMaterialBiz'); $biz_id = intval($this->input_param('biz_id')); $re = $this->mdBiz->get(array('id' => $biz_id, 'status' => 1)); if (!$re || empty($re)) { @@ -47,12 +137,12 @@ class Biz extends Wxapp } //加店铺浏览 $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); + $re_s = $this->mdMaterialBizStatistics->get($where_s); if ($re_s) { - $this->mdBizStatistics->update(['browse_num = browse_num+1' => null], $where_s); + $this->mdMaterialBizStatistics->update(['browse_num = browse_num+1' => null], $where_s); } else { $where_s['browse_num'] = 1; - $this->mdBizStatistics->add($where_s); + $this->mdMaterialBizStatistics->add($where_s); } $auto_brands = $list = array(); if ($re['jsondata']) { @@ -77,8 +167,8 @@ class Biz extends Wxapp '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)); + $re_s = $this->mdMaterialBizStatistics->sum('browse_num', ['app_id' => $this->app_id, 'biz_id' => $biz_id]); + //$orders = $this->mdMaterialBizStatistics->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']; @@ -101,6 +191,7 @@ class Biz extends Wxapp { $biz_id = intval($this->input_param('biz_id')); $t_id = intval($this->input_param('t_id')); + $type = $this->input_param('type'); if (!$biz_id || !$this->session['mobile']) { throw new Hd_exception('参数错误', API_CODE_FAIL); } @@ -108,14 +199,21 @@ class Biz extends Wxapp if (!$re_biz) { return $this->Hd_exception(SYS_CODE_FAIL, '预约的门店不存在!'); } + if ($type == 'biz') { + $cf_id = 29; + $cf_title = '自有资源'; + } else { + $cf_id = $this->cf_id; + $cf_title = '素材推广'; + } $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, + 'cf_title' => $cf_title, + 'cf_id' => $cf_id, 't_id' => $t_id, 'p_time' => date('Y-m-d H:i:s'), 'c_time' => time() @@ -124,7 +222,8 @@ class Biz extends Wxapp $t_id && $where['t_id'] = $t_id; $re_cus = $this->mdCustomers->get($where); if ($re_cus) { - throw new Hd_exception('您已经预约报名了', API_CODE_FAIL); + //throw new Hd_exception('您已经预约报名了', API_CODE_FAIL); + throw new Hd_exception('预约报名成功!', API_CODE_SUCCESS); } $id = $this->mdCustomers->add($add_data); if (!$id) { diff --git a/common/models/biz/Biz_statistics_model.php b/common/models/biz/Biz_statistics_model.php new file mode 100644 index 00000000..341482c5 --- /dev/null +++ b/common/models/biz/Biz_statistics_model.php @@ -0,0 +1,19 @@ +table_name, 'default'); + } +}