liche update for admin goods do better

This commit is contained in:
xxb
2021-08-24 20:42:52 +08:00
parent f06825359c
commit 56037000ad
2 changed files with 450 additions and 97 deletions
+278 -70
View File
@@ -17,6 +17,7 @@ class Goods extends HD_Controller
$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("sys/sys_addr_model", 'addr_model');
}
public function index()
@@ -41,14 +42,49 @@ class Goods extends HD_Controller
if ($params['v_id']) {
$where['v_id'] = $params['v_id'];
}
if($params['addr_id']){
$where['addr_id'] = $params['addr_id'];
} else if($params['city_id']){
$where_addr = array('status>0' => null, 'city_id' => $params['city_id']);
if($params['county_id']){
$where_addr['county_id'] = $params['county_id'];
}
$orderby = 'id desc';
$select = 'id';
$rows_addr = $this->addr_model->select($where_addr, $orderby, 0, 0, $select);
if($rows_addr){
$str_ids = implode(',', array_column($rows_addr, 'id'));
$where["addr_id in ({$str_ids})"] = null;
} else {
$where['addr_id'] = -1;
}
} else {
$params['city_id'] = '';
$params['county_id'] = '';
$params['addr_id'] = '';
}
if(strlen($params['status'])>0){
$where['status'] = $params['status'];
} else {
$params['status'] = '';
}
if($params['vin']){
$where["vin like '%{$params['vin']}%'"] = null;
}
$autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name');
$count = $this->mdItems->count($where);
$lists = array();
if ($count) {
$fileds = 'id,brand_id,s_id,ori_price,sale_price,bill_price,c_time,if_pack,discount,buy_price,address,status
,v_id,cor_id,incor_id';
$fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,p_time,addr_id';
$rows = $this->mdItems->select($where, 'id desc', $page, $size, $fileds);
$brand_id_arr = array_unique(array_column($rows, 'brand_id'));
$brand_id_arr = array();
$addr_ids = array();
foreach($rows as $v){
!in_array($v['brand_id'], $brand_id_arr) && $brand_id_arr[] = $v['brand_id'];
$v['addr_id'] && !in_array($v['addr_id'], $addr_ids) && $addr_ids[] = $v['addr_id'];
}
$brands_rows = $this->mdAutoBrand->get_map_by_ids($brand_id_arr, 'id,name');
$series_id_arr = array_unique(array_column($rows, 's_id'));
$series_rows = $this->mdAutoSeries->get_map_by_ids($series_id_arr, 'id,name');
@@ -58,7 +94,19 @@ class Goods extends HD_Controller
$attr_corid_rows = $this->mdAutoAttr->get_map_by_ids($attr_corid_arr, 'id,title');
$attr_incorid_arr = array_unique(array_column($rows, 'incor_id'));
$attr_incorid_rows = $this->mdAutoAttr->get_map_by_ids($attr_incorid_arr, 'id,title');
$map_addr = array();
if($addr_ids){
$str_ids = implode(',', $addr_ids);
$where = array("id in ({$str_ids})" => null);
$orderby = 'id desc';
$select = 'id, title';
$map_addr = $this->addr_model->map('id', 'title', $where, $orderby, 0, 0, $select);
}
foreach ($rows as $key => $val) {
$p_days = '';
if('0000-00-00 00:00:00' != $val['p_time']){
$p_days = intval((time() - strtotime($val['p_time']))/3600/24);
}
$setVal = array();
$setVal['id'] = $val['id'];
$setVal['brand_name'] = isset($brands_rows[$val['brand_id']]) ? $brands_rows[$val['brand_id']][0]['name'] : '';
@@ -66,12 +114,10 @@ class Goods extends HD_Controller
$setVal['v_name'] = isset($attr_vid_rows[$val['v_id']]) ? $attr_vid_rows[$val['v_id']][0]['title'] : '';
$setVal['cor_name'] = isset($attr_corid_rows[$val['cor_id']]) ? $attr_corid_rows[$val['cor_id']][0]['title'] : '';
$setVal['incor_name'] = isset($attr_incorid_rows[$val['incor_id']]) ? $attr_incorid_rows[$val['incor_id']][0]['title'] : '';
$setVal['if_pack_name'] = $val['if_pack'];
$setVal['ori_price'] = $val['ori_price'];
$setVal['discount'] = $val['discount'] ? $val['discount'] . '%' : '100%';
$setVal['buy_price'] = $val['buy_price'];
$setVal['status_name'] = $this->statusAry[$val['status']];
$setVal['address'] = $val['address'] ? '收货地址:' . $val['address'] : '';
$setVal['vin'] = $val['vin'];
$setVal['address'] = $val['addr_id'] ? $map_addr[$val['addr_id']] : '';
$setVal['p_time'] = '0000-00-00 00:00:00' == $val['p_time'] ? '' : $val['p_time'];
$setVal['p_days'] = $p_days;
$lists[] = $setVal;
}
}
@@ -79,6 +125,7 @@ class Goods extends HD_Controller
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
$this->data['params'] = $params;
$this->data['autoList'] = $autoList;
$this->data['statusAry'] = $this->statusAry;
$this->data['_title'] = '商品管理';
return $this->show_view('/items/goods/lists', true);
}
@@ -111,7 +158,6 @@ class Goods extends HD_Controller
}
if($info['addr_id']){
$this->load->model("sys/sys_addr_model", 'addr_model');
$row_addr = $this->addr_model->get(array('id' => $info['addr_id']));
$info['city_id'] = $row_addr['city_id'];
$info['county_id'] = $row_addr['county_id'];
@@ -173,7 +219,6 @@ class Goods extends HD_Controller
$info['out_time'] = $re['out_time'] != '0000-00-00 00:00:00' ? $re['out_time'] : '';
$info['bill_time'] = $re['bill_time'] != '0000-00-00 00:00:00' ? $re['bill_time'] : '';
if($info['addr_id']){
$this->load->model("sys/sys_addr_model", 'addr_model');
$row_addr = $this->addr_model->get(array('id' => $info['addr_id']));
$info['address'] = $row_addr['city_name'].$row_addr['county_name'].$row_addr['title'];
} else {
@@ -241,65 +286,10 @@ class Goods extends HD_Controller
return $this->show_json(SYS_CODE_SUCCESS, '添加成功!');
}
//编辑单条数据
public function edit()
{
$info = $this->input->post('info');
$checkInfo = $this->checkInfo($info);
if (!$checkInfo['code']) {
return $this->show_json($checkInfo['code'], $checkInfo['msg']);
}
$editData['brand_id'] = $info['brand_id'];
$editData['s_id'] = $info['s_id'];
$editData['v_id'] = $info['v_id'];
$editData['cor_id'] = $info['cor_id'];
$editData['incor_id'] = $info['incor_id'];
$editData['if_pack'] = $info['if_pack'];
$editData['status'] = $info['status'];
$editData['address'] = $info['address'];
$editData['vin'] = $info['vin'];
$editData['stdard_num'] = $info['stdard_num'];
$editData['engine_num'] = $info['engine_num'];
$editData['ori_price'] = $info['ori_price'];
$editData['discount'] = $info['discount'];
$editData['dis_price'] = $info['dis_price'];
$editData['bill_num'] = $info['bill_num'];
$editData['bill_price'] = $info['bill_price'];
$editData['buy_price'] = $info['buy_price'];
$editData['pro_time'] = $info['pro_time'];
$editData['p_time'] = $info['p_time'];
$editData['out_time'] = $info['out_time'];
$editData['bill_time'] = $info['bill_time'];
//存货地址
$editData['addr_id'] = $info['addr_id'] ? $info['addr_id'] : 0;
$ret = $this->mdItems->update($editData, array('id' => $info['id']));
if (!$ret) {
return $this->show_json(SYS_CODE_FAIL, '修改失败!');
}
$this->data['status'] = 2;
return $this->show_json(SYS_CODE_SUCCESS, '修改成功!');
}
//删除单条数据
public function del()
{
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
}
/**
* 导入
* @return bool
*/
public function add_excel()
{
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
@@ -363,6 +353,224 @@ class Goods extends HD_Controller
return $this->show_json(SYS_CODE_SUCCESS, '导入完成,导入总条数为:' . $j);
}
//编辑单条数据
public function edit()
{
$info = $this->input->post('info');
$checkInfo = $this->checkInfo($info);
if (!$checkInfo['code']) {
return $this->show_json($checkInfo['code'], $checkInfo['msg']);
}
$editData['brand_id'] = $info['brand_id'];
$editData['s_id'] = $info['s_id'];
$editData['v_id'] = $info['v_id'];
$editData['cor_id'] = $info['cor_id'];
$editData['incor_id'] = $info['incor_id'];
$editData['if_pack'] = $info['if_pack'];
$editData['status'] = $info['status'];
$editData['address'] = $info['address'];
$editData['vin'] = $info['vin'];
$editData['stdard_num'] = $info['stdard_num'];
$editData['engine_num'] = $info['engine_num'];
$editData['ori_price'] = $info['ori_price'];
$editData['discount'] = $info['discount'];
$editData['dis_price'] = $info['dis_price'];
$editData['bill_num'] = $info['bill_num'];
$editData['bill_price'] = $info['bill_price'];
$editData['buy_price'] = $info['buy_price'];
$editData['pro_time'] = $info['pro_time'];
$editData['p_time'] = $info['p_time'];
$editData['out_time'] = $info['out_time'];
$editData['bill_time'] = $info['bill_time'];
//存货地址
$editData['addr_id'] = $info['addr_id'] ? $info['addr_id'] : 0;
$ret = $this->mdItems->update($editData, array('id' => $info['id']));
if (!$ret) {
return $this->show_json(SYS_CODE_FAIL, '修改失败!');
}
$this->data['status'] = 2;
return $this->show_json(SYS_CODE_SUCCESS, '修改成功!');
}
//删除单条数据
public function del()
{
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
$params = $this->input->get();
$where = array();
if ($params['brand_id']) {
$where['brand_id'] = $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']) {
$where['s_id'] = $params['s_id'];
$autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $params['s_id']), 'id desc', 0, 0, 'id,title as name');
}
if ($params['v_id']) {
$where['v_id'] = $params['v_id'];
}
if($params['addr_id']){
$where['addr_id'] = $params['addr_id'];
} else if($params['city_id']){
$where_addr = array('status>0' => null, 'city_id' => $params['city_id']);
if($params['county_id']){
$where_addr['county_id'] = $params['county_id'];
}
$orderby = 'id desc';
$select = 'id';
$rows_addr = $this->addr_model->select($where_addr, $orderby, 0, 0, $select);
if($rows_addr){
$str_ids = implode(',', array_column($rows_addr, 'id'));
$where["addr_id in ({$str_ids})"] = null;
} else {
$where['addr_id'] = -1;
}
} else {
$params['city_id'] = '';
$params['county_id'] = '';
$params['addr_id'] = '';
}
if(strlen($params['status'])>0){
$where['status'] = $params['status'];
} else {
$params['status'] = '';
}
if($params['vin']){
$where["vin like '%{$params['vin']}%'"] = null;
}
$total = $this->mdItems->count($where);
if($total > 10000){
return $this->show_json(SYS_CODE_FAIL, '数据量超过1w导出太为难我了');
} else if(0 == $total) {
return $this->show_json(SYS_CODE_SUCCESS, '当前没有数据');
}
$fileName = "车辆明细";
$indexs = array(
'id' => 'ID',
'brand_name' =>'品牌',
's_name' =>'车系',
'v_name' =>'车型',
'cor_name' =>'车身颜色',
'incor_name' =>'内饰颜色',
'ori_price' =>'指导价',
'sale_price' =>'售价',
'bill_price' =>'开票金额',
'buy_price' =>'采购成本',
'dis_price' =>'折扣价',
'discount' =>'折扣百分比',
'city_name' => '城市名',
'county_name' => '行政区',
'address' =>'存放地址',
'vin' =>'车架号',
'engine_num' =>'发动机号',
'stdard_num' =>'合格证号',
'bill_num' =>'开票号',
'if_pack' =>'精品加装',
'status' =>'状态',
'pro_time' =>'生产时间',
'p_time' =>'分配时间',
'out_time' =>'出库时间',
'bill_time' =>'开票时间',
);
$rows = $this->mdItems->select($where, 'id desc', 0, 0, '*');
$lists[] = $indexs;
$brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $addr_ids = array();
foreach($rows as $v){
$v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_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'];
$v['incor_id'] && !in_array($v['incor_id'], $attr_incorids) && $attr_incorids[] = $v['incor_id'];
}
$map_brand = $map_sery = $map_vid = $map_corid = $map_incorid = $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($attr_incorids){
$str_ids = implode(',', $attr_incorids);
$where = array("id in ({$str_ids})" => null);
$map_incorid = $this->mdAutoAttr->map('id', 'title', $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';
$map_addr = $this->addr_model->map('id', '*', $where, $orderby, 0, 0, $select);
}
foreach($rows as $v){
$addr = $map_addr[$v['addr_id']];
$lists[] = array(
'id' => $v['id'],
'brand_name' => $map_brand[$v['brand_id']],
's_name' => $map_sery[$v['s_id']],
'v_name' => $map_vid[$v['v_id']],
'cor_name' => $map_corid[$v['cor_id']],
'incor_name' => $map_incorid[$v['incor_id']],
'ori_price' =>$v['ori_price'],
'sale_price' => $v['sale_price'],
'bill_price' => $v['bill_price'],
'buy_price' => $v['buy_price'],
'dis_price' => $v['dis_price'],
'discount' => $v['discount'],
'city_name' => $addr ? $addr['city_name'] : '',
'county_name' => $addr ? $addr['county_name'] : '',
'address' => $addr ? $addr['title'] : '',
'vin' => $v['vin'],
'engine_num' => $v['engine_num'],
'stdard_num' =>$v['stdard_num'],
'bill_num' => $v['bill_num'],
'if_pack' => $v['if_pack'],
'status' => $this->statusAry[$v['status']],
'pro_time' => '0000-00-00 00:00:00' == $v['pro_time'] ? '' : $v['pro_time'],
'p_time' => '0000-00-00 00:00:00' == $v['p_time'] ? '' : $v['p_time'],
'out_time' => '0000-00-00 00:00:00' == $v['out_time'] ? '' : $v['out_time'],
'bill_time' => '0000-00-00 00:00:00' == $v['bill_time'] ? '' : $v['bill_time'],
);
}
$this->load->library('excel');
$this->excel->out_csv($lists, $indexs, $fileName . "_" . date('YmdHis'));
return 1;
}
/**
* Notes:上传excel
* Created on: 2021/7/14 15:06
+172 -27
View File
@@ -46,6 +46,46 @@
</select>
</div>
</div>
<div class="am-form-group fl">
<label class="am-para-label w100">车架号:</label>
<div class="am-para-inline w120">
<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 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">
<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="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 fl">
<label class="am-para-label w100">状态:</label>
<div class="am-para-inline w120">
<select title="状态" name="status" v-model="params.status">
<option value="">选择状态</option>
<option :value="i" v-for="(v,i) in statusAry">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group fl ml100">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
@@ -57,6 +97,7 @@
</div>
<div class="am-form-group fl ml10">
<button type="button" id="import" class="am-btn am-btn-success am-btn-sm w100">导入</button>
<button type="button" id="export" class="am-btn am-btn-success am-btn-sm w100">导出</button>
</div>
</div>
</div>
@@ -66,17 +107,17 @@
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="5%"><span>商品ID</span></th>
<th width="5%"><span>ID</span></th>
<th width="10%"><span>品牌</span></th>
<th width="10%"><span>车系</span></th>
<th width="10%"><span>车型</span></th>
<th width="6%"><span>车身颜色</span></th>
<th width="6%"><span>内饰颜色</span></th>
<th width="6%"><span>选装包</span></th>
<th width="6%"><span>市场平台价</span></th>
<th width="6%"><span>折扣%</span></th>
<th width="6%"><span>采购成本</span></th>
<th width="6%"><span>车辆状态</span></th>
<th width="10%"><span>车架号</span></th>
<th width="15%"><span>存放地</span></th>
<th width="10%"><span>分配日期</span></th>
<th width="6%"><span>存放天数</span></th>
<th width=""><span>操作</span></th>
</tr>
</thead>
<tbody>
@@ -89,27 +130,18 @@
<td><?= $v['v_name'] ?></td>
<td><?= $v['cor_name'] ?></td>
<td><?= $v['incor_name'] ?></td>
<td><?= $v['if_pack_name'] ?></td>
<td><?= $v['ori_price'] ?></td>
<td><?= $v['discount'] ?></td>
<td><?= $v['buy_price'] ?></td>
<td><?= $v['status_name'] ?></td>
</tr>
<tr>
<td colspan="11">
<div class="row">
<div class="col-md-4 align-l">
<?= $v['address'] ?>
</div>
<div class="col-md-8 align-r" style="padding-right: 30px;">
<a href="javascript:void(0);"
data-modal="/items/goods/goods/get_info?id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs"
data-title="详情">查看</a>
<a href="javascript:void(0);"
data-open="/items/goods/goods/get?id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs">编辑</a>
</div>
<td><?= $v['vin'] ?></td>
<td><?= $v['address'] ?></td>
<td><?= $v['p_time'] ?></td>
<td><?= $v['p_days'] ?></td>
<td>
<a href="javascript:void(0);"
data-modal="/items/goods/goods/get_info?id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs"
data-title="详情">查看</a>
<a href="javascript:void(0);"
data-open="/items/goods/goods/get?id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs">编辑</a>
</td>
</tr>
<?php }
@@ -187,6 +219,107 @@
}
$(function () {
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params:[],
statusAry:[],
cityAry:[],
countyAry:[],
addrAry:[]
},
mounted:function() {
var vm = this;
var lists = [];
lists = <?=json_encode($lists)?>;
vm.params = <?=json_encode($params)?>;
vm.statusAry = <?=json_encode($statusAry)?>;
vm.init_citys();
},
methods:{
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;
}
}
});
}
},
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.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 == thayt.addrAry[i].id){
addr_id = that.params.addr_id;
break;
}
}
that.params.addr_id = addr_id;
}
}
}
});
}
}
}
});
<?php page_script($pager) ?>
$("#import").click(function () {
$("#goods-file").val('');
layer.open({
@@ -202,5 +335,17 @@
});
});
$('#export').click(function () {
var count = <?=$pager['totle']?>;
if (count > 10000) {
layer.msg('单次导出数据不能超过10000');
return false;
}
var href = $.menu.parseUri(window.location.href);
var arr = href.split('?');
href = '/items/goods/goods/export?' + arr[1];
window.location.href = href;
});
});
</script>