diff --git a/frontend/controllers/DatabaseController.php b/frontend/controllers/DatabaseController.php index 496d21c..ed2578d 100644 --- a/frontend/controllers/DatabaseController.php +++ b/frontend/controllers/DatabaseController.php @@ -437,7 +437,7 @@ class DatabaseController extends BaseController if(!$invalid_info) { $invalid_info = new CarInvalidT(false); $invalid_info->id = $car_info->id; - $invalid_info->user_id = 0; + $invalid_info->user_id = $this->my->id; $invalid_info->invalid_id = $invalid_id; if(!$invalid_info->save(false)) { throw new Exception(print_r($invalid_info->getFirstErrors(),true)); @@ -934,6 +934,79 @@ class DatabaseController extends BaseController } return $result; } + //钩选B库到无效库 + public function actionBInvalid() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $result = array(); + $result['success'] = false; + $result['msg'] = '操作失败'; + + if($request->isPost) { + $ids = explode(',',$request->post('ids')); + $invalid_id = $request->post('invalid_id',0); + if($invalid_id == 0) { + $result['msg'] = '请选择无效理由'; + return $result; + } + if($ids[0] == '') { + $result['msg'] = '请先钩选车辆'; + return $result; + } + + $tran = CarT::getDb()->beginTransaction(); + try { + foreach($ids as $id) { + $car_info = CarT::findOne(['id'=>$id]); + if($car_info->location == 2) { + $car_info->location = 5; + if(!$car_info->save(false)) { + throw new Exception(print_r($car_info->getFirstErrors(),true)); + } + + $invalid_info = CarInvalidT::findOne(['id'=>$car_info->id]); + if(!$invalid_info) { + $invalid_info = new CarInvalidT(false); + $invalid_info->id = $car_info->id; + $invalid_info->user_id = $this->my->id; + $invalid_info->invalid_id = $invalid_id; + if(!$invalid_info->save(false)) { + throw new Exception(print_r($invalid_info->getFirstErrors(),true)); + } + } + + $b_info = CarBT::findOne(['id'=>$id]); + if($b_info->user_id > 0) { + //删除预约 + AppointmentT::deleteAll('car_id='.$b_info->id); + + //删除保单 还没有正本生成的保单可以直接删除,正本生成后,需要退单操作 + //删除操作人员 + $orders = OrderT::find() + ->where('car_id='.$b_info->id.' and status_id<5') + ->all(); + foreach($orders as $order_info) { + OrderUserT::deleteAll('order_id='.$order_info->id); + //删除保单 + $order_info->delete(); + } + } + $this->addLog($car_info->id,'从B库移动到无效库',1); + } + } + + $result['success'] = true; + $result['msg'] = '操作成功'; + + $tran->commit(); + } catch (\Exception $e) { + $tran->rollBack(); + $result['msg'] = $e->getMessage(); + } + } + return $result; + } //C库 //C库列表页 @@ -1532,6 +1605,79 @@ class DatabaseController extends BaseController } return $result; } + //钩选C库到无效库 + public function actionCInvalid() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $result = array(); + $result['success'] = false; + $result['msg'] = '操作失败'; + + if($request->isPost) { + $ids = explode(',',$request->post('ids')); + $invalid_id = $request->post('invalid_id',0); + if($invalid_id == 0) { + $result['msg'] = '请选择无效理由'; + return $result; + } + if($ids[0] == '') { + $result['msg'] = '请先钩选车辆'; + return $result; + } + + $tran = CarT::getDb()->beginTransaction(); + try { + foreach($ids as $id) { + $car_info = CarT::findOne(['id'=>$id]); + if($car_info->location == 3) { + $car_info->location = 5; + if(!$car_info->save(false)) { + throw new Exception(print_r($car_info->getFirstErrors(),true)); + } + + $invalid_info = CarInvalidT::findOne(['id'=>$car_info->id]); + if(!$invalid_info) { + $invalid_info = new CarInvalidT(false); + $invalid_info->id = $car_info->id; + $invalid_info->user_id = $this->my->id; + $invalid_info->invalid_id = $invalid_id; + if(!$invalid_info->save(false)) { + throw new Exception(print_r($invalid_info->getFirstErrors(),true)); + } + } + + $c_info = CarCT::findOne(['id'=>$id]); + if($c_info->user_id > 0) { + //删除预约 + AppointmentT::deleteAll('car_id='.$c_info->id); + + //删除保单 还没有正本生成的保单可以直接删除,正本生成后,需要退单操作 + //删除操作人员 + $orders = OrderT::find() + ->where('car_id='.$c_info->id.' and status_id<5') + ->all(); + foreach($orders as $order_info) { + OrderUserT::deleteAll('order_id='.$order_info->id); + //删除保单 + $order_info->delete(); + } + } + $this->addLog($car_info->id,'从C库移动到无效库',1); + } + } + + $result['success'] = true; + $result['msg'] = '操作成功'; + + $tran->commit(); + } catch (\Exception $e) { + $tran->rollBack(); + $result['msg'] = $e->getMessage(); + } + } + return $result; + } //D库 //D库列表页 @@ -2036,6 +2182,79 @@ class DatabaseController extends BaseController } return $result; } + //钩选C库到无效库 + public function actionDInvalid() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $result = array(); + $result['success'] = false; + $result['msg'] = '操作失败'; + + if($request->isPost) { + $ids = explode(',',$request->post('ids')); + $invalid_id = $request->post('invalid_id',0); + if($invalid_id == 0) { + $result['msg'] = '请选择无效理由'; + return $result; + } + if($ids[0] == '') { + $result['msg'] = '请先钩选车辆'; + return $result; + } + + $tran = CarT::getDb()->beginTransaction(); + try { + foreach($ids as $id) { + $car_info = CarT::findOne(['id'=>$id]); + if($car_info->location == 4) { + $car_info->location = 5; + if(!$car_info->save(false)) { + throw new Exception(print_r($car_info->getFirstErrors(),true)); + } + + $invalid_info = CarInvalidT::findOne(['id'=>$car_info->id]); + if(!$invalid_info) { + $invalid_info = new CarInvalidT(false); + $invalid_info->id = $car_info->id; + $invalid_info->user_id = $this->my->id; + $invalid_info->invalid_id = $invalid_id; + if(!$invalid_info->save(false)) { + throw new Exception(print_r($invalid_info->getFirstErrors(),true)); + } + } + + $d_info = CarDT::findOne(['id'=>$id]); + if($d_info->user_id > 0) { + //删除预约 + AppointmentT::deleteAll('car_id='.$d_info->id); + + //删除保单 还没有正本生成的保单可以直接删除,正本生成后,需要退单操作 + //删除操作人员 + $orders = OrderT::find() + ->where('car_id='.$d_info->id.' and status_id<5') + ->all(); + foreach($orders as $order_info) { + OrderUserT::deleteAll('order_id='.$order_info->id); + //删除保单 + $order_info->delete(); + } + } + $this->addLog($car_info->id,'从C库移动到无效库',1); + } + } + + $result['success'] = true; + $result['msg'] = '操作成功'; + + $tran->commit(); + } catch (\Exception $e) { + $tran->rollBack(); + $result['msg'] = $e->getMessage(); + } + } + return $result; + } //无效库列表页 private function getInvalidQuery($request) @@ -2125,13 +2344,7 @@ class DatabaseController extends BaseController { $invalid_items = InvalidT::getTree(); return $this->render('invalid-index',[ - 'invalid_items' - ]); - } - public function actionInvalidSearch() { - $invalid_items = InvalidT::getTree(); - return $this->render('invalid-index-search',[ - 'invalid_items' => $invalid_items + 'invalid_items'=>$invalid_items ]); } public function actionInvalidIndexJson() @@ -2160,6 +2373,8 @@ class DatabaseController extends BaseController $row['factory_model'] = MyLib::substr_cut($car_info->factory_model, 8); $row['car_man'] = MyLib::substr_cut($car_info->car_man, 8); $row['op_user'] = $item->user?$item->user->getShowName():''; + $row['invalid_info'] = $item->invalid->getPath(); + $row['invalid_time'] = $item->invalid->created_at; $data['rows'][] = $row; } return $data; @@ -2638,14 +2853,16 @@ class DatabaseController extends BaseController $result['msg'] = '操作失败'; if($request->isPost) { - $ids = $request->post('ids',array()); + $ids = explode(',',$request->post('ids')); $tran = CarT::getDb()->beginTransaction(); try { foreach($ids as $id) { $car_info = CarT::findOne(['id'=>$id]); $car_info->location = 1; - $car_info->save(); + if(!$car_info->save()) { + throw new \Exception(print_r($car_info->getErrors(), true)); + } CarInvalidT::deleteAll('id='.$id); AppointmentHistoryT::deleteAll('car_id='.$id); @@ -2657,7 +2874,7 @@ class DatabaseController extends BaseController $tran->commit(); } catch (\Exception $e) { $tran->rollBack(); - echo $e->getMessage(); + $result['msg'] = $e->getMessage(); } } return $result; @@ -2674,10 +2891,10 @@ class DatabaseController extends BaseController if($request->isPost) { $invalid_id = $request->post('invalid_id'); - if($invalid_id == 0) { - $result['msg'] = '请先选择无效理由'; - return $result; - } +// if($invalid_id == 0) { +// $result['msg'] = '请先选择无效理由'; +// return $result; +// } $data = $this->getInvalidQuery($request); $query = $data['query']; @@ -2686,7 +2903,9 @@ class DatabaseController extends BaseController foreach($query->each(1000) as $item) { $car_info = $item->car; $car_info->location = 1; - $car_info->save(); + if(!$car_info->save()) { + throw new \Exception(print_r($car_info->getErrors(), true)); + } AppointmentHistoryT::deleteAll('car_id='.$item->id); $item->delete(); $this->addLog($item->id,'从无效数据中恢复数据',1); @@ -2698,7 +2917,7 @@ class DatabaseController extends BaseController $tran->commit(); } catch (\Exception $e) { $tran->rollBack(); - throw $e; + $result['msg'] = $e->getMessage(); } } return $result; diff --git a/frontend/views/common/index.php b/frontend/views/common/index.php index 0420637..195d3ef 100644 --- a/frontend/views/common/index.php +++ b/frontend/views/common/index.php @@ -64,6 +64,8 @@