From 449a90d2431b199c3b74b862eadef354ea373abf Mon Sep 17 00:00:00 2001 From: dengbw Date: Tue, 9 Nov 2021 13:45:32 +0800 Subject: [PATCH] goods_logs_1109 --- admin/controllers/items/goods/Goods.php | 11 +- admin/controllers/items/goods/Logs.php | 228 ++++++++++- admin/views/items/logs/get.php | 65 +-- admin/views/items/logs/lists.php | 477 +++++++++++++++++++++++ api/controllers/plan/Temp.php | 49 +++ common/libraries/entity/Items_entity.php | 1 + 6 files changed, 778 insertions(+), 53 deletions(-) create mode 100644 admin/views/items/logs/lists.php diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 54aa3ba8..6014c5a8 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -8,7 +8,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class Goods extends HD_Controller { - private $statusAry = array(1 => '未配', 2 => '已配', 0 => '下架'); + private $statusAry = array(1 => '未分配', 2 => '已分配', 0 => '下架'); public function __construct() { @@ -784,27 +784,28 @@ class Goods extends HD_Controller , 'com_time' => $info['bill_time'], 'biz_id' => $info['biz_id'], 'addr_id' => $info['addr_id']); $this->items_entity->add_log($params); } + $com_time = date('Y-m-d H:i:s'); if ($re['biz_id'] > 0 && $biz_id > 0) {//门店间变化 if ($re['biz_id'] != $biz_id) { $params = array('item_id' => $info['id'], 'type' => 2, 'uid' => $this->uid, 'uname' => $this->username - , 'com_time' => $info['bill_time'], 'biz_id' => $re['biz_id'], 'biz_id_to' => $biz_id); + , 'com_time' => $com_time, 'biz_id' => $re['biz_id'], 'biz_id_to' => $biz_id); $this->items_entity->add_log($params); } } else if ($re['biz_id'] > 0 && $biz_id == -1) {//门店转地址变化 if ($addr_id) { $params = array('item_id' => $info['id'], 'type' => 2, 'uid' => $this->uid, 'uname' => $this->username - , 'com_time' => $info['bill_time'], 'biz_id' => $re['biz_id'], 'addr_id_to' => $addr_id); + , 'com_time' => $com_time, 'biz_id' => $re['biz_id'], 'addr_id_to' => $addr_id); $this->items_entity->add_log($params); } } else if ($re['biz_id'] == -1 && $biz_id == -1) {//地址间变化 if ($re['addr_id'] != $addr_id) { $params = array('item_id' => $info['id'], 'type' => 2, 'uid' => $this->uid, 'uname' => $this->username - , 'com_time' => $info['bill_time'], 'biz_id' => -1, 'addr_id' => $re['addr_id'], 'addr_id_to' => $addr_id); + , 'com_time' => $com_time, 'biz_id' => -1, 'addr_id' => $re['addr_id'], 'addr_id_to' => $addr_id); $this->items_entity->add_log($params); } } else if ($re['biz_id'] == -1 && $biz_id > 0) {//地址转门店变化 $params = array('item_id' => $info['id'], 'type' => 2, 'uid' => $this->uid, 'uname' => $this->username - , 'com_time' => $info['bill_time'], 'biz_id' => -1, 'addr_id' => $re['addr_id'], 'biz_id_to' => $biz_id); + , 'com_time' => $com_time, 'biz_id' => -1, 'addr_id' => $re['addr_id'], 'biz_id_to' => $biz_id); $this->items_entity->add_log($params); } $this->data['status'] = 2; diff --git a/admin/controllers/items/goods/Logs.php b/admin/controllers/items/goods/Logs.php index 9e20bb9f..c06db5f3 100644 --- a/admin/controllers/items/goods/Logs.php +++ b/admin/controllers/items/goods/Logs.php @@ -8,15 +8,20 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class Logs extends HD_Controller { + private $statusAry = array(1 => '未分配', 2 => '已分配', 0 => '下架'); public function __construct() { parent::__construct(); + $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('items/items_oplogs_model', 'mdItemsOplogs'); $this->load->model('items/items_model', 'mdItems'); $this->load->model("biz/biz_model", 'mdBiz'); $this->load->model("sys/sys_addr_model", 'mdAddr'); $this->load->model('area_model', 'mdArea'); + $this->load->model('items/items_relate_model'); } public function index() @@ -26,6 +31,178 @@ class Logs extends HD_Controller public function lists() { + $params = $this->input->get(); + $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; + $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; + $where = array('id<>1' => null, 'status>' => 0); + $autoList = 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['cor_id']) { + $where['cor_id'] = $params['cor_id']; + } else { + $params['cor_id'] = ''; + } + //地址筛选 + if ($params['biz_id']) { + $where['biz_id'] = $params['biz_id']; + } + if ($params['biz_id'] == -1 && $params['addr_id']) { + $where['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'); + 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['addr_id'] = ''; + $params['biz_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'); + $statusAry = $this->statusAry; + $count = $this->mdItems->count($where); + $lists = array(); + if ($count) { + $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,bill_time,biz_id,addr_id,status'; + $orderby = "id desc"; + $rows = $this->mdItems->select($where, $orderby, $page, $size, $fileds); + $brand_ids = $s_ids = $attr_vids = $attr_corids = $biz_ids = $addr_ids = array(); + $ids = array(); + foreach ($rows as $v) { + $ids[] = $v['id']; + $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_incorid = $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->mdAddr->select($where, $orderby, 0, 0, $select); + foreach ($rows_addr as $v) { + $map_addr[$v['id']] = ['title' => "{$v['city_name']} {$v['county_name']} 其它 {$v['title']}", 'name' => $v['title']]; + } + } + foreach ($rows as $k => $v) { + $address = $last_db_time = $log_max = $log_min_kc = $log_max_kc = $inventory_time = $biz_name = ''; + if ($v['biz_id'] > 0) { + $address = $map_biz[$v['biz_id']]; + $biz_name = $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}"; + } + $log_max = $this->mdItemsOplogs->max('com_time', ["type in(1,2) AND item_id={$v['id']} + AND (biz_id={$v['biz_id']} or biz_id_to={$v['biz_id']})" => null]); + $log_min_kc = $this->mdItemsOplogs->get(["item_id={$v['id']} + AND (biz_id={$v['biz_id']} or biz_id_to={$v['biz_id']})" => null], 'com_time'); + $log_max_kc = $this->mdItemsOplogs->max('com_time', ["item_id={$v['id']} + AND (biz_id={$v['biz_id']} or biz_id_to={$v['biz_id']})" => null]); + } else if ($v['biz_id'] == -1 && $v['addr_id']) { + $address = $map_addr[$v['addr_id']]['title']; + $biz_name = $map_addr[$v['addr_id']]['name']; + $log_max = $this->mdItemsOplogs->max('com_time', ["type in(1,2) AND item_id={$v['id']} + AND (addr_id={$v['addr_id']} or addr_id_to={$v['addr_id']})" => null]); + $log_min_kc = $this->mdItemsOplogs->get(["item_id={$v['id']} + AND (addr_id={$v['addr_id']} or addr_id_to={$v['addr_id']})" => null], 'com_time'); + $log_max_kc = $this->mdItemsOplogs->max('com_time', ["item_id={$v['id']} + AND (addr_id={$v['addr_id']} or addr_id_to={$v['addr_id']})" => null]); + } + ($log_max['com_time'] && '0000-00-00 00:00:00' != $log_max['com_time']) && $last_db_time = $log_max['com_time']; + if (!$last_db_time && $v['in_time'] != '0000-00-00 00:00:00') { + $last_db_time = $v['in_time']; + } + $days = 0; + if (($log_min_kc['com_time'] && $log_max_kc['com_time']) && ($log_min_kc['com_time'] != $log_max_kc['com_time'])) { + $days = round((strtotime($log_max_kc['com_time']) - strtotime($log_min_kc['com_time'])) / 3600 / 24); + } else if ($v['in_time'] != '0000-00-00 00:00:00' && $v['bill_time'] != '0000-00-00 00:00:00') { + $days = round((strtotime($v['bill_time']) - strtotime($v['in_time'])) / 3600 / 24); + } else if ($v['in_time'] != '0000-00-00 00:00:00') { + $days = round((time() - strtotime($v['in_time'])) / 3600 / 24); + } + $title = "{$map_brand[$v['brand_id']]}-{$map_sery[$v['s_id']]}-{$map_vid[$v['v_id']]}-{$map_corid[$v['cor_id']]}"; + $lists[] = array( + 'id' => $v['id'], + 'title' => $title, + 'biz_name' => $biz_name, + 'vin' => $v['vin'], + 'address' => $address, + 'in_time' => '0000-00-00 00:00:00' != $v['in_time'] ? date('Y-m-d', strtotime($v['in_time'])) : '', + 'status_name' => $statusAry[$v['status']], + 'bill_time' => '0000-00-00 00:00:00' != $v['bill_time'] ? '已出售' : '未出售', + 'last_db_time' => $last_db_time, + 'inventory_time' => $days > 0 ? '库存' . $days . '天' : '', + ); + } + } + unset($statusAry[0]); + $this->data['lists'] = $lists; + $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $this->data['params'] = $params; + $this->data['autoList'] = $autoList; + $this->data['statusAry'] = $statusAry; + $this->data['_title'] = '门店调拨记录'; + return $this->show_view('/items/logs/lists', true); } public function get() @@ -36,6 +213,7 @@ class Logs extends HD_Controller return $this->show_json(SYS_CODE_FAIL, '商品不存在!'); } $title = $this->input->get('title'); + $biz_name = $this->input->get('biz_name'); $res_log = $this->mdItemsOplogs->select(array('item_id' => $id), 'id asc', 0, 0); $biz_ids = $biz_ids_to = $addr_ids = $addr_ids_to = array(); foreach ($res_log as $v) { @@ -123,17 +301,17 @@ class Logs extends HD_Controller } if ($value['biz_id'] > 0) { if ($value['biz_id_to'] > 0) { - if ($map_biz[$value['biz_id']]['s_time']) { - $days = round(($value['c_time'] - $map_biz[$value['biz_id']]['s_time']) / 3600 / 24); + if ($map_biz[$value['biz_id']]['s_time'] > 0) { + $days = round((strtotime($value['com_time']) - strtotime($map_biz[$value['biz_id']]['s_time'])) / 3600 / 24); $setValue['log'] = $setValue['log'] . ',库存' . $days . '天'; } - $map_biz[$value['biz_id_to']]['s_time'] = $value['c_time']; + $value['com_time'] != '0000-00-00 00:00:00' && $map_biz[$value['biz_id_to']]['s_time'] = $value['com_time']; } else { - if ($value['type'] == 3 && $map_biz[$value['biz_id']]['s_time']) { - $days = round(($value['c_time'] - $map_biz[$value['biz_id']]['s_time']) / 3600 / 24); - $setValue['log'] = $setValue['log'] . ',用时' . $days . '天售出车辆'; + if ($value['type'] == 3 && $map_biz[$value['biz_id']]['s_time'] > 0) { + $days = round((strtotime($value['com_time']) - strtotime($map_biz[$value['biz_id']]['s_time'])) / 3600 / 24); + $setValue['log'] = $setValue['log'] . ',用时' . $days . '天出售车辆'; } - $map_biz[$value['biz_id']]['s_time'] = $value['c_time']; + $value['com_time'] != '0000-00-00 00:00:00' && $map_biz[$value['biz_id']]['s_time'] = $value['com_time']; } $map_biz[$value['biz_id']]['lists'][] = $setValue; } @@ -142,40 +320,52 @@ class Logs extends HD_Controller } if ($value['addr_id'] > 0) { if ($value['biz_id_to'] > 0) { - if ($map_addr[$value['addr_id']]['s_time']) { - $days = round(($value['c_time'] - $map_addr[$value['addr_id']]['s_time']) / 3600 / 24); + if ($map_addr[$value['addr_id']]['s_time'] > 0) { + $days = round((strtotime($value['com_time']) - strtotime($map_addr[$value['addr_id']]['s_time'])) / 3600 / 24); $setValue['log'] = $setValue['log'] . ',库存' . $days . '天'; } - $map_addr[$value['addr_id_to']]['s_time'] = $value['c_time']; + $value['com_time'] != '0000-00-00 00:00:00' && $map_addr[$value['addr_id_to']]['s_time'] = $value['com_time']; } else { - if ($value['type'] == 3 && $map_addr[$value['addr_id']]['s_time']) { - $days = round(($value['c_time'] - $map_addr[$value['addr_id']]['s_time']) / 3600 / 24); - $setValue['log'] = $setValue['log'] . ',用时' . $days . '天售出车辆'; + if ($value['type'] == 3 && $map_addr[$value['addr_id']]['s_time'] > 0) { + $days = round((strtotime($value['com_time']) - strtotime($map_addr[$value['addr_id']]['s_time'])) / 3600 / 24); + $setValue['log'] = $setValue['log'] . ',用时' . $days . '天出售车辆'; } - $map_addr[$value['addr_id']]['s_time'] = $value['c_time']; + $value['com_time'] != '0000-00-00 00:00:00' && $map_addr[$value['addr_id']]['s_time'] = $value['com_time']; } $map_addr[$value['addr_id']]['lists'][] = $setValue; } $lists[] = $setValue; } - //echo json_encode($map_biz,JSON_UNESCAPED_UNICODE); $all = array('lists' => $lists); if ($re['in_time'] != '0000-00-00 00:00:00' && $re['bill_time'] != '0000-00-00 00:00:00') { $days = round((strtotime($re['bill_time']) - strtotime($re['in_time'])) / 3600 / 24); - $all['title'] = "总用时{$days}天售出车辆"; - } else { + $all['title'] = "总用时{$days}天出售车辆"; + } else if ($re['in_time'] != '0000-00-00 00:00:00') { $days = round((time() - strtotime($re['in_time'])) / 3600 / 24); $all['title'] = "至今已库存{$days}天"; } $lists = array(); foreach ($map_biz as $key => $value) { - $lists[] = $value; + if ($biz_name) { + if ($value['title'] == $biz_name) { + $lists[] = $value; + } + } else { + $lists[] = $value; + } } foreach ($map_addr as $key => $value) { - $lists[] = $value; + if ($biz_name) { + if ($value['title'] == $biz_name) { + $lists[] = $value; + } + } else { + $lists[] = $value; + } } $this->data['all'] = $all; $this->data['lists'] = $lists; + $this->data['biz_name'] = $biz_name; $this->data['_title'] = $title; return $this->show_view('/items/logs/get', true); } diff --git a/admin/views/items/logs/get.php b/admin/views/items/logs/get.php index 992f8b7d..7fe8c5b3 100644 --- a/admin/views/items/logs/get.php +++ b/admin/views/items/logs/get.php @@ -9,42 +9,49 @@
-
-
- - - - - - - - - - - $val) { ?> + +
+
+
操作人员内容类型操作时间
+ - - - - + + + + - - -
操作人员内容类型操作时间
-
+ + + $val) { ?> + + + + + + + + + +
+ $val) { ?> -
+
diff --git a/admin/views/items/logs/lists.php b/admin/views/items/logs/lists.php new file mode 100644 index 00000000..9f2aa494 --- /dev/null +++ b/admin/views/items/logs/lists.php @@ -0,0 +1,477 @@ +
+ +
+
+ +
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
共有条数据
+
+ + + + + + + + + + + + + + + + +
ID门店车辆车架号入库日期最后调拨时间库存时间是否出售状态
+
+
+
+ +
+
+
+ + + + diff --git a/api/controllers/plan/Temp.php b/api/controllers/plan/Temp.php index 67cfb9bb..ddbd083e 100644 --- a/api/controllers/plan/Temp.php +++ b/api/controllers/plan/Temp.php @@ -16,6 +16,55 @@ class Temp extends HD_Controller $this->log_file = 'temp.log'; } + /** + * Notes:更新商品操作日志 + * Created on: 2021/9/18 11:58 + * Created by: dengbw + * https://liche-api-dev.xiaoyu.com/plan/temp/items_oplogs + * https://api.liche.cn/plan/temp/items_oplogs + */ + public function items_oplogs() + { + $this->load->model('items/items_model', 'mdItems'); + $this->load->model('items/items_oplogs_model', 'mdItemsOplogs'); + $this->load->library('entity/items_entity'); + $param = $this->input->get(); + $param['page'] = intval($param['page']); + $param['size'] = intval($param['size']); + !$param['size'] && $param['size'] = 50; + !$param['page'] && $param['page'] = 1; + $counts = intval($param['counts']); + ob_start(); //打开缓冲区 + $where = array('status >' => 0, 'in_time <>' => '0000-00-00 00:00:00'); + $res = $this->mdItems->select($where, 'id ASC', $param['page'], $param['size'], 'id,biz_id,addr_id,in_time'); + if (!$res) { + echo '
本次更新商品操作日志完成了:'; + echo '

成功更新 ' . $counts . ' 条'; + echo '

点击将再次更新商品操作日志>>>'; + exit; + } + $log = array(); + foreach ($res as $key => $value) { + $re_c = $this->mdItemsOplogs->get(array('item_id' => $value['id'], 'biz_id' => $value['biz_id'], 'type' => 1)); + if (!$re_c['id']) { + if ($value['biz_id'] == -1 && !$value['addr_id']) { + continue; + } + $params = array('item_id' => $value['id'], 'type' => 1, 'uid' => 0, 'uname' => '系统' + , 'com_time' => $value['in_time'], 'biz_id' => $value['biz_id'], 'addr_id' => $value['addr_id']); + $this->items_entity->add_log($params); + $log[] = array('id' => $value['id']); + $counts++; + } + } + echo '
成功更新:'; + $log && print_r($log); + echo '

数据库获取:'; + echo json_encode($res, JSON_UNESCAPED_UNICODE); + header('refresh:3;url=/plan/temp/items_oplogs?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1)); + ob_end_flush();//输出全部内容到浏览器 + } + /** * Notes:更新客户表来源id * Created on: 2021/9/18 11:58 diff --git a/common/libraries/entity/Items_entity.php b/common/libraries/entity/Items_entity.php index ee3a6402..c75f9b86 100644 --- a/common/libraries/entity/Items_entity.php +++ b/common/libraries/entity/Items_entity.php @@ -45,6 +45,7 @@ class Items_entity } elseif ($params['type'] == 2) {//调拨 $params['biz_id_to'] && $add_data['biz_id_to'] = $params['biz_id_to']; $params['addr_id_to'] && $add_data['addr_id_to'] = $params['addr_id_to']; + $params['com_time'] && $add_data['com_time'] = $params['com_time']; } if ($edit_data) { $result = $this->ci->mdItemsOplogs->update($edit_data, ['item_id' => $params['item_id'], 'type' => $params['type']]);