[{"id":"课程ID","num":"购买的课程数量"}],'其他key'=>"其他Value" ] * User: wniu * Date: 2022/3/18 * Time: 3:21 下午 * */ public function actionToSubmitOrder() { $post = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($post, [ [['list'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); //todo 测试数据 // $post['list'] = [[ // 'id' => 2, // 'num' => 1 // ]]; $data = AddonsCourseOrders::preview($this->user, $this->mall_id, $post); return $this->success('success', $data); } /** * 提交订单 * requestData 数据结构 array ['list' =>[{"id":"课程ID","num":"购买的课程数量"}],'其他key'=>"其他Value" ] * User: wniu * Date: 2022/3/18 * Time: 3:31 下午 * */ public function actionDoSubmitOrder() { $post = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($post, [ [['list'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); // $post['list'] = [[ // 'id' => 2, // 'num' => 1 // ]]; $res = AddonsCourseOrders::createOrder($this->user, $this->mall_id, $post); if ($res === false) return $this->error(AddonsCourseOrders::getStaticError()); return $this->success('操作成功', $res); } public function actionSuccess() { $get = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($get, [ [['orderno'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $order = AddonsCourseOrders::getOne([['order_no' => $get['orderno']]]); if (empty($order)) { throw new \Exception("订单不存在"); } $data['orderno'] = $order->order_no; $data['status'] = $order->order_status; $data['pay_type'] = $order->pay_type; $config = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_COURSE, 'basic'); unset($config['index_link']); $data['pay_sucess_conf'] = $config; return $this->success('success', $data); } /** * 查看课程订单详情 * @Author guyu * @DateTime 2021-5-21 * @return string * @copyright Copyright */ public function actionDetail() { $get = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($get, [ [['bought_id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $course_bought = AddonsCourseBought::getOne([['id' => $get['bought_id']]]); if (!empty($course_bought)) { $main_order_detail = []; if (1 == $course_bought->buy_type) { // 单独购买课程 $course_order = AddonsCourseOrders::getOne([['id' => $course_bought->order_id, 'mall_id' => $course_bought->mall_id]]); } elseif (2 == $course_bought->buy_type) { // 购买商品附赠课程 $order = Order::getOne([['id' => $course_bought->order_id, 'mall_id' => $course_bought->mall_id]]); $course_order = AddonsCourseOrders::getOne([['course_id' => $course_bought->course_id, 'mall_id' => $course_bought->mall_id, 'order_no' => $order->order_no]]); //课程购买类型为商品赠送时,获取主订单详情 $main_order_detail = OrderDetail::find() ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'order_id' => $course_bought->order_id]) ->asArray() ->all(); } $course_info = AddonsCourse::getOne([['id' => $course_bought->course_id, 'mall_id' => $course_bought->mall_id]]); $payment_type_list = PayTypeEnum::getMap(); $order_detail = [ 'id' => $course_bought->id, 'course_id' => $course_bought->course_id, 'orderno' => $course_order->order_no, 'real_pay' => $course_order->pay_money, 'pay_type' => $payment_type_list[$course_order->pay_type], 'created_at' => $course_order->created_at, 'pay_time' => $course_order->pay_time, 'course_name' => $course_info->name, 'introduce' => $course_info->introduce, 'logo' => $course_info->logo, 'buy_type' => $course_bought->buy_type, 'main_order_detail' => $main_order_detail, ]; } else { $order_detail = []; } return $this->success('success', $order_detail); } }