567 lines
28 KiB
PHP
567 lines
28 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:车辆调拨
|
|
* Created on: 2021/12/10 16:43
|
|
* Created by: dengbw
|
|
*/
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
|
|
class Transfer extends Wxapp
|
|
{
|
|
|
|
function __construct($inputs, $app_key)
|
|
{
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg = array();//授权微信信息
|
|
$this->load->model('items/items_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("biz/biz_model", 'mdBiz');
|
|
$this->load->model('sys/Sys_admin_model', 'mdSysAdmin');
|
|
}
|
|
|
|
protected function get_tabs()
|
|
{
|
|
return [['id' => 1, 'name' => '进行中'], ['id' => 2, 'name' => '已完成']];
|
|
}
|
|
|
|
/**
|
|
* Notes:调拨提醒
|
|
* Created on: 2021/12/10 17:03
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_remind()
|
|
{
|
|
$where = ['lc_items_transfer_remind.uid' => $this->myuid, 'lc_items_transfer_remind.status' => 1
|
|
, 'lc_items_transfer.status<>' => -1];
|
|
$total = $this->db->select('lc_items_transfer_remind.tran_id')
|
|
->join('lc_items_transfer', 'lc_items_transfer.id = lc_items_transfer_remind.tran_id', 'left')
|
|
->where($where)
|
|
->group_by('lc_items_transfer_remind.tran_id')
|
|
->count_all_results('lc_items_transfer_remind');
|
|
return ['total' => $total];
|
|
}
|
|
|
|
protected function get_lists()
|
|
{
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
$s_date = $this->input_param('s_date');
|
|
$e_date = $this->input_param('e_date');
|
|
$channel = intval($this->input_param('channel'));//1渠道自已提醒操作
|
|
|
|
!$page && $page = 1;
|
|
!$size && $size = 5;
|
|
if ($this->session['group_id'] == 4 && !$channel) {//渠道经理
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
!$biz_id && $biz_id = -1;
|
|
$where = ['status <>' => -1, "biz_id in({$biz_id})" => null];
|
|
$s_date && $where['c_time >='] = strtotime($s_date . ' 00:00:00');
|
|
$e_date && $where['c_time <='] = strtotime($e_date . ' 23:59:59');
|
|
$count = $this->mdTransfer->count($where);
|
|
} else {
|
|
$type = intval($this->input_param('type'));
|
|
$tabs_id = intval($this->input_param('tabs_id'));
|
|
$where = ['lc_items_transfer_remind.uid' => $this->myuid, 'lc_items_transfer.status<>' => -1];
|
|
if ($type == 1) {//提车人/备用提车人
|
|
$where['lc_items_transfer_remind.type in(1,2)'] = null;
|
|
} else if ($type == 2) {//接车人/备用接车人
|
|
$where['lc_items_transfer_remind.type in(3,4)'] = null;
|
|
}
|
|
if ($tabs_id == 2) {//已完成
|
|
$where['lc_items_transfer_remind.status'] = 2;
|
|
} else {//进行中
|
|
$where['lc_items_transfer_remind.status'] = 1;
|
|
}
|
|
$s_date && $where['lc_items_transfer_remind.c_time >='] = strtotime($s_date . ' 00:00:00');
|
|
$e_date && $where['lc_items_transfer_remind.c_time <='] = strtotime($e_date . ' 23:59:59');
|
|
$count = $this->db->select('lc_items_transfer_remind.tran_id')
|
|
->join('lc_items_transfer', 'lc_items_transfer.id = lc_items_transfer_remind.tran_id', 'left')
|
|
->where($where)
|
|
->group_by('lc_items_transfer_remind.tran_id')
|
|
->count_all_results('lc_items_transfer_remind');
|
|
}
|
|
$url = '/pages/allot/detail/index?id=';
|
|
$lists = [];
|
|
if ($count) {
|
|
$offset = ($page - 1) * $size;
|
|
$limit = $size;
|
|
if ($this->session['group_id'] == 4 && !$channel) {//渠道经理
|
|
$res = $this->mdTransfer->select($where, 'id desc', $page, $limit, 'id,item_id,out_uid,in_uid,jsondata,c_time,biz_id');
|
|
$url = '/pages/allot/detail/index?tran_id=';
|
|
} else {
|
|
$this->db->from('lc_items_transfer_remind');
|
|
$this->db->join('lc_items_transfer', "lc_items_transfer.id = lc_items_transfer_remind.tran_id", 'left');
|
|
$this->db->select('lc_items_transfer_remind.id,lc_items_transfer.item_id,lc_items_transfer.out_uid,lc_items_transfer.in_uid
|
|
,lc_items_transfer.jsondata,lc_items_transfer.c_time,lc_items_transfer.biz_id,lc_items_transfer.out_type,lc_items_transfer.in_type');
|
|
$this->db->where($where);
|
|
$this->db->order_by('lc_items_transfer_remind.id Desc');
|
|
$this->db->group_by('lc_items_transfer_remind.tran_id');
|
|
$this->db->limit($limit, $offset);
|
|
$res = $this->db->get()->result_array();
|
|
}
|
|
$out_uids = $in_uids = [];
|
|
$out_uids_ad = $in_uids_ad = [];
|
|
foreach ($res 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');
|
|
$bizs = $this->mdBiz->get_map_by_ids(array_unique(array_column($res, 'biz_id')), 'id,biz_name');//门店
|
|
foreach ($res as $key => $val) {
|
|
$jsondata = $val['jsondata'] ? json_decode($val['jsondata'], true) : [];
|
|
$item_info = $this->item_info($val['item_id']);
|
|
$setValue = $other_data = [];
|
|
$setValue['biz_name'] = $val['biz_id'] ? $bizs[$val['biz_id']][0]['biz_name'] : '';
|
|
$setValue['c_time'] = '调拨时间:' . date('Y-m-d H:i', $val['c_time']);
|
|
$out_uid_title = $in_uid_title = '-';
|
|
if ($val['out_uid']) {
|
|
if ($val['out_type'] == 1) {
|
|
$out_uid_title = $uids[$val['out_uid']][0]['uname'];
|
|
} else if ($val['out_type'] == 2) {
|
|
$out_uid_title = $uids_ad[$val['out_uid']][0]['uname'];
|
|
}
|
|
}
|
|
if ($val['in_uid']) {
|
|
if ($val['in_type'] == 1) {
|
|
$in_uid_title = $uids[$val['in_uid']][0]['uname'];
|
|
} else if ($val['in_type'] == 2) {
|
|
$in_uid_title = $uids_ad[$val['in_uid']][0]['uname'];
|
|
}
|
|
}
|
|
$other_data[] = ['title' => '品牌车型', 'value' => $item_info['title_1']];
|
|
$other_data[] = ['title' => '颜色型号', 'value' => $item_info['title_2']];
|
|
$other_data[] = ['title' => '车架号', 'value' => $item_info['vin']];
|
|
$other_data[] = ['title' => '调拨时间', 'value' => date('Y-m-d', $val['c_time'])];
|
|
$other_data[] = ['title' => '提车人', 'value' => $out_uid_title];
|
|
$other_data[] = ['title' => '接车人', 'value' => $in_uid_title];
|
|
$other_data[] = ['title' => '运输员', 'value' => $jsondata['transport']['name']];
|
|
$setValue['other_data'] = $other_data;
|
|
$setValue['url'] = $url ? $url . $val['id'] : '';
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'total' => $count
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
protected function get()
|
|
{
|
|
$id = intval($this->input_param('id'));
|
|
$tran_id = intval($this->input_param('tran_id'));
|
|
if (!$id && !$tran_id) {
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$btn = [];
|
|
$status = 0;
|
|
if ($id) {//有id才能操作
|
|
$re_m = $this->mdTransferRemind->get(['id' => $id]);
|
|
if (!$re_m) {
|
|
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$tran_id = $re_m['tran_id'];
|
|
$status = $re_m['status'];
|
|
if ($re_m['status'] == 1) {
|
|
$btn[] = ['title' => '报备异常', 'id' => $re_m['tran_id'], 'type' => 1];
|
|
if ($re_m['type'] == 1 || $re_m['type'] == 2) {
|
|
$btn[] = ['title' => '确认发车', 'id' => $id, 'type' => 2];
|
|
} else {
|
|
$btn[] = ['title' => '确认接车', 'id' => $id, 'type' => 3];
|
|
}
|
|
}
|
|
}
|
|
$re = $this->mdTransfer->get(['id' => $tran_id]);
|
|
if (!$re) {
|
|
throw new Exception('车辆调拨不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
|
|
$transport_imgs = [];
|
|
$start_mileage = $end_mileage = '';
|
|
if ($jsondata['transport']) {
|
|
$transport = $jsondata['transport'];
|
|
if ($transport['imgs']) {//运输单
|
|
foreach ($jsondata['transport']['imgs'] as $key => $value) {
|
|
$value && $transport_imgs[] = ['value' => $value, 'src' => build_qiniu_image_url($value)];
|
|
}
|
|
}
|
|
if ($transport['start_mileage']) {//发车里程数
|
|
$start_mileage = $transport['start_mileage'];
|
|
$start_mileage['title'] = '发车里程数';
|
|
$start_mileage['tag'] = 'km';
|
|
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'];
|
|
$end_mileage['title'] = '接车里程数';
|
|
$end_mileage['tag'] = 'km';
|
|
foreach ($end_mileage['imgs'] as $key => $value) {
|
|
$value && $end_mileage['imgs'][$key] = ['src' => build_qiniu_image_url($value), 'value' => $value];
|
|
}
|
|
}
|
|
}
|
|
$data['transport'] = ['title' => '运输负责人', 'name' => $jsondata['transport']['name']
|
|
, 'mobile' => $jsondata['transport']['mobile'], 'cardid' => $jsondata['transport']['cardid'], 'imgs' => $transport_imgs
|
|
, 'start_mileage' => $start_mileage, 'end_mileage' => $end_mileage];
|
|
$this->db->from('lc_items_transfer_remind');
|
|
$this->db->join('lc_app_licheb_users', "lc_app_licheb_users.id = lc_items_transfer_remind.uid", 'left');
|
|
$this->db->select('lc_items_transfer_remind.type,lc_app_licheb_users.uname');
|
|
$this->db->where(['lc_items_transfer_remind.tran_id' => $tran_id]);
|
|
$this->db->order_by('lc_items_transfer_remind.type asc');
|
|
$this->db->limit(50);
|
|
$res_r = $this->db->get()->result_array();
|
|
$item_info = $this->item_info($re['item_id']);
|
|
$other_data[] = ['title' => '品牌车型', 'value' => $item_info['title_1']];
|
|
$other_data[] = ['title' => '颜色型号', 'value' => $item_info['title_2']];
|
|
$other_data[] = ['title' => '车架号', 'value' => $item_info['vin']];
|
|
$uname1 = $uname2 = $uname3 = $uname4 = '';
|
|
foreach ($res_r as $key => $value) {
|
|
if ($value['type'] == 1) {
|
|
$uname1 = $value['uname'];
|
|
} else if ($value['type'] == 2) {
|
|
$uname2 = $value['uname'];
|
|
} else if ($value['type'] == 3) {
|
|
$uname3 = $value['uname'];
|
|
} else if ($value['type'] == 4) {
|
|
$uname4 = $value['uname'];
|
|
}
|
|
}
|
|
$res_a = $this->mdTransferAdmin->select(['tran_id' => $tran_id], 'type asc', 0, 0, 'uid,type');
|
|
foreach ($res_a as $key => $value) {
|
|
$re_admin = $this->mdSysAdmin->get(array('id' => $value['uid']));
|
|
$username = $re_admin['username'] ? $re_admin['username'] : '';
|
|
if ($value['type'] == 1) {
|
|
$uname1 = $username;
|
|
} else if ($value['type'] == 2) {
|
|
$uname2 = $username;
|
|
} else if ($value['type'] == 3) {
|
|
$uname3 = $username;
|
|
} else if ($value['type'] == 4) {
|
|
$uname4 = $username;
|
|
}
|
|
}
|
|
$other_data[] = ['title' => '提车人', 'value' => $uname1];
|
|
$uname2 && $other_data[] = ['title' => '备用提车人', 'value' => $uname2];
|
|
$other_data[] = ['title' => '接车人', 'value' => $uname3];
|
|
$uname4 && $other_data[] = ['title' => '备用接车人', 'value' => $uname4];
|
|
if ($re['arti_id']) {
|
|
$this->load->model('auto/auto_article_model', 'mdArticle');
|
|
$res_a = $this->mdArticle->select(["id in ({$re['arti_id']})" => null], 'id desc', 0, 0, 'title');
|
|
if ($res_a) {
|
|
$articles = array_unique(array_column($res_a, 'title'));
|
|
$other_data[] = ['title' => '随车物品', 'list' => $articles];
|
|
}
|
|
}
|
|
//异常显示
|
|
$abnormal = '';
|
|
if ($re['abnormal'] && $jsondata['abnormal']) {
|
|
$abnormal = $jsondata['abnormal'];
|
|
foreach ($abnormal['imgs'] as $key => $value) {
|
|
$abnormal['imgs'][$key] = $value ? build_qiniu_image_url($value) : '';
|
|
}
|
|
}
|
|
$data['btn'] = $btn;
|
|
$data['abnormal'] = $abnormal;
|
|
$data['other_data'] = $other_data;
|
|
$data['id'] = $tran_id;
|
|
$data['status'] = $status;
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:确认发车/接车
|
|
* Created on: 2021/12/10 15:41
|
|
* Created by: dengbw
|
|
* @throws Exception
|
|
*/
|
|
protected function put()
|
|
{
|
|
$id = intval($this->input_param('id'));
|
|
if (!$id) {
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$re_m = $this->mdTransferRemind->get(['id' => $id]);
|
|
if (!$re_m) {
|
|
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
if ($re_m['status'] != 1) {
|
|
throw new Exception('已不能操作', ERR_PARAMS_ERROR);
|
|
}
|
|
if ($re_m['uid'] != $this->myuid) {
|
|
throw new Exception('无操作权限', ERR_PARAMS_ERROR);
|
|
}
|
|
$tran_id = $re_m['tran_id'];
|
|
$re_tr = $this->mdTransfer->get(['id' => $tran_id]);
|
|
if (!$re_tr) {
|
|
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$jsondata = $re_tr['jsondata'] ? json_decode($re_tr['jsondata'], true) : [];
|
|
$transport_json = $jsondata['transport'] ? $jsondata['transport'] : [];
|
|
if ($re_m['type'] == 1 || $re_m['type'] == 2) {//确认提车
|
|
$start_mileage = $this->input_param('start_mileage');
|
|
$start_mileage_value = myTrim($start_mileage['value']);
|
|
if (!$start_mileage_value) {
|
|
throw new Exception('请输入发车里程数', ERR_PARAMS_ERROR);
|
|
}
|
|
if (!$start_mileage['imgs']) {
|
|
throw new Exception('请上传发车仪表盘里程数照片', ERR_PARAMS_ERROR);
|
|
}
|
|
$start_mileage_imgs = '';
|
|
foreach ($start_mileage['imgs'] as $key => $value) {
|
|
$start_mileage_imgs[] = $value['value'];
|
|
}
|
|
$transport_json['start_mileage'] = ['value' => $start_mileage_value, 'imgs' => $start_mileage_imgs];
|
|
$ret = $this->mdTransferRemind->update(['status' => 2], ['tran_id' => $tran_id, 'type in(1,2)' => null]);//门店已完成
|
|
if ($ret) {
|
|
$this->mdTransferAdmin->update(['status' => 2], ['tran_id' => $tran_id, 'type in(1,2)' => null]);//信息员已完成
|
|
//更新有门店/信息员确认接车
|
|
$this->mdTransferRemind->update(['status' => 1], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//门店显示
|
|
$this->mdTransferAdmin->update(['status' => 1], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//信息员显示
|
|
//更新车辆调拨
|
|
$this->mdTransfer->update(['status' => 1, 'out_type' => 1, 'out_uid' => $this->myuid
|
|
, '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');
|
|
$re_t = $this->mdTransfer->get(['id' => $tran_id]);
|
|
$item_info = $this->item_info($re_t['item_id']);
|
|
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 {//确认接车
|
|
$end_mileage = $this->input_param('end_mileage');
|
|
$end_mileage_value = myTrim($end_mileage['value']);
|
|
if (!$end_mileage_value) {
|
|
throw new Exception('请输入接车里程数', ERR_PARAMS_ERROR);
|
|
}
|
|
if (!$end_mileage['imgs']) {
|
|
throw new Exception('请上传接车仪表盘里程数照片', ERR_PARAMS_ERROR);
|
|
}
|
|
$end_mileage_imgs = '';
|
|
foreach ($end_mileage['imgs'] as $key => $value) {
|
|
$end_mileage_imgs[] = $value['value'];
|
|
}
|
|
$transport_json['end_mileage'] = ['value' => $end_mileage_value, 'imgs' => $end_mileage_imgs];
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
if ($this->session['group_id'] == 4) {//渠道操作时调用数据库的 biz_id
|
|
$biz_id = $re_m['biz_id'];
|
|
}
|
|
$ret = $this->mdTransferRemind->update(['status' => 2], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//门店已完成
|
|
if ($ret) {
|
|
$this->mdTransferAdmin->update(['status' => 2], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//信息员已完成
|
|
$this->mdTransfer->update(['status' => 2, 'in_type' => 1, 'in_uid' => $this->myuid, 'biz_id' => $biz_id, 'addr_id' => 0
|
|
, 'in_time' => date("Y-m-d H:i:s")], ['id' => $tran_id]);//更新车辆调拨
|
|
//更新车辆存放地
|
|
$re_t = $this->mdTransfer->get(['id' => $tran_id]);
|
|
$item_id = intval($re_t['item_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' => $biz_id, 'addr_id' => 0], ['id' => $item_id]);//更新车辆调拨
|
|
//添加车辆存放日志
|
|
if ($ret_i) {
|
|
$this->load->library('entity/items_entity');
|
|
$uname = $this->session['uname'] ? $this->session['uname'] : '';
|
|
if ($re_items['biz_id'] > 0) {//门店间变化
|
|
$params = array('item_id' => $item_id, 'type' => 2, 'uid' => -$this->myuid, 'uname' => $uname
|
|
, 'com_time' => $com_time, 'biz_id' => $re_items['biz_id'], 'biz_id_to' => $biz_id);
|
|
$this->items_entity->add_log($params);
|
|
} else if ($re_items['biz_id'] == -1) {//地址转门店变化
|
|
$params = array('item_id' => $item_id, 'type' => 2, 'uid' => -$this->myuid, 'uname' => $uname
|
|
, 'com_time' => $com_time, 'biz_id' => -1, 'addr_id' => $re_items['addr_id'], 'biz_id_to' => $biz_id);
|
|
$this->items_entity->add_log($params);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($ret) {
|
|
$jsondata['transport'] = $transport_json;
|
|
$this->mdTransfer->update(['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)], ['id' => $tran_id]);
|
|
throw new Exception('确认成功', API_CODE_SUCCESS);
|
|
} else {
|
|
throw new Exception('确认失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:报备异常
|
|
* Created on: 2021/12/10 16:07
|
|
* Created by: dengbw
|
|
* @throws Exception
|
|
*/
|
|
protected function post()
|
|
{
|
|
$id = intval($this->input_param('id'));
|
|
if (!$id) {
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$imgs = $this->input_param('imgs');
|
|
$note = $this->input_param('note');
|
|
if (!$imgs && !$note) {
|
|
throw new Exception('请拍照或填写备注信息', ERR_PARAMS_ERROR);
|
|
}
|
|
$re = $this->mdTransfer->get(['id' => $id]);
|
|
if (!$re) {
|
|
throw new Exception('车辆调拨不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
|
|
!$note && $note = '';
|
|
!$imgs && $imgs = '';
|
|
$jsondata['abnormal'] = ['imgs' => $imgs, 'note' => $note];
|
|
$ret = $this->mdTransfer->update(['abnormal' => 1, 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)], ['id' => $id]);
|
|
if ($ret) {
|
|
throw new Exception('报备成功', API_CODE_SUCCESS);
|
|
} else {
|
|
throw new Exception('报备失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:上传运输单
|
|
* Created on: 2021/12/27 16:19
|
|
* Created by: dengbw
|
|
* @throws Exception
|
|
*/
|
|
protected function post_transport()
|
|
{
|
|
$id = intval($this->input_param('id'));
|
|
if (!$id) {
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$imgs = $this->input_param('imgs');
|
|
// if (!$imgs) {
|
|
// throw new Exception('请上传运输单', ERR_PARAMS_ERROR);
|
|
// }
|
|
$re = $this->mdTransfer->get(['id' => $id]);
|
|
if (!$re) {
|
|
throw new Exception('车辆调拨不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
|
|
$transport = $jsondata['transport'] ? $jsondata['transport'] : [];
|
|
$transport['imgs'] = $imgs ? $imgs : '';
|
|
$jsondata['transport'] = $transport;
|
|
$ret = $this->mdTransfer->update(['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)], ['id' => $id]);
|
|
if ($ret) {
|
|
throw new Exception('上传运输单成功', API_CODE_SUCCESS);
|
|
} else {
|
|
throw new Exception('上传运输单失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:获取商品信息
|
|
* Created on: 2021/12/9 10:47
|
|
* Created by: dengbw
|
|
* @param $item_id
|
|
* @param int $type
|
|
* @return array
|
|
*/
|
|
private function item_info($item_id)
|
|
{
|
|
$re = $this->mdItems->get(array('id' => $item_id));
|
|
if (!$re || empty($re)) {
|
|
return [];
|
|
}
|
|
$re_b = $this->mdAutoBrand->get(array('id' => $re['brand_id']), 'name');
|
|
$re_s = $this->mdAutoSeries->get(array('id' => $re['s_id']), 'name');
|
|
$re_v = $this->mdAutoAttr->get(array('id' => $re['v_id']), 'title');
|
|
$re_cor = $this->mdAutoAttr->get(array('id' => $re['cor_id']), 'title');
|
|
$title_1 = $title_2 = '';
|
|
$re_b['name'] && $title_1 = $re_b['name'];
|
|
$re_s['name'] && $title_1 = $title_1 ? $title_1 . '-' . $re_s['name'] : $re_s['name'];
|
|
$re_v['title'] && $title_2 = $re_v['title'];
|
|
$re_cor['title'] && $title_2 = $title_2 ? $title_2 . '-' . $re_cor['title'] : $re_cor['title'];
|
|
$info['title_1'] = $title_1;
|
|
$info['title_2'] = $title_2;
|
|
$info['vin'] = $re['vin'];
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 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_1'];
|
|
$item_info['title_2'] && $car .= '-' . $item_info['title_2'];
|
|
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, 'id,mobile');
|
|
if ($params['tran_id']) {//小程序配置
|
|
$this->load->model('app/app_model', 'mdApp');
|
|
$wxconfig = $this->mdApp->appConfig()[2]['wx'];
|
|
$this->load->library('hdwechat', $wxconfig);
|
|
}
|
|
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']]));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|