stock_402

This commit is contained in:
dengbw
2022-04-02 15:24:57 +08:00
parent 7c5cbf02a9
commit f690fb1b7b
2 changed files with 440 additions and 0 deletions
+153
View File
@@ -0,0 +1,153 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Notes:库存车辆
* Created on: 2022/4/02 16:43
* Created by: dengbw
*/
class Stock extends HD_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('items/items_stock_log_model', 'mdStockLog');
$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("biz/biz_model", 'mdBiz');
$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 = [];
$params['days_sort'] = $params['days_sort'] ? $params['days_sort'] : '';
if ($params['days_sort']) {
$order = $params['days_sort'] == 1 ? 'stay_days desc,id desc' : 'stay_days asc,id desc';
} else {
$order = "id desc";
}
if ($params['brand_id']) {
$where['brand_id'] = $params['brand_id'];
}
if ($params['s_id']) {
$where['s_id'] = $params['s_id'];
}
if ($params['vin']) {
$where["item_id in(select id from lc_items where vin like '%{$params['vin']}%')"] = null;
}
if ($params['biz_id']) {
$where['biz_id'] = $params['biz_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');
if ($res_biz) {
$str_ids = implode(',', array_column($res_biz, 'id'));
$where["biz_id in ({$str_ids})"] = null;
} else {
$where['biz_id'] = -2;
}
} else {
$params['city_id'] = '';
$params['county_id'] = '';
$params['biz_id'] = '';
}
if ($params['time']) {
$time = explode(' ~ ', $params['time']);
$time[0] && $where["log_date>="] = $time[0];
$time[1] && $where["log_date<="] = $time[1];
}
$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');
}
$total = $this->mdStockLog->count($where);
if ($total) {
$res = $this->mdStockLog->select($where, $order, $params['page'], $params['size']);
$brand_ids = $s_ids = $biz_ids = $item_ids = array();
foreach ($res as $v) {
$v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_id'];
$v['s_id'] && !in_array($v['s_id'], $s_ids) && $s_ids[] = $v['s_id'];
$v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_id'];
$v['item_id'] && !in_array($v['item_id'], $item_ids) && $item_ids[] = $v['item_id'];
}
$map_brand = $map_sery = $map_biz = $map_item = array();
if ($brand_ids) {
$str_ids = implode(',', $brand_ids);
$map_brand = $this->mdAutoBrand->map('id', 'name', ["id in ({$str_ids})" => null]);
}
if ($s_ids) {
$str_ids = implode(',', $s_ids);
$map_sery = $this->mdAutoSeries->map('id', 'name', ["id in ({$str_ids})" => null]);
}
if ($biz_ids) {
$str_ids = implode(',', $biz_ids);
$map_biz = $this->mdBiz->map('id', 'biz_name', ["id in ({$str_ids})" => null]);
}
if ($item_ids) {
$str_ids = implode(',', $item_ids);
$map_item = $this->mdItems->map('id', 'vin', ["id in ({$str_ids})" => null]);
}
foreach ($res as $v) {
$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}";
}
$title = "{$map_brand[$v['brand_id']]}-{$map_sery[$v['s_id']]}";
$vin = $map_item[$v['item_id']];
$in_time = !$v['in_time'] || '0000-00-00 00:00:00' == $v['in_time'] ? '' : substr($v['in_time'], 0, 10);
$lists[] = ['item_id' => $v['item_id'], 'title' => $title, 'vin' => $vin, 'in_time' => $in_time, 'address' => $address
, 'log_date' => $v['log_date'], 'stay_days' => $v['stay_days']];
}
}
$this->data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total);
$this->data['lists'] = $lists;
$this->data['autoList'] = $autoList;
$this->data['params'] = $params;
$this->data['_title'] = "库存车辆日志";
$this->show_view('items/stock/lists', true);
}
public function get()
{
}
public function add()
{
}
public function edit()
{
}
public function del()
{
}
public function batch()
{
}
public function export()
{
}
}
+287
View File
@@ -0,0 +1,287 @@
<div class="coms-table-wrap mt10">
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="items/stock">
<input type="hidden" id="days_sort" name="days_sort" value="<?= $params['days_sort'] ?>">
<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">
<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">
<label class="am-para-label w80">门店:</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 w200">
<select title="门店" name="biz_id" v-model="params.biz_id">
<option value="">选择门店</option>
<option :value="v.id" v-for="(v,i) in bizAry">{{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-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>
</div>
</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="10%"><span>车辆</span></th>
<th width="15%"><span>车架号</span></th>
<th width="20%"><span>门店</span></th>
<th width="10%"><span>入库日期</span></th>
<th width="10%"><span>停留天数</span> <a href="javascript:" @click="days_sort"><i class="fa fa-sort"></i>
<? if ($params['days_sort'] == '1') { ?>
<i class="fa fa-arrow-down"></i>
<? } else if ($params['days_sort'] == '2') { ?>
<i class="fa fa-arrow-up"></i>
<? } ?>
</a></th>
<th width="10%"><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['in_time'] ?></td>
<td><?= $v['stay_days'] ?></td>
<td><?= $v['log_date'] ?></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;
}
$('#' + source_id).val(date);
});
});
$(function () {
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params: {},
cityAry: [],//城市
countyAry: [],//行政区
bizAry: [],//门店
},
mounted: function () {
var vm = this;
vm.params = <?=json_encode($params)?>;
vm.init_citys();
},
methods: {
days_sort: function () {
var days_sort = $('#days_sort').val();
if (!days_sort) {
days_sort = '1';
} else if (days_sort == '1') {
days_sort = '2';
} else if (days_sort == '2') {
days_sort = '';
}
$('#days_sort').val(days_sort);
var $form = $('#vue-app');
$form.submit();
},
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.params.biz_id = that.params.addr_id = '';
},
reset: function () {
var that = this;
that.params.city_id = '';
that.params.vin = '';
$('#id-time').val('');
$('#bd-auto1-id').val(0);
$('#bd-auto2-id').val(0);
}
},
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.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;
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;
}
}
});
}
},
}
});
<?php page_script($pager) ?>
$('#bd-auto1-id').change(function () {
$('#bd-auto2-id').empty();
});
});
</script>