310 lines
14 KiB
PHP
310 lines
14 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('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');
|
|
}
|
|
|
|
/**
|
|
* Notes:调拨提醒
|
|
* Created on: 2021/12/10 17:03
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_remind()
|
|
{
|
|
if ($this->session['group_id'] == 4) {
|
|
$total = 0;
|
|
} else {
|
|
$total = $this->mdTransferRemind->count(['uid' => $this->myuid, 'status' => 1]);
|
|
}
|
|
$data = ['total' => $total];
|
|
return $data;
|
|
}
|
|
|
|
protected function get_lists()
|
|
{
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
$s_date = $this->input_param('s_date');
|
|
$e_date = $this->input_param('e_date');
|
|
!$page && $page = 1;
|
|
!$size && $size = 5;
|
|
if ($this->session['group_id'] == 4) {//渠道经理
|
|
$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 {
|
|
$where = ['lc_items_transfer_remind.status' => 1, 'lc_items_transfer_remind.uid' => $this->myuid, 'lc_items_transfer.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)
|
|
->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) {//渠道经理
|
|
$res = $this->mdTransfer->select($where, 'id desc', $page, $limit, 'id,item_id,out_uid,in_uid,jsondata,c_time,biz_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');
|
|
$this->db->where($where);
|
|
$this->db->order_by('lc_items_transfer_remind.id Desc');
|
|
$this->db->limit($limit, $offset);
|
|
$res = $this->db->get()->result_array();
|
|
}
|
|
$out_uids = array_unique(array_column($res, 'out_uid'));
|
|
$in_uids = array_unique(array_column($res, 'in_uid'));
|
|
$uids = $this->mdUsers->get_map_by_ids(array_merge($out_uids, $in_uids), 'id,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']);
|
|
$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' => $val['out_uid'] ? $uids[$val['out_uid']][0]['uname'] : '-'];
|
|
$other_data[] = ['title' => '接车人', 'value' => $val['in_uid'] ? $uids[$val['in_uid']][0]['uname'] : '-'];
|
|
$other_data[] = ['title' => '运输员', 'value' => $jsondata['transport']['name']];
|
|
$setValue['other_data'] = $other_data;
|
|
$setValue['url'] = $url ? '/pages/allot/detail/index?id=' . $val['id'] : '';
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'total' => $count
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
protected function get()
|
|
{
|
|
$id = intval($this->input_param('id'));
|
|
if (!$id) {
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
if ($this->session['group_id'] == 4) {//渠道不显示按钮
|
|
$btn = [];
|
|
$tran_id = $id;
|
|
} else {
|
|
$re_m = $this->mdTransferRemind->get(['id' => $id]);
|
|
if (!$re_m) {
|
|
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$tran_id = $re_m['tran_id'];
|
|
$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' => 2];
|
|
}
|
|
}
|
|
$re = $this->mdTransfer->get(['id' => $tran_id]);
|
|
if (!$re) {
|
|
throw new Exception('车辆调拨不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
|
|
$data['transport'] = ['title' => '运输负责人', 'name' => $jsondata['transport']['name']
|
|
, 'mobile' => $jsondata['transport']['mobile']];
|
|
$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' => $re_m['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']];
|
|
foreach ($res_r as $key => $value) {
|
|
if ($value['type'] == 1) {
|
|
$other_data[] = ['title' => '提车人', 'value' => $value['uname']];
|
|
} else if ($value['type'] == 2) {
|
|
$other_data[] = ['title' => '备用提车人', 'value' => $value['uname']];
|
|
} else if ($value['type'] == 3) {
|
|
$other_data[] = ['title' => '接车人', 'value' => $value['uname']];
|
|
} else if ($value['type'] == 4) {
|
|
$other_data[] = ['title' => '备用接车人', 'value' => $value['uname']];
|
|
}
|
|
}
|
|
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['abnormal'] = $abnormal;
|
|
$data['other_data'] = $other_data;
|
|
$data['btn'] = $btn;
|
|
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['uid'] != $this->myuid) {
|
|
throw new Exception('无操作权限', ERR_PARAMS_ERROR);
|
|
}
|
|
$tran_id = $re_m['tran_id'];
|
|
if ($re_m['type'] == 1 || $re_m['type'] == 2) {//确认提车
|
|
$ret = $this->mdTransferRemind->update(['status' => 0], ['tran_id' => $tran_id, 'type in(1,2)' => null]);//隐藏
|
|
if ($ret) {
|
|
$this->mdTransferRemind->update(['status' => 1], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//显示
|
|
$this->mdTransfer->update(['status' => 1, 'out_uid' => $this->myuid, 'out_time' => date("Y-m-d H:i:s")]
|
|
, ['id' => $tran_id]);//更新车辆调拨
|
|
//调拨接车人短信提醒
|
|
$res_tm = $this->mdTransferRemind->select(['status' => 1, 'tran_id' => $tran_id, 'type in(3,4)' => null], 'type asc', 0, 0, 'uid');
|
|
if ($res_tm) {
|
|
$uids_str = implode(',', array_unique(array_column($res_tm, 'uid')));
|
|
$res_u = $this->mdUsers->select(["id in({$uids_str})" => null], 'id desc', 0, 0, 'mobile');
|
|
$re_t = $this->mdTransfer->get(['id' => $re_m['tran_id']]);
|
|
$item_info = $this->item_info($re_t['item_id']);
|
|
foreach ($res_u as $key => $value) {
|
|
$car = $item_info['title_1'];
|
|
$item_info['title_2'] && $car .= '-' . $item_info['title_2'];
|
|
send_alisms(array('mobile' => $value['mobile'], 'template' => 'SMS_229648438'
|
|
, 'param' => ['car' => $car, 'vin' => $item_info['vin']]));
|
|
}
|
|
}
|
|
}
|
|
} else {//确认接车
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
$ret = $this->mdTransferRemind->update(['status' => 0], ['tran_id' => $tran_id, 'type in(3,4)' => null]);//隐藏
|
|
if ($ret) {
|
|
$this->mdTransfer->update(['status' => 2, 'biz_id' => $biz_id, 'in_uid' => $this->myuid, 'in_time' => date("Y-m-d H:i:s")]
|
|
, ['id' => $tran_id]);//更新车辆调拨
|
|
}
|
|
}
|
|
if ($ret) {
|
|
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/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;
|
|
}
|
|
}
|