request->param('pageSize', 12); $list = $model->getList($this->request->param(), $pageSize); return $this->renderSuccess(compact('list')); } /** * 文章详情 * @param int $articleId * @return array|\think\response\Json * @throws \app\common\exception\BaseException */ public function detail(int $id) { $detail = SchoolSpecialityModel::getDetail($id); return $this->renderSuccess(compact('detail')); } /** * 学校专业选项 * @return Json */ public function options() { $model = new SchoolSpecialityModel; $list = $model->getOptionList($this->request->param()); return $this->renderSuccess(compact('list')); } /** * 同类专业学校 * @return Json * @throws \think\db\exception\DbException */ public function sameList() { // 获取列表数据 $model = new School; $pageSize = $this->request->param('pageSize', 12); $list = $model->getListBySpeciality($this->request->param(), $pageSize); return $this->renderSuccess(compact('list')); } /** * 获取热门专业 * @return Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function hots() { $limit = $this->request->param('limit', 6); $list = (new SchoolSpecialityModel)->getHots(0, 'speciality_id,speciality_name,views', (int)$limit); return $this->renderSuccess(compact('list')); } /** * 报名 * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function book() { if (getPlatform() !== 'MP-WEIXIN') { return $this->renderError('很抱歉,报名功能暂时仅支持微信小程序端'); } // 生成订单 $model = new Order(); if (!$model->createOrder($this->request->param())) { return $this->renderError($model->getError() ?: '报名提交失败'); } // 充值状态提醒 $order = ['order_id'=> $model['order_id'],'type'=>'普通订单','message' => '报名提交成功']; return $this->renderSuccess(compact('order')); } /** * @param int $order_id * @param int $payType * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function bookPay(int $order_id, int $payType = OrderPayTypeEnum::WECHAT) { // 订单信息 $model = new Order(); $model = $model::getUserOrderDetail($order_id); if (!$model) { return $this->renderError($model->getError() ?: '报名订单不存在'); } // 验证 if(!$model->checkPay($model)) { return $this->renderError($model->getError() ?: '订单支付失败'); } $pilOrder = false; $userInfo = UserService::getCurrentLoginUser(true); $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0; if($userId != $model['user_id']) { $pilOrder = true; $data['pil_user_id'] = $userId; $model->save($data); } // 构建微信支付 try { $payment = PaymentService::wechat( $model['order_id'], $model['order_no'], $model['total_price'], OrderTypeEnum::BOOK ); } catch (\Exception $exception) { $data = ['order_no'=> 'BK'.OrderService::createOrderNo()]; $model->save($data); $payment = PaymentService::wechat( $model['order_id'], $model['order_no'], $model['total_price'], OrderTypeEnum::BOOK ); } // $message = ['success' => '报名成功','type'=> $pilOrder? '代付订单':'普通订单', 'error' => '订单支付中']; return $this->renderSuccess(compact('payment', 'message')); } /** * @param int $orderId * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function bookConfirm() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); $notieImg = $this->request->param('notice_img',''); if(!$model->confirmOrder((int)$orderId, $notieImg)){ return $this->renderError($model->getError() ?: '报名确认错误'); } return $this->renderSuccess(['order_id'=>$orderId], '报名确认成功'); } /** * 订单发货 * @param int $orderId * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function delivery() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); if(!$model->setDelivery((int)$orderId, $this->request->param())){ return $this->renderError($model->getError() ?: '订单设置发货失败'); } return $this->renderSuccess(['order_id'=>$orderId], '订单设置发货成功'); } /** * 订单收货 * @param int $orderId * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function receipt() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); if(!$model->receiptOrder((int)$orderId)){ return $this->renderError($model->getError() ?: '订单收货失败'); } return $this->renderSuccess(['order_id'=>$orderId], '订单收货成功'); } /** * 设置订单为可退款 * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function setRefund() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); if(!$model->setRefund((int)$orderId)){ return $this->renderError($model->getError() ?: '报名订单设置退款错误'); } return $this->renderSuccess(['order_id'=>$orderId], '订单成功设置为可退款'); } /** * 订单退款提交 * @param int $orderId * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function refund() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); $refundResult = $this->request->param('refund_result',''); if(!$model->refundOrder((int)$orderId, $refundResult)){ return $this->renderError($model->getError() ?: '订单申请退款失败'); } return $this->renderSuccess(['order_id'=>$orderId], '订单申请退款成功'); } /** * 订单退款确认 * @param int $orderId * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function refundConfirm() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); $refundImg = $this->request->param('refund_img',''); if(!$model->refundConfirm((int)$orderId, $refundImg)){ return $this->renderError($model->getError() ?: '订单确认退款失败'); } return $this->renderSuccess(['order_id'=>$orderId], '订单确认退款成功'); } /** * 修改订单信息 * @return Json */ public function modifyOrder() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); if(!$model->modifyOrder((int)$orderId, $this->request->param())){ return $this->renderError($model->getError() ?: '修改订单信息失败'); } return $this->renderSuccess(['order_id'=>$orderId], '修改订单信息成功'); } /** * 取消订单 * @return Json */ public function cancelOrder() { // 订单处理 $model = new Order; $orderId = $this->request->param('order_id',0); if(!$model->cancelOrder((int)$orderId, $this->request->param('remark'))){ return $this->renderError($model->getError() ?: '取消订单失败'); } return $this->renderSuccess(['order_id'=>$orderId], '取消订单成功'); } /** * 报名订单列表 * @return Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DbException */ public function orderList() { // 订单处理 $model = new Order; $params = $this->request->param(); $pageSize = $this->request->param('pageSize', 15); $type = $this->request->param('type', 1); $userInfo = UserService::getCurrentLoginUser(true); $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0; if($type == 1){ $params['book_user_id'] = $userId; }else{ $params['user_id'] = $userId; } $list = $model->getList($params, (int)$pageSize); return $this->renderSuccess(compact('list')); } }