Files
liche/api/controllers/wxapp/material/Biz.php
T
2021-10-14 15:54:18 +08:00

136 lines
5.5 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/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);
}
}