# @Date: 2022-05-22T07:37:46+08:00 # @Email: fm453@lukegzs.com # @Last modified by: fm453 # @Last modified time: 2022-05-22T07:37:46+08:00 # @Copyright: www.hiluker.cn namespace backend\controllers; use Yii; use yii\data\Pagination; use yii\helpers\Url; use addons\models\AcTruck; use addons\models\AcDriver; use addons\models\AcTruckOnline; use addons\models\AcTruckCars; use addons\models\AcStore; use addons\models\AcCar; use addons\models\AcCarBrand; use addons\models\AcCarSeries; use addons\models\AcOrder; use addons\models\AcEmployee; use addons\models\AcGps; use addons\models\AcGpsRoute; class TruckolController extends Common { //出车单 public function actionIndex() { $AcTruckOnline = new AcTruckOnline(); $where = []; $where[]='and'; $where[] = ['=','pid',Yii::$app->session->get('pid')]; $where[] = ['>','status_code',0]; $post = Yii::$app->request->post(); $search = []; $search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : ''; if (!empty($search['title'])) { $where[] = ['LIKE','num_left',$search['title']]; } $where[] = ['=','deleted',0]; $data = $AcTruckOnline->find()->where($where); $pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '10']); $res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all(); $status = Yii::$app->params['TruckOnlineStatus']; $stores = []; $AcStore = new AcStore(); if ($res) { $store_ids = []; foreach ($res as $r) { $store_ids[$r->from_store] = $r->from_store; $store_ids[$r->end_store] = $r->end_store; } array_unique($store_ids); $_stores = $AcStore->find()->where(['IN','id',$store_ids])->all(); if ($_stores) { foreach ($_stores as $r) { $stores[$r->id] = $r->toArray(); } } } return $this->render('index', [ 'list'=>$res, 'pager' => $pages, 'status'=>$status, 'stores'=>$stores, 'search'=>$search ]); } //在线板车列表(标记了发车状态——装车中的) public function actionList() { $AcTruck = new AcTruck(); $where = []; $where[]='and'; $where[] = ['=','pid',Yii::$app->session->get('pid')]; $where[] = ['=','status_code',4]; $post = Yii::$app->request->post(); $search = []; $search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : ''; if (!empty($search['title'])) { $where[] = ['LIKE','num_left',$search['title']]; } $where[] = ['=','deleted',0]; $data = $AcTruck->find()->where($where); $pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']); $res = $data->offset($pages->offset)->limit($pages->limit)->all(); $status = Yii::$app->params['TruckStatus']; $AcDriver = new AcDriver(); $where = []; $where['pid'] = Yii::$app->session->get('pid'); $_drivers = $AcDriver->find()->where($where)->all(); $drivers = []; foreach ($_drivers as $s) { $drivers[$s->id] = $s->toArray(); } return $this->render('list', [ 'trucks'=>$res, 'pager' => $pages, 'drivers'=>$drivers, 'status'=>$status, 'search'=>$search ]); } //选择可装车的板车 public function actionSelect() { $AcTruck = new AcTruck(); $where = []; $where[]='and'; $where[] = ['=','pid',Yii::$app->session->get('pid')]; $where[] = ['=','status_code',4]; $post = Yii::$app->request->post(); $search = []; $search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : ''; if (!empty($search['title'])) { $where[] = ['LIKE','num_left',$search['title']]; } $where[] = ['=','deleted',0]; $data = $AcTruck->find()->where($where); $pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']); $res = $data->offset($pages->offset)->limit($pages->limit)->all(); $status = Yii::$app->params['TruckStatus']; $AcDriver = new AcDriver(); $where = []; $where['pid'] = Yii::$app->session->get('pid'); $_drivers = $AcDriver->find()->where($where)->all(); $drivers = []; foreach ($_drivers as $s) { $drivers[$s->id] = $s->toArray(); } $callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truckol'; return $this->render('select', [ 'trucks'=>$res, 'pager' => $pages, 'drivers'=>$drivers, 'status'=>$status, 'search'=>$search, 'callback'=>$callback ]); } public function actionSelect2() { $AcTruckOnline = new AcTruckOnline(); $where = []; $where[]='and'; $where[] = ['=','pid',Yii::$app->session->get('pid')]; $where[] = ['>','status_code',0]; $post = Yii::$app->request->post(); $search = []; $search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : ''; if (!empty($search['title'])) { $where[] = ['LIKE','num_left',$search['title']]; } $where[] = ['=','deleted',0]; $data = $AcTruckOnline->find()->where($where); $pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '10']); $res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all(); $status = Yii::$app->params['TruckOnlineStatus']; $stores = []; $AcStore = new AcStore(); if ($res) { $store_ids = []; foreach ($res as $r) { $store_ids[$r->from_store] = $r->from_store; $store_ids[$r->end_store] = $r->end_store; } array_unique($store_ids); $_stores = $AcStore->find()->where(['IN','id',$store_ids])->all(); if ($_stores) { foreach ($_stores as $r) { $stores[$r->id] = $r->toArray(); } } } $callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truckol'; return $this->render('select2', [ 'list'=>$res, 'pager' => $pages, 'status'=>$status, 'stores'=>$stores, 'search'=>$search, 'callback'=>$callback ]); } public function actionNew() { $status = Yii::$app->params['TruckOnlineStatus']; $AcTruckOnline = []; $AcTruckOnline['status_code'] = 0; return $this->render('edit', ['status'=>$status,'detail'=>$AcTruckOnline]); } //编辑板车装车计划资料 public function actionEdit() { // $id = Yii::$app->request->get('id'); //装车任务ID $id = 0; $truck_id = Yii::$app->request->get('truck_id'); //板车ID $store_id = $store2_id = 0; $pid = Yii::$app->session->get('pid'); $AcTruckOnline = new AcTruckOnline(); $AcTruck = new AcTruck(); $truckol = []; $truck = $AcTruck->findOne($truck_id); if (!$truck) { $post = Yii::$app->request->post(); $return = []; $return['msg'] = '关联板车数据获取异常,发车任务编辑失败'; $return['errorcode'] = 0; $return['url'] = Url::toRoute(['truck/list',$post]); $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'); } if (!$id) { $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['=','truck_id',$truck_id]; $where[] = ['<','status_code',99]; $where[] = ['=','deleted',0]; $res = $AcTruckOnline->find()->where($where)->orderby('id ASC')->one(); if ($res) { $id = $res->id; $store_id = $res->from_store; $store2_id = $res->end_store; $truckol = $res->toArray(); } } $truckol['truck_id'] = $truck_id; $truckol['truck_title'] = $truck->num_p.$truck->num_area.$truck->num_left; $truckol['truck_num'] = $truckol['truck_title'] ? $truckol['truck_title'] : $truckol['truck_num']; $AcStore = new AcStore(); $store = $AcStore->findOne($store_id); if ($store) { $truckol['fromstore_title'] = $store->title; } $store2 = $AcStore->findOne($store2_id); if ($store2) { $truckol['endstore_title'] = $store2->title; } $AcDriver = new AcDriver(); $driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one(); $truckol['driver_title'] = $truckol['driver_mobile'] = ''; if ($driver) { $truckol['driver_title'] = $driver->name; $truckol['driver_mobile'] = $driver->mobile; } $truckol['driver_name'] = isset($truckol['driver_name']) ? $truckol['driver_name'] : $truckol['driver_title']; $truckol['driver_mobiles'] = isset($truckol['driver_mobiles']) ? $truckol['driver_mobiles'] : $truckol['driver_mobile']; $status = Yii::$app->params['TruckOnlineStatus']; return $this->render('edit', ['status'=>$status,'detail'=>$truckol]); } //更新板车装车任务资料 public function actionModify() { $id = Yii::$app->request->get('id'); //装车任务ID // $truck_id = Yii::$app->request->get('truck_id'); //板车ID $truck_id = 0; $store_id = $store2_id = 0; $pid = Yii::$app->session->get('pid'); $AcTruckOnline = new AcTruckOnline(); $AcTruck = new AcTruck(); $truckol = []; $res = $AcTruckOnline->findOne($id); if ($res) { $truck_id = $res->truck_id; $store_id = $res->from_store; $store2_id = $res->end_store; $truckol = $res->toArray(); } $truck = $AcTruck->findOne($truck_id); if (!$truck) { $post = Yii::$app->request->post(); $return = []; $return['msg'] = '关联板车数据获取异常,发车任务编辑失败'; $return['errorcode'] = 0; $return['url'] = Url::toRoute(['truck/list',$post]); $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'); } $truckol['truck_id'] = $truck_id; $truckol['truck_title'] = $truck->num_p.$truck->num_area.$truck->num_left; $truckol['truck_num'] = $truckol['truck_title'] ? $truckol['truck_title'] : $truckol['truck_num']; $AcStore = new AcStore(); $store = $AcStore->findOne($store_id); if ($store) { $truckol['fromstore_title'] = $store->title; } $store2 = $AcStore->findOne($store2_id); if ($store2) { $truckol['endstore_title'] = $store2->title; } $AcDriver = new AcDriver(); $driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one(); $truckol['driver_title'] = $truckol['driver_mobile'] = ''; if ($driver) { $truckol['driver_title'] = $driver->name; $truckol['driver_mobile'] = $driver->mobile; } $truckol['driver_name'] = isset($truckol['driver_name']) ? $truckol['driver_name'] : $truckol['driver_title']; $truckol['driver_mobiles'] = isset($truckol['driver_mobiles']) ? $truckol['driver_mobiles'] : $truckol['driver_mobile']; $status = Yii::$app->params['TruckOnlineStatus']; return $this->render('modify', ['status'=>$status,'detail'=>$truckol]); } //保存装车基础资料 public function actionSave() { $post = Yii::$app->request->post(); $id = (int)$post['id']; $pid = Yii::$app->session->get('pid'); //格式化数据 //目标键=》POST键 $cols = ['driver_name'=>'driver_name','driver_mobiles'=>'driver_mobiles','driver_idcard'=>'driver_idcard','truck_num'=>'truck_num','end_city'=>'end_city','from_city'=>'from_city']; foreach ($cols as $col=>$key) { $data[$col] = isset($post[$key]) ? trim($post[$key]) : ''; } $cols = ['truck_id'=>'truck_id','from_store'=>'from_store','end_store'=>'end_store']; foreach ($cols as $col=>$key) { $data[$col] = isset($post[$key]) ? (int)$post[$key] : 0; } $key = 'status_code'; if (isset($post[$key])) { $data[$key] = (int)$post[$key]; } /*板车规则判断 *一辆板车只能有一条可用装车任务表单 **/ $truck_id = $data['truck_id']; if (!$truck_id) { $return['msg'] = '未指定板车信息,保存失败'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } $AcTruck = new AcTruck(); $truck = $AcTruck->findOne($truck_id); if (!$truck) { $return['msg'] = '未找到指定板车,保存失败'; $return['errorcode'] = 404; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } $AcTruckOnline = new AcTruckOnline(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['=','truck_id',$truck_id]; $where[] = ['<','status_code',99]; $where[] = ['=','deleted',0]; $truckol = $AcTruckOnline->find()->where($where)->orderby('id ASC')->one(); if ($truckol) { if ($id != $truckol->id) { $return['msg'] = '该板车已有未完成的托运任务,不允许重复指派'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } } $key = 'remark'; $data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : ''; $_time = time(); $key = 'from_date'; $data[$key] = isset($post[$key]) ? strtotime($post[$key]) : $_time; $key = 'end_date'; if (isset($post[$key])) { $data[$key] = strtotime($post[$key]); } if (!$id) { $data['create_at'] = $_time; } $data['update_at'] = $_time; ; $data['pid'] = $pid; //保存板车资料 $AcTruckOnline = new AcTruckOnline(); foreach ($data as $key=>$val) { $AcTruckOnline->$key = $val; } if ($id) { $res = $AcTruckOnline->updateAll($data, ['id'=>$id]); } else { $res = $AcTruckOnline->save(); $id = $AcTruckOnline->attributes['id']; //获取插入后id } if ($res) { \Yii::$app->getSession()->setFlash('success', '信息保存成功!'); return $this->redirect(['modify','id'=>$id]); } else { \Yii::$app->getSession()->setFlash('warning', '信息保存失败!'); return $this->goBack(); } } //随车车辆管理 public function actionCars() { $pid = Yii::$app->session->get('pid'); $id = Yii::$app->request->get('id'); //装车任务ID $AcTruckOnline = new AcTruckOnline(); $truckol = []; $res = $AcTruckOnline->findOne($id); if (!$res) { $post = Yii::$app->request->post(); $return = []; $return['msg'] = '发车任务记录获取失败,请重新获取'; $return['errorcode'] = 0; $return['url'] = Url::toRoute(['truckol/list',$post]); $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'); } $truck_id = $res->truck_id; $store_id = $res->from_store; $store2_id = $res->end_store; $truckol = $res->toArray(); $AcTruck = new AcTruck(); $truck = $AcTruck->findOne($truck_id); $AcStore = new AcStore(); $store = $AcStore->findOne($store_id); if ($store) { $truckol['fromstore_title'] = $store->title; } $store2 = $AcStore->findOne($store2_id); if ($store2) { $truckol['endstore_title'] = $store2->title; } $online_id = $id; $AcTruckCars = new AcTruckCars(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['=','online_id',$online_id]; $where[] = ['=','deleted',0]; $truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all(); $carids = $orderids = []; if ($truckcars) { foreach ($truckcars as $t) { $carids[] = $t->car_id; $orderids[] = $t->order_id; } } $AcCar = new AcCar(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['IN','id',$carids]; $where[] = ['=','deleted',0]; $cars = $AcCar->find()->where($where)->indexby('id')->all(); $status = Yii::$app->params['TruckCarsStatus']; $truckOnLineStatus = Yii::$app->params['TruckOnlineStatus']; return $this->render('cars', [ 'status'=>$status, 'truckOnLineStatus'=>$truckOnLineStatus, 'truckol'=>$truckol, 'cars'=>$cars, 'truckcars'=>$truckcars ]); } //保存装车随车资料 public function actionCarssave() { $post = Yii::$app->request->post(); $online_id = (int)$post['id']; $pid = Yii::$app->session->get('pid'); //格式化数据 //目标键=》POST键 $cols = ['car_id','order_id']; foreach ($cols as $key) { if (!isset($post[$key])) { $return['msg'] = '未传入的运单或车辆信息,保存失败'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } } $car_ids = $post['car_id']; if (!is_array($car_ids)) { $return['msg'] = '传入的车辆数据不正确,保存失败'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } $order_ids = $post['order_id']; if (!is_array($order_ids)) { $return['msg'] = '传入的运单数据不正确,保存失败'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } if (count($car_ids) != count($order_ids)) { $return['msg'] = '传入的车辆数据与运单数据不匹配,保存失败'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } /*筛除已在运输中的运单及车辆数据 TBD*/ $AcTruckCars = new AcTruckCars(); $cars = []; $_time = time(); foreach ($car_ids as $k=>$car_id) { $car = []; $car['pid'] = $pid; $car['online_id'] = $online_id; $car['car_id'] = $car_id; $car['order_id'] = $order_ids[$k]; $car['create_at'] = $_time; $car['update_at'] = $_time; $cars[] = $car; $model = clone $AcTruckCars; foreach ($car as $key=>$val) { $model->$key = $val; } $model->save(); } $return['msg'] = '操作完成,请刷新页面并检查数据'; $return['errorcode'] = 200; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } //板车出发 public function actionChufa() { $id = Yii::$app->request->get('id'); //装车任务ID $return = []; $AcTruckOnline = new AcTruckOnline(); $truckol = []; $res = $AcTruckOnline->findOne($id); if (!$res) { $post = Yii::$app->request->post(); $return['msg'] = '发车任务记录获取失败,请重新获取'; $return['errorcode'] = 404; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } if ($res->status_code!=0) { $return['msg'] = '关联出车任务非“待出发”状态,操作失败'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } $truck_id = $res->truck_id; $truckol = $res->toArray(); $AcTruck = new AcTruck(); $truck = $AcTruck->findOne($truck_id); if (!$truck) { $return['msg'] = '关联板车数据获取异常,操作失败'; $return['errorcode'] = 404; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } /*更新数据*/ $_time = time(); $data = []; $data['update_at'] = $_time; $data['status_code'] = 1; $res = $AcTruckOnline->updateAll($data, ['id'=>$id]); $data = []; $data['update_at'] = $_time; $data['status_code'] = 5; $AcTruck->updateAll($data, ['id'=>$truck_id]); if ($res) { $return['msg'] = '出车任务出发标记操作成功'; $return['errorcode'] = 200; } else { $return['msg'] = '出发标记操作失败'; $return['errorcode'] = 100; } exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } //板车到达 public function actionArrive() { $id = Yii::$app->request->get('id'); //装车任务ID $return = []; $AcTruckOnline = new AcTruckOnline(); $truckol = []; $res = $AcTruckOnline->findOne($id); if (!$res) { $post = Yii::$app->request->post(); $return['msg'] = '发车任务记录获取失败,请重新获取'; $return['errorcode'] = 404; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } if ($res->status_code!=1) { $return['msg'] = '关联出车任务非“进行中”(在途)状态,操作失败'; $return['errorcode'] = 400; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } $truck_id = $res->truck_id; $truckol = $res->toArray(); $AcTruck = new AcTruck(); $truck = $AcTruck->findOne($truck_id); if (!$truck) { $return['msg'] = '关联板车数据获取异常,操作失败'; $return['errorcode'] = 404; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } /*更新数据*/ $_time = time(); $data = []; $data['update_at'] = $_time; $data['status_code'] = 99; $res = $AcTruckOnline->updateAll($data, ['id'=>$id]); $data = []; $data['update_at'] = $_time; $data['status_code'] = 0; $AcTruck->updateAll($data, ['id'=>$truck_id]); if ($res) { $return['msg'] = '出车任务运达标记操作成功'; $return['errorcode'] = 200; } else { $return['msg'] = '运达标记操作失败'; $return['errorcode'] = 100; } exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } //删除板车装车任务 public function actionDelete() { $get = Yii::$app->request->get(); $post = Yii::$app->request->post(); $id = (int)$get['id']; $data = $where = []; $where['pid'] = Yii::$app->session->get('pid'); $where['id'] = $id; $data['update_at'] = time(); $data['deleted'] = 1; $model = new AcTruck(); $res = $model->updateAll($data, $where); $return = []; $return['url'] = Url::toRoute('truckol/index'); $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 actionPrint() { $pid = Yii::$app->session->get('pid'); $id = Yii::$app->request->get('id'); //装车任务ID $AcTruckOnline = new AcTruckOnline(); $truckol = []; $res = $AcTruckOnline->findOne($id); if (!$res) { $post = Yii::$app->request->post(); $return = []; $return['msg'] = '发车任务记录获取失败,请重新获取'; $return['errorcode'] = 0; $return['url'] = Url::toRoute(['truckol/list',$post]); $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'); } $truck_id = $res->truck_id; $store_id = $res->from_store; $store2_id = $res->end_store; $truckol = $res->toArray(); $AcTruck = new AcTruck(); $truck = $AcTruck->findOne($truck_id); $AcStore = new AcStore(); $store = $AcStore->findOne($store_id); if ($store) { $truckol['fromstore_title'] = $store->title; } $store2 = $AcStore->findOne($store2_id); if ($store2) { $truckol['endstore_title'] = $store2->title; } $online_id = $id; $AcTruckCars = new AcTruckCars(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['=','online_id',$online_id]; $where[] = ['=','deleted',0]; $where[] = ['>','status_code',0]; $truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all(); $carids = $orderids = []; if ($truckcars) { foreach ($truckcars as $t) { $carids[] = $t->car_id; $orderids[] = $t->order_id; } } $counts = []; $AcCar = new AcCar(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['IN','id',$carids]; $where[] = ['=','deleted',0]; $cars = $AcCar->find()->where($where)->indexby('id')->all(); $AcOrder = new AcOrder(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['IN','id',$orderids]; $where[] = ['=','deleted',0]; $orders = $AcOrder->find()->where($where)->indexby('id')->all(); $employee_ids = []; $count['fee_total'] = $count['pay_receive'] = 0; foreach ($orders as $v) { $employee_ids[] = $v->employee_id; $count['fee_total'] += $v->fee_total; $count['pay_receive'] += $v->pay_receive; } $AcEmployee = new AcEmployee(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['IN','id',$employee_ids]; $where[] = ['=','deleted',0]; $employees = $AcEmployee->find()->where($where)->indexby('id')->all(); $count['cars'] = count($truckcars); $status = Yii::$app->params['TruckCarsStatus']; $truckOnLineStatus = Yii::$app->params['TruckOnlineStatus']; return $this->render('print', [ 'status'=>$status, 'truckOnLineStatus'=>$truckOnLineStatus, 'truckol'=>$truckol, 'cars'=>$cars, 'orders'=>$orders, 'employees'=>$employees, 'truckcars'=>$truckcars, 'count'=>$count ]); } //浏览详情 public function actionDetail() { $pid = Yii::$app->session->get('pid'); $id = Yii::$app->request->get('id'); //装车任务ID $AcTruckOnline = new AcTruckOnline(); $truckol = []; $res = $AcTruckOnline->findOne($id); if (!$res) { $post = Yii::$app->request->post(); $return = []; $return['msg'] = '发车任务记录获取失败,请重新获取'; $return['errorcode'] = 0; $return['url'] = Url::toRoute(['truckol/list',$post]); $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'); } $truck_id = $res->truck_id; $store_id = $res->from_store; $store2_id = $res->end_store; $truckol = $res->toArray(); $AcTruck = new AcTruck(); $truck = $AcTruck->findOne($truck_id); $AcStore = new AcStore(); $store = $AcStore->findOne($store_id); if ($store) { $truckol['fromstore_title'] = $store->title; } $store2 = $AcStore->findOne($store2_id); if ($store2) { $truckol['endstore_title'] = $store2->title; } $online_id = $id; $AcTruckCars = new AcTruckCars(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['=','online_id',$online_id]; $where[] = ['=','deleted',0]; $where[] = ['>','status_code',1]; $truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all(); $carids = $orderids = []; if ($truckcars) { foreach ($truckcars as $t) { $carids[] = $t->car_id; $orderids[] = $t->order_id; } } $counts = []; $AcCar = new AcCar(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['IN','id',$carids]; $where[] = ['=','deleted',0]; $cars = $AcCar->find()->where($where)->indexby('id')->all(); $AcOrder = new AcOrder(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['IN','id',$orderids]; $where[] = ['=','deleted',0]; $orders = $AcOrder->find()->where($where)->indexby('id')->all(); $employee_ids = []; $count['fee_total'] = $count['pay_receive'] = 0; foreach ($orders as $v) { $employee_ids[] = $v->employee_id; $count['fee_total'] += $v->fee_total; $count['pay_receive'] += $v->pay_receive; } $AcEmployee = new AcEmployee(); $where = []; $where[] = 'and'; $where[] = ['=','pid',$pid]; $where[] = ['IN','id',$employee_ids]; $where[] = ['=','deleted',0]; $employees = $AcEmployee->find()->where($where)->indexby('id')->all(); $count['cars'] = count($truckcars); $status = Yii::$app->params['TruckCarsStatus']; $truckOnLineStatus = Yii::$app->params['TruckOnlineStatus']; return $this->render('detail', [ 'status'=>$status, 'truckOnLineStatus'=>$truckOnLineStatus, 'truckol'=>$truckol, 'cars'=>$cars, 'orders'=>$orders, 'employees'=>$employees, 'truckcars'=>$truckcars, 'count'=>$count ]); } }