diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 12a15541..54aa3ba8 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() { @@ -379,8 +379,10 @@ class Goods extends HD_Controller } else if ($v['biz_id'] == -1 && $v['addr_id']) { $address = $map_addr[$v['addr_id']]; } + $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, 'brand_name' => $map_brand[$v['brand_id']], 's_name' => $map_sery[$v['s_id']], 'v_name' => $map_vid[$v['v_id']], @@ -613,8 +615,13 @@ class Goods extends HD_Controller 'status' => 1 ); } - $ret = $this->items_relate_model->add_batch($adds); + $this->items_relate_model->add_batch($adds); } + //添加入库日志 + $this->load->library('entity/items_entity'); + $params = array('item_id' => $id, 'type' => 1, 'uid' => $this->uid, 'uname' => $this->username + , 'com_time' => $addData['in_time'], 'biz_id' => $addData['biz_id'], 'addr_id' => $addData['addr_id']); + $this->items_entity->add_log($params); $this->data['status'] = 1; $url = $info['bill_time'] ? '/items/goods/goods?sold=1' : "/items/goods/goods"; return $this->show_json(SYS_CODE_SUCCESS, '添加成功!', $url); @@ -705,7 +712,7 @@ class Goods extends HD_Controller return $this->show_json(SYS_CODE_FAIL, 'vin码已存在'); } } - + $re = $this->mdItems->get(['id' => $info['id']]); $editData['brand_id'] = $info['brand_id']; $editData['s_id'] = $info['s_id']; $editData['v_id'] = $info['v_id']; @@ -766,7 +773,40 @@ class Goods extends HD_Controller } $adds && $this->items_relate_model->add_batch($adds); } - + //添加日志 + $this->load->library('entity/items_entity'); + if ($re['in_time'] != $info['in_time']) {//入库时间不同修改日志 + $params = array('item_id' => $info['id'], 'type' => 1, 'com_time' => $info['in_time']); + $this->items_entity->add_log($params); + } + if ($info['bill_time'] && $re['bill_time'] != $info['bill_time']) {//开票时间不同修改日志 + $params = array('item_id' => $info['id'], 'type' => 3, 'uid' => $this->uid, 'uname' => $this->username + , 'com_time' => $info['bill_time'], 'biz_id' => $info['biz_id'], 'addr_id' => $info['addr_id']); + $this->items_entity->add_log($params); + } + 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); + $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); + $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); + $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); + $this->items_entity->add_log($params); + } $this->data['status'] = 2; $url = $info['bill_time'] ? '/items/goods/goods?sold=1' : "/items/goods/goods"; return $this->show_json(SYS_CODE_SUCCESS, '修改成功!', $url); diff --git a/admin/controllers/items/goods/Logs.php b/admin/controllers/items/goods/Logs.php new file mode 100644 index 00000000..9e20bb9f --- /dev/null +++ b/admin/controllers/items/goods/Logs.php @@ -0,0 +1,204 @@ +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'); + } + + public function index() + { + $this->lists(); + } + + public function lists() + { + } + + public function get() + { + $id = $this->input->get('id'); + $re = $this->mdItems->get(array('id' => $id)); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '商品不存在!'); + } + $title = $this->input->get('title'); + $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) { + $v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_id']; + $v['biz_id_to'] && !in_array($v['biz_id_to'], $biz_ids_to) && $biz_ids_to[] = $v['biz_id_to']; + $v['addr_id'] && !in_array($v['addr_id'], $addr_ids) && $addr_ids[] = $v['addr_id']; + $v['addr_id_to'] && !in_array($v['addr_id_to'], $addr_ids_to) && $addr_ids_to[] = $v['addr_id_to']; + } + $map_biz = $map_addr = array(); + if ($biz_ids || $biz_ids_to) { + if ($biz_ids && $biz_ids_to) { + $biz_ids = array_merge($biz_ids, $biz_ids_to); + } else if ($biz_ids_to) { + $biz_ids = $biz_ids_to; + } + $str_ids = implode(',', $biz_ids); + $where = array("id in ({$str_ids})" => null); + $rows_biz = $this->mdBiz->select($where, 'id desc', 0, 0, 'id,biz_name,city_id,county_id'); + foreach ($rows_biz as $v) { + $address = $v['biz_name']; + if ($v['county_id']) { + $re_area = $this->mdArea->get(array('county_id' => $v['county_id'])); + $re_area && $address = "{$re_area['city_name']} {$re_area['county_name']} {$address}"; + } else if ($v['city_id']) { + $re_area = $this->mdArea->get(array('city_id' => $v['city_id'])); + $re_area && $address = "{$re_area['city_name']} {$address}"; + } + $map_biz[$v['id']] = ['title' => $v['biz_name'], 'address' => $address]; + } + } + if ($addr_ids || $addr_ids_to) { + if ($addr_ids && $addr_ids_to) { + $addr_ids = array_merge($addr_ids, $addr_ids_to); + } else if ($addr_ids_to) { + $addr_ids = $addr_ids_to; + } + $str_ids = implode(',', $addr_ids); + $where = array("id in ({$str_ids})" => null); + $rows_addr = $this->mdAddr->select($where, 'id desc', 0, 0, 'id, title, city_name, county_name'); + foreach ($rows_addr as $v) { + $address = "{$v['city_name']} {$v['county_name']} {$v['title']}"; + $map_addr[$v['id']] = ['title' => $v['title'], 'address' => $address]; + } + } + $typeAry = $this->mdItemsOplogs->typeAry(); + $lists = array(); + foreach ($res_log as $key => $value) { + $setValue = array(); + $log = ''; + if ($value['type'] == 1) { + $log = '[' . $value['com_time'] . '] 入库'; + if ($value['biz_id'] > 0) { + $log .= ',存放门店 [' . $map_biz[$value['biz_id']]['address'] . ']'; + } elseif ($value['addr_id']) { + $log .= ',存放地址 [' . $map_addr[$value['addr_id']]['address'] . ']'; + } else { + $log .= ',未选择存放地'; + } + } else if ($value['type'] == 2) { + if ($value['biz_id'] > 0 && $value['biz_id_to'] > 0) { + $log = '从 [' . $map_biz[$value['biz_id']]['address'] . '] 调拨到 [' . $map_biz[$value['biz_id_to']]['address'] . ']'; + } else if ($value['biz_id'] > 0 && $value['addr_id_to']) { + $log = '从 [' . $map_biz[$value['biz_id']]['address'] . '] 调拨到 [' . $map_addr[$value['addr_id_to']]['address'] . ']'; + } else if ($value['addr_id'] && $value['biz_id_to'] > 0) { + $log = '从 [' . $map_addr[$value['addr_id']]['address'] . '] 调拨到 [' . $map_biz[$value['biz_id_to']]['address'] . ']'; + } else if ($value['addr_id'] && $value['addr_id_to']) { + $log = '从 [' . $map_addr[$value['addr_id']]['address'] . '] 调拨到 [' . $map_addr[$value['addr_id_to']]['address'] . ']'; + } + } else if ($value['type'] == 3) { + $log = '[' . $value['com_time'] . '] 开票'; + if ($value['biz_id'] > 0) { + $log .= ',出售门店 [' . $map_biz[$value['biz_id']]['address'] . ']'; + } elseif ($value['addr_id']) { + $log .= ',出售地址 [' . $map_addr[$value['addr_id']]['address'] . ']'; + } else { + $log .= ',未选择出售地'; + } + } + $setValue['log'] = $log; + $setValue['uname'] = $value['uname']; + $setValue['type_name'] = $typeAry[$value['type']]; + $setValue['c_time'] = date('Y-m-d H:i', $value['c_time']); + if ($value['biz_id_to'] > 0) { + $map_biz[$value['biz_id_to']]['lists'][] = $setValue; + } + 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); + $setValue['log'] = $setValue['log'] . ',库存' . $days . '天'; + } + $map_biz[$value['biz_id_to']]['s_time'] = $value['c_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 . '天售出车辆'; + } + $map_biz[$value['biz_id']]['s_time'] = $value['c_time']; + } + $map_biz[$value['biz_id']]['lists'][] = $setValue; + } + if ($value['addr_id_to'] > 0) { + $map_addr[$value['addr_id_to']]['lists'][] = $setValue; + } + 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); + $setValue['log'] = $setValue['log'] . ',库存' . $days . '天'; + } + $map_addr[$value['addr_id_to']]['s_time'] = $value['c_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 . '天售出车辆'; + } + $map_addr[$value['addr_id']]['s_time'] = $value['c_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 { + $days = round((time() - strtotime($re['in_time'])) / 3600 / 24); + $all['title'] = "至今已库存{$days}天"; + } + $lists = array(); + foreach ($map_biz as $key => $value) { + $lists[] = $value; + } + foreach ($map_addr as $key => $value) { + $lists[] = $value; + } + $this->data['all'] = $all; + $this->data['lists'] = $lists; + $this->data['_title'] = $title; + return $this->show_view('/items/logs/get', true); + } + + public function add() + { + } + + public function edit() + { + } + + public function del() + { + } + + public function batch() + { + + } + + public function export() + { + + } +} diff --git a/admin/controllers/receiver/Orders.php b/admin/controllers/receiver/Orders.php index 42b99c60..4090c49a 100644 --- a/admin/controllers/receiver/Orders.php +++ b/admin/controllers/receiver/Orders.php @@ -582,9 +582,16 @@ class Orders extends HD_Controller $row_order = $this->orders_model->get(array('id' => $row['o_id'])); if ($row_order) { $this->load->model('items/items_model'); - $upd = array('bill_time' => date('Y-m-d H:i:s')); + $bill_time = date('Y-m-d H:i:s'); + $upd = array('bill_time' => $bill_time); $where = array('id' => $row_order['item_id']); $ret = $this->items_model->update($upd, $where); + if ($ret) { //添加开票日志 + $this->load->library('entity/items_entity'); + $params = array('item_id' => $id, 'type' => 3, 'uid' => $this->uid, 'uname' => $this->username + , 'com_time' => $bill_time, 'biz_id' => $row_order['biz_id'], 'addr_id' => $row_order['addr_id']); + $this->items_entity->add_log($params); + } } return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } else { diff --git a/admin/views/items/goods/edit.php b/admin/views/items/goods/edit.php index 5bdd5627..ef2cb2ce 100644 --- a/admin/views/items/goods/edit.php +++ b/admin/views/items/goods/edit.php @@ -1,46 +1,3 @@ - - -
|
-
-
- 入库日期
-
- |
- ||
|
-
指导价
-
+ 入库日期
+
|
-
-
-
- 折扣%
-
- |
-
-
-
- 折扣金额
-
- |
-
|
开票日期
@@ -248,26 +182,48 @@
|
-
- 发票号
-
- |
-
-
-
发票金额
-
+ 指导价
+
|
|
-
-
- 采购成本
-
- |
- - | |