| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wniu
- * Date: 2022/3/16
- * Time: 3:19 下午
- */
- namespace addons\Course\api\modules\v1\controllers;
- use addons\Course\common\enums\CourseEnum;
- use addons\Course\common\logic\Notify;
- use addons\Course\common\models\AddonsCourse;
- use addons\Course\common\models\AddonsCourseBought;
- use addons\Course\common\models\AddonsCourseOrders;
- use api\controllers\OnAuthController;
- use common\enums\AddonsEnum;
- use common\enums\PaymentTradeOrderEnum;
- use common\enums\PayTypeEnum;
- use common\enums\StatusEnum;
- use common\models\order\Order;
- use common\models\order\OrderDetail;
- class OrderController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- /**
- * 预览订单
- * requestData 数据结构 array ['list' =>[{"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);
- }
- }
|