ctms/ctms-admin/controllers/OrderController.php
fm453 39282ec584 修复登陆日志入库错误,升级部分composer依赖项;
临时修复登陆通知邮件不能多发的问题;
2025-04-10 23:19:15 +08:00

1641 lines
66 KiB
PHP
Executable File
Raw Permalink 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
# @Author: 嗨噜客(三亚) <fm453>
# @Date: 2022-04-24T20:55:17+08:00
# @Email: fm453@lukegzs.com
# @Last modified by: fm453
# @Last modified time: 2022-05-26T20:15:44+08:00
# @Copyright: www.hiluker.cn
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
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\Fans;
class OrderController extends Common
{
//主界面
public function actionIndex()
{
global $_HI,$_FM;
return $this->render('../layouts/dev', []);
}
//订单列表
public function actionList()
{
global $_HI,$_FM;
$pid = $this->pid;
$session = Yii::$app->session;
$model = new AcOrder();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = Yii::$app->request->post();
$get = Yii::$app->request->get();
$searchSession = 'orders::search';
if (isset($_GET['reset']) && $_GET['reset']==1) {
$post['search'] = [];
}
if (isset($post['search'])) {
$search = $post['search'];
$session->set($searchSession, $search);
} elseif ($session->get($searchSession)) {
$search = $session->get($searchSession);
}
$search['car_id'] = isset($search['car_id']) ? (int)$search['car_id'] : '';
$CarModel = new AcCar();
if (empty($search['car_id'])) {
$search['car_id'] = isset($get['car_id']) ? (int)$get['car_id'] : 0;
}
if (!empty($search['car_id'])) {
$where[] = ['=','car_id',$search['car_id']];
$car = $CarModel->findOne($search['car_id']);
$search['car_title'] = isset($car->title) ? $car->title : '';
}
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : '';
if (empty($search['employee'])) {
$search['employee'] = isset($get['employee_id']) ? (int)$get['employee_id'] : 0;
}
$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 Fans();
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']) ? (int)$search['wtdw'] : 0;
if ($search['wtdw']) {
$where[] = ['=','weituo',$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];
}
$search['is_turnover'] = isset($search['is_turnover']) ? $search['is_turnover'] : 0;
if (isset($_GET['turnover'])) {
$search['is_turnover'] = (int)$_GET['turnover']>=0 ? -1 : 0; //0排除1包含 -1仅查看
}
if ($search['is_turnover']==0) {
$where[]=['<>','is_turnover',1];
} elseif ($search['is_turnover']==-1) {
$where[]=['=','is_turnover',1];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$_orderby = 'id DESC';
if (isset($search['orderby']) && $search['orderby']=='sign_date') {
$_orderby = 'sign_date DESC,id DESC';
}
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
$status = Yii::$app->params['OrderStatus'];
$cids = $sids = $eids = $mids = [];
if ($res) {
foreach ($res 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 Fans();
$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();
}
$AcCarBrand = new AcCarBrand();
$where = [];
$brands = [];
$_brands = $AcCarBrand->find()->where($where)->andwhere(['in','id',$bids])->all();
if ($_brands) {
foreach ($_brands as $r) {
$brands[$r->id] = $r->toArray();
}
}
$AcCarSeries = new AcCarSeries();
$where = [];
$_series = $AcCarSeries->find()->where($where)->andwhere(['in','id',$sids])->all();
$series = [];
if ($_series) {
foreach ($_series as $r) {
$series[$r->id] = $r->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 = [];
foreach ($res as $s) {
$s = $s->toArray();
if (isset($exts[$s['from_mid']])) {
foreach ($exts[$s['from_mid']] as $col=>$val) {
$s[$col] = $val;
}
}
$orders[$s['id']] = $s;
}
if (isset($get['export']) && $get['export']=='all') {
$this->export($orders, $employees, $stores, $users, $cars, $brands, $series, $status);
die;
}
return $this->render('list', [
'orders' => $orders,
'pager' => $pages,
'employees'=>$employees,
'stores'=>$stores,
'users'=>$users,
'cars'=>$cars,
'brands'=>$brands,
'series'=>$series,
'status'=>$status,
'search'=>$search,
'totalCount'=>$data->count()
]);
}
//导出数据
public function export($orders, $employees, $stores, $users, $cars, $brands, $series, $status)
{
/* 输入到CSV文件 */
$html = "\xEF\xBB\xBF";//UTF8标记
$html .= "\n";
/* 输出表头 */
$filter = array(
'id' => '序号',
'car_number2' => '车牌号',
'car_title' => '车型',
'sender_name' => '发车人姓名',
'sender_mobiles' => '发车人电话',
'receiver_name' => '接车人姓名',
'receiver_mobiles' => '接车人电话',
'sign_date' => '签约时间',
'start_where' => '始发地',
'end_where' => '目的地',
'store' => '网点',
'employee' => '经办人',
'bind' => '委托方',
'car_value' => '车辆保价',
'fee_insurance' => '保费',
'fee_truck' => '运费',
'fee_total' => '总费用',
'pay_send' => '现付',
'pay_receive' => '到收',
'fee_pickup' => '提车费',
'fee_deliver'=>'送车费',
'status' => '运单状态',
'remark'=> '备注'
);
foreach ($filter as $key => $title) {
$html .= $title . ",\t";
}
$html .= "\n";//换行
$htmldata = "";
foreach ($orders as $vo) {
foreach ($filter as $key => $title) {
switch ($key) {
case 'car_number2':
$htmldata .= isset($cars[$vo['car_id']]['number2']) ? $cars[$vo['car_id']]['number2'] : '';
$htmldata .= ",\t";
break;
case 'car_title':
$htmldata .= isset($cars[$vo['car_id']]['title']) ? $cars[$vo['car_id']]['title'] : '';
$htmldata .= ",\t";
break;
case 'sign_date':
$htmldata .= date('Y年m月d日', $vo['sign_date']).",\t";
break;
case 'start_where':
$htmldata .= isset(Yii::$app->params['regionAreas'][$vo['start_province']]) ? Yii::$app->params['regionAreas'][$vo['start_province']] : '';
$htmldata .= '-';
$htmldata .= isset($vo['start_city']) ? $vo['start_city'] : '';
$htmldata .= ",\t";
break;
case 'store':
$htmldata .= isset($stores[$vo['store_id']]['title']) ? $stores[$vo['store_id']]['title'] : '';
$htmldata .= ",\t";
break;
case 'employee':
$htmldata .= isset($employees[$vo['employee_id']]['name']) ? $employees[$vo['employee_id']]['name'] : '';
$htmldata .= ",\t";
break;
case 'end_where':
$htmldata .= isset(Yii::$app->params['regionAreas'][$vo['aim_province']]) ? Yii::$app->params['regionAreas'][$vo['aim_province']] : '';
$htmldata .= '-';
$htmldata .= isset($vo['aim_city']) ? $vo['aim_city'] : '';
$htmldata .= ",\t";
break;
case 'remark':
$htmldata .= strip_tags(htmlspecialchars_decode($vo['remark'])).",\t";
break;
case 'status':
$htmldata .= $status[$vo['status_code']].",\t";
break;
case 'pay_receive':
case 'pay_send':
case 'fee_total':
case 'fee_truck':
case 'fee_insurance':
case 'car_value':
$htmldata .= isset($vo[$key]) ? (int)$vo[$key] : 0;
$htmldata .= ",\t";
break;
default:
$htmldata .= isset($vo[$key]) ? $vo[$key] : '';
$htmldata .= ",\t";
break;
}
}
$htmldata .= "\n";
}
$html .=$htmldata;
/* 输出XLS文件 */
header("Content-type:text/xls");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:text/comma-separated-values;charset=UTF-8");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Transfer-Encoding:binary");
header("Content-Disposition:attachment; filename=运单列表".date('ymd').".xls");
echo $html;
}
//选择装车
public function actionZhuangcheselect()
{
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$session = Yii::$app->session;
$model = new AcOrder();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = Yii::$app->request->post();
$get = Yii::$app->request->get();
$searchSession = 'orders::search';
if (isset($post['search'])) {
$search = $post['search'];
$session->set($searchSession, $search);
} elseif ($session->get($searchSession)) {
$search = $session->get($searchSession);
}
$search['car_id'] = isset($search['car_id']) ? (int)$search['car_id'] : '';
$CarModel = new AcCar();
if (empty($search['car_id'])) {
$search['car_id'] = isset($get['car_id']) ? (int)$get['car_id'] : 0;
}
if (!empty($search['car_id'])) {
$where[] = ['=','car_id',$search['car_id']];
$car = $CarModel->findOne($search['car_id']);
$search['car_title'] = isset($car->title) ? $car->title : '';
}
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : '';
if (empty($search['employee'])) {
$search['employee'] = isset($get['employee_id']) ? (int)$get['employee_id'] : 0;
}
$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 Fans();
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']) : '';
if (!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']];
}
$search['status_code'] = 5;
$where[] = ['=','status_code',$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];
}
$turnover = 0;
if (isset($_GET['turnover'])) {
$turnover = isset($_GET['turnover']) ? ((int)$_GET['turnover']>=0 ? 1 : 0) : 0;
}
$turnover = isset($search['is_turnover']) ? ((int)$search['is_turnover']==1 ? 1 : 0) : 0;
$where[]=['=','is_turnover',$turnover];
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('sign_date DESC,id DESC')->all();
$status = Yii::$app->params['OrderStatus'];
$cids = $sids = $eids = $mids = [];
if ($res) {
foreach ($res 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 Fans();
$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();
}
$AcCarBrand = new AcCarBrand();
$where = [];
$brands = [];
$_brands = $AcCarBrand->find()->where($where)->andwhere(['in','id',$bids])->all();
if ($_brands) {
foreach ($_brands as $r) {
$brands[$r->id] = $r->toArray();
}
}
$AcCarSeries = new AcCarSeries();
$where = [];
$_series = $AcCarSeries->find()->where($where)->andwhere(['in','id',$sids])->all();
$series = [];
if ($_series) {
foreach ($_series as $r) {
$series[$r->id] = $r->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 = [];
foreach ($res as $s) {
$s = $s->toArray();
if (isset($exts[$s['from_mid']])) {
foreach ($exts[$s['from_mid']] as $col=>$val) {
$s[$col] = $val;
}
}
$orders[$s['id']] = $s;
}
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'order';
return $this->render('select', [
'orders' => $orders,
'pager' => $pages,
'employees'=>$employees,
'stores'=>$stores,
'users'=>$users,
'cars'=>$cars,
'brands'=>$brands,
'series'=>$series,
'status'=>$status,
'search'=>$search,
'callback'=>$callback
]);
}
public function actionNew()
{
$status = Yii::$app->params['OrderStatus'];
$AcOrder = new AcOrder();
$AcOrder->status_code = 0;
$detail = $AcOrder->toArray();
return $this->render('modify', ['status'=>$status,'detail'=>$detail]);
}
public function actionEdit()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
$detail = $order->toArray();
$imgKeys = ['driving_lisence','thumb_f','thumb_b','thumb_l','thumb_r'];
foreach ($imgKeys as $k) {
$detail[$k] = $detail[$k] ? $detail[$k] : '';
$url_pre = substr($detail[$k], 0, 4);
if ($url_pre =='/pic') {
$detail[$k.'_url'] = Url::to('@upload'.$detail[$k]);
} elseif ($url_pre =='http') {
$detail[$k.'_url'] = $detail[$k];
} else {
$detail[$k.'_url'] = Url::to('@upload/pics/nopic.jpg');
}
}
$detail['thumbs'] = $detail['thumbs']?json_decode($detail['thumbs']):[];
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);
} elseif ($url_pre =='http') {
$v_url = $v;
}
$thumbs_url[$k] = ['src'=>$v,'url'=>$v_url];
}
$detail['thumbs_url'] = $thumbs_url;
}
$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 Fans();
$user = $model->findOne($detail['from_mid']);
$AcCarOwner = new AcCarOwner();
$owner = $AcCarOwner->findOne($detail['car_owner_id']);
if ($owner) {
// $_owner = Fans::findOne($detail['car_owner_id']); //fans表更新已无此字段
// $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;
}
$op = Yii::$app->request->get('op');
$tpl = 'modify';
if ($op=='print') {
$tpl = 'print';
$sn = '00000000000'; //11位
$sn = substr($sn, 0, 11-strlen($id));
$sn .=$id;
$detail['sn'] = $sn;
}
return $this->render(
$tpl,
[
'status'=>$status,
'detail'=>$detail,
'store'=>$store,
'employee'=>$employee,
'id'=>$id
]
);
}
/*复制订单*/
public function actionCopy()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
$detail = $order->toArray();
$imgKeys = ['driving_lisence','thumb_f','thumb_b','thumb_l','thumb_r'];
foreach ($imgKeys as $k) {
$detail[$k] = '';
$detail[$k.'_url'] = '';
}
$detail['thumbs'] = [];
$detail['thumbs_url'] = [];
$detail['remark'] = '';
$detail['start_km'] = '';
$detail['checker'] = '';
$detail['is_checked'] = 0;
$detail['create_by'] = null;
$detail['no_driving_lisence'] = 0;
unset($detail['id']);
$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;
$op = Yii::$app->request->get('op');
$tpl = 'modify';
return $this->render(
$tpl,
[
'status'=>$status,
'detail'=>$detail,
'store'=>$store,
'employee'=>$employee,
'id'=>0
]
);
}
public function actionDetail()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
$detail = $order->toArray();
$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]);
} elseif ($url_pre =='http') {
$detail[$k.'_url'] = $detail[$k];
}
}
$detail['thumbs'] = json_decode($detail['thumbs']);
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);
} elseif ($url_pre =='http') {
$v_url = $v;
}
$thumbs_url[] = ['src'=>$v,'url'=>$v_url];
}
$detail['thumbs_url'] = $thumbs_url;
}
$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 Fans();
$user = $model->findOne($detail['from_mid']);
$AcCarOwner = new AcCarOwner();
$owner = $AcCarOwner->findOne($detail['car_owner_id']);
if ($owner) {
$_owner = Fans::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;
return $this->render(
'detail',
[
'status'=>$status,
'detail'=>$detail,
'store'=>$store,
'employee'=>$employee,
'id'=>$id
]
);
}
//保存运单信息
public function actionSave()
{
$post = Yii::$app->request->post();
$id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
$AcOrder = new AcOrder();
if ($id) {
$order = $AcOrder->findOne($id);
if (($order->create_by != Yii::$app->user->identity->id) && (Yii::$app->user->identity->id != 1)) {
//不允许修改非本人操作的表单
$return['msg'] = '您不是该运单的制单人,不允许进行修改!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
//格式化数据 为空的项则不修改
//目标键=》POST键
$cols = ['start_province'=>'start_province','start_city'=>'start_city','aim_province'=>'aim_province','aim_city'=>'aim_city','signer'=>'signer','sender_name'=>'sender_name','sender_idcard'=>'sender_idcard','sender_mobiles'=>'sender_mobiles','receiver_name'=>'receiver_name','receiver_idcard'=>'receiver_idcard','receiver_mobiles'=>'receiver_mobiles','aim_address'=>'aim_address','thumb_f'=>'thumb_f','thumb_b'=>'thumb_b','thumb_l'=>'thumb_l','thumb_r'=>'thumb_r','car_extra'=>'car_extra','bind'=>'bind','driving_lisence'=>'driving_lisence','wtdw'=>"wtdw",'checker'=>'checker'];
foreach ($cols as $col=>$key) {
if (isset($post[$key]) && $post[$key] !='') {
$data[$col] = trim($post[$key]);
}
// $data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['car_id'=>'car_id','employee_id'=>'employee_id','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','is_checked'=>'is_checked','is_turnover'=>'is_turnover','no_driving_lisence'=>'no_driving_lisence','start_km'=>'start_km','not_insurance'=>'not_insurance','weituo'=>'weituo','pre_id'=>'pre_id','store_id'=>'store_id','from_mid'=>'from_mid','from_bid'=>'from_bid'];
foreach ($cols as $col=>$key) {
$data[$col] = 0;
if (isset($post[$key]) && $post[$key] !='') {
$data[$col] = (int)$post[$key];
}
// $data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
//图片组处理
$cols = ['thumbs'=>'thumbs'];
foreach ($cols as $col=>$key) {
if (isset($post[$key]) && !empty($post[$key])) {
$imgs = $post[$key]; //数组格式
$imgs = array_unique($imgs);
$imgs = json_encode($imgs);
$data[$col] = $imgs;
}
}
$cols = ['remark'=>'editor'];
foreach ($cols as $col=>$key) {
if (isset($post[$key]) && $post[$key] !='') {
$data[$col] = htmlspecialchars($post[$key]);
}
// $data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
}
$sign_date = isset($post['sign_date']) ? strtotime($post['sign_date']) : '';
$data['sign_date'] = $sign_date ? $sign_date : time();
if (!$id) {
$data['create_by'] = Yii::$app->user->identity->id;
}
//部分规则校验
$has_err = false;
$data['is_cwqr'] = 0; //修改财务确认状态为待确认
if (!$id) {
$data['status_code'] = 1;
}
/*不投保的保额不超过20W保费为0*/
if ($data['not_insurance']) {
if ($data['fee_insurance']) {
$data['fee_insurance']=0;
\Yii::$app->getSession()->setFlash('warning', '勾选了不投保已强制修改保费为0');
}
if ($data['car_value']>Yii::$app->params['DefaultCarInsuranceValueMax']) {
$has_err = true;
$data['car_value'] = Yii::$app->params['DefaultCarInsuranceValueMax'];
\Yii::$app->getSession()->setFlash('danger', '勾选了不投保,默认最高赠送的运输险保额不超过'.Yii::$app->params['DefaultCarInsuranceValueMax'].'万元,已自动强制校正');
}
}
$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']) {
$has_err = true;
\Yii::$app->getSession()->setFlash('danger', '请注意,运费未正确填写!');
}
if (!$data['pay_send']&&!$data['pay_receive']) {
$has_err = true;
\Yii::$app->getSession()->setFlash('danger', '请注意,到收运费及起运地预收运费均未填写!');
}
if ($fee_total !=$data['fee_total']) {
$has_err = true;
\Yii::$app->getSession()->setFlash('danger', '请注意,所填运费、保费、提车费、送车费、额外费用、加急费等各项费用汇总的值与所填写的总费用不一致,请检查并更新');
}
if ($fee_pay !=$data['fee_total']) {
$has_err = true;
\Yii::$app->getSession()->setFlash('danger', '请注意,所填起运地预付运费、到收运费的汇总值与所填写的总费用不一致,请检查并更新');
}
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$data['pid'] = $pid;
$model = new AcEmployee();
$employee = $model->findOne($data['employee_id']);
if ($employee) {
$data['store_id'] = $employee->store_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();
}
}
//保存资料
if ($id) {
unset($data['create_at']);
$res = $AcOrder->updateAll($data, ['id'=>$id]);
} else {
foreach ($data as $key=>$val) {
$AcOrder->$key = $val;
}
$res = $AcOrder->save();
$id = $AcOrder->attributes['id']; //获取插入后id
}
if ($res) {
if ($has_err) {
\Yii::$app->getSession()->setFlash('success', '订单保存成功,但有价格数据录入错误,请根据情况检查更新!');
} else {
\Yii::$app->getSession()->setFlash('success', '订单保存成功!');
}
return $this->redirect(['edit','id'=>$id]);
} else {
\Yii::$app->getSession()->setFlash('warning', '订单保存失败!');
return $this->goBack();
}
}
/*财务人员操作*/
public function actionCaiwu()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
$detail = $order->toArray();
$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 Fans();
$user = $model->findOne($detail['from_mid']);
$AcCarOwner = new AcCarOwner();
$owner = $AcCarOwner->findOne($detail['car_owner_id']);
if ($owner) {
$_owner = Fans::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;
}
$op = Yii::$app->request->get('op');
$sn = '00000000000'; //11位
$sn = substr($sn, 0, 11-strlen($id));
$sn .=$id;
$detail['sn'] = $sn;
return $this->render(
'caiwu',
[
'status'=>$status,
'detail'=>$detail,
'store'=>$store,
'employee'=>$employee,
'id'=>$id
]
);
}
/*财务保存*/
public function actionCwsave()
{
$post = Yii::$app->request->post();
$id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
$_time = time();
if (!isset($post['vcode'])) {
$return['msg'] = '填写财务操作验证码才能继续!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
} elseif ($post['vcode']=='') {
$return['msg'] = '填写财务操作验证码才能继续!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
} else {
//校验验证码
$plat = AcPlat::findOne($pid);
$platExt = json_decode($plat->remark, true);
$vcodeModel = new CVcode();
//查询上次发送记录
$where=[];
$where['mobile'] = $platExt['cw_phone'];
$where['deleted'] = 0;
$where['type'] = 'caiwu';
$res = $vcodeModel->find()->where($where)->orderby('id DESC')->one();
if ($res) {
if (($_time-$res->create_at)>7200) {
$return['msg'] = '验证码已超时,请重新获取后再填写提交!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
} else {
if ($post['vcode']!=$res->code) {
$return['msg'] = '财务操作验证码校验失败,请检查并重新输入验证码!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
} else {
$return['msg'] = '财务操作验证码校验失败,请确认是否配置了财务手机号或发送了验证码!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
$AcOrder = new AcOrder();
if ($id) {
$order = $AcOrder->findOne($id);
if ($order->pid != $pid) {
//不允许修改非本平台操作的表单
$return['msg'] = '该运单不属于当前平台,您没有修改修改权限!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
//格式化数据
//目标键=》POST键
$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'];
foreach ($cols as $col=>$key) {
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
//部分规则校验
/*不投保的保额不超过20W*/
if ($data['not_insurance']) {
if ($data['fee_insurance']) {
$return['msg'] = '勾选了不投保,不应该有保费,请检查!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($data['car_value']>Yii::$app->params['DefaultCarInsuranceValueMax']) {
$hasConfirmCarValue = Yii::$app->session->get('hasConfirmCarValue');
if (!$hasConfirmCarValue) {
Yii::$app->session->set('hasConfirmCarValue', 1);
$return['msg'] = '勾选了不投保,但车辆保价超过默认最高赠送的运输险保额'.Yii::$app->params['DefaultCarInsuranceValueMax'].'元;如果确认,再次点击确认提交按钮即可!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
}
$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']) {
$return['msg'] = '请注意运费不应为0请正确填写请检查';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if (!$data['pay_send']&&!$data['pay_receive']) {
$return['msg'] = '请注意,到收运费及起运地预收运费均未填写,请检查!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($fee_total !=$data['fee_total']) {
$return['msg'] = '请注意,所填运费、保费、提车费、送车费、额外费用、加急费等各项费用汇总的值与所填写的总费用不一致,请检查并更新!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($fee_pay !=$data['fee_total']) {
$return['msg'] = '请注意,所填起运地预付运费、到付运费的汇总值与所填写的总费用不一致,请检查并更新!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
$data['is_cwqr'] = 1; //修改财务确认状态为已确认
$data['update_at'] = $_time;
//保存车辆资料
foreach ($data as $key=>$val) {
$AcOrder->$key = $val;
}
$res = $AcOrder->updateAll($data, ['id'=>$id]);
if ($res) {
$return['msg'] = '财务审核成功!';
$return['errorcode'] = 0;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
} else {
$return['msg'] = '财务审核失败!';
$return['errorcode'] = 0;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
public function actionDelete()
{
$get = Yii::$app->request->get();
$post = Yii::$app->request->post();
$id = (int)$get['id'];
$return = [];
$model = new AcOrder();
$order = $model->findOne($id);
if (!$order) {
$return['msg'] = '订单数据不存在';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
} else {
if ($order->deleted>0) {
$return['msg'] = '订单已被删除了';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->is_cwqr>0) {
$return['msg'] = '订单已入账,不允许删除';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->status_code!=0) {
$return['msg'] = '订单非初始状态,不可删除;如果该订单不正确,可取消操作';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
$data = $where = [];
$where['pid'] = Yii::$app->session->get('pid');
$where['id'] = $id;
$data['update_at'] = time();
$data['deleted'] = 1;
$model->id = $id;
$res = $model->updateAll($data, $where);
$return = [];
$return['url'] = Url::toRoute('order/list');
$return['timeout'] = 3; //3秒后自动跳转
$return['status'] = 0;
if ($res) {
$return['msg'] = '订单删除成功';
$return['errorcode'] = 200;
$return['data'] = $id;
} else {
$return['msg'] = '订单删除失败';
$return['errorcode'] = 0;
}
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
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 actionCommission()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
if (empty($order->bind)) {
$return = [];
$return['msg'] = '该运单未声明介绍人,无法设置佣金/返款!';
$return['errorcode'] = 0;
$return['url'] = '';
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}
$detail = $order->toArray();
return $this->render(
'commission',
[
'status'=>$status,
'detail'=>$detail,
'id'=>$id
]
);
}
/*佣金保存*/
public function actionCommissionsave()
{
$pid = Yii::$app->session->get('pid');
$post = Yii::$app->request->post();
$id = Yii::$app->request->post('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
$return = [];
if (!$order) {
$return['msg'] = '订单数据不存在';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->create_by!=Yii::$app->user->identity->id) {
$return['msg'] = '您不是该运单的制单人,不允许修改数据!';
$return['errorcode'] = 100;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->is_cwqr==1) {
$return['msg'] = '该运单已经财务审核确认,不允许再作佣金修改!';
$return['errorcode'] = 100;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->is_over==1) {
$return['msg'] = '该运单已经结束,不允许再作修改!';
$return['errorcode'] = 100;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->status_code==-1) {
$return['msg'] = '该运单已经取消,不允许再作佣金修改!';
$return['errorcode'] = 100;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if (empty($order->bind)) {
$return['msg'] = '该运单未声明介绍人,无法设置佣金/返款!';
$return['errorcode'] = 100;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if (!isset($post['commission'])) {
$return['msg'] = '未设置佣金金额,操作无效!';
$return['errorcode'] = 400;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
$commission = (int)$post['commission'];
if (!$commission>0) {
$return['msg'] = '佣金金额设置无效,操作失败!';
$return['errorcode'] = 400;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
$data = [];
$data['update_at'] = time();
$data['is_commission'] = 1;
$data['commission'] = $data['commission_left'] = $commission;
$res = $order->updateAll($data, ['id'=>$id]);
if (!$res) {
$return['msg'] = '运单数据保存失败,请稍后再试!';
$return['errorcode'] = 400;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
$return['msg'] = '操作成功';
$return['errorcode'] = 200;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}