inventory_302
This commit is contained in:
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Notes:车辆盘点
|
||||
* Created on: 2022/2/18 16:43
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Inventory extends HD_Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$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", 'addr_model');
|
||||
$this->load->model('area_model', 'mdArea');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->lists();
|
||||
}
|
||||
|
||||
public function lists()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
||||
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
||||
$lists = $where = [];
|
||||
if ($params['time']) {
|
||||
$time = explode(' ~ ', $params['time']);
|
||||
$time[0] && $where["c_time>="] = strtotime($time[0] . ' 00:00:00');
|
||||
$time[1] && $where["c_time<="] = strtotime($time[1] . ' 23:59:59');
|
||||
}
|
||||
$total = $this->mdInventory->count($where);
|
||||
if ($total) {
|
||||
$res = $this->mdInventory->select($where, "c_time desc", $params['page'], $params['size']);
|
||||
foreach ($res as $key => $value) {
|
||||
$setValue = [];
|
||||
$setValue['id'] = $value['id'];
|
||||
$setValue['title'] = '盘点时间_' . date('Y-m-d', $value['c_time']);
|
||||
$lists[] = $setValue;
|
||||
}
|
||||
}
|
||||
$this->data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total);
|
||||
$this->data['lists'] = $lists;
|
||||
$this->data['params'] = $params;
|
||||
$this->data['_title'] = "车辆盘点";
|
||||
$this->show_view('items/inventory/lists', true);
|
||||
}
|
||||
|
||||
public function lists_log()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
||||
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
||||
if (!$params['inve_id']) {
|
||||
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
||||
}
|
||||
$re = $this->mdInventory->get(array('id' => $params['inve_id']));
|
||||
if (!$re || empty($re)) {
|
||||
return $this->show_json(SYS_CODE_FAIL, '车辆盘点不存在!');
|
||||
}
|
||||
$lists = $where = [];
|
||||
if (strlen($params['status'])) {
|
||||
$where['lc_items_inventory_log.status'] = $params['status'];
|
||||
} else {
|
||||
$params['lc_items_inventory_log.status in(0,1)'] = null;
|
||||
$params['status'] = '-99';
|
||||
}
|
||||
if ($params['biz_id']) {
|
||||
$where['lc_items_inventory_log.biz_id'] = $params['biz_id'];
|
||||
}
|
||||
if ($params['biz_id'] == -1 && $params['addr_id']) {
|
||||
$where['lc_items_inventory_log.addr_id'] = $params['addr_id'];
|
||||
} else if ($params['city_id']) {
|
||||
$where_biz['status'] = 1;
|
||||
$params['city_id'] && $where_biz['city_id'] = $params['city_id'];
|
||||
$params['county_id'] && $where_biz['county_id'] = $params['county_id'];
|
||||
$res_biz = $this->mdBiz->select($where_biz, 'id desc', 0, 0, 'id');
|
||||
$res_addr = $this->addr_model->select($where_biz, 'id desc', 0, 0, 'id');
|
||||
if ($res_biz && $res_addr) {
|
||||
$str_ids = implode(',', array_column($res_biz, 'id'));
|
||||
$str_addr_ids = implode(',', array_column($res_addr, 'id'));
|
||||
$where["(lc_items_inventory_log.biz_id in ({$str_ids}) or lc_items_inventory_log.addr_id in ({$str_addr_ids}))"] = null;
|
||||
} else if ($res_biz) {
|
||||
$str_ids = implode(',', array_column($res_biz, 'id'));
|
||||
$where["lc_items_inventory_log.biz_id in ({$str_ids})"] = null;
|
||||
} else if ($res_addr) {
|
||||
$str_addr_ids = implode(',', array_column($res_addr, 'id'));
|
||||
$where["lc_items_inventory_log.addr_id in ({$str_addr_ids})"] = null;
|
||||
} else {
|
||||
$where['lc_items_inventory_log.biz_id'] = -2;
|
||||
}
|
||||
} else {
|
||||
$params['city_id'] = '';
|
||||
$params['county_id'] = '';
|
||||
$params['addr_id'] = '';
|
||||
$params['biz_id'] = '';
|
||||
}
|
||||
if ($params['item_status']) {
|
||||
if ($params['item_status'] == 3) {
|
||||
$where["lc_items.bill_time<>"] = '0000-00-00 00:00:00';
|
||||
} else {
|
||||
$where["lc_items.status"] = $params['item_status'];
|
||||
}
|
||||
}
|
||||
if ($params['vin']) {
|
||||
$where["lc_items.vin like '%{$params['vin']}%'"] = null;
|
||||
}
|
||||
$autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name');
|
||||
if ($params['brand_id']) {
|
||||
$autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $params['brand_id']), 'id desc', 0, 0, 'id,name');
|
||||
}
|
||||
if ($params['s_id']) {
|
||||
$autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $params['s_id']), 'id desc', 0, 0, 'id,title as name');
|
||||
}
|
||||
$statusAry = $this->mdInventoryLog->statusAry();
|
||||
$carImgAry = $this->mdInventoryLog->carImgAry();
|
||||
$total = $this->db->select('lc_items_inventory_log.id')
|
||||
->join('lc_items', 'lc_items.id = lc_items_inventory_log.item_id', 'left')
|
||||
->where($where)
|
||||
->count_all_results('lc_items_inventory_log');
|
||||
if ($total) {
|
||||
$offset = ($params['page'] - 1) * $params['size'];
|
||||
$limit = $params['size'];
|
||||
$this->db->from('lc_items_inventory_log');
|
||||
$this->db->join('lc_items', 'lc_items.id = lc_items_inventory_log.item_id', 'left');
|
||||
$this->db->select('lc_items_inventory_log.item_id,lc_items_inventory_log.biz_id,lc_items_inventory_log.addr_id
|
||||
,lc_items_inventory_log.status,lc_items_inventory_log.jsondata
|
||||
,lc_items.status as itemStatus,lc_items.bill_time,lc_items.brand_id,lc_items.s_id,lc_items.v_id,lc_items.cor_id,lc_items.vin,lc_items.in_time,lc_items.in_time');
|
||||
$this->db->where($where);
|
||||
$this->db->order_by('lc_items_inventory_log.id Desc');
|
||||
$this->db->limit($limit, $offset);
|
||||
$res = $this->db->get()->result_array();
|
||||
$brand_ids = $s_ids = $attr_vids = $attr_corids = $biz_ids = $addr_ids = array();
|
||||
foreach ($res as $v) {
|
||||
$v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_id'];
|
||||
$v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_id'];
|
||||
$v['addr_id'] && !in_array($v['addr_id'], $addr_ids) && $addr_ids[] = $v['addr_id'];
|
||||
$v['s_id'] && !in_array($v['s_id'], $s_ids) && $s_ids[] = $v['s_id'];
|
||||
$v['v_id'] && !in_array($v['v_id'], $attr_vids) && $attr_vids[] = $v['v_id'];
|
||||
$v['cor_id'] && !in_array($v['cor_id'], $attr_corids) && $attr_corids[] = $v['cor_id'];
|
||||
}
|
||||
$map_brand = $map_sery = $map_vid = $map_corid = $map_biz = $map_addr = array();
|
||||
if ($brand_ids) {
|
||||
$str_ids = implode(',', $brand_ids);
|
||||
$where = array("id in ({$str_ids})" => null);
|
||||
$map_brand = $this->mdAutoBrand->map('id', 'name', $where);
|
||||
}
|
||||
if ($s_ids) {
|
||||
$str_ids = implode(',', $s_ids);
|
||||
$where = array("id in ({$str_ids})" => null);
|
||||
$map_sery = $this->mdAutoSeries->map('id', 'name', $where);
|
||||
}
|
||||
if ($attr_vids) {
|
||||
$str_ids = implode(',', $attr_vids);
|
||||
$where = array("id in ({$str_ids})" => null);
|
||||
$map_vid = $this->mdAutoAttr->map('id', 'title', $where);
|
||||
}
|
||||
if ($attr_corids) {
|
||||
$str_ids = implode(',', $attr_corids);
|
||||
$where = array("id in ({$str_ids})" => null);
|
||||
$map_corid = $this->mdAutoAttr->map('id', 'title', $where);
|
||||
}
|
||||
if ($biz_ids) {
|
||||
$str_ids = implode(',', $biz_ids);
|
||||
$where = array("id in ({$str_ids})" => null);
|
||||
$map_biz = $this->mdBiz->map('id', 'biz_name', $where);
|
||||
}
|
||||
if ($addr_ids) {
|
||||
$str_ids = implode(',', $addr_ids);
|
||||
$where = array("id in ({$str_ids})" => null);
|
||||
$orderby = 'id desc';
|
||||
$select = 'id, title, city_name, county_name';
|
||||
$rows_addr = $this->addr_model->select($where, $orderby, 0, 0, $select);
|
||||
foreach ($rows_addr as $v) {
|
||||
$map_addr[$v['id']] = "{$v['city_name']} {$v['county_name']} 其它 {$v['title']}";
|
||||
}
|
||||
}
|
||||
foreach ($res as $key => $v) {
|
||||
$address = $mileage = $itemStatus_name = $car_img = $where_logs = '';
|
||||
if ($v['biz_id'] > 0) {
|
||||
$address = $map_biz[$v['biz_id']];
|
||||
$re_biz = $this->mdBiz->get(array('id' => $v['biz_id']));
|
||||
if ($re_biz['county_id']) {
|
||||
$re_area = $this->mdArea->get(array('county_id' => $re_biz['county_id']));
|
||||
$re_area && $address = "{$re_area['city_name']} {$re_area['county_name']} {$address}";
|
||||
} else if ($re_biz['city_id']) {
|
||||
$re_area = $this->mdArea->get(array('city_id' => $re_biz['city_id']));
|
||||
$re_area && $address = "{$re_area['city_name']} {$address}";
|
||||
}
|
||||
$where_logs = ["item_id" => $v['item_id'], 'type' => 2, 'biz_id_to' => $v['biz_id']];
|
||||
} else if ($v['biz_id'] == -1 && $v['addr_id']) {
|
||||
$address = $map_addr[$v['addr_id']];
|
||||
$where_logs = ["item_id" => $v['item_id'], 'type' => 2, 'addr_id_to' => $v['addr_id']];
|
||||
}
|
||||
$title = "{$map_brand[$v['brand_id']]}-{$map_sery[$v['s_id']]}-{$map_vid[$v['v_id']]}-{$map_corid[$v['cor_id']]}";
|
||||
if ($v['bill_time'] != '0000-00-00 00:00:00') {
|
||||
$itemStatus_name = '已销售';
|
||||
} else if ($v['itemStatus'] == 1) {
|
||||
$itemStatus_name = '未分配';
|
||||
} else if ($v['itemStatus'] == 2) {
|
||||
$itemStatus_name = '已分配';
|
||||
}
|
||||
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
|
||||
$jsondata['mileage'] && $mileage = $jsondata['mileage'];
|
||||
if ($jsondata['car_img']) {
|
||||
foreach ($carImgAry as $key2 => $value2) {
|
||||
$src = $jsondata['car_img'][$key2];
|
||||
$src && $car_img[] = ['title' => $value2, 'src' => build_qiniu_image_url($src)];
|
||||
}
|
||||
}
|
||||
$in_time = $v['in_time'];
|
||||
if ($where_logs) {
|
||||
$re_logs = $this->mdItemsOplogs->max('com_time', $where_logs);
|
||||
$re_logs['com_time'] && $in_time = $re_logs['com_time'];
|
||||
}
|
||||
$lists[] = ['item_id' => $v['item_id'], 'title' => $title, 'vin' => $v['vin'], 'address' => $address,
|
||||
'itemStatus_name' => $itemStatus_name, 'status_name' => $statusAry[$v['status']], 'mileage' => $mileage, 'car_img' => $car_img,
|
||||
'in_time' => '0000-00-00 00:00:00' == $in_time ? '' : substr($in_time, 0, 10)];
|
||||
}
|
||||
}
|
||||
$this->data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total);
|
||||
$this->data['lists'] = $lists;
|
||||
$this->data['params'] = $params;
|
||||
$this->data['autoList'] = $autoList;
|
||||
$this->data['showInfo'] = ['statusAry' => $statusAry, 'itemStatusAry' => [1 => '未分配', 2 => '已分配', 3 => '已销售']];
|
||||
$this->data['_title'] = '盘点(' . date('Y-m-d', $re['c_time']) . ")详情";
|
||||
$this->show_view('items/inventory/lists_log', true);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$c_time = time();
|
||||
$inve_id = $this->mdInventory->add(['c_time' => $c_time]);
|
||||
if (!$inve_id) {
|
||||
return $this->show_json(SYS_CODE_FAIL, '发起盘点失败');
|
||||
}
|
||||
$where = array('status>' => 0, 'bill_time' => '0000-00-00 00:00:00');
|
||||
$res = $this->mdItems->select($where, 'id asc', 0, 0, 'id,biz_id,addr_id');
|
||||
$addDate = [];
|
||||
foreach ($res as $key => $value) {
|
||||
$addDate[] = ['inve_id' => $inve_id, 'item_id' => $value['id'], 'biz_id' => $value['biz_id'], 'addr_id' => $value['addr_id'], 'c_time' => $c_time];
|
||||
}
|
||||
$counts = count($addDate);
|
||||
if ($counts) {
|
||||
$ret = $this->mdInventoryLog->add_batch($addDate);
|
||||
if (!$ret) {
|
||||
return $this->show_json(SYS_CODE_FAIL, '发起盘点失败');
|
||||
}
|
||||
}
|
||||
return $this->show_json(SYS_CODE_SUCCESS, '发起盘点成功');
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
}
|
||||
|
||||
public function del()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function batch()
|
||||
{
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<div class="coms-table-wrap mt10">
|
||||
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
|
||||
action="items/inventory">
|
||||
<div class="am-form am-form-horizontal">
|
||||
<div class="am-form-group fl">
|
||||
<label class="am-para-label w100">发起时间:</label>
|
||||
<div class="am-form-group fl">
|
||||
<div class="am-para-inline w300">
|
||||
<input id="id-time" name="time" type="text" value="<?= $params['time'] ?>"
|
||||
placeholder="开始时间 ~ 结束时间" autocomplete="off"/>
|
||||
</div>
|
||||
<div class="am-para-inline" style="padding-top: 5px;">
|
||||
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="today"
|
||||
data-source="id-time">今天</a>
|
||||
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="yesterday"
|
||||
data-source="id-time">昨日</a>
|
||||
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="7day"
|
||||
data-source="id-time">最近7天</a>
|
||||
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="30day"
|
||||
data-source="id-time">最近30天</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl ml20">
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
|
||||
</div>
|
||||
<div class="am-form-group fl ml10">
|
||||
<a data-ajax="post" data-action="/items/inventory/add" class="am-btn am-btn-success am-btn-sm w100">发起盘点</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="coms-table-bd">
|
||||
<div class="fr">共有<?= $pager['totle'] ?>条数据</div>
|
||||
<table class="am-table am-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%"><span>id</span></th>
|
||||
<th width="50%"><span>标题</span></th>
|
||||
<th width="12%"><span>操作</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ($lists) {
|
||||
foreach ($lists as $v) { ?>
|
||||
<tr>
|
||||
<td><?= $v['id'] ?></td>
|
||||
<td><?= $v['title'] ?></td>
|
||||
<td><a href="javascript:void(0);"
|
||||
data-open="/items/inventory/lists_log?inve_id=<?= $v['id'] ?>"
|
||||
class="am-btn am-btn-primary am-btn-xs">查看详情</a></td>
|
||||
</tr>
|
||||
<?php }
|
||||
} ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="coms-table-ft clearfix">
|
||||
<div class="hander am-form">
|
||||
</div>
|
||||
<div class="coms-pagination fr mr20">
|
||||
<?php page_view($pager) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
require(['laydate', 'autocomplete'], function (laydate) {
|
||||
laydate.render({
|
||||
elem: '#id-time', range: '~'
|
||||
});
|
||||
$('.id-day-btn').click(function () {
|
||||
var type = $(this).data('date'), date = '', d_obj = new Date();
|
||||
var source_id = $(this).data('source') || 'id-time';
|
||||
switch (type) {
|
||||
case 'today':
|
||||
date = d_obj.Format('yyyy-MM-dd');
|
||||
date = date + ' ~ ' + date;
|
||||
break;
|
||||
case 'yesterday':
|
||||
date = (new Date(d_obj.getTime() - 86400000)).Format('yyyy-MM-dd');
|
||||
date = date + ' ~ ' + date;
|
||||
break;
|
||||
case '7day':
|
||||
date = (new Date(d_obj.getTime() - 86400000 * 7)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
|
||||
break;
|
||||
case '30day':
|
||||
date = (new Date(d_obj.getTime() - 86400000 * 29)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
|
||||
break;
|
||||
}
|
||||
$('#' + source_id).val(date);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,406 @@
|
||||
<div class="coms-table-wrap mt10">
|
||||
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
|
||||
action="items/inventory/lists_log">
|
||||
<input type="hidden" name="inve_id" v-model="params.inve_id">
|
||||
<div class="am-form am-form-horizontal">
|
||||
<div class="am-form-group fl">
|
||||
<label class="am-para-label w100">车型:</label>
|
||||
<div class="am-para-inline w120">
|
||||
<select id="bd-auto1-id" name="brand_id" data-toggle="next-select"
|
||||
data-refurl="/common/auto?pid={value}&type=2"
|
||||
data-next="#bd-auto2-id">
|
||||
<option value="0">选择品牌</option>
|
||||
<? if ($autoList[1]) {
|
||||
foreach ($autoList[1] as $v) { ?>
|
||||
<option value="<?= $v['id'] ?>" <?= $v['id'] == $params['brand_id'] ? 'selected' : '' ?>
|
||||
><?= $v['name'] ?></option>
|
||||
<? }
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl">
|
||||
<div class="am-para-inline w120">
|
||||
<select id="bd-auto2-id" name="s_id" data-toggle="next-select"
|
||||
data-refurl="/common/auto?pid={value}&type=3"
|
||||
data-next="#bd-auto3-id" @change="set_sery">
|
||||
<option value="0">选择车系</option>
|
||||
<?php if ($autoList[2]) {
|
||||
foreach ($autoList[2] as $v) { ?>
|
||||
<option value="<?= $v['id'] ?>" <?= $v['id'] == $params['s_id'] ? 'selected' : '' ?>
|
||||
><?= $v['name'] ?></option>
|
||||
<?php }
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl">
|
||||
<div class="am-para-inline w120">
|
||||
<select id="bd-auto3-id" name="v_id">
|
||||
<option value="0">选择车型</option>
|
||||
<?php if ($autoList[3]) {
|
||||
foreach ($autoList[3] as $v) { ?>
|
||||
<option value="<?= $v['id'] ?>" <?= $v['id'] == $params['v_id'] ? 'selected' : '' ?>
|
||||
><?= $v['name'] ?></option>
|
||||
<?php }
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl">
|
||||
<div class="am-para-inline w120">
|
||||
<select id="bd-auto4-id" name="cor_id" v-model="params.cor_id">
|
||||
<option value="">车身颜色</option>
|
||||
<option :value="v.id" v-for="(v,i) in attrs_cor">{{v.title}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group" style="margin-bottom: 0px;"></div>
|
||||
<div class="am-form-group fl">
|
||||
<label class="am-para-label w100">盘点地址:</label>
|
||||
<div class="am-para-inline w120">
|
||||
<select title="城市" name="city_id" v-model="params.city_id">
|
||||
<option value="">选择城市</option>
|
||||
<option :value="v.id" v-for="(v,i) in cityAry">{{v.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl">
|
||||
<div class="am-para-inline w120">
|
||||
<select title="行政区" name="county_id" v-model="params.county_id" @change="set_county">
|
||||
<option value="">选择行政区</option>
|
||||
<option :value="v.id" v-for="(v,i) in countyAry">{{v.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl">
|
||||
<div class="am-para-inline w120">
|
||||
<select title="门店" name="biz_id" v-model="params.biz_id" @change="set_biz">
|
||||
<option value="">选择门店</option>
|
||||
<option :value="v.id" v-for="(v,i) in bizAry">{{v.title}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl" v-show="params.biz_id==-1">
|
||||
<div class="am-para-inline w160">
|
||||
<select title="地址" name="addr_id" v-model="params.addr_id">
|
||||
<option value="">选择地址</option>
|
||||
<option :value="v.id" v-for="(v,i) in addrAry">{{v.title}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group" style="margin-bottom: 0px;"></div>
|
||||
<div class="am-form-group fl">
|
||||
<label class="am-para-label w80">车架号:</label>
|
||||
<div class="am-para-inline w200">
|
||||
<input type="text" name="vin" placeholder="车架号关键字" v-model="params.vin"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl">
|
||||
<label class="am-para-label w100">车辆状态:</label>
|
||||
<div class="am-para-inline w100">
|
||||
<select name="item_status">
|
||||
<option value="">选择状态</option>
|
||||
<? foreach ($showInfo['itemStatusAry'] as $key => $value) { ?>
|
||||
<option value="<?= $key ?>" <?= $key == $params['item_status'] ? 'selected' : '' ?>
|
||||
><?= $value ?></option>
|
||||
<? } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl">
|
||||
<label class="am-para-label w100">盘点状态:</label>
|
||||
<div class="am-para-inline w100">
|
||||
<select name="status">
|
||||
<option value="">选择状态</option>
|
||||
<? foreach ($showInfo['statusAry'] as $key => $value) { ?>
|
||||
<option value="<?= $key ?>" <?= $key == $params['status'] ? 'selected' : '' ?>
|
||||
><?= $value ?></option>
|
||||
<? } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="am-form-group fl ml30">
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
|
||||
</div>
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="button" class="am-btn am-btn-success am-btn-sm w100" @click="reset">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="coms-table-bd">
|
||||
<div class="fr">共有<?= $pager['totle'] ?>条数据</div>
|
||||
<table class="am-table am-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="23%"><span>车辆</span></th>
|
||||
<th width="14%"><span>车架号</span></th>
|
||||
<th width="17%"><span>盘点地址</span></th>
|
||||
<th width="8%"><span>盘点状态</span></th>
|
||||
<th width="8%"><span>里程数</span></th>
|
||||
<th width="12%"><span>盘点图片</span></th>
|
||||
<th width="8%"><span>入库时间</span></th>
|
||||
<th width="8%"><span>车辆状态</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ($lists) {
|
||||
foreach ($lists as $v) { ?>
|
||||
<tr>
|
||||
<td><?= $v['title'] ?></td>
|
||||
<td><a href="javascript:void(0);"
|
||||
data-modal="/items/goods/goods/get_info?id=<?= $v['item_id'] ?>"
|
||||
data-title="详情"><?= $v['vin'] ?></a></td>
|
||||
<td><?= $v['address'] ?></td>
|
||||
<td><?= $v['status_name'] ?></td>
|
||||
<td><?= $v['mileage'] ?></td>
|
||||
<td><? if ($v['car_img']) {
|
||||
foreach ($v['car_img'] as $key => $v2) { ?>
|
||||
<img title="<?= $v2['title'] ?>" src="<?= $v2['src'] ?>" data-tips-image
|
||||
style="width:22px;height:22px;margin-right: 5px;">
|
||||
<?
|
||||
}
|
||||
} ?>
|
||||
</td>
|
||||
<td><?= $v['in_time'] ?></td>
|
||||
<td><?= $v['itemStatus_name'] ?></td>
|
||||
</tr>
|
||||
<?php }
|
||||
} ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="coms-table-ft clearfix">
|
||||
<div class="hander am-form">
|
||||
</div>
|
||||
<div class="coms-pagination fr mr20">
|
||||
<?php page_view($pager) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function () {
|
||||
vue_obj = new Vue({
|
||||
el: '.coms-table-wrap',
|
||||
data: {
|
||||
params: {},
|
||||
cityAry: [],//城市
|
||||
countyAry: [],//行政区
|
||||
bizAry: [],//门店
|
||||
addrAry: [],//地址
|
||||
attrs_cor: [],//车身颜色选项
|
||||
},
|
||||
mounted: function () {
|
||||
var vm = this;
|
||||
vm.params = <?=json_encode($params)?>;
|
||||
vm.set_sery();
|
||||
vm.init_citys();
|
||||
},
|
||||
methods: {
|
||||
set_sery: function () {
|
||||
var vm = this;
|
||||
var s_id = $('#bd-auto2-id').val();
|
||||
if (s_id > 0) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/auto/attr/json_lists',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
s_id: s_id,
|
||||
status: 1,
|
||||
type: 0
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.code == 1) {
|
||||
vm.attrs_cor = response.data.list;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
vm.attrs_cor = [];
|
||||
vm.params.cor_id = '';
|
||||
}
|
||||
},
|
||||
init_citys: function () {
|
||||
var vm = this;
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '/common/area',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
id: '350',
|
||||
key: 'city',
|
||||
type: 1
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.code == 1) {
|
||||
vm.cityAry = response.data;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
set_county: function () {
|
||||
var that = this;
|
||||
that.bizAry = that.addrAry = [];
|
||||
that.params.biz_id = that.params.addr_id = '';
|
||||
},
|
||||
set_biz: function () {
|
||||
var that = this;
|
||||
that.addrAry = [];
|
||||
that.params.addr_id = '';
|
||||
},
|
||||
reset: function () {
|
||||
var that = this;
|
||||
that.params.cor_id = '';
|
||||
that.params.city_id = '';
|
||||
that.params.vin = '';
|
||||
$('#bd-auto1-id').val(0);
|
||||
$('#bd-auto2-id').val(0);
|
||||
$('#bd-auto3-id').val(0);
|
||||
$('#bd-auto4-id').val('');
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'params.city_id': function (nv, ov) {
|
||||
var that = this;
|
||||
if (nv == '') {
|
||||
that.countyAry = [];
|
||||
that.params.county_id = '';
|
||||
} else {
|
||||
if (nv.substring(0, 4) != that.params.county_id.substring(0, 4)) {
|
||||
that.params.county_id = '';
|
||||
}
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '/common/area',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
id: nv,
|
||||
key: 'county',
|
||||
type: 1
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.code == 1) {
|
||||
that.countyAry = response.data;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
'params.county_id': function (nv, ov) {
|
||||
var that = this;
|
||||
if (nv == '') {
|
||||
that.bizAry = that.addrAry = [];
|
||||
that.params.biz_id = that.params.addr_id = '';
|
||||
} else {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/biz/store/store/json_lists',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
city_id: that.params.city_id,
|
||||
county_id: that.params.county_id,
|
||||
status: 1
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.code == 1) {
|
||||
that.bizAry = response.data.list;
|
||||
that.bizAry.push({id: -1, title: '其它'});
|
||||
var biz_id = '';
|
||||
if (that.params.biz_id > 0 || that.params.biz_id == -1) {
|
||||
for (var i in that.bizAry) {
|
||||
if (that.params.biz_id == that.bizAry[i].id) {
|
||||
biz_id = that.params.biz_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
that.params.biz_id = biz_id;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
'params.biz_id': function (nv, ov) {
|
||||
var that = this;
|
||||
if (that.params.biz_id != -1) {
|
||||
return;
|
||||
}
|
||||
nv = that.params.county_id;
|
||||
if (nv == '') {
|
||||
that.addrAry = [];
|
||||
that.params.addr_id = '';
|
||||
} else {
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '/sys/addr/json_lists',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
county_id: nv,
|
||||
status: 1
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.code == 1) {
|
||||
that.addrAry = response.data.lists;
|
||||
if (that.params.addr_id > 0) {
|
||||
var addr_id = '';
|
||||
for (var i in that.addrAry) {
|
||||
if (that.params.addr_id == that.addrAry[i].id) {
|
||||
addr_id = that.params.addr_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
that.params.addr_id = addr_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
<?php page_script($pager) ?>
|
||||
|
||||
$('#bd-auto1-id').change(function () {
|
||||
$('#bd-auto2-id').empty();
|
||||
$('#bd-auto3-id').empty();
|
||||
$('#bd-auto4-id').empty();
|
||||
$("#bd-auto3-id").prepend("<option value='0'>选择车型</option>");
|
||||
$("#bd-auto4-id").prepend("<option value=''>车身颜色</option>");
|
||||
});
|
||||
$('#bd-auto2-id').change(function () {
|
||||
$('#bd-auto3-id').empty();
|
||||
$('#bd-auto4-id').empty();
|
||||
$("#bd-auto4-id").prepend("<option value=''>车身颜色</option>");
|
||||
});
|
||||
});
|
||||
require(['laydate', 'autocomplete'], function (laydate) {
|
||||
laydate.render({
|
||||
elem: '#id-time', range: '~'
|
||||
});
|
||||
$('.id-day-btn').click(function () {
|
||||
var type = $(this).data('date'), date = '', d_obj = new Date();
|
||||
var source_id = $(this).data('source') || 'id-time';
|
||||
switch (type) {
|
||||
case 'today':
|
||||
date = d_obj.Format('yyyy-MM-dd');
|
||||
date = date + ' ~ ' + date;
|
||||
break;
|
||||
case 'yesterday':
|
||||
date = (new Date(d_obj.getTime() - 86400000)).Format('yyyy-MM-dd');
|
||||
date = date + ' ~ ' + date;
|
||||
break;
|
||||
case '7day':
|
||||
date = (new Date(d_obj.getTime() - 86400000 * 7)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
|
||||
break;
|
||||
case '30day':
|
||||
date = (new Date(d_obj.getTime() - 86400000 * 29)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
|
||||
break;
|
||||
}
|
||||
$('#' + source_id).val(date);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -18,6 +18,67 @@ class Licheb extends HD_Controller
|
||||
$this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:更新车辆调拨状态
|
||||
* Created on: 2022/2/28 17:15
|
||||
* Created by: dengbw
|
||||
* https://liche-api-dev.xiaoyu.com/plan/licheb/inventory_log
|
||||
* https://api.liche.cn/plan/licheb/inventory_log
|
||||
*/
|
||||
public function inventory_log()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$size = 100;//每次最多处理多少条
|
||||
$rds = intval($this->input->get('rds'));
|
||||
$redis = &load_cache('redis');
|
||||
$redisKey = 'inventory_log_id';
|
||||
$id = $redis->get($redisKey);
|
||||
!$id && $id = 0;
|
||||
if ($rds) {//手动清除缓存
|
||||
$id = 0;
|
||||
$redis->delete($redisKey);
|
||||
}
|
||||
$log = array();
|
||||
$this->load->model('items/Items_inventory_log_model', 'mdInventoryLog');
|
||||
$this->load->model('items/items_model', 'mdItems');
|
||||
$where = array('id >' => $id, 'status' => 0);
|
||||
$res_log = $this->mdInventoryLog->select($where, 'id asc', 1, $size, 'id,item_id,biz_id,addr_id');
|
||||
if (!$res_log) {
|
||||
echo '执行到当前id:' . $id . '暂无数据';
|
||||
$redis->delete($redisKey);
|
||||
return;
|
||||
}
|
||||
foreach ($res_log as $key => $value) {
|
||||
$id = $value['id'];
|
||||
$res_item = $this->mdItems->get(['id' => $value['item_id']]);
|
||||
if ($res_item) {
|
||||
$status = '';
|
||||
if ($res_item['bill_time'] != '0000-00-00 00:00:00') {//已售
|
||||
$status = -2;
|
||||
} else if ($res_item['biz_id'] != $value['biz_id'] || $res_item['addr_id'] != $value['addr_id']) {//已调拨
|
||||
$status = -1;
|
||||
}
|
||||
if ($status) {
|
||||
$ret = $this->mdInventoryLog->update(['status' => $status], ['id' => $id]);
|
||||
if ($ret) {
|
||||
$log[] = array('id' => $id, 'status' => $status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$redis->save($redisKey, $id);//保存最后id
|
||||
if ($params['sd']) {
|
||||
echo '<br>执行到当前id:' . $id;
|
||||
echo '<br>成功更新:<br>';
|
||||
if ($log) {
|
||||
echo json_encode($log, JSON_UNESCAPED_UNICODE);
|
||||
echo '<br>';
|
||||
}
|
||||
echo '数据库获取:<br>';
|
||||
echo json_encode($res_log, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:更新车辆调拨异常
|
||||
* Created on: 2022/1/4 13:53
|
||||
|
||||
@@ -33,6 +33,7 @@ class Plan extends CI_Controller
|
||||
$plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_level')), 'interval' => 1);//更新客户等级
|
||||
$plan[] = array('url' => base_url(array('plan', 'licheb', 'visit_sales_sms')), 'interval' => 1);//给销售发送待回访短信
|
||||
$plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_manager_sms')), 'interval' => 1);//给店长发送待分配短信
|
||||
$plan[] = array('url' => base_url(array('plan', 'licheb', 'inventory_log')), 'interval' => 5);//更新车辆调拨状态
|
||||
$this->plan = $plan;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<?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()
|
||||
{
|
||||
$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 ($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']];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$list && $warning = ['title' => '库存超期预警', 'note' => '库存天数已超过20天,请尽快销售,以免造成损失!', 'list' => $list];
|
||||
}
|
||||
if ($warning) {//库存预警
|
||||
$date = ['total' =>2,'inventory' => ['title' => "库存车辆({$total})", 'value' => '库存超期'
|
||||
, 'color1' => '#fe606c', 'color2' => '#ff9026'], 'warning' => $warning];
|
||||
} else {
|
||||
$date = ['inventory' => ['title' => "库存车辆({$total})", 'value' => '库存良好'
|
||||
, 'color1' => '#30cfbd', 'color2' => '#2cbf8b'], '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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
<?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
|
||||
private $addrManage = [491 => '129', 492 => '130'];//信息员管理地址
|
||||
|
||||
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->addrManage[$this->myuid]) {//信息员管理
|
||||
$where = ['biz_id' => -1, "addr_id in({$this->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->addrManage[$this->myuid]) {//信息员管理
|
||||
$where = ['biz_id' => -1, "addr_id in({$this->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;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ class User extends Wxapp
|
||||
$this->load->model("biz/biz_model");
|
||||
$this->load->model('auto/auto_brand_model');
|
||||
$this->load->model('items/items_model', 'mdItems');
|
||||
$this->load->model('items/items_oplogs_model', 'mdItemsOplogs');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,6 +124,7 @@ class User extends Wxapp
|
||||
'uid' => $uid,
|
||||
'uname' => $user['uname'],
|
||||
'mobile' => $user['mobile'],
|
||||
'headimg' => $user['headimg'],
|
||||
'tel' => $tel,
|
||||
'group_id' => $user['group_id'],
|
||||
'group_name' => $group_name,
|
||||
@@ -134,6 +136,81 @@ class User extends Wxapp
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function put()
|
||||
{
|
||||
$encrypted = $this->input_param('encryptedData');
|
||||
$iv = $this->input_param('iv');
|
||||
$intro = $this->input_param('intro');
|
||||
|
||||
//获取用户信息
|
||||
$uid = $this->session['uid'];
|
||||
$user = $this->app_user_model->get(array('id' => $uid));
|
||||
|
||||
$upd = array();
|
||||
$mobile = '';
|
||||
//授权
|
||||
if (!is_null($encrypted)) {
|
||||
if (!$encrypted || !$iv) {
|
||||
throw new Exception('授权失败', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
$wxdata = $this->wx_data($encrypted, $iv);
|
||||
|
||||
if (!$wxdata) {
|
||||
throw new Exception('授权失败', API_CODE_FAIL);
|
||||
}
|
||||
$openid = $wxdata['openId'];
|
||||
$nickname = $wxdata['nickName'];
|
||||
$sex = $wxdata['gender'];
|
||||
$headimg = $wxdata['avatarUrl'];
|
||||
$unionid = $wxdata['unionId'];
|
||||
$mobile = $wxdata['phoneNumber'];
|
||||
if (!$mobile && isset($wxdata['phoneNumber'])) {
|
||||
throw new Exception('微信未绑定手机号', API_CODE_FAIL);
|
||||
}
|
||||
$mobile && !$user['mobile'] && $upd['mobile'] = $mobile;
|
||||
$nickname && $upd['nickname'] = $nickname;
|
||||
$headimg && $upd['headimg'] = $headimg;
|
||||
if ($mobile) {//判断手机号是否重复
|
||||
if (!mobile_valid($mobile)) {
|
||||
throw new Exception("请输入正确的手机号", API_CODE_FAIL);
|
||||
}
|
||||
$where = array('mobile' => $mobile, 'id <>' => $uid, "status<>" => -1);
|
||||
$count = $this->app_user_model->count($where);
|
||||
if ($count > 0) {
|
||||
throw new Exception("{$mobile}已被绑", API_CODE_FAIL);
|
||||
}
|
||||
}
|
||||
} else {//编辑其他信息
|
||||
$userInfo = $this->input_param('userInfo');
|
||||
$userInfo['nickName'] && $upd['nickname'] = $userInfo['nickName'];
|
||||
$userInfo['avatarUrl'] && $upd['headimg'] = $userInfo['avatarUrl'];
|
||||
if ($intro) {
|
||||
if (mb_strlen($intro, 'utf8') > 20) {
|
||||
throw new Exception('介绍自己20个字够啦', API_CODE_FAIL);
|
||||
}
|
||||
$upd['signature'] = $intro;
|
||||
}
|
||||
}
|
||||
if ($upd) {
|
||||
$ret = $this->app_user_model->update($upd, array('id' => $uid));
|
||||
if (!$ret) {
|
||||
debug_log("[error]# " . $this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
||||
throw new Exception('请求失败', API_CODE_FAIL);
|
||||
}
|
||||
}
|
||||
$data = array(
|
||||
'mobile' => $mobile,
|
||||
'nickname' => $upd['nickname'] ? $upd['nickname'] : $user['nickname'],
|
||||
'headimg' => $upd['headimg'] ? $upd['headimg'] : $user['headimg'],
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计数据
|
||||
*/
|
||||
@@ -296,10 +373,10 @@ class User extends Wxapp
|
||||
$biz_id_arr = explode(',', $this->session['biz_id']);
|
||||
$fileds = 'id,biz_name,jsondata';
|
||||
if ($this->session['biz_id'] && $biz_id_arr) {
|
||||
$city_id && $o_where = ['city_id' => $city_id,'type<>'=>4];
|
||||
$city_id && $o_where = ['city_id' => $city_id, 'type<>' => 4];
|
||||
$bizs = $this->biz_model->get_by_id_arr($biz_id_arr, $o_where, $fileds);
|
||||
} else {
|
||||
$bizs = $this->biz_model->select(['status' => 1, 'city_id' => $city_id,'type<>'=>4], 'id desc', '', '', $fileds);
|
||||
$bizs = $this->biz_model->select(['status' => 1, 'city_id' => $city_id, 'type<>' => 4], 'id desc', '', '', $fileds);
|
||||
}
|
||||
if ($bizs) {
|
||||
foreach ($bizs as $key => $val) {
|
||||
@@ -314,10 +391,25 @@ class User extends Wxapp
|
||||
];
|
||||
$brands = $this->auto_brand_model->select($where, '', 0, 0, 'id,name');
|
||||
foreach ($brands as $key2 => $val2) {
|
||||
$count_items = $this->mdItems->count(['brand_id' => $val2['id'], 'status<>' => 0, 'biz_id' => $val['id']
|
||||
, 'bill_time' => '0000-00-00 00:00:00']);
|
||||
$bg_color = $count_items ? '#fff' : '#999';
|
||||
$auto_brands[] = ['name' => $val2['name'], 'bg_color' => $bg_color];
|
||||
// $count_items = $this->mdItems->count(['brand_id' => $val2['id'], 'status<>' => 0, 'biz_id' => $val['id']
|
||||
// , 'bill_time' => '0000-00-00 00:00:00']);
|
||||
$res_items = $this->mdItems->select(['brand_id' => $val2['id'], 'status<>' => 0, 'biz_id' => $val['id']
|
||||
, 'bill_time' => '0000-00-00 00:00:00'], 'in_time asc', 0, 0, 'id,in_time,c_time');
|
||||
$str_ids = $res_items ? implode(',', array_column($res_items, 'id')) : '';
|
||||
$bg_color = '#999';
|
||||
$name = $val2['name'];
|
||||
if ($str_ids) {
|
||||
$bg_color = '#fff';
|
||||
$in_time = $res_items[0]['in_time'] != '0000-00-00 00:00:00' ? strtotime($res_items[0]['in_time']) : $res_items[0]['c_time'];
|
||||
$re_logs = $this->mdItemsOplogs->select(["item_id in({$str_ids})" => null, 'type' => 2, 'biz_id_to' => $val['id']
|
||||
], 'c_time asc', 1, 1, 'com_time');//找出调拨最早
|
||||
$re_logs && $in_time = strtotime($re_logs[0]['com_time']);
|
||||
if ($in_time) {//计算库存天数
|
||||
$days = round((time() - $in_time) / 3600 / 24);
|
||||
$days > 0 && $name = $val2['name'] . '(' . $days . '天)';
|
||||
}
|
||||
}
|
||||
$auto_brands[] = ['name' => $name, 'bg_color' => $bg_color];
|
||||
}
|
||||
}
|
||||
$lists[] = [
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Notes:车辆盘点_日志
|
||||
* Created on: 2022/2/21 16:43
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Items_inventory_log_model extends HD_Model
|
||||
{
|
||||
private $table_name = 'lc_items_inventory_log';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($this->table_name, 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:盘点状态
|
||||
* Created on: 2021/12/16 16:46
|
||||
* Created by: dengbw
|
||||
* @param string $id
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function statusAry($id = '')
|
||||
{
|
||||
$ary = [0 => '进行中', 1 => '已完成'];
|
||||
if (strlen($id)) {
|
||||
$ary = $ary[$id];
|
||||
}
|
||||
return $ary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:盘点图片类型
|
||||
* Created on: 2022/2/24 11:53
|
||||
* Created by: dengbw
|
||||
* @param string $key
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function carImgAry($key = '')
|
||||
{
|
||||
$ary = ['car_body' => '车身', 'vin' => '车架号', 'dashboard' => '仪表盘'];
|
||||
if (strlen($key)) {
|
||||
$ary = $ary[$key];
|
||||
}
|
||||
return $ary;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Notes:车辆盘点
|
||||
* Created on: 2022/2/21 16:43
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Items_inventory_model extends HD_Model
|
||||
{
|
||||
private $table_name = 'lc_items_inventory';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($this->table_name, 'default');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,40 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xuxb
|
||||
* Date: 2021/8/20
|
||||
* Time: 17:43
|
||||
*/
|
||||
class Sys_addr_model extends HD_Model{
|
||||
class Sys_addr_model extends HD_Model
|
||||
{
|
||||
private $table_name = 'lc_sys_addr';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($this->table_name, 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:根据id获取数据
|
||||
* Created on: 2022/2/25 10:01
|
||||
* Created by: dengbw
|
||||
* @param $ids
|
||||
* @param string $fileds
|
||||
* @return array
|
||||
*/
|
||||
public function get_map_by_ids($ids, $fileds = '')
|
||||
{
|
||||
$rows = [];
|
||||
$ids = array_filter($ids);
|
||||
if ($ids) {
|
||||
$cf_ids = implode(',', $ids);
|
||||
$where = [
|
||||
"id in ($cf_ids)" => null
|
||||
];
|
||||
$rows = $this->map('id', '', $where, '', '', '', $fileds);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user