render('index'); } /** * @return string */ public function actionSubmit() { $e = new stdClass(); $e->success = false; $e->message = 'ok'; $userId = $this->getUserId(); $req = Yii::$app->request; $carNo = HtmlPurifier::process($req->post('carNo'), ['HTML.Allowed' => '']); $carModel = HtmlPurifier::process($req->post('carModel'), ['HTML.Allowed' => '']); $customer = HtmlPurifier::process($req->post('customer'), ['HTML.Allowed' => '']); $phone = HtmlPurifier::process($req->post('phone'), ['HTML.Allowed' => '']); $preRepair = HtmlPurifier::process($req->post('preRepair'), ['HTML.Allowed' => '']); $predictPrice = HtmlPurifier::process($req->post('repairPrice'), ['HTML.Allowed' => '']); $finishDate = HtmlPurifier::process($req->post('finishDate'), ['HTML.Allowed' => '']); $images = $req->post('images'); if (empty($carNo)) { $e->message = '车牌号码未填'; return $this->renderJson($e); } if (empty($carModel)) { $e->message = '车辆型号未填'; return $this->renderJson($e); } if (empty($phone)) { $e->message = '联系电话未填'; return $this->renderJson($e); } if (empty($finishDate)) { $predict_finish_time= null; } else { $predict_finish_time = strtotime($finishDate.':00:00'); } $data = [ 'user_id' => $userId, 'car_no' => $carNo, 'car_model' => $carModel, 'customer' => $customer, 'contact_mobile' => $phone, 'predict_fault' => $preRepair, 'predict_price' => $predictPrice, 'predict_finish_time' => $predict_finish_time, 'status' => RepairOrderStatus::WORKING, ]; $tran = Yii::$app->db->beginTransaction(); try { $repairOrder = RepairOrder::create($data); $uuid = $repairOrder->uuid; RepairOrderImages::createBrokenImages($repairOrder->id, $uuid, $images); $tran->commit(); RepairOrderImages::mvBrokenImages($uuid, $images); $e->orderId = $uuid; $e->success = true; } catch(Exception $ex) { $tran->rollBack(); $e->orderId = ''; $e->message = '提交失败'; } return $this->renderJson($e); } /** * @return string */ public function actionOrderList() { $e = new stdClass(); $e->success = false; $e->page = null; $e->page_count = null; $e->items = []; $page = $this->request->get('page'); $status = $this->request->get('status'); if (empty($page)) { $page = 1; } $allItemList = [0, 0, 0]; if ('working' == $status || '' == $status) { $allItemList = $this->getOrderList($page, RepairOrderStatus::WORKING); } else { $allItemList = $this->getOrderList($page, RepairOrderStatus::FINISH); } $e->page_count = $allItemList[1]; $e->page = $page; $e->items = $allItemList[2]; $e->success = true; return $this->renderJson($e); } /** * @param $page * @param $status */ private function getOrderList($page, $status) { $pageSize = 8 ; $pager_offset = ($page -1) * $pageSize; $limitPage = $pageSize; $userId = $this->getUserId(); $where = ['status' => $status, 'user_id' => $userId]; $list = RepairOrderRepository::getList($pager_offset, $limitPage, $where); $count = RepairOrderRepository::getListCount($where); $items = []; $pageCount = ceil(($count*1) / $pageSize); foreach($list as $k => $item) { $items[] = [ 'id'=> $item['uuid'] ,'carNo' => $item['car_no'], 'carModel' => $item['car_model'], 'status' => $item['status'], 'customer' => $item['customer'] ,'createdTime' => date('Y-m-d H:i', $item['created_at']) ]; } return [$count, $pageCount, $items]; } /** * @return string */ public function actionOrderDetails() { $e = new stdClass(); $e->success = false; $e->message = 'ok'; $orderUUId = $this->request->post('id'); $userId = $this->getUserId(); $orderModel = RepairOrderRepository::findOne(['uuid' => $orderUUId, 'user_id' => $userId]); if (empty($orderModel)) { $e->message = '找不到该订单'; return $this->renderJson($e); } $orderId = $orderModel->id; $brokenImageModels = RepairOrderRepository::findOrderImageAll(['repair_order_id' => $orderId]); $brokenImages = []; $baseURL = Yii::$app->request->getHostInfo(); foreach($brokenImageModels as $k => $v) { $brokenImages[] = $baseURL.'/'.$v->image_path; } $totalPrice = $orderModel->order_price; $rPlans = RepairOrderRepository::findOrderPlansAll(['repair_order_id' => $orderId]); $repairPlans = []; foreach($rPlans as $k => $plan) { $repairPlans[] = ['plan' => $plan['repair_plan'] ,'price' => $plan['price']]; } $fImages = RepairOrderRepository::findOrderFinishImageAll(['repair_order_id' => $orderId]); $finishImages = []; foreach($fImages as $k => $image) { $finishImages[] = $baseURL.'/'.$image['image_path']; } $hasComment = false; $comments = []; $rateModel = RepairOrderRateRepository::findOne(['repair_order_id' => $orderId]); if ($rateModel) { $hasComment = true; $comments = ['starTxt' => RepairOrderRate::starLabel($rateModel->star_count), 'comment' => $rateModel->comment]; } $shortId = $orderModel->short_uuid; $preFinishDate = '暂无'; $predictPrice = '暂无'; if($orderModel->predict_finish_time) { $preFinishDate = date('Y-m-d H:00', $orderModel->predict_finish_time); } if($orderModel->predict_price) { $predictPrice = $orderModel->predict_price.'元'; } $e->success = true; $e->item = [ 'carNo' => $orderModel->car_no, 'carModel' => $orderModel->car_model, 'customer' => $orderModel->customer, 'mobile' => $orderModel->contact_mobile, 'preRepair' => empty($orderModel->predict_fault)?'暂无':$orderModel->predict_fault, 'repairPrice' => $predictPrice, 'preFinishDate' => $preFinishDate, 'orderDateTime' => date('Y-m-d H:00', $orderModel->created_at), 'status' => RepairOrderStatus::getEnLabel($orderModel->status), 'hasComment' => $hasComment, 'comments' => $comments, 'brokenImages' => $brokenImages, 'shortId' => $shortId, 'repairPlans' => $repairPlans, 'totalPrice' => $totalPrice, 'finishImages' => $finishImages ]; $e->showCustomerComment = true; return $this->renderJson($e); } /** * @return string */ public function actionSubmitRepairPlans() { $e = new stdClass(); $e->success = false; $e->message = 'ok'; $repairPlans = $this->request->post('plans'); $images = $this->request->post('images'); $orderUUId = $this->request->post('id'); $userId = $this->getUserId(); $orderModel = RepairOrderRepository::findOne(['uuid' => $orderUUId, 'user_id' => $userId]); if (empty($orderModel)) { $e->message = '找不到订单'; return $this->renderJson($e); } if (RepairOrderStatus::FINISH == $orderModel->status) { $e->message = '订单已完成,不能编辑'; return $this->renderJson($e); } $orderId = $orderModel->id; $tran = Yii::$app->db->beginTransaction(); try { $totalPrice = RepairOrderRepairPlan::batchCreate($orderId, $repairPlans); RepairFinishImages::createFinishImages($orderId, $orderModel->uuid, $images); $orderModel->status = RepairOrderStatus::FINISH; $orderModel->finish_at = time(); $orderModel->order_price = $totalPrice; $orderModel->save(); $tran->commit(); RepairFinishImages::mvFinishImages($orderModel->uuid, $images); $e->success = true; } catch (Exception $ex) { $tran->rollBack(); $e->success = false; $e->message = '提交失败'; $e->innerMEssage = $ex->getMessage(); } return $this->renderJson($e); } /** * 查找汽车型号 * @return string */ public function actionSearchModel() { $e = new stdClass(); $e->success = false; $request = Yii::$app->request; $keyword = $request->post('keyword'); if (empty($keyword)) { $e->message = '关键字为空'; return $this->renderJson($e); } $items = []; $models = [ ['name' => '宝马X1'], ['name' => '宝马X2'], ['name' => '宝马X3'], ['name' => '宝马X4'], ['name' => '宝马X5'], ['name' => '宝马X6'], ['name' => '宝马X7'], ['name' => '奔驰C200K'], ['name' => '奔驰C280'], ['name' => '奔驰E200K'], ['name' => '奔驰E230'], ['name' => '奔驰E280'], ]; foreach ($models as $k => $v) { if (false !== strpos($v['name'], strtoupper($keyword))) { $items[] = $v; } } $e->items = $items; $e->success = true; return $this->renderJson($e); } }