Files
liche/api/controllers/wxapp/material/Biz.php
T
2021-11-04 10:39:08 +08:00

222 lines
9.7 KiB
PHP

<?php
defined('WXAPP_ITEMS') OR exit('No direct script access allowed');
ini_set('display_errors', 'On');
error_reporting(E_ERROR);
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
/**
* Notes:店铺
* Created on: 2021/10/9 15:16
* Created by: dengbw
*/
class Biz extends Wxapp
{
private $cf_id = 24;//素材报名
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = '';//
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
$this->majia_white = array('get');//超级管理员披上马甲可操作权限
$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;//获取狸车宝数据
}
/**
* Notes:店铺首页
* Created on: 2021/10/12 11:47
* Created by: dengbw
* @return array
* @throws Exception
*/
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 = [
[
'brand_id' => 1, 'cms_id' => 0, 'sort' => 0,
'title' => '东风EX1', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '45700 ~ 52700'],
'img' => 'https://img.liche.cn/liche/2021/08/d646e4d674bbd4ce/01391b9663c09c6e.png'
],
[
'brand_id' => 2, 'cms_id' => 0, 'sort' => 0,
'title' => '雷丁芒果', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '29800 ~ 54900'],
'img' => 'https://img.liche.cn/liche/2021/08/263d62f0cfee4729/169ea481e36f5b19.png'
],
[
'brand_id' => 4, 'cms_id' => 0, 'sort' => 0,
'title' => '哪吒V', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '63900 ~ 72900'],
'img' => 'https://img.liche.cn/liche/2021/09/1b2acea849cf0aba/803b58e45d98fc75.png'
],
[
'brand_id' => 5, 'cms_id' => 0, 'sort' => 0,
'title' => '零跑T03', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '59800 ~ 76800'],
'img' => 'https://img.liche.cn/liche/2021/10/16563346c511be65/1db60b37c1418006.png'
],
[
'brand_id' => 5, 'cms_id' => 0, 'sort' => 0,
'title' => '零跑C11', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '159800 ~ 199800'],
'img' => 'https://img.liche.cn/liche/2021/10/a5d183944abf748b/b67eb2e08f84890f.png'
],
];
shuffle($lists);
foreach ($lists as $key => $val) {
$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'] && $lists[$key]['cms_id'] = $re_l['id'];
$count = $this->mdItems->count(['brand_id' => $val['brand_id'], 'status<>' => 0, 'biz_id' => $biz_id
, 'bill_time' => '0000-00-00 00:00:00']);
$lists[$key]['sort'] = $count ? $count + 5 : 5 - $key;
}
$countKey = array_column($lists, 'sort');
array_multisort($countKey, SORT_DESC, $lists);//排序
$this->data['title'] = '店铺';
$this->data['bg_img'] = 'https://qs.haodian.cn/wechat_app/liche/storeInfo/theme.png';
$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)) {
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->mdMaterialBizStatistics->get($where_s);
if ($re_s) {
$this->mdMaterialBizStatistics->update(['browse_num = browse_num+1' => null], $where_s);
} else {
$where_s['browse_num'] = 1;
$this->mdMaterialBizStatistics->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->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'];
$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['statistics'] = $re_s['browse_num'] . '人浏览';
$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'));
$type = $this->input_param('type');
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, '预约的门店不存在!');
}
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_title,
'cf_id' => $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' => $add_data['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);
throw new Hd_exception('预约报名成功了!', API_CODE_SUCCESS);
}
$id = $this->mdCustomers->add($add_data);
if (!$id) {
throw new Hd_exception('预约报名失败!', API_CODE_FAIL);
}
throw new Hd_exception('预约报名成功!', API_CODE_SUCCESS);
}
}