269 lines
12 KiB
PHP
269 lines
12 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:店铺操作
|
|
* Created on: 2021/12/15 16:43
|
|
* Created by: dengbw
|
|
*/
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
|
|
class Biz extends Wxapp
|
|
{
|
|
|
|
function __construct($inputs, $app_key)
|
|
{
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg = array();//授权微信信息
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
$this->load->model("biz/biz_brand_model", 'mdBizBrand');
|
|
$this->load->model("biz/biz_base_model", 'mdBizBase');
|
|
$this->load->model("biz/biz_sell_model", 'mdBizSell');
|
|
$this->load->model('area_model');
|
|
$this->load->model('sys/sys_street_model', 'mdStreet');
|
|
$this->load->model('receiver/order/receiver_orders_model', 'mdOrders');
|
|
}
|
|
|
|
/**
|
|
* Notes:店铺概况_tab
|
|
* Created on: 2022/1/5 15:13
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_situation_tabs()
|
|
{
|
|
return [['id' => 1, 'name' => '基础信息'], ['id' => 2, 'name' => '售卖情况']];
|
|
}
|
|
|
|
protected function get_situation()
|
|
{
|
|
$tabs_id = intval($this->input_param('tabs_id'));
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
$re_biz = $this->mdBiz->get(['id' => $biz_id, 'status' => 1]);
|
|
if (!$re_biz) {
|
|
throw new Hd_exception('店铺不存在!', API_CODE_FAIL);
|
|
}
|
|
$info = [];
|
|
if ($tabs_id == 2) {//售卖情况
|
|
$this->load->model('auto/auto_brand_model', 'mdAutoBrand');
|
|
$jsondata = $re_biz['jsondata'] ? json_decode($re_biz['jsondata'], true) : [];
|
|
$y_month = date('Y-m', strtotime("-1 month"));//上个月
|
|
$re_sell = $this->mdBizSell->get(['biz_id' => $biz_id, 'y_month' => $y_month]);
|
|
$fields = $this->mdBizSell->get_fields();
|
|
foreach ($fields as $key => $value) {
|
|
if ($key == 'y_month') {
|
|
$fields[$key]['value'] = $y_month;
|
|
} else if ($key == 'cooperation_car' && $jsondata['auto_brands']) {
|
|
$auto_brands = implode(',', $jsondata['auto_brands']);
|
|
$res_ab = $this->mdAutoBrand->select(["id in({$auto_brands})" => null], 'id desc', 0, 0, 'name');
|
|
$res_ab && $fields[$key]['value'] = array_column($res_ab, 'name');
|
|
} else if ($key == 'sales') {
|
|
$last_month_s = date("Y-m-01", strtotime("-1 month"));//上1个月1日
|
|
$last_month_e = date("Y-m-d", strtotime("$last_month_s +1 month -1 day")); //上1个月最后一天
|
|
$where = ['biz_id' => $biz_id, 'status<>' => -1, 'brand_id<>' => 3, 'biz_id<>' => 1];
|
|
$orders = $this->mdOrders->count(array_merge($where, ['c_time >=' => strtotime($last_month_s . ' 00:00:00')
|
|
, 'c_time <=' => strtotime($last_month_e . ' 23:59:59')]));
|
|
$fields[$key]['value'] = $orders;
|
|
} else {
|
|
$re_sell[$key] && $fields[$key]['value'] = $re_sell[$key];
|
|
}
|
|
$setValue = $fields[$key];
|
|
$setValue['field'] = $key;
|
|
$info[] = $setValue;
|
|
}
|
|
} else {//基础信息
|
|
$re_base = $this->mdBizBase->get(['biz_id' => $biz_id]);
|
|
$fields = $this->mdBizBase->get_fields();
|
|
foreach ($fields as $key => $value) {
|
|
$list = '';
|
|
if ($key == 'county_id') {//县区
|
|
$result = $this->area_model->get(['county_id' => $re_biz['county_id']]);
|
|
$result['county_name'] && $fields[$key]['value'] = $result['county_name'];
|
|
} else if ($key == 'street_id' && $re_biz['county_id']) {//乡镇
|
|
$list[] = $value['list'];
|
|
$result = $this->area(['type' => $key, 'id' => $re_biz['county_id']]);
|
|
foreach ($result as $key2 => $value2) {
|
|
$list[] = $value2;
|
|
}
|
|
$fields[$key]['list'] = $list;
|
|
$re_biz['street_id'] && $fields[$key]['value'] = $re_biz['street_id'];
|
|
} else if ($key == 'company' && $re_biz['brand_id']) {//公司名称
|
|
$result = $this->mdBizBrand->get(['id' => $re_biz['brand_id']]);
|
|
$result['brand_name'] && $fields[$key]['value'] = $result['brand_name'];
|
|
} else if ($key == 'type') {//类型
|
|
$fields[$key]['value'] = $this->mdBiz->type_ary($re_biz['type']);
|
|
} else if ($key == 'level') {//级别
|
|
$fields[$key]['value'] = $this->level($biz_id);
|
|
} else if ($key == 'address' && $re_biz['address']) {//位置
|
|
$fields[$key]['value'] = $re_biz['address'];
|
|
} else if ($key == 'lead') {//负责人
|
|
$list[] = $value['list'];
|
|
$result = $this->app_user_model->select(['biz_id' => $biz_id], 'id DESC', 0, 0, 'id,uname as name');
|
|
foreach ($result as $key2 => $value2) {
|
|
$list[] = $value2;
|
|
}
|
|
$fields[$key]['list'] = $list;
|
|
$re_base[$key] && $fields[$key]['value'] = $re_base[$key];
|
|
} else if ($key == 'imgs') {//负责人
|
|
$imgs = $re_base[$key] ? json_decode($re_base[$key], true) : [];
|
|
foreach ($fields[$key]['list'] as $key2 => $value2) {
|
|
$setValue = $value2;
|
|
if ($imgs[$value2['id']]) {
|
|
$setValue['value'] = $imgs[$value2['id']];
|
|
$setValue['src'] = build_qiniu_image_url($setValue['value']);
|
|
} else {
|
|
$setValue['value'] = '';
|
|
$setValue['src'] = '';
|
|
}
|
|
$list[] = $setValue;
|
|
}
|
|
$fields[$key]['list'] = $list;
|
|
} else if ($re_base && $re_base[$key]) {//有字段赋值
|
|
$fields[$key]['value'] = $re_base[$key];
|
|
}
|
|
$setValue = $fields[$key];
|
|
$setValue['field'] = $key;
|
|
$info[] = $setValue;
|
|
}
|
|
}
|
|
return $info;
|
|
}
|
|
|
|
protected function get_street()
|
|
{
|
|
$id = intval($this->input->get('id'));
|
|
$list[] = ['id' => 0, 'name' => '选择乡镇'];
|
|
if (!$id) {
|
|
return $list;
|
|
}
|
|
$result = $this->area(['type' => 'street', 'id' => $id]);
|
|
foreach ($result as $key => $value) {
|
|
$list[] = $value;
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
public function area($params)
|
|
{
|
|
$result = [];
|
|
if ($params['id']) {
|
|
if ($params['type'] == 'county_id' || $params['type'] == 'county') {
|
|
$result = $this->area_model->county($params['id'], 1);
|
|
} else if ($params['type'] == 'street_id' || $params['type'] == 'street') {
|
|
$result = $this->mdStreet->select(['county_id' => $params['id']], 'id ASC', 0, 0, 'street_id as id,street_name as name');
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
protected function post_situation()
|
|
{
|
|
$tabs_id = intval($this->input_param('tabs_id'));
|
|
$info = $this->input_param('info');
|
|
if (!$tabs_id || !$info) {
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
if ($tabs_id == 2) {//售卖情况
|
|
$date = [];
|
|
foreach ($info as $key => $value) {
|
|
if ($value['field'] == 'sale_cars' || $value['field'] == 'clues_channel') {
|
|
} else if ($value['field'] == 'cooperation_car') {
|
|
$date[$value['field']] = $value['value'] ? implode(',', $value['value']) : '';
|
|
} else {
|
|
$date[$value['field']] = $value['value'];
|
|
}
|
|
}
|
|
$y_month = date('Y-m', strtotime("-1 month"));//上个月
|
|
$re_sell = $this->mdBizSell->get(['biz_id' => $biz_id, 'y_month' => $y_month]);
|
|
if (!$re_sell) {//新增
|
|
$date['biz_id'] = $biz_id;
|
|
$date['y_month'] = $y_month;
|
|
$date['status'] = 1;
|
|
$date['c_time'] = time();
|
|
$this->mdBizSell->add($date);
|
|
} else {//更新
|
|
$this->mdBizSell->update($date, ['id' => $re_sell['id']]);
|
|
}
|
|
} else {//基础信息
|
|
$date = $biz = [];
|
|
foreach ($info as $key => $value) {
|
|
if ($value['field'] == 'company' || $value['field'] == 'level' || $value['field'] == 'type' || $value['field'] == 'county_id') {
|
|
} else if ($value['field'] == 'address' || $value['field'] == 'street_id') {//更新门店信息
|
|
$biz[$value['field']] = $value['value'];
|
|
} else if ($value['field'] == 'imgs') {
|
|
$imgs = [];
|
|
foreach ($value['list'] as $key2 => $value2) {
|
|
$imgs[$value2['id']] = $value2['value'];
|
|
}
|
|
$date[$value['field']] = json_encode($imgs, JSON_UNESCAPED_UNICODE);
|
|
} else {
|
|
$date[$value['field']] = $value['value'];
|
|
}
|
|
}
|
|
$re_base = $this->mdBizBase->get(['biz_id' => $biz_id]);
|
|
if (!$re_base) {//新增
|
|
$date['biz_id'] = $biz_id;
|
|
$date['status'] = 1;
|
|
$date['c_time'] = time();
|
|
$this->mdBizBase->add($date);
|
|
} else {//更新
|
|
$this->mdBizBase->update($date, ['id' => $re_base['id']]);
|
|
}
|
|
$this->mdBiz->update($biz, ['id' => $biz_id]);//更新门店信息
|
|
}
|
|
throw new Exception('保存成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
private function level($biz_id = 0)
|
|
{
|
|
$str = '';
|
|
if ($biz_id) {
|
|
$where = ['biz_id' => $biz_id, 'status<>' => -1, 'brand_id<>' => 3, 'biz_id<>' => 1];
|
|
$last_month_s = date("Y-m-01", strtotime("-1 month"));//上1个月1日
|
|
$last_month_e = date("Y-m-d", strtotime("$last_month_s +1 month -1 day")); //上1个月最后一天
|
|
$orders = $this->mdOrders->count(array_merge($where, ['c_time >=' => strtotime($last_month_s . ' 00:00:00')
|
|
, 'c_time <=' => strtotime($last_month_e . ' 23:59:59')]));
|
|
if ($orders >= 12) {
|
|
$str = 'A1';
|
|
} else if ($orders >= 9) {
|
|
$str = 'A2';
|
|
} else if ($orders >= 6) {
|
|
$str = 'A3';
|
|
} else if ($orders >= 5) {
|
|
$str = 'B1';
|
|
} else if ($orders >= 4) {
|
|
$str = 'B2';
|
|
} else if ($orders >= 3) {
|
|
$str = 'B3';
|
|
} else {
|
|
$month_s = date("Y-m-01", strtotime("-3 month")); //上3个月1日
|
|
$month_e = date("Y-m-d", strtotime("$month_s +1 month -1 day")); //上3个月最后一天
|
|
$orders = $this->mdOrders->count(array_merge($where, ['c_time >=' => strtotime($month_s . ' 00:00:00')
|
|
, 'c_time <=' => strtotime($month_e . ' 23:59:59')]));
|
|
if ($orders && $orders <= 8) {
|
|
$str = 'C1';
|
|
} else {
|
|
$month_s = date("Y-m-d", strtotime("$last_month_s -15 day"));//45天前
|
|
$month_e = $last_month_e; //上个月最后一天
|
|
$orders = $this->mdOrders->count(array_merge($where, ['c_time >=' => strtotime($month_s . ' 00:00:00')
|
|
, 'c_time <=' => strtotime($month_e . ' 23:59:59')]));
|
|
if ($orders == 1) {
|
|
$str = 'C2';
|
|
} else if ($orders == 0) {
|
|
$this->load->model('items/items_model', 'mdItems');
|
|
$count_items = $this->mdItems->count(['status<>' => 0, 'biz_id' => $biz_id, 'brand_id<>' => 3, 'biz_id<>' => 1]);
|
|
!$count_items && $str = 'C3';//门店有样车未开单
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $str;
|
|
}
|
|
|
|
}
|