1382 lines
51 KiB
PHP
Executable File
1382 lines
51 KiB
PHP
Executable File
<?php
|
||
|
||
# @Author: 嗨噜客(三亚) <fm453>
|
||
# @Date: 2022-04-24T20:28:47+08:00
|
||
# @Email: fm453@lukegzs.com
|
||
# @Last modified by: fm453
|
||
# @Last modified time: 2024-07-01T18:27:23+08:00
|
||
# @Copyright: www.hiluker.cn
|
||
|
||
namespace backend\controllers;
|
||
|
||
use Yii;
|
||
use yii\data\Pagination;
|
||
use yii\helpers\Url;
|
||
use backend\controllers\Common;
|
||
use addons\models\AcCar;
|
||
use addons\models\AcCarOwner;
|
||
use addons\models\AcCarBrand;
|
||
use addons\models\AcCarSeries;
|
||
use addons\models\AcStore;
|
||
use addons\models\AcEmployee;
|
||
use addons\models\AcOrder;
|
||
use addons\models\AcOrderPre;
|
||
use addons\models\AcOrderStatus;
|
||
use addons\models\AcTruck;
|
||
use addons\models\AcDriver;
|
||
use addons\models\AcPlat;
|
||
use common\models\CVcode;
|
||
use addons\models\AcContact;
|
||
use common\models\Member as User;
|
||
use addons\models\AcUserExt;
|
||
use common\models\Fans;
|
||
|
||
class OrderController extends Common
|
||
{
|
||
public function beforeAction($action)
|
||
{
|
||
if (!$this->pid) {
|
||
// $this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||
}
|
||
return parent::beforeAction($action);
|
||
}
|
||
|
||
public function actionIndex()
|
||
{
|
||
$apis = [
|
||
'list'=>'搜索运单',
|
||
'detail'=>'运单详情',
|
||
'create'=>'创建运单',
|
||
'today'=>'今日运单',
|
||
'yesterday'=>'昨日运单',
|
||
'qiantian'=>'前日运单',
|
||
'nocheck'=>'待验车运单'
|
||
];
|
||
$this->result('您正使用CMTS系统订单管理接口!', $apis, 200);
|
||
}
|
||
|
||
//订单列表
|
||
public function actionList()
|
||
{
|
||
$pid = $this->pid;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$search = isset($post['search']) ? $post['search'] : null;
|
||
if (!$search) {
|
||
$search = [];
|
||
}
|
||
$CarModel = new AcCar();
|
||
if (isset($search['carno']) && !empty($search['carno'])) {
|
||
$search['carno'] = trim($search['carno']);
|
||
$cars = $CarModel->find()->where(['LIKE','num_left',$search['carno']])->limit(5)->offset(0)->all(); //最多仅显示可匹配车牌号的前5个
|
||
if (empty($cars)) {
|
||
$return['code'] = 400;
|
||
$return['msg'] = '未查询到相关车辆';
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||
} else {
|
||
$car_ids = [];
|
||
foreach ($cars as $car) {
|
||
$car_ids[] = $car->id;
|
||
}
|
||
$where[] = ['IN','car_id',$car_ids];
|
||
}
|
||
}
|
||
|
||
if (isset($search['city']) && !empty($search['city'])) {
|
||
$search['city'] = trim($search['city']);
|
||
$where[] = ['LIKE','aim_city',$search['city']];
|
||
}
|
||
|
||
if (isset($search['phone']) && !empty($search['phone'])) {
|
||
$search['phone'] = trim($search['phone']);
|
||
$orwhere = ['or',['LIKE','sender_mobiles',$search['phone']],['LIKE','receiver_mobiles',$search['phone']]];
|
||
}
|
||
|
||
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : '';
|
||
$EmployeeModel = new AcEmployee();
|
||
if (!empty($search['employee'])) {
|
||
$where[] = ['=','employee_id',$search['employee']];
|
||
$employee = $EmployeeModel->findOne($search['employee']);
|
||
$search['employee_title'] = isset($employee->name) ? $employee->name : '';
|
||
}
|
||
$search['store_id'] = isset($search['store_id']) ? (int)$search['store_id'] : '';
|
||
if (empty($search['sotre_id'])) {
|
||
$search['store_id'] = isset($get['store_id']) ? (int)$get['store_id'] : 0;
|
||
}
|
||
$StoreModel = new AcStore();
|
||
if (!empty($search['store_id'])) {
|
||
$where[] = ['=','store_id',$search['store_id']];
|
||
$store = $StoreModel->findOne($search['store_id']);
|
||
$search['store_title'] = isset($store->title) ? $store->title : '';
|
||
}
|
||
$search['from_mid'] = isset($search['from_mid']) ? (int)$search['from_mid'] : '';
|
||
$UserModel = new User();
|
||
if (!empty($search['from_mid'])) {
|
||
$where[] = ['=','from_mid',$search['from_mid']];
|
||
$user = $UserModel->findById(['id' => $search['from_mid']]);
|
||
$search['from_mtitle'] = isset($user->username) ? $user->username : '';
|
||
}
|
||
$search['start_province'] = isset($search['start_province']) ? trim($search['start_province']) : '';
|
||
if (!empty($search['start_province'])) {
|
||
$where[] = ['=','start_province',$search['start_province']];
|
||
}
|
||
$search['start_city'] = isset($search['start_city']) ? trim($search['start_city']) : '';
|
||
if (!empty($search['start_city'])) {
|
||
$where[] = ['LIKE','start_city',$search['start_city']];
|
||
}
|
||
$search['aim_province'] = isset($search['aim_province']) ? trim($search['aim_province']) : '';
|
||
if (!empty($search['aim_province'])) {
|
||
$where[] = ['=','aim_province',$search['aim_province']];
|
||
}
|
||
$search['aim_city'] = isset($search['aim_city']) ? trim($search['aim_city']) : '';
|
||
if (!empty($search['aim_city'])) {
|
||
$where[] = ['LIKE','aim_city',$search['aim_city']];
|
||
}
|
||
$search['signer'] = isset($search['signer']) ? trim($search['signer']) : '';
|
||
$search['wtdw'] = isset($search['wtdw']) ? trim($search['wtdw']) : '';
|
||
$search['weituo'] = isset($search['weituo']) ? (int)$search['weituo'] : 0;
|
||
if ($search['weituo']) {
|
||
$where[] = ['=','weituo',$search['weituo']];
|
||
} elseif (!empty($search['wtdw'])) {
|
||
$where[] = ['LIKE','wtdw',$search['wtdw']];
|
||
} elseif (!empty($search['signer'])) {
|
||
$where[] = ['LIKE','signer',$search['signer']];
|
||
}
|
||
|
||
$search['sender_name'] = isset($search['sender_name']) ? trim($search['sender_name']) : '';
|
||
if (!empty($search['sender_name'])) {
|
||
$where[] = ['LIKE','sender_name',$search['sender_name']];
|
||
}
|
||
$search['receiver_name'] = isset($search['receiver_name']) ? trim($search['receiver_name']) : '';
|
||
if (!empty($search['receiver_name'])) {
|
||
$where[] = ['LIKE','receiver_name',$search['receiver_name']];
|
||
}
|
||
$search['bind'] = isset($search['bind']) ? trim($search['bind']) : '';
|
||
if (!empty($search['bind'])) {
|
||
$where[] = ['LIKE','bind',$search['bind']];
|
||
}
|
||
if (isset($search['status_code']) && $search['status_code'] !='all') {
|
||
$search['status_code'] = (int)$search['status_code'];
|
||
$where[] = ['=','status_code',$search['status_code']];
|
||
} else {
|
||
unset($search['status_code']);
|
||
}
|
||
|
||
if (isset($search['is_holdon'])) {
|
||
$search['is_holdon'] = (int)$search['is_holdon'];
|
||
$where[] = ['=','is_holdon',$search['is_holdon']];
|
||
}
|
||
if (isset($search['is_over'])) {
|
||
$search['is_over'] = (int)$search['is_over'];
|
||
$where[] = ['=','is_over',$search['is_over']];
|
||
}
|
||
if (isset($search['is_commission'])) {
|
||
$search['is_commission'] = (int)$search['is_commission'];
|
||
$where[] = ['=','is_commission',$search['is_commission']];
|
||
}
|
||
$search['is_cwqr'] = isset($search['is_cwqr']) ? $search['is_cwqr'] : '';
|
||
if ($search['is_cwqr']=='') {
|
||
$search['is_cwqr'] = isset($get['is_cwqr']) ? $get['is_cwqr'] : '';
|
||
}
|
||
if ($search['is_cwqr'] !='') {
|
||
$search['is_cwqr'] = (int)$get['is_cwqr'];
|
||
$where[] = ['=','is_cwqr',$search['is_cwqr']];
|
||
}
|
||
|
||
//签约时间筛选
|
||
$search['sign_m'] = isset($search['sign_m']) ? $search['sign_m'] : '';
|
||
$search['sign_after'] = isset($search['sign_after']) ? $search['sign_after'] : '';
|
||
$search['sign_before'] = isset($search['sign_before']) ? $search['sign_before'] : '';
|
||
//按月份筛选
|
||
if (!empty($search['sign_m'])) {
|
||
$start = strtotime($search['sign_m']);
|
||
$s = date("Y-m-d H:i:s", $start);
|
||
$ldm = strtotime("last day of ".$s);
|
||
$m = date("Y-m-d", $ldm)." 23:59:59";
|
||
$end = strtotime($m);
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
}
|
||
//按指定时段筛选
|
||
elseif (!empty($search['sign_after']) && !empty($search['sign_before'])) {
|
||
$start = strtotime($search['sign_after']);
|
||
$end = strtotime($search['sign_before']);
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
}
|
||
//按指定时间临界点筛选(以不早于为优先筛选条件)
|
||
elseif (!empty($search['sign_after'])) {
|
||
$start = strtotime($search['sign_after']);
|
||
$where[] = ['>=','sign_date',$start];
|
||
} elseif (!empty($search['sign_before'])) {
|
||
$end = strtotime($search['sign_before']);
|
||
$where[] = ['<=','sign_date',$end];
|
||
}
|
||
if (isset($search['onlyme']) && $search['onlyme']==1) {
|
||
$where[] = ['=','create_by',Yii::$app->user->identity->id];
|
||
}
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
$data = $model->find()->where($where)->andwhere($orwhere);
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
public function actionDetail()
|
||
{
|
||
$pid = $this->pid;
|
||
$status = Yii::$app->params['OrderStatus'];
|
||
$post = $this->postdata;
|
||
|
||
$id = isset($post['oid']) ? $post['oid'] : 0;
|
||
if ($id<=0) {
|
||
$this->result('查询参数错误!');
|
||
}
|
||
$AcOrder = new AcOrder();
|
||
$order = $AcOrder->findOne($id);
|
||
$detail = $order->toArray();
|
||
$detail['thumbs'] = $detail['thumbs'] ? json_decode($detail['thumbs']) : [];
|
||
|
||
$model = new AcStore();
|
||
$store = $model->findOne($detail['store_id']);
|
||
if ($store) {
|
||
$detail['store_title'] = $store->title;
|
||
}
|
||
|
||
$model = new AcEmployee();
|
||
$employee = $model->findOne($detail['employee_id']);
|
||
if ($employee) {
|
||
$detail['employee_title'] = $employee->name;
|
||
}
|
||
|
||
$detail['car_owner_id']=$detail['car_brand_id']=$detail['car_series_id']=0;
|
||
$model = new AcCar();
|
||
$car = $model->findOne($detail['car_id']);
|
||
if ($car) {
|
||
$detail['car_owner_id'] = $car->owner_id;
|
||
$detail['car_brand_id'] = $car->brand_id;
|
||
$detail['car_series_id'] = $car->series_id;
|
||
$detail['car_number'] = $car->num_p.$car->num_area.$car->num_left;
|
||
$detail['car_number'] = $detail['car_number'] ? $detail['car_number'] : $car->num_frame;
|
||
}
|
||
|
||
$model = new User();
|
||
$user = $model->findOne($detail['from_mid']);
|
||
|
||
$model = new AcUserExt();
|
||
$exts = [];
|
||
$_exts = $model->find()->where(['mid'=>$detail['from_mid'],'pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
|
||
foreach ($_exts as $ext) {
|
||
$ext = $ext->toArray();
|
||
if (isset($users[$s['id']])) {
|
||
if ($ext['mobile']==$user->mobile) {
|
||
$exts[$ext['mid']][$ext['key']] = $ext['value'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$AcCarOwner = new AcCarOwner();
|
||
$owner = $AcCarOwner->findOne($detail['car_owner_id']);
|
||
if ($owner) {
|
||
$_owner = User::findOne($detail['car_owner_id']);
|
||
$detail['car_owner'] = $_owner->username.'【'.$_owner->mobile.'】';
|
||
}
|
||
|
||
$AcCarBrand = new AcCarBrand();
|
||
$brand = $AcCarBrand->findOne($detail['car_brand_id']);
|
||
if ($brand) {
|
||
$detail['car_title'] = $brand->title;
|
||
}
|
||
|
||
$AcCarSeries = new AcCarSeries();
|
||
$where = [];
|
||
$series= $AcCarSeries->findOne($detail['car_series_id']);
|
||
if ($series) {
|
||
$detail['car_title'] .= $series->title;
|
||
}
|
||
|
||
$sn = '00000000000'; //11位
|
||
$sn = substr($sn, 0, 11-strlen($id));
|
||
$sn .=$id;
|
||
$detail['sn'] = $sn;
|
||
|
||
$weekdays = [0=>'日',1=>'一',2=>'二',3=>'三',4=>'四',5=>'五',6=>'六'];
|
||
$wk = date('w', $detail['sign_date']);
|
||
$detail['signdate'] = date('Y-m-d 星期'.$weekdays[$wk], $detail['sign_date']);
|
||
$detail['from_province'] = Yii::$app->params['regionAreas'][$detail['start_province']];
|
||
$detail['to_province'] = Yii::$app->params['regionAreas'][$detail['aim_province']];
|
||
$detail['remark'] = htmlspecialchars_decode($detail['remark']);
|
||
|
||
$imgDir = Yii::getAlias('@upload');
|
||
$imgKeys = ['driving_lisence','thumb_f','thumb_b','thumb_l','thumb_r'];
|
||
foreach ($imgKeys as $k) {
|
||
$detail[$k] = $detail[$k] ? $detail[$k] : '/pics/nopic.jpg';
|
||
$url_pre = substr($detail[$k], 0, 4);
|
||
if ($url_pre =='/pic') {
|
||
$detail[$k.'_url'] = Url::to('@upload'.$detail[$k], $this->imgHttp);
|
||
} elseif ($url_pre =='http') {
|
||
$detail[$k.'_url'] = $detail[$k];
|
||
}
|
||
}
|
||
|
||
if ($detail['thumbs']) {
|
||
$thumbs = $detail['thumbs'];
|
||
$thumbs_url = [];
|
||
foreach ($thumbs as $k=>$v) {
|
||
$url_pre = substr($v, 0, 4);
|
||
if ($url_pre =='/pic') {
|
||
$v_url = Url::to('@upload'.$v, $this->imgHttp);
|
||
} elseif ($url_pre =='http') {
|
||
$v_url = $v;
|
||
}
|
||
$thumbs_url[] = ['src'=>$v,'url'=>$v_url];
|
||
}
|
||
$detail['thumbs_url'] = $thumbs_url;
|
||
}
|
||
|
||
$unsets = ['commission','commission_left','fee_truck','create_at','create_by','deleted','income','expense','fee_deliver','fee_extra','fee_insurance','fee_pickup','fee_urgent','from_bid','from_mid','is_commission','is_cwqr','is_holdon','is_over','pay_receive_pids','pay_send_pids','pre_id'];
|
||
foreach ($unsets as $us) {
|
||
unset($detail[$us]);
|
||
}
|
||
|
||
$this->result('订单查询成功!', $detail, 200);
|
||
}
|
||
|
||
public function actionCreate()
|
||
{
|
||
$get = Yii::$app->request->get();
|
||
$post = $this->postdata;
|
||
$pid = $this->pid;
|
||
|
||
//格式化数据 为空的项则不修改
|
||
//目标键=》POST键
|
||
$cols = ['start_province'=>'start_province','start_city'=>'start_city','aim_province'=>'aim_province','aim_city'=>'aim_city','aim_address'=>'aim_address',
|
||
'signer'=>'signer','bind'=>'bind','wtdw'=>"wtdw",
|
||
'sender_name'=>'sender_name','sender_idcard'=>'sender_idcard','sender_mobiles'=>'sender_mobiles',
|
||
'receiver_name'=>'receiver_name','receiver_idcard'=>'receiver_idcard','receiver_mobiles'=>'receiver_mobiles',
|
||
'car_extra'=>'car_extra'];
|
||
foreach ($cols as $col=>$key) {
|
||
if (isset($post[$key]) && $post[$key] !='') {
|
||
$data[$col] = trim($post[$key]);
|
||
}
|
||
}
|
||
//'car_id'=>'car_id','employee_id'=>'employee_id',
|
||
$cols = ['car_value'=>'car_value','fee_insurance'=>'fee_insurance','fee_truck'=>'fee_truck','fee_deliver'=>'fee_deliver','fee_pickup'=>'fee_pickup','fee_urgent'=>'fee_urgent','fee_extra'=>'fee_extra','fee_total'=>'fee_total','pay_send'=>'pay_send','pay_receive'=>'pay_receive','not_insurance'=>'not_insurance','weituo'=>'weituo'];
|
||
foreach ($cols as $col=>$key) {
|
||
$data[$col] = 0;
|
||
if (isset($post[$key]) && $post[$key] !='') {
|
||
$data[$col] = (int)$post[$key];
|
||
}
|
||
}
|
||
|
||
$cols = ['remark'=>'remark'];
|
||
foreach ($cols as $col=>$key) {
|
||
if (isset($post[$key]) && $post[$key] !='') {
|
||
$data[$col] = htmlspecialchars($post[$key]);
|
||
}
|
||
}
|
||
$data['remark'] = isset($data['remark']) ? isset($data['remark']) : '';
|
||
|
||
/*@sign_date: 1649952000000*/
|
||
$sign_date = isset($post['sign_date']) ? $post['sign_date']/1000 : '';
|
||
$data['sign_date'] = $sign_date ? $sign_date : time();
|
||
|
||
$mid = isset($post['mid']) ? (int)$post['mid'] : 11 ; //11是方孟
|
||
$data['create_by'] = $mid;
|
||
$data['is_cwqr'] = 0; //修改财务确认状态为待确认
|
||
$data['status_code'] = 1; //订单处于创建待审核状态
|
||
|
||
//部分规则校验
|
||
$hasError = 0;
|
||
$msg = '';
|
||
$fee_total = $data['fee_truck']+$data['fee_insurance']+$data['fee_deliver']+$data['fee_pickup']+$data['fee_urgent']+$data['fee_extra'];
|
||
$fee_pay = $data['pay_send']+$data['pay_receive'];
|
||
if (!$data['fee_truck']) {
|
||
$hasError += 1;
|
||
$msg .= '请注意,运费未正确填写!';
|
||
}
|
||
|
||
if ($fee_total !=$data['fee_total']) {
|
||
$hasError += 1;
|
||
$msg .= '所填各项费用汇总的值与所填写的总费用不一致!';
|
||
}
|
||
if ($fee_pay !=$data['fee_total']) {
|
||
$hasError += 1;
|
||
$msg .= '所填现付与到收费用汇总的值与所填写的总费用不一致!';
|
||
}
|
||
|
||
$data['create_at'] = time();
|
||
$data['update_at'] = $data['create_at'];
|
||
$data['pid'] = $pid;
|
||
|
||
$data['employee_id'] = isset($post['employee_id']) ? (int)$post['employee_id'] : 1; //1是宫雪
|
||
$data['store_id'] = 0;
|
||
$model = new AcEmployee();
|
||
$employee = $model->findOne($data['employee_id']);
|
||
if ($employee) {
|
||
$data['store_id'] = $employee->store_id;
|
||
}
|
||
|
||
//校验生成部分补充数据
|
||
//生成现付说明
|
||
$payments = [
|
||
'wechat'=>'微信',
|
||
'alipay'=>'支付宝',
|
||
'cash'=>'现金',
|
||
'bankcard'=>'银行卡',
|
||
'bankunion'=>'银联',
|
||
'others'=>'其他'
|
||
];
|
||
if ($post['pay_send']) {
|
||
$txt = $post['payto'].'收款'.$post['pay_send'].'元('.$payments[$post['payment']].')';
|
||
if ($data['remark']) {
|
||
$data['remark'] .= ' ; '.$txt;
|
||
} else {
|
||
$data['remark'] = $txt;
|
||
}
|
||
}
|
||
//生成车辆信息
|
||
$carModel = new AcCar();
|
||
$where = [];
|
||
if ($post['isTempCarno']) {
|
||
$post['carno_left'] .='临';
|
||
}
|
||
if (empty($post['carno_frame'])) {
|
||
$where['num_p'] = $post['carno_p'];
|
||
$where['num_area'] = $post['carno_area'];
|
||
$where['num_left'] = $post['carno_left'];
|
||
}
|
||
$post['carno_frame'] = isset($post['carno_frame']) ? $post['carno_frame'] : '';
|
||
if (!empty($post['carno_frame'])) {
|
||
$where['num_frame'] = $post['carno_frame'];
|
||
}
|
||
$car = $carModel->find()->where($where)->one();
|
||
if (empty($car)) {
|
||
$carModel->pid = $pid;
|
||
$carModel->num_frame = $post['carno_frame'];
|
||
$carModel->num_p = $post['carno_p'];
|
||
$carModel->num_area = $post['carno_area'];
|
||
$carModel->num_left = $post['carno_left'];
|
||
$carModel->title = $post['carno_title'];
|
||
$carModel->title = $post['carno_title'];
|
||
$carModel->status_code = 1;
|
||
$carModel->create_at = time();
|
||
$carModel->update_at = time();
|
||
$carModel->save();
|
||
$car_id = $carModel->attributes['id'];
|
||
} else {
|
||
$car_id = $car->id;
|
||
}
|
||
$data['car_id'] = $car_id;
|
||
|
||
//查询联系人信息是否在库
|
||
$sender_mobiles = isset($data['sender_mobiles']) ? $data['sender_mobiles'] : null;
|
||
$receiver_mobiles = isset($data['receiver_mobiles']) ? $data['receiver_mobiles'] : null;
|
||
if ($sender_mobiles) {
|
||
//项目分支自有数据表
|
||
$contactModel = new AcContact();
|
||
$contactor = $contactModel->find()->where(['mobile'=>$data['sender_mobiles'],'pid'=>$pid])->one();
|
||
if (empty($contactor)) {
|
||
$contactModel->name = isset($data['sender_name']) ? $data['sender_name'] : '客户';
|
||
$contactModel->mobile = $data['sender_mobiles'];
|
||
$contactModel->pid = $pid;
|
||
$contactModel->idcard = isset($data['sender_idcard']) ? $data['sender_idcard'] : '';
|
||
$contactModel->create_at = time();
|
||
$contactModel->status_code = 1;
|
||
$contactModel->save();
|
||
} else {
|
||
$_contactDatas = [];
|
||
$_contactDatas['name'] = isset($data['sender_name']) ? $data['sender_name'] : $contactModel->name;
|
||
$_contactDatas['idcard'] = isset($data['idcard']) ? $data['idcard'] : $contactModel->idcard;
|
||
if ($_contactDatas['name']==$contactModel->name && $_contactDatas['idcard'] ==$contactModel->idcard) {
|
||
//无须做任何变化
|
||
} else {
|
||
$_contactDatas['update_at'] = time();
|
||
$contactModel->updateAll($_contactDatas, ['id'=>$contactModel->id]);
|
||
}
|
||
}
|
||
|
||
//框架核心数据表Fans
|
||
$userModel = new Fans();
|
||
$user = $userModel->findByUsername($sender_mobiles);
|
||
if (empty($user)) {
|
||
$userModel->mobile = $sender_mobiles;
|
||
$userModel->email = $sender_mobiles.'@hiluker.com';
|
||
$userModel->setPassword(Yii::$app->params['defaultFansPassword']);
|
||
$userModel->generateAuthKey();
|
||
$userModel->created_at = time();
|
||
$userModel->from = 'ctms';
|
||
$userModel->save();
|
||
}
|
||
}
|
||
if ($receiver_mobiles && $receiver_mobiles != $sender_mobiles) {
|
||
//项目分支自有数据表
|
||
$contactModel2 = new AcContact();
|
||
$contactor2 = $contactModel2->find()->where(['mobile'=>$data['receiver_mobiles'],'pid'=>$pid])->one();
|
||
if (empty($contactor2)) {
|
||
$contactModel2->name = isset($data['receiver_name']) ? $data['receiver_name'] : '客户';
|
||
$contactModel2->mobile = $data['receiver_mobiles'];
|
||
$contactModel2->pid = $pid;
|
||
$contactModel2->idcard = isset($data['receiver_idcard']) ? $data['receiver_idcard'] : '';
|
||
$contactModel2->create_at = time();
|
||
$contactModel2->status_code = 1;
|
||
$contactModel2->save();
|
||
} else {
|
||
$_contactDatas = [];
|
||
$_contactDatas['name'] = isset($data['receiver_name']) ? $data['receiver_name'] : $contactModel2->name;
|
||
$_contactDatas['idcard'] = isset($data['idcard']) ? $data['idcard'] : $contactModel2->idcard;
|
||
if ($_contactDatas['name']==$contactModel2->name && $_contactDatas['idcard'] ==$contactModel2->idcard) {
|
||
//无须做任何变化
|
||
} else {
|
||
$_contactDatas['update_at'] = time();
|
||
$contactModel2->updateAll($_contactDatas, ['id'=>$contactModel2->id]);
|
||
}
|
||
}
|
||
//框架核心数据表Fans
|
||
$userModel = new Fans();
|
||
$user = $userModel->findByUsername($receiver_mobiles);
|
||
if (empty($user)) {
|
||
$userModel->mobile = $receiver_mobiles;
|
||
$userModel->email = $receiver_mobiles.'@hiluker.com';
|
||
$userModel->setPassword(Yii::$app->params['defaultFansPassword']);
|
||
$userModel->generateAuthKey();
|
||
$userModel->created_at = time();
|
||
$userModel->from = 'ctms';
|
||
$userModel->save();
|
||
}
|
||
}
|
||
|
||
//保存资料
|
||
$AcOrder = new AcOrder();
|
||
foreach ($data as $key=>$val) {
|
||
$AcOrder->$key = $val;
|
||
}
|
||
|
||
$res = $AcOrder->save();
|
||
$id = $AcOrder->attributes['id']; //获取插入后id
|
||
|
||
if ($res) {
|
||
$return = [];
|
||
$return['code'] = 200;
|
||
$return['msg'] = '订单保存成功!'.$msg;
|
||
$return['data']= ['id'=>$id];
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||
} else {
|
||
$return = [];
|
||
$return['code'] = 100;
|
||
$return['msg'] = '订单保存失败!';
|
||
$return['data']= [];
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||
}
|
||
}
|
||
|
||
public function actionAjax()
|
||
{
|
||
$get = Yii::$app->request->get();
|
||
$post = Yii::$app->request->post();
|
||
$id = (int)$get['id'];
|
||
$data = $where = [];
|
||
$where['id'] = $id;
|
||
$data['update_at'] = time();
|
||
|
||
$model = new AcOrder();
|
||
$res = $model->findOne($id);
|
||
$return = [];
|
||
$return['timeout'] = 1; //几秒后自动跳转
|
||
$return['status'] = 0;
|
||
$return['ajax'] = 1;
|
||
|
||
if (!$res) {
|
||
$return['msg'] = '订单数据不存在';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
} else {
|
||
$order = $res;
|
||
if ($order->deleted>0) {
|
||
$return['msg'] = '订单已被删除了,无法操作';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
}
|
||
|
||
switch ($get['do']) {
|
||
case 'cancel':
|
||
if ($order->is_cwqr>0) {
|
||
$return['msg'] = '订单已入账,请先联系财务销账后再取消';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($order->status_code>1) {
|
||
$return['msg'] = '订单已进入运输后流程,无法操作取消';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($order->status_code==-1) {
|
||
$return['msg'] = '订单已经是被取消状态';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
$data['status_code'] = -1;
|
||
$model->id = $id;
|
||
$res = $model->updateAll($data, $where);
|
||
if ($res) {
|
||
$return['msg'] = '订单取消成功';
|
||
$return['errorcode'] = 200;
|
||
$return['data'] = ['css'=>'btn-info'];
|
||
} else {
|
||
$return['msg'] = '订单取消失败';
|
||
$return['errorcode'] = 0;
|
||
}
|
||
break;
|
||
case 'truckcar':
|
||
if ($order->status_code==-1) {
|
||
$return['msg'] = '订单已被取消,不能承运';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($order->status_code!=1) {
|
||
$return['msg'] = '订单当前非初始状态(协议签订),不可作承运处理';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
$data['status_code'] = 5;
|
||
$model->id = $id;
|
||
$res = $model->updateAll($data, $where);
|
||
if ($res) {
|
||
$return['msg'] = '订单已转为待承运状态';
|
||
$return['errorcode'] = 200;
|
||
$return['data'] = ['css'=>'default'];
|
||
} else {
|
||
$return['msg'] = '订单标记失败,请稍后再试';
|
||
$return['errorcode'] = 0;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
|
||
//订单列表-昨日运单
|
||
public function actionYesterday()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
//签约时间筛选
|
||
$date = strtotime('-1 day');
|
||
$day = date('Y-m-d', $date);
|
||
$s = $day." 00:00:00";
|
||
$start = strtotime($s);
|
||
$e = $day." 23:59:59";
|
||
$end = strtotime($e);
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
// this->result('没有符合条件的结果',['total'=>0,'page'=>1,'data'=>null]);
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-今日运单
|
||
public function actionToday()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
// $session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
//签约时间筛选
|
||
$day = date('Y-m-d');
|
||
$s = $day." 00:00:00"; //注意开始必须是0分0秒
|
||
$start = strtotime($s);
|
||
$e = $day." 23:59:59";
|
||
$end = strtotime($e);
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('今日暂无运单');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-前天运单
|
||
public function actionQiantian()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
//签约时间筛选
|
||
$date = strtotime('-2 day');
|
||
$day = date('Y-m-d', $date);
|
||
$s = $day." 00:00:00";
|
||
$start = strtotime($s);
|
||
$e = $day." 23:59:59";
|
||
$end = strtotime($e);
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-本周运单
|
||
public function actionWeek()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//签约时间筛选;周日作为每周第一天
|
||
$week = date('w'); //今天周几(0~6);
|
||
$days = $week-1;
|
||
if ($week==0) {
|
||
$date = strtotime('-6'.' day'); //几天前
|
||
} else {
|
||
$date = strtotime('-'.$days.' day'); //几天前
|
||
}
|
||
|
||
$day = date('Y-m-d', $date);
|
||
$s = $day." 00:00:00";
|
||
$start = strtotime($s);
|
||
$e = $day." 23:59:59";
|
||
$end = strtotime($e);
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-上周运单
|
||
public function actionPreweek()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//签约时间筛选;周日作为每周第一天
|
||
$week = date('w'); //今天周几(0~6);
|
||
$days = 7+($week-1);
|
||
if ($week==0) {
|
||
$date = strtotime('-13'.' day'); //几天前
|
||
$date_end = strtotime('-7'.' day'); //几天前
|
||
} else {
|
||
$date = strtotime('-'.$days.' day'); //几天前
|
||
$date_end = strtotime('-'.$week.' day'); //几天前
|
||
}
|
||
$day = date('Y-m-d', $date);
|
||
$s = $day." 00:00:00";
|
||
$start = strtotime($s);
|
||
|
||
$day = date('Y-m-d', $date_end);
|
||
$e = $day." 23:59:59";
|
||
$end = strtotime($e);
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-本月运单
|
||
public function actionMonth()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//签约时间筛选;
|
||
$month = date('Y-m');
|
||
$s = $month."-01 00:00:00";
|
||
$start = strtotime($s);
|
||
|
||
$last_day = strtotime("last day of ".$month);
|
||
$e = date("Y-m-d", $last_day)." 23:59:59";
|
||
$end = strtotime($e);
|
||
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-上月运单
|
||
public function actionPremonth()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//签约时间筛选;
|
||
$month = date('Y-m', strtotime("-1 month"));
|
||
$s = $month."-01 00:00:00";
|
||
$start = strtotime($s);
|
||
|
||
$last_day = strtotime("last day of ".$month);
|
||
$e = date("Y-m-d", $last_day)." 23:59:59";
|
||
$end = strtotime($e);
|
||
|
||
$where[] = ['between','sign_date',$start,$end];
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-东北运单(黑吉辽方向)(包含部分内蒙古的)
|
||
public function actionDongbei()
|
||
{
|
||
$pid = $this->pid = 1;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//省份筛选
|
||
$provices = ['210000','220000','230000']; //辽,吉,黑
|
||
$citys = ['海拉尔','齐齐哈尔'];
|
||
$orWhere = [
|
||
'or',
|
||
['IN','aim_province',$provices],
|
||
['IN','start_province',$provices]
|
||
];
|
||
$orWhere2 = [];
|
||
$orWhere2[] = 'or';
|
||
foreach ($citys as $city) {
|
||
$orWhere2[] = ['LIKE','aim_city',$city];
|
||
}
|
||
$orWhere[] = $orWhere2;
|
||
|
||
$data = $model->find()->andWhere($where)->andWhere($orWhere);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-京津冀运单(包含部分内蒙古的)
|
||
public function actionArea1()
|
||
{
|
||
$pid = $this->pid = 1;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//省份筛选
|
||
$provices = ['110000','120000','130000']; //京,津,冀
|
||
$citys = ['包头','呼和浩特'];
|
||
// $where[]=['IN','aim_province',$provices];
|
||
// $orWhere = [];
|
||
// $orWhere[] = 'or';
|
||
// $orWhere[] = ['IN','aim_province',$provices];
|
||
// $orWhere[] = ['IN','from_province',$provices];
|
||
$orWhere = [
|
||
'or',
|
||
['IN','aim_province',$provices],
|
||
['IN','start_province',$provices]
|
||
];
|
||
$orWhere2 = [];
|
||
$orWhere2[] = 'or';
|
||
foreach ($citys as $city) {
|
||
$orWhere2[] = ['LIKE','aim_city',$city];
|
||
}
|
||
$orWhere[] = $orWhere2;
|
||
|
||
$data = $model->find()->andWhere($where)->andWhere($orWhere);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-川渝云贵运单
|
||
public function actionArea2()
|
||
{
|
||
$pid = $this->pid = 1;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//省份筛选
|
||
$provices = ['500000','510000','520000','530000']; //渝\川\贵\云
|
||
$citys = [];
|
||
$orWhere = [
|
||
'or',
|
||
['IN','aim_province',$provices],
|
||
['IN','start_province',$provices]
|
||
];
|
||
if ($citys) {
|
||
$orWhere2 = [];
|
||
$orWhere2[] = 'or';
|
||
foreach ($citys as $city) {
|
||
$orWhere2[] = ['LIKE','aim_city',$city];
|
||
}
|
||
$orWhere[] = $orWhere2;
|
||
}
|
||
|
||
$data = $model->find()->andWhere($where)->andWhere($orWhere);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-江浙沪运单
|
||
public function actionArea3()
|
||
{
|
||
$pid = $this->pid = 1;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//省份筛选
|
||
$provices = ['500000','510000','520000','530000']; //渝\川\贵\云
|
||
$citys = [];
|
||
$orWhere = [
|
||
'or',
|
||
['IN','aim_province',$provices],
|
||
['IN','start_province',$provices]
|
||
];
|
||
if ($citys) {
|
||
$orWhere2 = [];
|
||
$orWhere2[] = 'or';
|
||
foreach ($citys as $city) {
|
||
$orWhere2[] = ['LIKE','aim_city',$city];
|
||
}
|
||
$orWhere[] = $orWhere2;
|
||
}
|
||
|
||
$data = $model->find()->andWhere($where)->andWhere($orWhere);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-未验车运单
|
||
public function actionNocheck()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','is_checked',0]; //未验车
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
$data = $model->find()->where($where);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
//订单列表-我的运单(我经手或我创建的)
|
||
public function actionMine()
|
||
{
|
||
$pid = $this->pid;
|
||
$mid = $this->user_id;
|
||
$employee_id = $this->employee_id;
|
||
|
||
$session = Yii::$app->session;
|
||
$return = [];
|
||
$model = new AcOrder();
|
||
$where = $orwhere = $search = [];
|
||
$where[]='and';
|
||
$where[] = ['=','pid',$pid];
|
||
$post = $this->postdata;
|
||
$page = $this->page;
|
||
$pageSize = $this->pageSize;
|
||
|
||
$deleted = 0;
|
||
$where[]=['=','deleted',$deleted];
|
||
$where[]=['=','is_turnover',0]; //排除交车单
|
||
|
||
//创建者或关联员工筛选
|
||
$orWhere = [];
|
||
$orWhere[] = 'or';
|
||
$orWhere[] = ['=','create_by',$mid];
|
||
$orWhere[] = ['=','employee_id',$employee_id];
|
||
|
||
$data = $model->find()->andWhere($where)->andWhere($orWhere);
|
||
|
||
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
|
||
$pages->setPage($page-1, true); //设置分页的当前页面值
|
||
$_orderby = 'sign_date DESC,id DESC';
|
||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||
|
||
if (!$res) {
|
||
$this->result('没有符合条件的结果');
|
||
}
|
||
$this->showOrder($res, $data);
|
||
}
|
||
|
||
public function showOrder($orderRes, $data)
|
||
{
|
||
$status = Yii::$app->params['OrderStatus'];
|
||
|
||
$cids = $sids = $eids = $mids = [];
|
||
if ($orderRes) {
|
||
foreach ($orderRes as $r) {
|
||
$cids[$r->car_id] = $r->car_id;
|
||
$sids[$r->store_id] = $r->store_id;
|
||
$eids[$r->employee_id] = $r->employee_id;
|
||
$mids[$r->from_mid] = $r->from_mid;
|
||
}
|
||
}
|
||
|
||
$model = new AcStore();
|
||
$where = [];
|
||
$where['pid'] = Yii::$app->session->get('pid');
|
||
$_stores = $model->find()->where(['in','id',$sids])->all();
|
||
$stores = [];
|
||
foreach ($_stores as $s) {
|
||
$stores[$s->id] = $s->toArray();
|
||
}
|
||
|
||
$model = new AcEmployee();
|
||
$employees = [];
|
||
$_employees = $model->find()->where(['in','id',$eids])->indexBy('id')->all();
|
||
foreach ($_employees as $s) {
|
||
$employees[$s->id] = $s->toArray();
|
||
}
|
||
|
||
$model = new User();
|
||
$users = [];
|
||
$_users = $model->find()->where(['in','id',$mids])->all();
|
||
foreach ($_users as $s) {
|
||
$s = $s->toArray();
|
||
$users[$s['id']] = $s;
|
||
}
|
||
|
||
$model = new AcCar();
|
||
$cars = [];
|
||
$_cars = $model->find()->where(['in','id',$cids])->indexBy('id')->all();
|
||
$bids = $sids =[];
|
||
foreach ($_cars as $s) {
|
||
$bids[] = $s->brand_id;
|
||
$sids[] = $s->series_id;
|
||
$cars[$s->id] = $s->toArray();
|
||
}
|
||
|
||
if ($cars) {
|
||
foreach ($cars as &$car) {
|
||
$car['title2'] = '';
|
||
if (isset($brands[$car['brand_id']])) {
|
||
$car['title2'] .= $brands[$car['brand_id']]['title'];
|
||
}
|
||
if (isset($series[$car['series_id']])) {
|
||
$car['title2'] .= $series[$car['series_id']]['title'];
|
||
}
|
||
$car['number2'] = $car['num_frame'];
|
||
if ($car['num_p']) {
|
||
$car['number2'] = $car['num_p'];
|
||
}
|
||
if ($car['num_area']) {
|
||
$car['number2'] .= $car['num_area'];
|
||
}
|
||
if ($car['num_left']) {
|
||
$car['number2'] .= $car['num_left'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$orders = [];
|
||
$unsets = ['pid','commission','commission_left','fee_truck','create_at','create_by','deleted','income','expense','fee_deliver','fee_extra','fee_insurance','fee_pickup','fee_urgent','from_bid','from_mid','is_commission','is_cwqr','is_holdon','is_over','pay_receive_pids','pay_send_pids','pre_id','remark','car_extra','thumb_b','thumb_f','thumb_l','thumb_r','thumbs','driving_lisence','videos'];
|
||
|
||
foreach ($orderRes as $s) {
|
||
$car = $cars[$s->car_id];
|
||
$s = $s->toArray();
|
||
if (isset($exts[$s['from_mid']])) {
|
||
foreach ($exts[$s['from_mid']] as $col=>$val) {
|
||
$s[$col] = $val;
|
||
}
|
||
}
|
||
foreach ($unsets as $us) {
|
||
unset($s[$us]);
|
||
}
|
||
$weekdays = [0=>'日',1=>'一',2=>'二',3=>'三',4=>'四',5=>'五',6=>'六'];
|
||
$wk = date('w', $s['sign_date']);
|
||
$s['signdate'] = date('Y-m-d ', $s['sign_date']) . '星期'.$weekdays[$wk];
|
||
$s['from_province'] = Yii::$app->params['regionAreas'][$s['start_province']];
|
||
$s['to_province'] = Yii::$app->params['regionAreas'][$s['aim_province']];
|
||
$s['car_number']= $car['number2'];
|
||
$s['car_title'] = $car['title'];
|
||
$s['status'] = $status[$s['status_code']];
|
||
$orders[] = $s;
|
||
}
|
||
|
||
$return = [];
|
||
$return['code'] = 200;
|
||
$return['msg'] = '订单查询成功!';
|
||
$return['data']= ['total'=>$data->count(),
|
||
'data'=>[
|
||
'orders' => $orders,
|
||
'employees'=>$employees,
|
||
'stores'=>$stores,
|
||
'users'=>$users
|
||
],
|
||
'page'=>$this->page];
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||
}
|
||
}
|