428 lines
20 KiB
PHP
428 lines
20 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:车辆调拨
|
|
* Created on: 2021/12/6 16:43
|
|
* Created by: dengbw
|
|
*/
|
|
class Transfer extends HD_Controller
|
|
{
|
|
private $cacheKeyTransports = 'admin_transports';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('items/items_transfer_model', 'mdTransfer');
|
|
$this->load->model('items/items_transfer_remind_model', 'mdTransferRemind');
|
|
$this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
|
|
$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("sys/sys_addr_model", 'mdAddr');
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
$this->load->model('area_model', 'mdArea');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
$this->load->model('auto/auto_brand_model', 'mdAutoBrand');
|
|
$this->load->model('auto/auto_series_model', 'mdAutoSeries');
|
|
$this->load->model('auto/auto_attr_model', 'mdAutoAttr');
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$re = $this->dataSelect($params);
|
|
$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');
|
|
}
|
|
$total = $re['total'];
|
|
$this->data['params'] = $re['params'];
|
|
$this->data['lists'] = $re['lists'];
|
|
$this->data['statusAry'] = $this->mdTransfer->statusAry();
|
|
$this->data['abnormalAry'] = $this->mdTransfer->abnormalAry();
|
|
$this->data['autoList'] = $autoList;
|
|
$this->data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total);
|
|
$this->data['_title'] = '车辆调拨';
|
|
$this->show_view('items/transfer/lists', true);
|
|
}
|
|
|
|
private function dataSelect($params)
|
|
{
|
|
$statusAry = $this->mdTransfer->statusAry();
|
|
$where = ['status<>' => -1];
|
|
if (strlen($params['status'])) {
|
|
$where['status'] = $params['status'];
|
|
} else {
|
|
$params['status'] = '';
|
|
}
|
|
if (strlen($params['abnormal'])) {
|
|
$where['abnormal'] = $params['abnormal'];
|
|
} else {
|
|
$params['abnormal'] = '';
|
|
}
|
|
if ($params['out_uid']) {
|
|
$where['out_uid'] = $params['out_uid'];
|
|
} 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['in_uid']) {
|
|
$where['in_uid'] = $params['in_uid'];
|
|
} 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['title']) {
|
|
$where["item_id in (select id from lc_items where vin like '%{$params['title']}%')"] = null;
|
|
}
|
|
if ($params['brand_id'] || $params['s_id'] || $params['v_id']) {
|
|
$where_items = "brand_id = {$params['brand_id']}";
|
|
$params['s_id'] && $where_items .= " and s_id = {$params['s_id']}";
|
|
$params['v_id'] && $where_items .= " and v_id = {$params['v_id']}";
|
|
$where["item_id in (select id from lc_items where $where_items)"] = null;
|
|
}
|
|
if ($params['out_time']) {
|
|
$out_time = explode(' ~ ', $params['out_time']);
|
|
$out_time[0] && $where["out_time >="] = $out_time[0] . ' 00:00:00';
|
|
$out_time[1] && $where["out_time <="] = $out_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['in_time']) {
|
|
$in_time = explode(' ~ ', $params['in_time']);
|
|
$in_time[0] && $where["in_time >="] = $in_time[0] . ' 00:00:00';
|
|
$in_time[1] && $where["in_time <="] = $in_time[1] . ' 23:59:59';
|
|
}
|
|
$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'));
|
|
$uids_arr = array_merge($out_uids, $in_uids);
|
|
$uids = $this->mdUsers->get_map_by_ids($uids_arr, 'id,uname');
|
|
foreach ($rows as $v) {
|
|
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
|
|
$item_info = $this->item_info($v['item_id'], 1);
|
|
$lists[] = array(
|
|
'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'])) : '-',
|
|
'transport_name' => $jsondata['transport']['name'],
|
|
'abnormal' => $this->mdTransfer->abnormalAry($v['abnormal']),
|
|
'c_time' => date('Y.m.d H:i', $v['c_time']),
|
|
'status_name' => $statusAry[$v['status']],
|
|
);
|
|
}
|
|
}
|
|
$data['lists'] = $lists;
|
|
$data['params'] = $params;
|
|
$data['total'] = $total;
|
|
return $data;
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
$id = $this->input->get('id');
|
|
$info = [];
|
|
if ($id) {
|
|
$re = $this->mdTransfer->get(array('id' => $id, 'status <>' => -1));
|
|
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 = $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'];
|
|
}
|
|
$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' => $jsondata['transport']['name'] . ' ' .
|
|
$jsondata['transport']['mobile'] . ' 身份证:' . $jsondata['transport']['cardid']];
|
|
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')));
|
|
}
|
|
$fields[] = ['title' => '随身物品', 'value' => $arti_content];
|
|
$fields[] = ['title' => '车辆异常', 'value' => $this->mdTransfer->abnormalAry()[$re['abnormal']]];
|
|
if ($re['abnormal'] && $jsondata['abnormal']) {
|
|
$abnormal = $jsondata['abnormal'];
|
|
foreach ($abnormal['imgs'] as $key => $value) {
|
|
$abnormal['imgs'][$key] = $value ? build_qiniu_image_url($value) : '';
|
|
}
|
|
}
|
|
$this->data['fields'] = $fields;
|
|
$this->data['abnormal'] = $abnormal;
|
|
$title = '车辆调拨详情';
|
|
$view = 'items/transfer/get';
|
|
} else {
|
|
$title = '新增车辆调拨';
|
|
$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' => '']];
|
|
//常用运输人员
|
|
$cache = &load_cache('redis');
|
|
$cache_transports = $cache->get($this->cacheKeyTransports);
|
|
$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['_title'] = $title;
|
|
return $this->show_view($view, true);
|
|
}
|
|
|
|
/**
|
|
* 新增物品
|
|
* @return bool
|
|
*/
|
|
public function add()
|
|
{
|
|
$info = $this->input->post('info');
|
|
if (!$info['arti_id']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请选择随车物品');
|
|
}
|
|
if (!$info['out_uid']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请选择提车人');
|
|
}
|
|
if (!$info['in_uid']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请选择接车人');
|
|
}
|
|
$trailer_fees = intval($info['trailer_fees']);
|
|
if (!$trailer_fees) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入运输费用');
|
|
}
|
|
if (!$info['transport']['name'] || !$info['transport']['mobile'] || !$info['transport']['cardid']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入运输人员姓名/电话/身份证号');
|
|
}
|
|
$re = $this->mdTransfer->get(['item_id' => $info['item_id'], 'status in(0,1)' => null]);
|
|
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'];
|
|
$c_time = time();
|
|
$add = [
|
|
'item_id' => $info['item_id'],
|
|
'biz_id' => $biz_id,
|
|
'arti_id' => $info['arti_id'] ? implode(',', $info['arti_id']) : '',
|
|
'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
|
|
'trailer_fees' => $trailer_fees,
|
|
'fees_city' => intval($info['fees_city']),
|
|
'fees_type' => $info['fees_type'],
|
|
'c_time' => $c_time,
|
|
];
|
|
$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']]));
|
|
}
|
|
}
|
|
//常用运输人员
|
|
$cache = &load_cache('redis');
|
|
$cache_transports = $cache->get($this->cacheKeyTransports);
|
|
$addTransports = true;
|
|
foreach ($cache_transports as $key => $value) {
|
|
if ($value['mobile'] == $info['transport']['mobile']) {
|
|
$value['time'] = date('Y-m-d');
|
|
$addTransports = false;
|
|
}
|
|
}
|
|
if ($addTransports) {
|
|
$info['transport']['time'] = date('Y-m-d');
|
|
$cache_transports[] = $info['transport'];
|
|
}
|
|
$cache->save($this->cacheKeyTransports, $cache_transports);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
* @return bool
|
|
*/
|
|
public function edit()
|
|
{
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
}
|
|
|
|
public function batch()
|
|
{
|
|
// TODO: Implement batch() method.
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = 1;
|
|
$params['size'] = 10000;
|
|
$data = $indexs = array();
|
|
$res = $this->dataSelect($params);
|
|
$fileName = "车辆调拨";
|
|
foreach ($res['lists'] as $key => $value) {
|
|
$temp['title'] = $value['title'];
|
|
$temp['vin'] = $value['vin'];
|
|
$temp['transport_name'] = $value['transport_name'];
|
|
$temp['c_time'] = $value['c_time'];
|
|
$temp['out_uid_title'] = $value['out_uid_title'];
|
|
$temp['in_uid_title'] = $value['in_uid_title'];
|
|
$temp['abnormal'] = $value['abnormal'];
|
|
$temp['status_name'] = $value['status_name'];
|
|
$data[] = $temp;
|
|
}
|
|
$indexs = [
|
|
'title' => '车辆',
|
|
'vin' => '车架号',
|
|
'transport_name' => '运输人员',
|
|
'c_time' => '调拨时间',
|
|
'out_uid_title' => '提车人/提车时间',
|
|
"in_uid_title" => "接车人/接车时间",
|
|
"abnormal" => "是否异常",
|
|
"status_name" => "状态",
|
|
];
|
|
array_unshift($data, $indexs);
|
|
$this->load->library('excel');
|
|
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
|
|
}
|
|
|
|
/**
|
|
* 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, $type = 0)
|
|
{
|
|
$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');
|
|
$title = '';
|
|
$re_b['name'] && $title = $re_b['name'];
|
|
$re_s['name'] && $title = $title ? $title . '-' . $re_s['name'] : $re_s['name'];
|
|
$re_v['title'] && $title = $title ? $title . '-' . $re_v['title'] : $re_v['title'];
|
|
if ($type == 1) {
|
|
$re_cor['title'] && $title = $title ? $title . '-' . $re_cor['title'] : $re_cor['title'];
|
|
}
|
|
$info['title'] = $title;
|
|
$info['vin'] = $re['vin'];
|
|
if ($type == 0) {
|
|
$info['id'] = $re['id'];
|
|
$info['cor'] = $re_cor['title'] ? $re_cor['title'] : '';
|
|
$address = '';
|
|
if ($re['biz_id'] > 0) {
|
|
$re_biz = $this->mdBiz->get(array('id' => $re['biz_id']));
|
|
$re_biz && $address = $re_biz['biz_name'];
|
|
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}";
|
|
}
|
|
} else if ($re['biz_id'] == -1 && $re['addr_id']) {
|
|
$row_addr = $this->mdAddr->get(array('id' => $re['addr_id']));
|
|
$row_addr && $address = "{$row_addr['city_name']} {$row_addr['county_name']} 其它 {$row_addr['title']}";
|
|
}
|
|
$info['address'] = $address;
|
|
}
|
|
return $info;
|
|
}
|
|
} |