Files
liche/admin/controllers/items/Transfer.php
T
2023-02-02 14:44:53 +08:00

1282 lines
64 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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('items/items_transfer_admin_model', 'mdTransferAdmin');
$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');
$this->load->model('sys/Sys_admin_model', 'mdSysAdmin');
}
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;
$re = $this->dataSelect($params);
//$autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name');
$autoList[1] = $this->mdAutoBrand->map_brand(array('status > -1' => null), false);
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('status' => 1, '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['showInfo'] = ['uidTypeAry' => $this->mdTransfer->uidTypeAry(), 'takeCar' => $re['takeCar'], 'trailerFeesAry' => [1 => '有', 2 => '无']];
$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 = [];
if (strlen($params['status'])) {
$where['status'] = $params['status'];
} else {
$params['status'] = '';
}
if (strlen($params['abnormal'])) {
$where['abnormal'] = $params['abnormal'];
} else {
$params['abnormal'] = '';
}
if ($params['trailer_fees']) {
if ($params['trailer_fees'] == 1) {
$where['trailer_fees >'] = 0;
} else {
$where['trailer_fees'] = 0;
}
} else {
$params['trailer_fees'] = '';
}
!$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;
if ($params['out_type'] == 2) {
$params['out_admin_id'] && $where['out_uid'] = $params['out_admin_id'];
if ($params['out_addr_id']) {
$where["id in (select distinct(tran_id) from lc_items_transfer_admin where type in(1,2) and addr_id={$params['out_addr_id']})"] = null;
} else {
$params['out_addr_id'] = '';
}
} else {
if ($params['out_uid']) {
$where['out_uid'] = $params['out_uid'];
} else if ($params['out_biz_id']) {
$where["id in (select distinct(tran_id) from lc_items_transfer_remind where type in(1,2) and biz_id={$params['out_biz_id']})"] = null;
} else {
$params['out_uid'] = '';
}
}
$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' => []];
!$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;
if ($params['in_type'] == 2) {
$params['in_admin_id'] && $where['in_uid'] = $params['in_admin_id'];
if ($params['in_addr_id']) {
$where['addr_id'] = $params['in_addr_id'];
} else {
$params['in_addr_id'] = '';
}
} else {
if ($params['in_uid']) {
$where['in_uid'] = $params['in_uid'];
} else if ($params['in_biz_id']) {
$where['biz_id'] = $params['in_biz_id'];
} else {
$params['in_uid'] = '';
}
}
$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;
}
if ($params['admin_name']) {
$where["admin_id in (select id from lc_sys_admin where username like '%{$params['admin_name']}%')"] = 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';
}
if ($params['c_time']) {
$c_time = explode(' ~ ', $params['c_time']);
$c_time[0] && $where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
$c_time[1] && $where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
}
$where['item_id in (select id from lc_items where brand_id in (select id from lc_auto_brand where status > -1))'] = null;
$total = $this->mdTransfer->count($where);
$lists = array();
if ($total) {
$rows = $this->mdTransfer->select($where, 'id desc', $params['page'], $params['size']);
$out_uids = $in_uids = $out_uids_ad = $in_uids_ad = $admin_ids = $map_admin = [];
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'];
}
}
$v2['admin_id'] && $admin_ids[] = $v2['admin_id'];//调拨人员id
}
$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');
if ($admin_ids) {
$str_admin_ids = implode(',', array_unique($admin_ids));
$map_admin = $this->mdSysAdmin->map('id', 'username', ["id in({$str_admin_ids})" => null]);
}
foreach ($rows as $v) {
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
$item_info = $this->item_info($v['item_id'], 1);
$out_uid_title = $in_uid_title = $transport_name = '-';
$tag = $params['size'] == 10000 ? '/' : '<br>';
$out_addr_name = $in_addr_name = '';
if ($v['out_uid']) {
$biz_id = $addr_id = 0;
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']));
$re_out = $this->mdTransferRemind->get(['tran_id' => $v['id'], 'uid' => $v['out_uid'], 'type in(1,2)']);
$biz_id = $re_out['biz_id'];
} 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']));
$re_out = $this->mdTransferAdmin->get(['tran_id' => $v['id'], 'uid' => $v['out_uid'], 'type in(1,2)']);
$addr_id = $re_out['addr_id'];
}
$out_addr_name = $this->take_biz(['uid' => $v['out_uid'], 'biz_id' => $biz_id, 'addr_id' => $addr_id], $v['out_type']);
}
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']));
}
$in_addr_name = $this->take_biz(['uid' => $v['in_uid'], 'biz_id' => $v['biz_id'], 'addr_id' => $v['addr_id']], $v['in_type']);
}
$jsondata['transport']['name'] && $transport_name = $jsondata['transport']['name'];
$admin_name = $v['admin_id'] ? $map_admin[$v['admin_id']] : '-';
$setValue = [
'id' => $v['id'],
'title' => $item_info['title'],
'vin' => $item_info['vin'],
'out_uid_title' => $out_uid_title,
'in_uid_title' => $in_uid_title,
'transport_name' => $transport_name,
'trailer_fees' => $v['trailer_fees'],
'abnormal' => $this->mdTransfer->abnormalAry($v['abnormal']),
'admin_name' => $admin_name,
'c_time' => date('Y.m.d H:i', $v['c_time']),
'status' => $v['status'],
'status_name' => $statusAry[$v['status']],
'out_addr_name' => $out_addr_name,
'in_addr_name' => $in_addr_name,
];
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['fees'] = $trailer_fees;
$setValue['reason'] = $jsondata['reason'] ? $jsondata['reason'] : '';
}
$lists[] = $setValue;
}
}
$data['lists'] = $lists;
$data['params'] = $params;
$data['takeCar'] = $takeCar;
$data['total'] = $total;
return $data;
}
public function get()
{
$id = intval($this->input->get('id'));
$info = [];
if ($id) {
$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']);
$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;
}
}
}
//信息员
$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']];
}
}
}
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$admin_name = date('Y-m-d H:i:s', $re['c_time']);
if ($re['admin_id']) {
$re_admin = $this->mdSysAdmin->get(array('id' => $re['admin_id']));
$re_admin && $admin_name = $re_admin['username'] . '&nbsp;&nbsp;&nbsp;' . $admin_name;
}
$fields[] = ['title' => '调拨信息', 'value' => $admin_name];
$fields[] = ['title' => '提车信息', 'value' => $out_content . $out_content_bak];
$fields[] = ['title' => '接车信息', 'value' => $in_content . $in_content_bak];
$fields[] = ['title' => '运输人员', 'value' => $jsondata['transport']['name'] . '&nbsp;&nbsp;&nbsp;' .
$jsondata['transport']['mobile'] . '&nbsp;&nbsp;&nbsp;身份证:' . $jsondata['transport']['cardid']];
if ($jsondata['transport']) {
$transport = $jsondata['transport'];
$imgs = [];
$start_mileage = $end_mileage = ['value' => '', 'imgs' => []];
if ($transport['imgs']) {
foreach ($transport['imgs'] as $key => $value) {
$value && $imgs[] = ['src' => build_qiniu_image_url($value), 'value' => $value];
}
}
if ($transport['start_mileage']) {//发车里程数
$start_mileage = $transport['start_mileage'];
foreach ($start_mileage['imgs'] as $key => $value) {
$value && $start_mileage['imgs'][$key] = ['src' => build_qiniu_image_url($value), 'value' => $value];
}
}
if ($transport['end_mileage']) {//接车里程数
$end_mileage = $transport['end_mileage'];
foreach ($end_mileage['imgs'] as $key => $value) {
$value && $end_mileage['imgs'][$key] = ['src' => build_qiniu_image_url($value), 'value' => $value];
}
}
$transport['imgs'] = $imgs;
$transport['start_mileage'] = $start_mileage;
$transport['end_mileage'] = $end_mileage;
}
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(' &nbsp;&nbsp;', 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'];
$imgs = [];
if ($abnormal['imgs']) {
foreach ($abnormal['imgs'] as $key => $value) {
$value && $imgs[] = ['src' => build_qiniu_image_url($value), 'value' => $value];
}
}
$abnormal['imgs'] = $imgs;
}
$jsondata['reason'] && $fields[] = ['title' => '调拨理由', 'value' => $jsondata['reason']];
if ($re['trailer_fees']) {
$trailer_fees = $re['trailer_fees'] ? $re['trailer_fees'] . '元' : '';
$trailer_fees .= '&nbsp;&nbsp;费用承担人:' . $this->mdTransfer->feesTypeAry($re['fees_type']);
if ($re['fees_city']) {
$re_area = $this->mdArea->get(array('city_id' => $re['fees_city']));
$trailer_fees .= '&nbsp;&nbsp;' . $re_area['city_name'];
}
if ($re['fees_type'] != 2 && $re['fees_biz_id']) {
$re_biz = $this->mdBiz->get(array('id' => $re['fees_biz_id']));
$trailer_fees .= '&nbsp;&nbsp;' . $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' => $vin, 'items_info' => ['id' => 0, 'title' => '', 'vin' => '', 'cor' => '', 'address' => ''],
'feesTypeAry' => $this->mdTransfer->feesTypeAry(), 'feesBizList' => [], 'uidTypeAry' => $this->mdTransfer->uidTypeAry()];
$info = ['id' => 0, 'status' => -1, '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' => ''];
$this->data['transports'] = $this->transports(['type' => 'get']);//运输人员
$this->data['showInfo'] = $showInfo;
}
$this->data['info'] = $info;
$this->data['_title'] = $title;
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, '车辆调拨不存在!');
}
// 2022.12.20 原来 确认接车 的状态 不能再修改调拨单,现在需要把这个限制去掉,所有状态都允许修改
/*if ($re['status'] == 2) {
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;
if ($re['status'] == 1) {//已提车显示信息
$out_content = $out_content_bak = '';
$res_r = $this->mdTransferRemind->select(['tran_id' => $id, 'type in(1,2)'], '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;
}
}
}
$res_a = $this->mdTransferAdmin->select(['tran_id' => $id, 'type in(1,2)'], '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) {
$out_content = $content;
} else if ($value['type'] == 2) {
$out_content_bak = $content;
}
}
}
$showInfo['out_content'] = $out_content . $out_content_bak;
}
$this->data['transports'] = $this->transports(['type' => 'get']);//运输人员
$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);
}
/**
* Notes:短信提醒
* Created on: 2022/1/5 10:05
* Created by: dengbw
* @return bool
*/
public function get_send_alisms()
{
$ids = $this->input->get('ids');
if (!$ids) {
return $this->show_json(SYS_CODE_FAIL, '请选择需要操作的数据!');
}
$res = $this->mdTransfer->select(["id in({$ids})" => null, 'status in(0,1)' => null], 'id desc', 0, 0, 'id,item_id');
foreach ($res as $key => $value) {
$res_r = $this->mdTransferRemind->select(['status' => 1, 'tran_id' => $value['id']], 'type asc', 0, 0, 'uid');
$res_a = $this->mdTransferAdmin->select(['status' => 1, 'tran_id' => $value['id']], 'type asc', 0, 0, 'uid');
$item_info = $this->item_info($value['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, 'tran_id' => $value['id']]);
}
if ($res_a) {//信息员调拨短信提醒
$send_admins = array_unique(array_column($res_a, 'uid'));
$this->send_alisms(['uids' => $send_admins, 'type' => 2, 'item_info' => $item_info]);
}
}
return $this->show_json(SYS_CODE_SUCCESS, '短信提醒成功');
}
/**
* 新增/修改调拨
* @return bool
*/
public function add()
{
$info = $this->input->post('info');
$takeCar = $this->input->post('takeCar');
$trailer_fees = intval($info['trailer_fees']);
$remind = $info['remind'];//1提交
$db_status = -1;
$db_status_not2_flag = true;
if ($info['id']) {//修改调拨
$re_t = $this->mdTransfer->get(array('id' => $info['id']));
if (!$re_t || empty($re_t)) {
return $this->show_json(SYS_CODE_FAIL, '车辆调拨不存在!');
}
$db_status = $re_t['status'];
if ($db_status == 2) {
$db_status_not2_flag = false; // 2022.12.20 “确认接车”状态的数据,修改提交后:不改状态,不发短信
#return $this->show_json(SYS_CODE_FAIL, '车辆已完成调拨,不能修改!');
}
}
if ($remind && $db_status == -1) {//提交且状态为-1时,状态设为0调拨
$db_status = 0;
}
!$db_status_not2_flag && $db_status = 2; // 2022.12.20 “确认接车”状态的数据,修改提交后:不改状态,不发短信
if ($remind == 1) {//提交时加判断
if (!$info['arti_id']) {
return $this->show_json(SYS_CODE_FAIL, '请选择随车物品');
}
if ($takeCar[1]['type'] == 2) {//提车信息员
if (!$takeCar[1]['admin_id']) {
return $this->show_json(SYS_CODE_FAIL, '请选择提车信息员');
}
if (!$takeCar[1]['addr_id']) {
return $this->show_json(SYS_CODE_FAIL, '请选择提车存放地');
}
} else {
if (!$takeCar[1]['uid']) {
return $this->show_json(SYS_CODE_FAIL, '请选择提车人');
}
}
if ($takeCar[3]['type'] == 2) {//接车信息员
if (!$takeCar[3]['admin_id']) {
return $this->show_json(SYS_CODE_FAIL, '请选择接车信息员');
}
if (!$takeCar[3]['addr_id']) {
return $this->show_json(SYS_CODE_FAIL, '请选择接车存放地');
}
} else {
if (!$takeCar[3]['uid']) {
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'] != 2 && !$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, '请输入运输人员姓名/电话/身份证号');
}
if (!$info['reason']) {
return $this->show_json(SYS_CODE_FAIL, '请输入调拨理由');
}
}
$re = $this->mdTransfer->get(['item_id' => $info['item_id'], 'status in(0,1)' => null]);
if ($re && $re['id'] != $info['id']) {
return $this->show_json(SYS_CODE_FAIL, '操作失败,车辆正在调拨中...');
}
$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'] != 2 ? intval($info['fees_biz_id']) : 0;
$json_takeCar = []; //保存临时调拨人
foreach ($takeCar as $key => $value) {
if ($key) {
if ($key == 2 || $key == 4) {
if ($key == 2 && $info['out_bak'] == 1) {
$json_takeCar[$key] = $value;
}
if ($key == 4 && $info['in_bak'] == 1) {
$json_takeCar[$key] = $value;
}
} else {
$json_takeCar[$key] = $value;
}
}
}
$jsondata['take_car'] = $json_takeCar;
$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_biz_id' => intval($info['fees_biz_id']),
'out_type' => $takeCar[1]['type'],
'in_type' => $takeCar[3]['type'],
'status' => $db_status
];
if ($info['id']) {
$id = $info['id'];
$this->mdTransfer->update($add, ['id' => $id]);
} else {
$add['admin_id'] = $this->uid;
$add['c_time'] = $c_time;
$id = $this->mdTransfer->add($add);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '添加失败');
}
}
//常用运输人员
$transport_name = $info['transport']['name'] ? trim($info['transport']['name']) : '';
$transport_mobile = $info['transport']['mobile'] ? trim($info['transport']['mobile']) : '';
$transport_cardid = $info['transport']['cardid'] ? trim($info['transport']['cardid']) : '';
$this->transports(['name' => $transport_name, 'mobile' => $transport_mobile, 'cardid' => $transport_cardid]);
if ($db_status == -1) {
return $this->show_json(SYS_CODE_SUCCESS, '保存成功', "/items/transfer");
}
//提车人操作
$send_uids = $send_admins = $addRemind = $addAdmin = [];
if ($info['id']) {//修改提车人/接车人
if ($db_status == 0) {//未提车,可修改提车人
//提车人
$results = $this->edit_remind_admin(['type' => 1, 'tran_id' => $id, 'c_time' => $c_time], $takeCar[1]);
if ($results['add'] == 1) {
if ($takeCar[1]['type'] == 2) {
$send_admins[] = $results['uid'];
$addAdmin[] = $results['addDate'];
} else {
$send_uids[] = $results['uid'];
$addRemind[] = $results['addDate'];
}
}
//备用提车人
if ($info['out_bak'] == 1) {
$results = $this->edit_remind_admin(['type' => 2, 'tran_id' => $id, 'c_time' => $c_time], $takeCar[2]);
if ($results['add'] == 1) {
if ($takeCar[2]['type'] == 2) {
$send_admins[] = $results['uid'];
$addAdmin[] = $results['addDate'];
} else {
$send_uids[] = $results['uid'];
$addRemind[] = $results['addDate'];
}
}
} else {
$this->mdTransferAdmin->delete(['tran_id' => $id, 'type' => 2]);//删除已有备用提车人
$this->mdTransferRemind->delete(['tran_id' => $id, 'type' => 2]);//删除已有备用提车人
}
}
// 2022.12.20 “确认接车”状态的数据,修改提交后:不改状态,不发短信
if ($db_status_not2_flag){
//接车人
$results = $this->edit_remind_admin(['type' => 3, 'tran_id' => $id, 'c_time' => $c_time, 'db_status' => $db_status], $takeCar[3]);
if ($results['add'] == 1) {
if ($takeCar[3]['type'] == 2) {
$results['uid'] && $send_admins[] = $results['uid'];
$addAdmin[] = $results['addDate'];
} else {
$results['uid'] && $send_uids[] = $results['uid'];
$addRemind[] = $results['addDate'];
}
}
//备用接车人
if ($info['in_bak'] == 1) {
$results = $this->edit_remind_admin(['type' => 4, 'tran_id' => $id, 'c_time' => $c_time, 'db_status' => $db_status], $takeCar[4]);
if ($results['add'] == 1) {
if ($takeCar[4]['type'] == 2) {
$results['uid'] && $send_admins[] = $results['uid'];
$addAdmin[] = $results['addDate'];
} else {
$results['uid'] && $send_uids[] = $results['uid'];
$addRemind[] = $results['addDate'];
}
}
} else {
$this->mdTransferAdmin->delete(['tran_id' => $id, 'type' => 4]);//删除已有备用接车人
$this->mdTransferRemind->delete(['tran_id' => $id, 'type' => 4]);//删除已有备用接车人
}
}
} else {//新增提车人/接车人
//提车人
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');
//门店调拨短信提醒
$db_status_not2_flag && $this->send_alisms(['uids' => $send_uids, 'type' => 1, 'item_info' => $item_info, 'tran_id' => $id]);
//信息员调拨短信提醒
$db_status_not2_flag && $this->send_alisms(['uids' => $send_admins, 'type' => 2, 'item_info' => $item_info]);
return $this->show_json(SYS_CODE_SUCCESS, '提交成功', "/items/transfer");
}
/**
* Notes:判断是否改动提车人或接车人
* Created on: 2022/1/26 17:58
* Created by: dengbw
* @param $params
* @param $takeCar
* @return array
*/
private function edit_remind_admin($params, $takeCar)
{
$add = $uid = $status = 0;
$addDate = [];
if ($takeCar['type'] == 2) {//信息员
$re = $this->mdTransferAdmin->get(['tran_id' => $params['tran_id'], 'uid' => $takeCar['admin_id']
, 'addr_id' => $takeCar['addr_id'], 'type' => $params['type']]);
if (!$re) {
$add = 1;
$this->mdTransferAdmin->delete(['tran_id' => $params['tran_id'], 'type' => $params['type']]);//删除已有
if ($params['type'] == 1 || $params['type'] == 2 || $params['db_status'] == 1) {
$uid = $takeCar['admin_id'];
$status = 1;
}
$addDate = ['tran_id' => $params['tran_id'], 'uid' => $takeCar['admin_id'], 'type' => $params['type']
, 'addr_id' => $takeCar['addr_id'], 'status' => $status, 'c_time' => $params['c_time']];
}
} else {//门店
$re = $this->mdTransferRemind->get(['tran_id' => $params['tran_id'], 'uid' => $takeCar['uid'], 'biz_id' => $takeCar['biz_id']
, 'type' => $params['type']]);
if (!$re) {
$add = 1;
$this->mdTransferRemind->delete(['tran_id' => $params['tran_id'], 'type' => $params['type']]);//删除已有
if ($params['type'] == 1 || $params['type'] == 2 || $params['db_status'] == 1) {
$uid = $takeCar['uid'];
$status = 1;
}
$addDate = ['tran_id' => $params['tran_id'], 'uid' => $takeCar['uid'], 'type' => $params['type']
, 'biz_id' => $takeCar['biz_id'], 'status' => $status, 'c_time' => $params['c_time']];
}
}
return ['add' => $add, 'uid' => $uid, 'addDate' => $addDate];
}
/**
* 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, '确认失败');
}
if ($opt_btn['type'] == 1) {
$start_mileage_value = myTrim($transport['start_mileage']['value']);
if (!$start_mileage_value) {
return $this->show_json(SYS_CODE_FAIL, '请输入发车里程数');
}
$transport['start_mileage']['value'] = $start_mileage_value;
if (!$transport['start_mileage']['imgs']) {
return $this->show_json(SYS_CODE_FAIL, '请上传发车仪表盘里程数照片');
}
} else if ($opt_btn['type'] == 2) {
$end_mileage_value = myTrim($transport['end_mileage']['value']);
if (!$end_mileage_value) {
return $this->show_json(SYS_CODE_FAIL, '请输入接车里程数');
}
$transport['end_mileage']['value'] = $end_mileage_value;
if (!$transport['end_mileage']['imgs']) {
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;
$set_abnormal = 0;
if ($jsondata['abnormal']['note'] || $jsondata['abnormal']['imgs']) {//有异常内容或图片
$set_abnormal = 1;
}
//运输单号
$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;
if ($opt_btn['type'] == 1) {//发车里程数
$start_mileage_imgs = '';
foreach ($transport['start_mileage']['imgs'] as $key => $value) {
$start_mileage_imgs[] = $value['value'];
}
$transport_json['start_mileage'] = ['value' => $transport['start_mileage']['value'], 'imgs' => $start_mileage_imgs];
}
if ($opt_btn['type'] == 2) {//接车里程数
$end_mileage_imgs = '';
foreach ($transport['end_mileage']['imgs'] as $key => $value) {
$end_mileage_imgs[] = $value['value'];
}
$transport_json['end_mileage'] = ['value' => $transport['end_mileage']['value'], 'imgs' => $end_mileage_imgs];
}
$jsondata['transport'] = $transport_json;
$this->mdTransfer->update(['abnormal' => $set_abnormal, '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, 'tran_id' => $tran_id]);
}
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()
{
$id = $this->input->post('id');
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$re = $this->mdTransfer->get(array('id' => $id));
if ($re && ($re['status'] > 0)) {
return $this->show_json(SYS_CODE_FAIL, '已发车或已接车,不能删除');
}
$this->mdTransfer->delete(['id' => $id]);
if ($re['status'] == 0) {//已调拨删除调拨记录
$this->mdTransferRemind->delete(['tran_id' => $id]);
$this->mdTransferAdmin->delete(['tran_id' => $id]);
}
return $this->show_json(SYS_CODE_SUCCESS, '删除成功!');
}
/**
* Notes:运输人员操作
* Created on: 2022/1/18 11:24
* Created by: dengbw
*/
public function get_transport()
{
$params = $this->input->get();
$data = $this->transports($params);
print_r($data);
exit;
}
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['admin_name'] = $value['admin_name'];
$temp['c_time'] = $value['c_time'];
$temp['out_uid_title'] = $value['out_uid_title'];
$temp['out_addr_name'] = $value['out_addr_name'];
$temp['in_uid_title'] = $value['in_uid_title'];
$temp['in_addr_name'] = $value['in_addr_name'];
$temp['abnormal'] = $value['abnormal'];
$temp['status_name'] = $value['status_name'];
$temp['trailer_fees'] = $value['trailer_fees'];
$temp['fees'] = $value['fees'];
$temp['reason'] = $value['reason'];
$data[] = $temp;
}
$indexs = [
'title' => '车辆',
'vin' => '车架号',
'transport_name' => '运输人员',
'admin_name' => '调拨人',
'c_time' => '调拨时间',
'out_uid_title' => '提车人',
'out_addr_name' => '提车地址',
"in_uid_title" => "接车人",
'in_addr_name' => '存放地址',
"abnormal" => "异常",
"status_name" => "状态",
"trailer_fees" => "运输费用",
"fees" => "费用承担方",
"reason" => "调拔理由",
];
array_unshift($data, $indexs);
$this->load->library('excel');
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
/**
* Notes:运输人员操作
* Created on: 2022/1/27 15:36
* Created by: dengbw
* @param $params
* @return array|int
*/
private function transports($params)
{
$transports = [];
$cache = &load_cache('redis');
$cache_transports = $cache->get($this->cacheKeyTransports);
if ($params['type'] == 'all') {//所有运输人员
return $cache_transports;
} else if ($params['type'] == 'get') {//排序后的运输人员
$saveTransports = false;
if ($cache_transports) {//按最近日期排序
foreach ($cache_transports as $key => $value) {
if ($value['name']) {
$transports[] = $value;
} else {
$saveTransports = true;
}
}
}
$saveTransports && $cache->save($this->cacheKeyTransports, $transports);//名字有空重新更新
if ($transports) {//按最近日期排序
$timeKey = array_column($transports, 'time');
array_multisort($timeKey, SORT_DESC, $transports);
}
return $transports;
} else if ($params['type'] == 'del') {
if ($cache_transports) {
if (strlen($params['id'])) {//删除指定id
unset($cache_transports[$params['id']]);
$transports = $cache_transports;
} else {//删除指定的名字
foreach ($cache_transports as $key => $value) {
if ($value['name'] == $params['name']) {
} else {
$transports[] = $value;
}
}
}
$cache->save($this->cacheKeyTransports, $transports);
}
return $transports;
} else {//新增/更新运输人员
if (!$params['name'] || !$params['mobile'] || !$params['cardid']) {
return 0;
}
if (strlen($params['id'])) {//修改指定id
$cache_transports[$params['id']] = ['name' => $params['name'], 'mobile' => $params['mobile']
, 'cardid' => $params['cardid'], 'time' => date('Y-m-d')];
} else {
$addTransports = true;
foreach ($cache_transports as $key => $value) {
if ($value['cardid'] == $params['cardid']) {//身份证一样更新数据
$cache_transports[$key]['name'] = $params['name'];
$cache_transports[$key]['mobile'] = $params['mobile'];
$cache_transports[$key]['time'] = date('Y-m-d');
$addTransports = false;
} else if (($value['cardid'] == '待定' || $value['cardid'] == '待补') && $value['mobile'] == $params['mobile']) {
$cache_transports[$key]['name'] = $params['name'];
$cache_transports[$key]['cardid'] = $params['cardid'];
$cache_transports[$key]['time'] = date('Y-m-d');
$addTransports = false;
}
}
if ($addTransports) {//新增
$cache_transports[] = ['name' => $params['name'], 'mobile' => $params['mobile']
, 'cardid' => $params['cardid'], 'time' => date('Y-m-d')];
}
}
$cache->save($this->cacheKeyTransports, $cache_transports);
return 1;
}
}
/**
* 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;
}
/**
* 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 => '&nbsp;&nbsp;备用提车人', 3 => '接车人', 4 => '&nbsp;&nbsp;备用接车人'];
if ($type == 1) {//门店
$re_user = $this->mdUsers->get(array('id' => $params['uid']));
$biz_id = $params['biz_id'] ? $params['biz_id'] : intval($re_user['biz_id']);
$re_biz = $this->mdBiz->get(array('id' => $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'] . '&nbsp;&nbsp;' . $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']}&nbsp;&nbsp;{$re_user['mobile']}&nbsp;&nbsp;{$city_name}&nbsp;&nbsp;{$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'] . '&nbsp;&nbsp;' . $re_addr['county_name'] . '&nbsp;&nbsp;' . $re_addr['title'];
}
$content = $titleAry[$params['type']] . "{$re_admin['username']}&nbsp;&nbsp;{$re_admin['mobile']}&nbsp;&nbsp;{$city_name}";
}
return $content;
}
/**
* Notes:提车/接车人地址
* Created on: 2021/12/30 10:16
* Created by: dengbw
* @param $params
* @param int $type
* @return string
*/
private function take_biz($params, $type = 1)
{
$content = $city_name = $title = '';
if ($type == 1) {//门店
if ($params['biz_id']) {
$biz_id = $params['biz_id'];
} else {
$re_user = $this->mdUsers->get(array('id' => $params['uid']));
$biz_id = intval($re_user['biz_id']);
}
$re_biz = $this->mdBiz->get(array('id' => $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 = "{$city_name}-{$re_biz['biz_name']}";
} else if ($type == 2) {
$re_addr = $this->mdAddr->get(array('id' => $params['addr_id']));
if ($re_addr) {
$content = $re_addr['city_name'] . '-' . $re_addr['county_name'] . '-' . $re_addr['title'];
}
}
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) { //门店调拨短信提醒
if ($params['tran_id']) {//小程序配置
$this->load->model('app/app_model', 'mdApp');
$wxconfig = $this->mdApp->appConfig()[2]['wx'];
$this->load->library('hdwechat', $wxconfig);
}
$uids_str = implode(',', $uids);
$res_u = $this->mdUsers->select(["id in({$uids_str})" => null], 'id desc', 0, 0, 'id,mobile');
foreach ($res_u as $key => $value) {
$code = '';
if ($params['tran_id']) {
$re_remind = $this->mdTransferRemind->get(["uid" => $value['id'], "tran_id" => $params['tran_id'], 'status' => 1]);
if ($re_remind['id']) {//查找调拨提醒id
$url_params = array('path' => '/pages/allot/detail/index', 'query' => 'id=' . $re_remind['id'],
'is_expire' => true, 'expire_time' => strtotime('+30 day'));
$result = $this->hdwechat->urlscheme($url_params);//获取小程序scheme码
if ($result['openlink']) {
$openlinks = explode("?t=", $result['openlink']); //weixin://dl/business/?t=xPihcWTrp3m
$openlinks[1] && $code = $openlinks[1];
}
}
}
send_alisms(array('mobile' => $value['mobile'], 'template' => 'SMS_232907986'
, 'param' => ['car' => $car, 'vin' => $item_info['vin'], 'code' => $code]));
}
} 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']]));
}
}
}
}
}