render('index'); } /** * @return string */ public function actionDoSubmit() { $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'); } $address = ''; $maintainer = ''; $tel = ''; $userModel = UserRepository::findOne(['id' => $userId]); if ($userModel) { $maintainer = $userModel->name; $tel = $userModel->mobile; $profileModel = $userModel->profile; $address = isset($profileModel)?$profileModel->address:''; } $data = [ 'user_id' => $userId, 'car_no' => $carNo, 'car_model' => $carModel, 'customer' => $customer, 'contact_mobile' => $phone, 'predict_fault' => $preRepair, 'predict_price' => $predictPrice, 'maintainer_address' => $address, 'maintainer_tel' => $tel, 'maintainer_name' => $maintainer, '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); $this->sendSubmitSMS($repairOrder, $userId); $e->orderId = $uuid; $e->success = true; } catch(Exception $ex) { $tran->rollBack(); Yii::getLogger()->log($ex->getMessage(), Logger::LEVEL_ERROR); $e->orderId = ''; $e->message = '提交失败'; } return $this->renderJson($e); } /** * 下维修单短信 * @param $orderModel * @param $userId * @return array */ private function sendSubmitSMS($orderModel, $userId) { /* 您好,维修厂${maintainer}已进行维修,预计完成时间${dateTime},预估维修内容${repairPlan},预估维修费用${repairPrice},维修厂地址:${address},联系电话:${tel} * */ $smsVars = ['maintainer' => '', 'tel' => '', 'address' => '', 'dateTime' => '', 'repairPlan' => '', 'repairPrice' => '']; $smsVars['maintainer'] = Utils::cutStrTxt($orderModel->maintainer_name); $smsVars['tel'] = $orderModel->maintainer_tel; $smsVars['address'] = Utils::cutStrTxt($orderModel->maintainer_address); $smsVars['dateTime'] = date('Y年m月d日 H点', $orderModel->predict_finish_time); $smsVars['repairPlan'] = Utils::cutStrTxt($orderModel->predict_fault); $smsVars['repairPrice'] = $orderModel->predict_price; $phone = $orderModel->contact_mobile; $sms = new SmsMessage(); return $sms->sendSubmitInfo($phone, $smsVars); } /** * @param $orderModel * @param $userId */ private function sendFinishSMS($orderModel, $userId) { /* 您好,${maintainer}已完成您的爱车维修,点击http://gkauto.jiwork.com/site/t?o=${code} 了解维修详情,同时您可以对本次服务进行评分。如有问题请拨打服务监督电话${tel}, 维修厂电话${rtel} */ $smsVars = ['maintainer' => '', 'code' => '', 'tel' => '']; $smsVars['tel'] = Yii::$app->params['SERVICE_PHONE']; $smsVars['maintainer'] = Utils::cutStrTxt($orderModel->maintainer_name); $smsVars['code'] = $orderModel->short_uuid." "; //防止后面的文字和这个参数粘贴在一起 $smsVars['rtel'] = $orderModel->maintainer_tel; // 维修厂电话 $phone = $orderModel->contact_mobile; $sms = new SmsMessage(); return $sms->sendFinishInfo($phone, $smsVars); } public function actionSms() { $userId = $this->getUserId(); $orderModel = RepairOrderRepository::findOne(['id' => 18]); //$result1 = $this->sendSubmitSMS($orderModel, $userId); //$result2 = $this->sendFinishSMS($orderModel, $userId); //var_dump($result1); //var_dump($result2); } /** * @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[] = [ 'url' => ImageManager::getUrl($v->image_path), 'thumb' => ImageManager::getUrl($v->image_path, 'min') ]; } $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[] = [ 'url' => ImageManager::getUrl($image['image_path']), 'thumb' => ImageManager::getUrl($image['image_path'], 'min') ]; } $hasComment = false; $comments = []; $rateModel = RepairOrderRateRepository::findOne(['repair_order_id' => $orderId]); if ($rateModel) { $hasComment = true; $comments = [ 'starTxt' => RepairOrderRate::starLabel($rateModel->star_count), 'qualityStarTxt' => RepairOrderRate::starLabel($rateModel->quality_star), 'effectStarTxt' => RepairOrderRate::starLabel($rateModel->effect_star), 'serviceStarTxt' => RepairOrderRate::starLabel($rateModel->service_star), '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 { $tt = time(); $predictFinishTime = $orderModel->predict_finish_time; $totalPrice = RepairOrderRepairPlan::batchCreate($orderId, $repairPlans); RepairFinishImages::createFinishImages($orderId, $orderModel->uuid, $images); $orderModel->status = RepairOrderStatus::FINISH; $orderModel->finish_at = $tt; $orderModel->repair_finish_status = RepairOrderStatus::getFinishStatus($predictFinishTime, $tt); $orderModel->order_price = $totalPrice; $orderModel->order_price = $totalPrice; $orderModel->save(); $tran->commit(); RepairFinishImages::mvFinishImages($orderModel->uuid, $images); $this->sendFinishSMS($orderModel, $userId); $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 = []; $where = ['and']; $where[] = [ 'or', ['like', 'serial', $keyword], ['like', 'brand', $keyword], ]; $models = CarModelRepository::findAll($where); foreach ($models as $k => $v) { if (empty( $v['brand'])) { $item = ['name' => $v['serial']]; } else { if (false !== strpos($v['serial'], $v['brand'])) { $item = ['name' => $v['serial']]; } else { $item = ['name' => $v['brand'].'-'.$v['serial']]; } } $items[] = $item; } $e->items = $items; $e->success = true; return $this->renderJson($e); } }