Files
2022-03-09 17:57:50 +08:00

162 lines
6.6 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Notes:商品操作
* Created on: 2022/3/01 16:43
* Created by: dengbw
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class Goods 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_model', 'mdItems');
$this->load->model('items/items_oplogs_model', 'mdItemsOplogs');
$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->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
}
/**
* Notes:库存车辆提醒
* Created on: 2022/3/01 17:03
* Created by: dengbw
* @return array
*/
protected function get_remind()
{
$type = intval($this->input_param('type'));
if ($type == 1) {
$this->load->model('items/Items_inventory_model', 'mdInventory');
if (!$this->mdInventory->addrManage($this->myuid)) {//非指定信息员管理地址不显示库存
return ['show' => 0, 'inventory' => ''];
}
}
$where = ['status<>' => 0, 'biz_id' => $this->biz_id, 'bill_time' => '0000-00-00 00:00:00'];
$res = $this->mdItems->select($where, 'id DESC', 0, 0, 'id,in_time,biz_id');
$total = count($res);
$warning = '';
$if_warning = 0;
if ($total) {
$list = [];
foreach ($res as $key => $val) {
$re_logs = $this->mdItemsOplogs->max('com_time', ["item_id" => $val['id'], 'type' => 2, 'biz_id_to' => $val['biz_id']]);
if ($re_logs['com_time'] || $val['in_time']) {
$in_time = $re_logs['com_time'] ? $re_logs['com_time'] : $val['in_time'];
$days = round((time() - strtotime($in_time)) / 3600 / 24);
if ($days > 20) {
$item_info = $this->item_info($val['id']);
$list[] = ['title' => $item_info['title'], 'vin' => $item_info['vin']
, 'days' => "已库存:{$days}", 'img' => $item_info['cor_img']];
}
if ($days > 30) {
$if_warning = 1;
}
}
}
$list && $warning = ['title' => '库存超期预警', 'note' => '库存天数已超过20天,请尽快销售,以免造成损失!', 'list' => $list];
}
if ($if_warning) {//库存预警
$inventory_title = '库存超期';
$inventory_color = '#f00';
} else {
$inventory_title = '库存良好';
$inventory_color = '#666';
}
$date = ['show' => 1, 'inventory' => ['title' => $inventory_title, 'value' => $total
, 'color' => $inventory_color], 'warning' => $warning];
return $date;
}
protected function get_lists()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 5;
$where = ['status<>' => 0, 'biz_id' => $this->biz_id, 'bill_time' => '0000-00-00 00:00:00'];
$count = $this->mdItems->count($where);
$lists = [];
if ($count) {
$res = $this->mdItems->select($where, 'id DESC', $page, $size, 'id,brand_id,s_id,v_id,cor_id,vin,in_time,biz_id');
foreach ($res as $key => $val) {
$setValue = $other_data = [];
$item_info = $this->item_info($val['id'], $val);
$setValue['title'] = $item_info['title'];
$other_data = $item_info['other_data'];
$setValue['other_data'] = $other_data;
$setValue['car_cor_img'] = $item_info['cor_img'];
$lists[] = $setValue;
}
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
/**
* Notes:获取商品信息
* Created on: 2022/3/2 15:20
* Created by: dengbw
* @param $item_id
* @param string $re
* @return array
*/
private function item_info($item_id, $re = '')
{
$type = 0;
if ($re) {
$type = 1;
} else {
$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_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'];
if ($re_cor['jsondata']) {
$jsondata = json_decode($re_cor['jsondata'], true);
$jsondata['img'] && $cor_img = build_qiniu_image_url($jsondata['img']);
}
if ($type == 0) {
$info['vin'] = $re['vin'];
} else {
$re_v = $this->mdAutoAttr->get(array('id' => $re['v_id']), 'title');
$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'];
if ($in_time) {
$other_data[] = ['title' => '入库时间', 'value' => $in_time];
$days = round((time() - strtotime($in_time)) / 3600 / 24);
$other_data[] = ['title' => '库存天数', 'value' => $days, 'color' => '#f9394d'];
}
$info['other_data'] = $other_data;
}
$info['title'] = $title;
$info['cor_img'] = $cor_img;//车辆颜色
return $info;
}
}