From e98d26a05fe59da45540b5b00a79e63eb28fa6cf Mon Sep 17 00:00:00 2001 From: dengbw Date: Wed, 2 Mar 2022 17:36:23 +0800 Subject: [PATCH] inventory_302 --- admin/controllers/items/Inventory.php | 284 ++++++++++++ admin/views/items/inventory/lists.php | 94 ++++ admin/views/items/inventory/lists_log.php | 406 ++++++++++++++++++ api/controllers/plan/Licheb.php | 61 +++ api/controllers/plan/Plan.php | 1 + api/controllers/wxapp/licheb/Goods.php | 148 +++++++ api/controllers/wxapp/licheb/Inventory.php | 235 ++++++++++ api/controllers/wxapp/licheb/User.php | 104 ++++- .../items/Items_inventory_log_model.php | 49 +++ common/models/items/Items_inventory_model.php | 18 + common/models/sys/Sys_addr_model.php | 26 +- 11 files changed, 1419 insertions(+), 7 deletions(-) create mode 100644 admin/controllers/items/Inventory.php create mode 100644 admin/views/items/inventory/lists.php create mode 100644 admin/views/items/inventory/lists_log.php create mode 100644 api/controllers/wxapp/licheb/Goods.php create mode 100644 api/controllers/wxapp/licheb/Inventory.php create mode 100644 common/models/items/Items_inventory_log_model.php create mode 100644 common/models/items/Items_inventory_model.php diff --git a/admin/controllers/items/Inventory.php b/admin/controllers/items/Inventory.php new file mode 100644 index 00000000..78f3861c --- /dev/null +++ b/admin/controllers/items/Inventory.php @@ -0,0 +1,284 @@ +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() + { + } +} \ No newline at end of file diff --git a/admin/views/items/inventory/lists.php b/admin/views/items/inventory/lists.php new file mode 100644 index 00000000..ff862ff4 --- /dev/null +++ b/admin/views/items/inventory/lists.php @@ -0,0 +1,94 @@ +
+ +
+
共有条数据
+ + + + + + + + + + + + + + + + + +
id标题操作
查看详情
+
+
+
+
+
+ +
+
+
+ diff --git a/admin/views/items/inventory/lists_log.php b/admin/views/items/inventory/lists_log.php new file mode 100644 index 00000000..598df125 --- /dev/null +++ b/admin/views/items/inventory/lists_log.php @@ -0,0 +1,406 @@ +
+ +
+
共有条数据
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
车辆车架号盘点地址盘点状态里程数盘点图片入库时间车辆状态
$v2) { ?> + + +
+
+
+
+
+
+ +
+
+
+ diff --git a/api/controllers/plan/Licheb.php b/api/controllers/plan/Licheb.php index 457aa0df..0ff3bc95 100644 --- a/api/controllers/plan/Licheb.php +++ b/api/controllers/plan/Licheb.php @@ -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 '
执行到当前id:' . $id; + echo '
成功更新:
'; + if ($log) { + echo json_encode($log, JSON_UNESCAPED_UNICODE); + echo '
'; + } + echo '数据库获取:
'; + echo json_encode($res_log, JSON_UNESCAPED_UNICODE); + } + } + /** * Notes:更新车辆调拨异常 * Created on: 2022/1/4 13:53 diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php index 74416a6a..ced06a9d 100644 --- a/api/controllers/plan/Plan.php +++ b/api/controllers/plan/Plan.php @@ -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; } diff --git a/api/controllers/wxapp/licheb/Goods.php b/api/controllers/wxapp/licheb/Goods.php new file mode 100644 index 00000000..d004a58a --- /dev/null +++ b/api/controllers/wxapp/licheb/Goods.php @@ -0,0 +1,148 @@ +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; + } +} diff --git a/api/controllers/wxapp/licheb/Inventory.php b/api/controllers/wxapp/licheb/Inventory.php new file mode 100644 index 00000000..00d649ee --- /dev/null +++ b/api/controllers/wxapp/licheb/Inventory.php @@ -0,0 +1,235 @@ + '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; + } +} diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php index cf6f79e1..39856ce7 100644 --- a/api/controllers/wxapp/licheb/User.php +++ b/api/controllers/wxapp/licheb/User.php @@ -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[] = [ diff --git a/common/models/items/Items_inventory_log_model.php b/common/models/items/Items_inventory_log_model.php new file mode 100644 index 00000000..cf9b85ea --- /dev/null +++ b/common/models/items/Items_inventory_log_model.php @@ -0,0 +1,49 @@ +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; + } +} \ No newline at end of file diff --git a/common/models/items/Items_inventory_model.php b/common/models/items/Items_inventory_model.php new file mode 100644 index 00000000..766b3f2a --- /dev/null +++ b/common/models/items/Items_inventory_model.php @@ -0,0 +1,18 @@ +table_name, 'default'); + } + +} \ No newline at end of file diff --git a/common/models/sys/Sys_addr_model.php b/common/models/sys/Sys_addr_model.php index e38d705e..2d948d1c 100644 --- a/common/models/sys/Sys_addr_model.php +++ b/common/models/sys/Sys_addr_model.php @@ -1,16 +1,40 @@ 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; + } } \ No newline at end of file