Files
2022-03-08 11:15:49 +08:00

235 lines
10 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Notes:车辆盘点
* Created on: 2022/2/24 16:43
* Created by: dengbw
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class Inventory extends Wxapp
{
private $biz_id;//门店id
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('items/Items_inventory_model', 'mdInventory');
$this->load->model('items/Items_inventory_log_model', 'mdInventoryLog');
$this->load->model('items/items_oplogs_model', 'mdItemsOplogs');
$this->load->model('items/items_model', 'mdItems');
$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("sys/sys_addr_model", 'mdAddr');
$this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
}
protected function get_tabs()
{
return [['id' => 1, 'name' => '进行中'], ['id' => 2, 'name' => '已完成']];
}
/**
* Notes:盘点提醒
* Created on: 2021/12/10 17:03
* Created by: dengbw
* @return array
*/
protected function get_remind()
{
$total = 0;
if ($this->mdInventory->addrManage($this->myuid)) {//信息员管理
$where = ['biz_id' => -1, "addr_id in({$this->mdInventory->addrManage($this->myuid)})" => null, 'status' => 0];
$total = $this->mdInventoryLog->count($where);
} else if ($this->biz_id) {//门店
$where = ['biz_id' => $this->biz_id, 'status' => 0];
$total = $this->mdInventoryLog->count($where);
}
return ['total' => $total];
}
protected function get_lists()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
$s_date = $this->input_param('s_date');
$e_date = $this->input_param('e_date');
!$page && $page = 1;
!$size && $size = 5;
$where = ['id' => 0];
$tabs_id = intval($this->input_param('tabs_id'));
if ($this->mdInventory->addrManage($this->myuid)) {//信息员管理
$where = ['biz_id' => -1, "addr_id in({$this->mdInventory->addrManage($this->myuid)})" => null];
$where['status'] = $tabs_id == 2 ? 1 : 0;
} elseif ($this->biz_id) {//门店
$where = ['biz_id' => $this->biz_id];
$where['status'] = $tabs_id == 2 ? 1 : 0;
} else if ($this->session['group_id'] == 4) {//渠道经理
$where = ['status(0,1)' => null, "biz_id in({$this->biz_id})" => null];
}
$s_date && $where['c_time >='] = strtotime($s_date . ' 00:00:00');
$e_date && $where['c_time <='] = strtotime($e_date . ' 23:59:59');
$count = $this->mdInventoryLog->count($where);
$lists = [];
if ($count) {
$res = $this->mdInventoryLog->select($where, 'id DESC', $page, $size, 'id,item_id,status,c_time,jsondata,biz_id,addr_id');
// $bizs = $this->mdBiz->get_map_by_ids(array_unique(array_column($res, 'biz_id')), 'id,biz_name');//门店
// $addrs = $this->mdAddr->get_map_by_ids(array_unique(array_column($res, 'addr_id')), 'id,title');//地址
foreach ($res as $key => $val) {
$setValue = $other_data = [];
$setValue['id'] = $val['id'];
// if ($val['biz_id'] == -1) {
// $biz_name = $addrs[$val['addr_id']][0]['title'];
// } else {
// $biz_name = $bizs[$val['biz_id']][0]['biz_name'];
// }
// $setValue['biz_name'] = $biz_name ? $biz_name : '';
$item_info = $this->item_info($val['item_id']);
$setValue['biz_name'] = $item_info['title'];
$other_data = $item_info['other_data'];
if ($val['status'] == 1) {
$jsondata = $val['jsondata'] ? json_decode($val['jsondata'], true) : [];
$jsondata['completion_time'] && $other_data[] = ['title' => '完成时间', 'value' => $jsondata['completion_time']];
}
$setValue['other_data'] = $other_data;
$setValue['car_cor_img'] = $item_info['cor_img'];
$lists[] = $setValue;
}
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
protected function get()
{
$id = intval($this->input_param('id'));
if (!$id) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$re = $this->mdInventoryLog->get(['id' => $id]);
if (!$re) {
throw new Exception('盘点不存在', ERR_PARAMS_ERROR);
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$mileage = $jsondata['mileage'] ? $jsondata['mileage'] : '';
$note = $jsondata['note'] ? $jsondata['note'] : '';
$car_img = [];
foreach ($this->mdInventoryLog->carImgAry() as $key => $value) {
$img_value = $img_src = '';
if ($jsondata['car_img'] && $jsondata['car_img'][$key]) {
$img_value = $jsondata['car_img'][$key];
$img_src = build_qiniu_image_url($img_value);
}
$car_img[] = ['title' => $value, 'key' => $key, 'value' => $img_value, 'src' => $img_src];
}
$item_info = $this->item_info($re['item_id']);
$other_data = $item_info['other_data'];
$other_data[] = ['title' => '盘点任务', 'value' => date('Y-m-d', $re['c_time'])];
$jsondata['completion_time'] && $other_data[] = ['title' => '完成时间', 'value' => $jsondata['completion_time']];
$data['id'] = $id;
$data['car_img'] = $car_img;
$data['car_cor_img'] = $item_info['cor_img'];
$data['mileage'] = $mileage;
$data['note'] = $note;
$data['other_data'] = $other_data;
$data['biz_name'] = $item_info['title'];
// $biz_name = '';
// if ($re['biz_id'] == -1) {//地址
// $re_addr = $this->mdAddr->get(['id' => $re['addr_id']]);
// $re_addr && $biz_name = $re_addr['title'];
// } else {//门店
// $re_biz = $this->mdBiz->get(['id' => $re['biz_id']]);
// $re_biz && $biz_name = $re_biz['biz_name'];
// }
return $data;
}
/**
* Notes:提交盘点
* Created on: 2022/2/25 16:07
* Created by: dengbw
* @throws Exception
*/
protected function post()
{
$id = intval($this->input_param('id'));
if (!$id) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$mileage = $this->input_param('mileage');
$car_img = $this->input_param('car_img');
$note = $this->input_param('note');
if (!$mileage) {
throw new Exception('里程数不能为空', ERR_PARAMS_ERROR);
}
if (!$car_img) {
throw new Exception('请上传图片', ERR_PARAMS_ERROR);
}
$jsonData['completion_time'] = date('Y-m-d H:i:s');
$jsonData['mileage'] = $mileage;
$jsonData['note'] = $note ? $note : '';
$jsonData['car_img'] = [];
foreach ($car_img as $key => $value) {
if (!$value['value']) {
throw new Exception('请上传' . $value['title'] . '图片', ERR_PARAMS_ERROR);
}
$jsonData['car_img'][$value['key']] = $value['value'];
}
$ret = $this->mdInventoryLog->update(['status' => 1, 'jsondata' => json_encode($jsonData, JSON_UNESCAPED_UNICODE)], ['id' => $id]);
if ($ret) {
throw new Exception('操作成功', API_CODE_SUCCESS);
} else {
throw new Exception('操作失败', ERR_PARAMS_ERROR);
}
}
/**
* Notes:获取商品信息
* Created on: 2021/12/9 10:47
* Created by: dengbw
* @param $item_id
* @param int $type
* @return array
*/
private function item_info($item_id)
{
$re = $this->mdItems->get(array('id' => $item_id));
if (!$re || empty($re)) {
return [];
}
$re_b = $this->mdAutoBrand->get(array('id' => $re['brand_id']), 'name');
$re_s = $this->mdAutoSeries->get(array('id' => $re['s_id']), 'name');
$re_v = $this->mdAutoAttr->get(array('id' => $re['v_id']), 'title');
$re_cor = $this->mdAutoAttr->get(array('id' => $re['cor_id']), 'title,jsondata');
$title = $cor_img = '';
$other_data = [];
$re_b['name'] && $title = $re_b['name'];
$re_s['name'] && $title = $title ? $title . '-' . $re_s['name'] : $re_s['name'];
$re_v['title'] && $other_data[] = ['title' => '版本', 'value' => $re_v['title']];
$re_cor['title'] && $other_data[] = ['title' => '颜色', 'value' => $re_cor['title']];
$re['vin'] && $other_data[] = ['title' => '车架号', 'value' => $re['vin']];
$in_time = $re['in_time'] != '0000-00-00 00:00:00' ? $re['in_time'] : '';
$re_logs = $this->mdItemsOplogs->max('com_time', ["item_id" => $item_id, 'type' => 2, 'biz_id_to' => $re['biz_id']]);
$re_logs['com_time'] && $in_time = $re_logs['com_time'];
$in_time && $other_data[] = ['title' => '入库时间', 'value' => $in_time];
if ($re_cor['jsondata']) {
$jsondata = json_decode($re_cor['jsondata'], true);
$jsondata['img'] && $cor_img = build_qiniu_image_url($jsondata['img']);
}
$info['title'] = $title;
$info['other_data'] = $other_data;
$info['cor_img'] = $cor_img;//车辆颜色
return $info;
}
}