From 7d192cce9445cd8177c0fa7ebf4a49c984c63df1 Mon Sep 17 00:00:00 2001 From: dengbw Date: Tue, 28 Dec 2021 15:49:37 +0800 Subject: [PATCH] transfer_1228 --- admin/controllers/Common.php | 3 +- admin/controllers/items/Transfer.php | 685 +++++++++++--- admin/views/items/goods/lists.php | 4 + admin/views/items/transfer/get.php | 117 ++- admin/views/items/transfer/get_add.php | 877 +++++++++++++++--- admin/views/items/transfer/lists.php | 574 +++++++----- api/controllers/wxapp/licheb/Transfer.php | 257 ++++- api/controllers/wxapp/licheb/User.php | 3 +- common/models/biz/Biz_model.php | 2 +- .../items/Items_transfer_admin_model.php | 28 + common/models/items/Items_transfer_model.php | 18 +- common/models/sys/Sys_admin_model.php | 18 +- 12 files changed, 2052 insertions(+), 534 deletions(-) create mode 100644 common/models/items/Items_transfer_admin_model.php diff --git a/admin/controllers/Common.php b/admin/controllers/Common.php index 61f3327d..450c9955 100644 --- a/admin/controllers/Common.php +++ b/admin/controllers/Common.php @@ -423,7 +423,7 @@ class Common extends CI_Controller $this->load->model('biz/biz_model', 'mdBiz'); $page = $this->input->post('page') ? intval($this->input->post('page')) : 1; $size = $this->input->post('size') ? intval($this->input->post('size')) : 10; - $type = $this->input->post('type'); + $type = intval($this->input->post('type')); $brand_id = intval($this->input->post('brand_id')); $city_id = intval($this->input->post('city_id')); $county_id = intval($this->input->post('county_id')); @@ -444,6 +444,7 @@ class Common extends CI_Controller $brand_id && $where['brand_id'] = $brand_id; $city_id && $where['city_id'] = $city_id; $county_id && $where['county_id'] = $county_id; + $type && $where['type'] = $type; $ids && $where['id not in (' . $ids . ')'] = null; $count = $this->mdBiz->count($where); if ($count) { diff --git a/admin/controllers/items/Transfer.php b/admin/controllers/items/Transfer.php index 96a217d3..7070ad96 100644 --- a/admin/controllers/items/Transfer.php +++ b/admin/controllers/items/Transfer.php @@ -15,6 +15,7 @@ class Transfer extends HD_Controller parent::__construct(); $this->load->model('items/items_transfer_model', 'mdTransfer'); $this->load->model('items/items_transfer_remind_model', 'mdTransferRemind'); + $this->load->model('items/items_transfer_admin_model', 'mdTransferAdmin'); $this->load->model('app/licheb/app_licheb_users_model', 'mdUsers'); $this->load->model('items/items_model', 'mdItems'); @@ -24,6 +25,7 @@ class Transfer extends HD_Controller $this->load->model("sys/sys_addr_model", 'mdAddr'); $this->load->model("biz/biz_model", 'mdBiz'); $this->load->model('area_model', 'mdArea'); + $this->load->model('sys/Sys_admin_model', 'mdSysAdmin'); } public function index() @@ -53,6 +55,7 @@ class Transfer extends HD_Controller $this->data['statusAry'] = $this->mdTransfer->statusAry(); $this->data['abnormalAry'] = $this->mdTransfer->abnormalAry(); $this->data['autoList'] = $autoList; + $this->data['showInfo'] = ['uidTypeAry' => $this->mdTransfer->uidTypeAry(), 'takeCar' => $re['takeCar']]; $this->data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total); $this->data['_title'] = '车辆调拨'; $this->show_view('items/transfer/lists', true); @@ -61,7 +64,7 @@ class Transfer extends HD_Controller private function dataSelect($params) { $statusAry = $this->mdTransfer->statusAry(); - $where = ['status<>' => -1]; + $where = []; if (strlen($params['status'])) { $where['status'] = $params['status']; } else { @@ -72,22 +75,54 @@ class Transfer extends HD_Controller } else { $params['abnormal'] = ''; } - if ($params['out_uid']) { - $where['out_uid'] = $params['out_uid']; + if ($params['out_type'] == 2) { + if ($params['out_addr_id']) { + $where['addr_id'] = $params['out_addr_id']; + $where['out_type'] = $params['out_type']; + } else { + $params['out_addr_id'] = ''; + } } else { - $params['out_uid'] = ''; - !$params['city_id_out'] && $params['city_id_out'] = ''; - !$params['county_id_out'] && $params['county_id_out'] = ''; - !$params['biz_id_out'] && $params['biz_id_out'] = ''; + if ($params['out_uid']) { + $where['out_uid'] = $params['out_uid']; + $where['out_type'] = $params['out_type']; + } else { + $params['out_uid'] = ''; + } } - if ($params['in_uid']) { - $where['in_uid'] = $params['in_uid']; + !$params['out_city_id'] && $params['out_city_id'] = ''; + !$params['out_county_id'] && $params['out_county_id'] = ''; + !$params['out_admin_id'] && $params['out_admin_id'] = ''; + !$params['out_biz_id'] && $params['out_biz_id'] = ''; + !$params['out_type'] && $params['out_type'] = 1; + $takeCar[1] = ['city_id' => $params['out_city_id'], 'county_id' => $params['out_county_id'], 'type' => $params['out_type'] + , 'biz_id' => $params['out_biz_id'], 'uid' => $params['out_uid'], 'admin_id' => $params['out_admin_id'], 'addr_id' => $params['out_addr_id'] + , 'cityList' => [], 'countyList' => [], 'bizList' => [], 'uidList' => [], 'adminList' => [], 'addrList' => []]; + + if ($params['in_type'] == 2) { + if ($params['in_addr_id']) { + $where['in_id'] = $params['in_addr_id']; + $where['in_type'] = $params['in_type']; + } else { + $params['in_addr_id'] = ''; + } } else { - $params['in_uid'] = ''; - !$params['city_id_in'] && $params['city_id_in'] = ''; - !$params['county_id_in'] && $params['county_id_in'] = ''; - !$params['biz_id_in'] && $params['biz_id_in'] = ''; + if ($params['in_uid']) { + $where['in_uid'] = $params['in_uid']; + $where['in_type'] = $params['in_type']; + } else { + $params['in_uid'] = ''; + } } + !$params['in_city_id'] && $params['in_city_id'] = ''; + !$params['in_county_id'] && $params['in_county_id'] = ''; + !$params['in_admin_id'] && $params['in_admin_id'] = ''; + !$params['in_biz_id'] && $params['in_biz_id'] = ''; + !$params['in_type'] && $params['in_type'] = 1; + $takeCar[3] = ['city_id' => $params['in_city_id'], 'county_id' => $params['in_county_id'], 'type' => $params['in_type'] + , 'biz_id' => $params['in_biz_id'], 'uid' => $params['in_uid'], 'admin_id' => $params['in_admin_id'], 'addr_id' => $params['in_addr_id'] + , 'cityList' => [], 'countyList' => [], 'bizList' => [], 'uidList' => [], 'adminList' => [], 'addrList' => []]; + if ($params['title']) { $where["item_id in (select id from lc_items where vin like '%{$params['title']}%')"] = null; } @@ -107,96 +142,193 @@ class Transfer extends HD_Controller $in_time[0] && $where["in_time >="] = $in_time[0] . ' 00:00:00'; $in_time[1] && $where["in_time <="] = $in_time[1] . ' 23:59:59'; } + if ($params['out_type']) { + $params['out_uid'] && $where["out_type"] = $params['out_type']; + } else { + $params['out_type'] = 1; + } + if ($params['in_type']) { + $params['in_uid'] && $where["in_type"] = $params['in_type']; + } else { + $params['in_type'] = 1; + } $total = $this->mdTransfer->count($where); $lists = array(); if ($total) { $rows = $this->mdTransfer->select($where, 'id desc', $params['page'], $params['size']); - $out_uids = array_unique(array_column($rows, 'out_uid')); - $in_uids = array_unique(array_column($rows, 'in_uid')); + $out_uids = $in_uids = []; + $out_uids_ad = $in_uids_ad = []; + foreach ($rows as $v2) { + if ($v2['out_uid']) { + if ($v2['out_type'] == 1) { + $out_uids[] = $v2['out_uid']; + } else if ($v2['out_type'] == 2) { + $out_uids_ad[] = $v2['out_uid']; + } + } + if ($v2['in_uid']) { + if ($v2['in_type'] == 1) { + $in_uids[] = $v2['in_uid']; + } else if ($v2['in_type'] == 2) { + $in_uids_ad[] = $v2['in_uid']; + } + } + } $uids_arr = array_merge($out_uids, $in_uids); + $uids_ad_arr = array_merge($out_uids_ad, $in_uids_ad); $uids = $this->mdUsers->get_map_by_ids($uids_arr, 'id,uname'); + $uids_ad = $this->mdSysAdmin->get_map_by_ids($uids_ad_arr, 'id,username as uname'); foreach ($rows as $v) { $jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : []; $item_info = $this->item_info($v['item_id'], 1); - $lists[] = array( + $out_uid_title = $in_uid_title = '-'; + $tag = $params['size'] == 10000 ? '/' : '
'; + if ($v['out_uid']) { + if ($v['out_type'] == 1) { + $out_uid_title = $uids[$v['out_uid']][0]['uname'] . $tag . date('Y-m-d H:i', strtotime($v['out_time'])); + } else if ($v['out_type'] == 2) { + $out_uid_title = $uids_ad[$v['out_uid']][0]['uname'] . $tag . date('Y-m-d H:i', strtotime($v['out_time'])); + } + } + if ($v['in_uid']) { + if ($v['in_type'] == 1) { + $in_uid_title = $uids[$v['in_uid']][0]['uname'] . $tag . date('Y-m-d H:i', strtotime($v['in_time'])); + } else if ($v['in_type'] == 2) { + $in_uid_title = $uids_ad[$v['in_uid']][0]['uname'] . $tag . date('Y-m-d H:i', strtotime($v['in_time'])); + } + } + $setValue = [ 'id' => $v['id'], 'title' => $item_info['title'], 'vin' => $item_info['vin'], - 'out_uid_title' => $v['out_uid'] ? $uids[$v['out_uid']][0]['uname'] . '/' . date('Y.m.d H:i', strtotime($v['out_time'])) : '-', - 'in_uid_title' => $v['in_uid'] ? $uids[$v['in_uid']][0]['uname'] . '/' . date('Y.m.d H:i', strtotime($v['in_time'])) : '-', + 'out_uid_title' => $out_uid_title, + 'in_uid_title' => $in_uid_title, 'transport_name' => $jsondata['transport']['name'], 'abnormal' => $this->mdTransfer->abnormalAry($v['abnormal']), 'c_time' => date('Y.m.d H:i', $v['c_time']), + 'status' => $v['status'], 'status_name' => $statusAry[$v['status']], - ); + ]; + $city_name = $county_name = $biz_name = ''; + if ($v['biz_id'] > 0) { + $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'])); + $city_name = $re_area['city_name']; + $county_name = $re_area['county_name']; + } else if ($re_biz['city_id']) { + $re_area = $this->mdArea->get(array('city_id' => $re_biz['city_id'])); + $city_name = $re_area['city_name']; + } + $biz_name = $re_biz['biz_name'] ? $re_biz['biz_name'] : ''; + } else if ($v['addr_id']) { + $re_addr = $this->mdAddr->get(array('id' => $v['addr_id'])); + if ($re_addr) { + $city_name = $re_addr['city_name']; + $county_name = $re_addr['county_name']; + $biz_name = $re_addr['title']; + } + } + if ($params['size'] == 10000) {//导出 + $jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : []; + $trailer_fees = $this->mdTransfer->feesTypeAry($v['fees_type']); + if ($v['fees_city']) { + $re_area = $this->mdArea->get(array('city_id' => $v['fees_city'])); + $trailer_fees .= '-' . $re_area['city_name']; + } + if ($v['fees_type'] == 1 && $v['fees_biz_id']) { + $re_biz = $this->mdBiz->get(array('id' => $v['fees_biz_id'])); + $trailer_fees .= '-' . $re_biz['biz_name']; + } + $setValue['city'] = $city_name; + $setValue['county'] = $county_name; + $setValue['biz_name'] = $biz_name; + $setValue['trailer_fees'] = $v['trailer_fees']; + $setValue['fees'] = $trailer_fees; + $setValue['reason'] = $jsondata['reason'] ? $jsondata['reason'] : ''; + } else { + $setValue['addr_name'] = "{$city_name}-{$county_name}-$biz_name"; + } + $lists[] = $setValue; } } $data['lists'] = $lists; $data['params'] = $params; + $data['takeCar'] = $takeCar; $data['total'] = $total; return $data; } public function get() { - $id = $this->input->get('id'); + $id = intval($this->input->get('id')); $info = []; if ($id) { - $re = $this->mdTransfer->get(array('id' => $id, 'status <>' => -1)); + $re = $this->mdTransfer->get(array('id' => $id)); if (!$re || empty($re)) { return $this->show_json(SYS_CODE_FAIL, '车辆调拨不存在!'); } $this->load->model('auto/auto_article_model', 'mdArticle'); $info['item_id'] = $re['item_id']; $info['items_info'] = $this->item_info($re['item_id']); - $res_r = $this->mdTransferRemind->select(['tran_id' => $id], 'type asc', 0, 0, 'uid,type'); - $out_content = $in_content = $arti_content = $abnormal = ''; - foreach ($res_r as $key => $value) { - if ($value['type'] == 1) { - $re_user = $this->mdUsers->get(array('id' => $value['uid'])); - $re_biz = $this->mdBiz->get(array('id' => $re_user['biz_id'])); - if ($re_biz['county_id']) { - $re_area = $this->mdArea->get(array('county_id' => $re_biz['county_id'])); - $city_name = $re_area['city_name'] . ' ' . $re_area['county_name']; - } else { - $re_area = $this->mdArea->get(array('city_id' => $re_biz['city_id'])); - $city_name = $re_area['city_name']; + $out_content = $out_content_bak = $in_content = $in_content_bak = $arti_content = $abnormal = $transport = ''; + //门店 + $res_r = $this->mdTransferRemind->select(['tran_id' => $id], 'type asc', 0, 0, 'uid,type,biz_id'); + if ($res_r) { + foreach ($res_r as $key => $value) { + $content = $this->take_car($value, 1); + if ($value['type'] == 1) { + $out_content = $content; + } else if ($value['type'] == 2) { + $out_content_bak = $content; + } else if ($value['type'] == 3) { + $in_content = $content; + } else if ($value['type'] == 4) { + $in_content_bak = $content; } - $out_content = $city_name . ' ' . $re_biz['biz_name'] . '    提车人:' . $re_user['uname'] - . '  ' . $re_user['mobile']; - } else if ($value['type'] == 2) { - $re_user = $this->mdUsers->get(array('id' => $value['uid'])); - $out_content .= '    备用提车人:' . $re_user['uname'] . '  ' . $re_user['mobile']; - } else if ($value['type'] == 3) { - $re_user = $this->mdUsers->get(array('id' => $value['uid'])); - $re_biz = $this->mdBiz->get(array('id' => $re_user['biz_id'])); - if ($re_biz['county_id']) { - $re_area = $this->mdArea->get(array('county_id' => $re_biz['county_id'])); - $city_name = $re_area['city_name'] . ' ' . $re_area['county_name']; - } else { - $re_area = $this->mdArea->get(array('city_id' => $re_biz['city_id'])); - $city_name = $re_area['city_name']; + } + } + //信息员 + $opt_btn = ['title' => '', 'type' => 0];//type1确认发车2确认接车 + $res_a = $this->mdTransferAdmin->select(['tran_id' => $id], 'type asc', 0, 0, 'uid,type,addr_id,status'); + if ($res_a) { + foreach ($res_a as $key => $value) { + $content = $this->take_car($value, 2); + if ($value['type'] == 1 || $value['type'] == 2) { + if ($value['type'] == 1) { + $out_content = $content; + } else { + $out_content_bak = $content; + } + if ($value['status'] == 1 && $value['uid'] == $this->uid) {//未操作且是自己 + $opt_btn = ['title' => '确认发车', 'type' => 1, 'tran_id' => $id, 'addr_id' => $value['addr_id']]; + } + } else if ($value['type'] == 3 || $value['type'] == 4) { + if ($value['type'] == 3) { + $in_content = $content; + } else { + $in_content_bak = $content; + } + if ($value['status'] == 1 && $value['uid'] == $this->uid) {//未操作且是自己 + $opt_btn = ['title' => '确认接车', 'type' => 2, 'tran_id' => $id, 'addr_id' => $value['addr_id']]; + } } - $in_content = $city_name . ' ' . $re_biz['biz_name'] . '    接车人:' . $re_user['uname'] - . '  ' . $re_user['mobile']; - } else if ($value['type'] == 4) { - $re_user = $this->mdUsers->get(array('id' => $value['uid'])); - $in_content .= '    备用接车人:' . $re_user['uname'] . '  ' . $re_user['mobile']; } } $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : []; - $trailer_fees = $re['trailer_fees'] ? $re['trailer_fees'] . '元' : ''; - $trailer_fees .= '  费用承担人:'; - if ($re['fees_city']) { - $re_area = $this->mdArea->get(array('city_id' => $re['fees_city'])); - $trailer_fees .= $re_area['city_name']; - } - $trailer_fees .= '  ' . $this->mdTransfer->feesTypeAry($re['fees_type']); - $fields[] = ['title' => '提车信息', 'value' => $out_content]; - $fields[] = ['title' => '接车信息', 'value' => $in_content]; - $fields[] = ['title' => '运输费用', 'value' => $trailer_fees]; + $fields[] = ['title' => '提车信息', 'value' => $out_content . $out_content_bak]; + $fields[] = ['title' => '接车信息', 'value' => $in_content . $in_content_bak]; $fields[] = ['title' => '运输人员', 'value' => $jsondata['transport']['name'] . '   ' . $jsondata['transport']['mobile'] . '   身份证:' . $jsondata['transport']['cardid']]; + if ($jsondata['transport']) { + $transport = $jsondata['transport']; + $imgs = []; + foreach ($transport['imgs'] as $key => $value) { + $value && $imgs[] = ['src' => build_qiniu_image_url($value), 'value' => $value]; + } + $transport['imgs'] = $imgs; + } + $jsondata['reason'] && $fields[] = ['title' => '调拨理由', 'value' => $jsondata['reason']]; if ($re['arti_id']) { $res_a = $this->mdArticle->select(["id in ({$re['arti_id']})" => null], 'id desc', 0, 0, 'title'); $res_a && $arti_content = implode('   ', array_unique(array_column($res_a, 'title'))); @@ -205,22 +337,44 @@ class Transfer extends HD_Controller $fields[] = ['title' => '车辆异常', 'value' => $this->mdTransfer->abnormalAry()[$re['abnormal']]]; if ($re['abnormal'] && $jsondata['abnormal']) { $abnormal = $jsondata['abnormal']; + $imgs = []; foreach ($abnormal['imgs'] as $key => $value) { - $abnormal['imgs'][$key] = $value ? build_qiniu_image_url($value) : ''; + $value && $imgs[] = ['src' => build_qiniu_image_url($value), 'value' => $value]; } + $abnormal['imgs'] = $imgs; + } + if ($re['trailer_fees']) { + $trailer_fees = $re['trailer_fees'] ? $re['trailer_fees'] . '元' : ''; + $trailer_fees .= '  费用承担人:' . $this->mdTransfer->feesTypeAry($re['fees_type']); + if ($re['fees_city']) { + $re_area = $this->mdArea->get(array('city_id' => $re['fees_city'])); + $trailer_fees .= '  ' . $re_area['city_name']; + } + if ($re['fees_type'] == 1 && $re['fees_biz_id']) { + $re_biz = $this->mdBiz->get(array('id' => $re['fees_biz_id'])); + $trailer_fees .= '  ' . $re_biz['biz_name']; + } + $fields[] = ['title' => '运输费用', 'value' => $trailer_fees]; + } + if (!$abnormal && $opt_btn['type']) {//1确认发车2确认接车可发异常 + $abnormal = ['imgs' => [], 'note' => '']; } $this->data['fields'] = $fields; + $this->data['opt_btn'] = $opt_btn; $this->data['abnormal'] = $abnormal; + $this->data['transport'] = $transport; $title = '车辆调拨详情'; $view = 'items/transfer/get'; } else { $title = '新增车辆调拨'; + $vin = $this->input->get('vin'); + !$vin && $vin = ''; $view = 'items/transfer/get_add'; - $showInfo = ['vin' => '', 'items_info' => ['id' => 0, 'title' => '', 'vin' => '', 'cor' => '', 'address' => ''], - 'feesTypeAry' => $this->mdTransfer->feesTypeAry()]; - $info = ['item_id' => 0, 'arti_id' => [], 'out_uid' => '', 'out_uid_bak' => '', 'in_uid' => '', 'in_uid_bak' => '' - , 'out_bak' => 0, 'in_bak' => 0, 'trailer_fees' => '', 'fees_city' => '', 'fees_type' => 1, 'transport' => ['name' => '', 'mobile' => '', 'cardid' => '']]; - //常用运输人员 + $showInfo = ['vin' => $vin, 'items_info' => ['id' => 0, 'title' => '', 'vin' => '', 'cor' => '', 'address' => ''], + 'feesTypeAry' => $this->mdTransfer->feesTypeAry(), 'feesBizList' => [], 'uidTypeAry' => $this->mdTransfer->uidTypeAry()]; + $info = ['id' => 0, 'status' => 0, 'item_id' => 0, 'arti_id' => [], 'out_bak' => 0, 'in_bak' => 0, 'trailer_fees' => '', 'fees_city' => '', 'trailer_fees' => 0, + 'fees_type' => 1, 'fees_biz_id' => '', 'transport' => ['name' => '', 'mobile' => '', 'cardid' => ''], 'reason' => '']; + //常用运输人 $transports = []; $cache = &load_cache('redis'); $cache_transports = $cache->get($this->cacheKeyTransports); @@ -242,25 +396,106 @@ class Transfer extends HD_Controller return $this->show_view($view, true); } + public function get_edit() + { + $id = intval($this->input->get('id')); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $re = $this->mdTransfer->get(array('id' => $id)); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '车辆调拨不存在!'); + } + if ($re['status'] != -1) { + return $this->show_json(SYS_CODE_FAIL, '车辆调拨已提交,不能修改!'); + } + $item_id = $re['item_id'] ? $re['item_id'] : 0; + $re_items = $this->mdItems->get(['id' => $item_id]); + $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : []; + $showInfo = ['vin' => $re_items['vin'], 'items_info' => ['id' => 0, 'title' => '', 'vin' => '', 'cor' => '', 'address' => ''], + 'feesTypeAry' => $this->mdTransfer->feesTypeAry(), 'feesBizList' => [], 'uidTypeAry' => $this->mdTransfer->uidTypeAry()]; + $info = ['id' => $id, 'status' => $re['status'], 'out_bak' => 0, 'in_bak' => 0 + , 'item_id' => $item_id + , 'arti_id' => $re['arti_id'] ? explode(',', $re['arti_id']) : [] + , 'trailer_fees' => $re['trailer_fees'] ? $re['trailer_fees'] : '' + , 'fees_city' => $re['fees_city'] ? $re['fees_city'] : '' + , 'fees_type' => $re['fees_type'] + , 'fees_biz_id' => $re['fees_biz_id'] ? $re['fees_biz_id'] : '' + , 'transport' => ['name' => $jsondata['transport']['name'] ? $jsondata['transport']['name'] : '' + , 'mobile' => $jsondata['transport']['mobile'] ? $jsondata['transport']['mobile'] : '' + , 'cardid' => $jsondata['transport']['mobile'] ? $jsondata['transport']['cardid'] : ''] + , 'reason' => $jsondata['reason'] ? $jsondata['reason'] : '']; + + $takeCar[1] = $takeCar[2] = $takeCar[3] = $takeCar[4] = ['city_id' => "", 'county_id' => "", 'type' => 1, 'biz_id' => "", 'uid' => "", 'admin_id' => "" + , 'addr_id' => "", 'cityList' => [], 'countyList' => [], 'bizList' => [], 'uidList' => [], 'adminList' => [], 'addrList' => []]; + if ($jsondata['take_car']) { + foreach ($jsondata['take_car'] as $key => $value) { + $takeCar[$key]['type'] = $value['type']; + if ($value['type'] == 2) { + $re_addr = $this->mdAddr->get(array('id' => $value['addr_id'])); + $takeCar[$key]['city_id'] = $re_addr['city_id'] ? $re_addr['city_id'] : ""; + $takeCar[$key]['county_id'] = $re_addr['county_id'] ? $re_addr['county_id'] : ""; + $takeCar[$key]['admin_id'] = $value['admin_id'] ? $value['admin_id'] : ''; + $takeCar[$key]['addr_id'] = $value['addr_id'] ? $value['addr_id'] : ''; + } else { + $re_biz = $this->mdBiz->get(array('id' => $value['biz_id'])); + $takeCar[$key]['city_id'] = $re_biz['city_id'] ? $re_biz['city_id'] : ""; + $takeCar[$key]['county_id'] = $re_biz['county_id'] ? $re_biz['county_id'] : ""; + $takeCar[$key]['uid'] = $value['uid'] ? $value['uid'] : ''; + $takeCar[$key]['biz_id'] = $value['biz_id'] ? $value['biz_id'] : ''; + } + $key == 2 && $info['out_bak'] = 1;//备用提车人 + $key == 4 && $info['in_bak'] = 1;//备用接车人 + } + } + $showInfo['takeCar'] = $takeCar; + //常用运输人 + $transports = []; + $cache = &load_cache('redis'); + $cache_transports = $cache->get($this->cacheKeyTransports); + if ($cache_transports) { + $time = date('Y-m-d', strtotime("-1 month")); + foreach ($cache_transports as $key => $value) { + if ($value['time'] >= $time) {//小于1个月过期不显示 + $transports[] = $value; + } + } + } + $cache->save($this->cacheKeyTransports, $transports); + $transports && $transports = array_reverse($transports);//倒序 + $this->data['transports'] = $transports;//常用运输人员 + $this->data['showInfo'] = $showInfo; + $this->data['info'] = $info; + $this->data['edit_url'] = '/items/transfer/edit_info'; + $this->data['_title'] = '修改车辆调拨'; + return $this->show_view('items/transfer/get_add', true); + } + /** - * 新增物品 + * 新增/修改调拨 * @return bool */ public function add() { $info = $this->input->post('info'); + $takeCar = $this->input->post('takeCar'); if (!$info['arti_id']) { return $this->show_json(SYS_CODE_FAIL, '请选择随车物品'); } - if (!$info['out_uid']) { + if (!$takeCar[1]['uid'] && !$takeCar[1]['addr_id']) { return $this->show_json(SYS_CODE_FAIL, '请选择提车人'); } - if (!$info['in_uid']) { + if (!$takeCar[3]['uid'] && !$takeCar[3]['addr_id']) { return $this->show_json(SYS_CODE_FAIL, '请选择接车人'); } $trailer_fees = intval($info['trailer_fees']); - if (!$trailer_fees) { - return $this->show_json(SYS_CODE_FAIL, '请输入运输费用'); + if ($trailer_fees) { + if (!$info['fees_city']) { + return $this->show_json(SYS_CODE_FAIL, '请选择费用承担城市'); + } + if ($info['fees_type'] == 1 && !$info['fees_biz_id']) { + return $this->show_json(SYS_CODE_FAIL, '请选择费用承担门店'); + } } if (!$info['transport']['name'] || !$info['transport']['mobile'] || !$info['transport']['cardid']) { return $this->show_json(SYS_CODE_FAIL, '请输入运输人员姓名/电话/身份证号'); @@ -269,44 +504,57 @@ class Transfer extends HD_Controller if ($re) { return $this->show_json(SYS_CODE_FAIL, '添加失败,车辆正在调拨中...'); } - $re_user = $this->mdUsers->get(array('id' => $info['in_uid']));//查找用户负责门店 - $biz_id = $re_user['biz_id'] ? $re_user['biz_id'] : 0; - $jsondata['transport'] = $info['transport']; + $jsondata['transport'] = $info['transport'];//运输人员 + $jsondata['reason'] = $info['reason'];//调拨理由 $c_time = time(); + if ($takeCar[3]['type'] == 2) {//接收信息员 + $biz_id = -1; + $addr_id = $takeCar[3]['addr_id']; + } else {//接收门店 + $biz_id = $takeCar[3]['biz_id']; + $addr_id = 0; + } + $info['fees_biz_id'] = $info['fees_type'] == 1 ? intval($info['fees_biz_id']) : 0; + if ($info['status'] == -1) {//保存临时调拨人 + $json_takeCar = []; + foreach ($takeCar as $key => $value) { + if ($key) { + if ($key == 2 || $key == 4) { + $info['out_bak'] == 1 && $json_takeCar[$key] = $value; + $info['in_bak'] == 1 && $json_takeCar[$key] = $value; + } else { + $json_takeCar[$key] = $value; + } + } + } + $jsondata['take_car'] = $json_takeCar; + } else { + if ($info['id']) { + unset($jsondata['take_car']);//删除临时调拨人 + } + } $add = [ 'item_id' => $info['item_id'], 'biz_id' => $biz_id, + 'addr_id' => $addr_id, 'arti_id' => $info['arti_id'] ? implode(',', $info['arti_id']) : '', 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE), 'trailer_fees' => $trailer_fees, + 'fees_type' => intval($info['fees_type']), 'fees_city' => intval($info['fees_city']), - 'fees_type' => $info['fees_type'], - 'c_time' => $c_time, + 'fees_biz_id' => $info['fees_biz_id'], + 'out_type' => $takeCar[1]['type'], + 'in_type' => $takeCar[3]['type'], + 'status' => intval($info['status']) ]; - $id = $this->mdTransfer->add($add); - if (!$id) { - return $this->show_json(SYS_CODE_FAIL, '添加失败'); - } - //车辆调拨提醒 - $send_uids[] = $info['out_uid']; - $addRemind[] = ['tran_id' => $id, 'uid' => $info['out_uid'], 'type' => 1, 'status' => 1, 'c_time' => $c_time];//提车人 - if ($info['out_uid_bak']) { - $addRemind[] = ['tran_id' => $id, 'uid' => $info['out_uid_bak'], 'type' => 2, 'status' => 1, 'c_time' => $c_time];//备用提车人 - $send_uids[] = $info['out_uid_bak']; - } - $addRemind[] = ['tran_id' => $id, 'uid' => $info['in_uid'], 'type' => 3, 'status' => 0, 'c_time' => $c_time];//接车人 - $info['in_uid_bak'] && $addRemind[] = ['tran_id' => $id, 'uid' => $info['in_uid_bak'], 'type' => 4, 'status' => 0, 'c_time' => $c_time];//备用接车人 - $this->mdTransferRemind->add_batch($addRemind); - //调拨短信提醒 - if ($send_uids) { - $item_info = $this->input->post('items_info'); - $uids_str = implode(',', $send_uids); - $res_u = $this->mdUsers->select(["id in({$uids_str})" => null], 'id desc', 0, 0, 'mobile'); - foreach ($res_u as $key => $value) { - $car = $item_info['title']; - $item_info['cor'] && $car .= '-' . $item_info['cor']; - send_alisms(array('mobile' => $value['mobile'], 'template' => 'SMS_229648438' - , 'param' => ['car' => $car, 'vin' => $item_info['vin']])); + if ($info['id']) { + $id = $info['id']; + $this->mdTransfer->update($add, ['id' => $id]); + } else { + $add['c_time'] = $c_time; + $id = $this->mdTransfer->add($add); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '添加失败'); } } //常用运输人员 @@ -324,15 +572,158 @@ class Transfer extends HD_Controller $cache_transports[] = $info['transport']; } $cache->save($this->cacheKeyTransports, $cache_transports); - return $this->show_json(SYS_CODE_SUCCESS, '添加成功'); + if ($info['status'] == -1) { + return $this->show_json(SYS_CODE_SUCCESS, '保存成功', "/items/transfer"); + } + //提车人操作 + $send_uids = $send_admins = $addRemind = $addAdmin = []; + //提车人 + if ($takeCar[1]['type'] == 2) { + $send_admins[] = $takeCar[1]['admin_id']; + $addAdmin[] = ['tran_id' => $id, 'uid' => $takeCar[1]['admin_id'], 'type' => 1, 'addr_id' => $takeCar[1]['addr_id'], 'status' => 1, 'c_time' => $c_time]; + } else { + $send_uids[] = $takeCar[1]['uid']; + $addRemind[] = ['tran_id' => $id, 'uid' => $takeCar[1]['uid'], 'type' => 1, 'biz_id' => $takeCar[1]['biz_id'], 'status' => 1, 'c_time' => $c_time]; + } + //备用提车人 + if ($info['out_bak'] == 1) { + if ($takeCar[2]['type'] == 2) { + $send_admins[] = $takeCar[2]['admin_id']; + $addAdmin[] = ['tran_id' => $id, 'uid' => $takeCar[2]['admin_id'], 'type' => 2, 'addr_id' => $takeCar[2]['addr_id'], 'status' => 1, 'c_time' => $c_time]; + } else { + $send_uids[] = $takeCar[2]['uid']; + $addRemind[] = ['tran_id' => $id, 'uid' => $takeCar[2]['uid'], 'type' => 2, 'biz_id' => $takeCar[2]['biz_id'], 'status' => 1, 'c_time' => $c_time]; + } + } + //接车人 + if ($takeCar[3]['type'] == 2) { + $addAdmin[] = ['tran_id' => $id, 'uid' => $takeCar[3]['admin_id'], 'type' => 3, 'addr_id' => $takeCar[3]['addr_id'], 'status' => 0, 'c_time' => $c_time]; + } else { + $addRemind[] = ['tran_id' => $id, 'uid' => $takeCar[3]['uid'], 'type' => 3, 'biz_id' => $takeCar[3]['biz_id'], 'status' => 0, 'c_time' => $c_time]; + } + //备用接车人 + if ($info['in_bak'] == 1) { + if ($takeCar[4]['type'] == 2) { + $addAdmin[] = ['tran_id' => $id, 'uid' => $takeCar[4]['admin_id'], 'type' => 4, 'addr_id' => $takeCar[4]['addr_id'], 'status' => 0, 'c_time' => $c_time]; + } else { + $addRemind[] = ['tran_id' => $id, 'uid' => $takeCar[4]['uid'], 'type' => 4, 'biz_id' => $takeCar[4]['biz_id'], 'status' => 0, 'c_time' => $c_time]; + } + } + if ($addRemind) { + $this->mdTransferRemind->add_batch($addRemind); + } + if ($addAdmin) { + $this->mdTransferAdmin->add_batch($addAdmin); + } + $item_info = $this->input->post('items_info'); + //门店调拨短信提醒 + $this->send_alisms(['uids' => $send_uids, 'type' => 1, 'item_info' => $item_info]); + //信息员调拨短信提醒 + $this->send_alisms(['uids' => $send_admins, 'type' => 2, 'item_info' => $item_info]); + return $this->show_json(SYS_CODE_SUCCESS, '提交成功', "/items/transfer"); } + /** - * 编辑 + * Notes:确认调拨 + * Created on: 2021/12/17 15:52 + * Created by: dengbw * @return bool */ public function edit() { + $opt_btn = $this->input->post('opt_btn'); + $abnormal = $this->input->post('abnormal'); + $transport = $this->input->post('transport'); + if (!$opt_btn['type']) { + return $this->show_json(SYS_CODE_FAIL, '确认失败'); + } + $tran_id = $opt_btn['tran_id']; + $re_tr = $this->mdTransfer->get(['id' => $tran_id]); + $item_id = intval($re_tr['item_id']); + if (!$re_tr) { + return $this->show_json(ERR_PARAMS_ERROR, '数据不存在'); + } + //更新异常 + $jsondata = $re_tr['jsondata'] ? json_decode($re_tr['jsondata'], true) : []; + $jsondata['abnormal']['note'] = $abnormal['note'] ? $abnormal['note'] : ''; + $abnor_imgs = ''; + if ($abnormal['imgs']) { + foreach ($abnormal['imgs'] as $key => $value) { + $abnor_imgs[] = $value['value']; + } + } + $jsondata['abnormal']['imgs'] = $abnor_imgs; + //运输单号 + $tran_imgs = ''; + if ($transport['imgs']) { + foreach ($transport['imgs'] as $key => $value) { + $tran_imgs[] = $value['value']; + } + } + $transport_json = $jsondata['transport'] ? $jsondata['transport'] : []; + $transport_json['imgs'] = $tran_imgs; + $jsondata['transport'] = $transport_json; + $this->mdTransfer->update(['abnormal' => 1, 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)], ['id' => $tran_id]); + $ret = ''; + if ($opt_btn['type'] == 1) {//确认发车 + $ret = $this->mdTransferAdmin->update(['status' => 2], ['tran_id' => $tran_id, 'type in(1,2)' => null]);//信息员已完成 + if ($ret) { + $this->mdTransferRemind->update(['status' => 2], ['tran_id' => $tran_id, 'type in(1,2)' => null]);//门店已完成 + $this->mdTransferAdmin->update(['status' => 1], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//信息员显示 + $this->mdTransferRemind->update(['status' => 1], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//门店显示 + //更新车辆调拨 + $this->mdTransfer->update(['status' => 1, 'out_type' => 2, 'out_uid' => $this->uid + , 'out_time' => date("Y-m-d H:i:s")], ['id' => $tran_id]); + //调拨接车人短信提醒 + $res_r = $this->mdTransferRemind->select(['status' => 1, 'tran_id' => $tran_id, 'type in(3,4)' => null], 'type asc', 0, 0, 'uid'); + $res_a = $this->mdTransferAdmin->select(['status' => 1, 'tran_id' => $tran_id, 'type in(3,4)' => null], 'type asc', 0, 0, 'uid'); + $item_info = $this->item_info($re_tr['item_id'], 1); + if ($res_r) {//门店调拨短信提醒 + $send_uids = array_unique(array_column($res_r, 'uid')); + $this->send_alisms(['uids' => $send_uids, 'type' => 1, 'item_info' => $item_info]); + } + if ($res_a) {//信息员调拨短信提醒 + $send_admins = array_unique(array_column($res_a, 'uid')); + $this->send_alisms(['uids' => $send_admins, 'type' => 2, 'item_info' => $item_info]); + } + } + } else if ($opt_btn['type'] == 2) {//确认接车 + $ret = $this->mdTransferAdmin->update(['status' => 2], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//信息员已完成 + if ($ret) { + $addr_id = $opt_btn['addr_id']; + $this->mdTransferRemind->update(['status' => 2], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//门店已完成 + //更新车辆调拨 + $this->mdTransfer->update(['status' => 2, 'in_type' => 2, 'in_uid' => $this->uid, 'addr_id' => $addr_id, 'biz_id' => -1 + , 'in_time' => date("Y-m-d H:i:s")], ['id' => $tran_id]); + //更新车辆存放地 + $re_items = $this->mdItems->get(['id' => $item_id]); + $com_time = date('Y-m-d H:i:s'); + $ret_i = $this->mdItems->update(['biz_id' => -1, 'addr_id' => $addr_id], ['id' => $item_id]); + //添加车辆存放日志 + if ($ret_i) { + $this->load->library('entity/items_entity'); + if ($re_items['biz_id'] > 0) {//门店转地址变化 + if ($addr_id) { + $params = array('item_id' => $item_id, 'type' => 2, 'uid' => $this->uid, 'uname' => $this->username + , 'com_time' => $com_time, 'biz_id' => $re_items['biz_id'], 'addr_id_to' => $addr_id); + $this->items_entity->add_log($params); + } + } else if ($re_items['biz_id'] == -1) {//地址间变化 + if ($re_items['addr_id'] != $addr_id) { + $params = array('item_id' => $item_id, 'type' => 2, 'uid' => $this->uid, 'uname' => $this->username + , 'com_time' => $com_time, 'biz_id' => -1, 'addr_id' => $re_items['addr_id'], 'addr_id_to' => $addr_id); + $this->items_entity->add_log($params); + } + } + } + } + } + if ($ret) { + return $this->show_json(SYS_CODE_SUCCESS, '确认成功'); + } else { + return $this->show_json(SYS_CODE_FAIL, '确认失败'); + } } public function del() @@ -361,6 +752,12 @@ class Transfer extends HD_Controller $temp['in_uid_title'] = $value['in_uid_title']; $temp['abnormal'] = $value['abnormal']; $temp['status_name'] = $value['status_name']; + $temp['city'] = $value['city']; + $temp['county'] = $value['county']; + $temp['biz_name'] = $value['biz_name']; + $temp['trailer_fees'] = $value['trailer_fees']; + $temp['fees'] = $value['fees']; + $temp['reason'] = $value['reason']; $data[] = $temp; } $indexs = [ @@ -368,10 +765,16 @@ class Transfer extends HD_Controller 'vin' => '车架号', 'transport_name' => '运输人员', 'c_time' => '调拨时间', - 'out_uid_title' => '提车人/提车时间', - "in_uid_title" => "接车人/接车时间", - "abnormal" => "是否异常", + 'out_uid_title' => '提车人', + "in_uid_title" => "接车人", + "abnormal" => "异常", "status_name" => "状态", + "city" => "城市", + "county" => "区域", + "biz_name" => "店名", + "trailer_fees" => "运输费用", + "fees" => "费用承担方", + "reason" => "调拔理由", ]; array_unshift($data, $indexs); $this->load->library('excel'); @@ -427,4 +830,72 @@ class Transfer extends HD_Controller } return $info; } + + /** + * Notes:提车/接车人信息 + * Created on: 2021/12/23 10:11 + * Created by: dengbw + * @param $params + * @param int $type + * @return string + */ + private function take_car($params, $type = 1) + { + $content = $city_name = $title = ''; + $titleAry = [1 => '提车人', 2 => '  备用提车人', 3 => '接车人', 4 => '  备用接车人']; + if ($type == 1) {//门店 + $re_user = $this->mdUsers->get(array('id' => $params['uid'])); + $re_biz = $this->mdBiz->get(array('id' => $params['biz_id'])); + if ($re_biz['county_id']) { + $re_area = $this->mdArea->get(array('county_id' => $re_biz['county_id'])); + $city_name = $re_area['city_name'] . '  ' . $re_area['county_name']; + } else if ($re_biz['city_id']) { + $re_area = $this->mdArea->get(array('city_id' => $re_biz['city_id'])); + $city_name = $re_area['city_name']; + } + $content = $titleAry[$params['type']] . "({$re_user['uname']}  {$re_user['mobile']}  {$city_name}  {$re_biz['biz_name']})"; + } else if ($type == 2) { + $re_admin = $this->mdSysAdmin->get(array('id' => $params['uid'])); + $re_addr = $this->mdAddr->get(array('id' => $params['addr_id'])); + $city_name = ''; + if ($re_addr) { + $city_name = $re_addr['city_name'] . '  ' . $re_addr['county_name'] . '  ' . $re_addr['title']; + } + $content = $titleAry[$params['type']] . "({$re_admin['username']}  {$re_admin['mobile']}  {$city_name})"; + } + return $content; + } + + /** + * Notes:短信提醒 + * Created on: 2021/12/23 10:42 + * Created by: dengbw + * @param array $params + */ + private function send_alisms($params = []) + { + $uids = $params['uids']; + $type = $params['type']; + + $item_info = $params['item_info']; + $car = $item_info['title']; + $item_info['cor'] && $car .= '-' . $item_info['cor']; + if ($uids && (count($uids) > 0)) { + if ($type == 1) { //门店调拨短信提醒 + $uids_str = implode(',', $uids); + $res_u = $this->mdUsers->select(["id in({$uids_str})" => null], 'id desc', 0, 0, 'mobile'); + foreach ($res_u as $key => $value) { + send_alisms(array('mobile' => $value['mobile'], 'template' => 'SMS_230960539' + , 'param' => ['car' => $car, 'vin' => $item_info['vin']])); + } + } else if ($type == 2) { //信息员调拨短信提醒 + $uids_str = implode(',', $uids); + $res_u = $this->mdSysAdmin->select(["id in({$uids_str})" => null], 'id desc', 0, 0, 'mobile'); + foreach ($res_u as $key => $value) { + send_alisms(array('mobile' => $value['mobile'], 'template' => 'SMS_231435509' + , 'param' => ['car' => $car, 'vin' => $item_info['vin']])); + } + } + } + } } \ No newline at end of file diff --git a/admin/views/items/goods/lists.php b/admin/views/items/goods/lists.php index 8a0e61ee..98759a30 100644 --- a/admin/views/items/goods/lists.php +++ b/admin/views/items/goods/lists.php @@ -226,6 +226,9 @@ {{v.auto_fine}} {{v.company_name}} 调拨 + 轨迹 调拨信息
$value) { ?> -
- -
- - -
- + +
+ + +
+
- -
- -
- -
- +
+
+ +
+
+ +
+ +
+ + +
+
+
+
+ + + + +
+
+
+ +
+ +
+
+
+ {{opt_btn.title}} +