232 lines
10 KiB
PHP
232 lines
10 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);
|
|
$key = "biz_browse_num_{$this->myuid}_{$this->app_id}_{$biz_id}";
|
|
if ($re_s) {
|
|
if (!$this->app_redis->get($key)) {
|
|
$this->mdBizStatistics->update(['browse_num = browse_num+1' => null], $where_s);
|
|
$this->app_redis->save($key, 1, 24 * 3600);//有效期1天
|
|
}
|
|
} else {
|
|
$where_s['browse_num'] = 1;
|
|
$this->mdBizStatistics->add($where_s);
|
|
$this->app_redis->save($key, 1, 24 * 3600);//有效期1天
|
|
}
|
|
$lists = [
|
|
[
|
|
'brand_id' => 1, 'cms_id' => 0, 'sort' => 0,
|
|
'title' => '东风 EX1 Pro', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '52700 ~ 59700'],
|
|
'img' => 'https://img.liche.cn/EX1.png'
|
|
],
|
|
[
|
|
'brand_id' => 4, 'cms_id' => 0, 'sort' => 0,
|
|
'title' => '哪吒V', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '74900 ~ 93900'],
|
|
'img' => 'https://img.liche.cn/NZV.png'
|
|
],
|
|
[
|
|
'brand_id' => 4, 'cms_id' => 0, 'sort' => 0,
|
|
'title' => '哪吒U', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '117800 ~ 179800'],
|
|
'img' => 'https://img.liche.cn/NZU.png'
|
|
],
|
|
[
|
|
'brand_id' => 5, 'cms_id' => 0, 'sort' => 0,
|
|
'title' => '零跑T03', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '68900 ~ 85900'],
|
|
'img' => 'https://img.liche.cn/T03.png'
|
|
],
|
|
[
|
|
'brand_id' => 5, 'cms_id' => 0, 'sort' => 0,
|
|
'title' => '零跑C11', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '179800 ~ 229800'],
|
|
'img' => 'https://img.liche.cn/C11.png'
|
|
],
|
|
[
|
|
'brand_id' => 7, 'cms_id' => 0, 'sort' => 0,
|
|
'title' => '合创Z03', 'ori_price' => ['title' => '厂商指导价¥', 'value' => '132800 ~ 178800'],
|
|
'img' => 'https://img.liche.cn/HCZ03.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';
|
|
$biz_name = strstr($re['biz_name'], '店') ? $re['biz_name'] : $re['biz_name'] . '店';
|
|
$this->data['biz_name'] = '狸车· ' . $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;
|
|
} else {
|
|
$cf_id = $this->cf_id;
|
|
}
|
|
$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' => '自有资源',
|
|
'of_id' => 5,
|
|
'of2_id' => 53,
|
|
'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']];
|
|
$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);
|
|
}
|
|
|
|
}
|