OrderController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace addons\Area\api\modules\v1\controllers;
  3. use addons\Area\common\service\OrderService;
  4. use api\controllers\OnAuthController;
  5. use Yii;
  6. use Exception;
  7. /**
  8. * Class OrderController
  9. * @package api\modules\order\controllers
  10. */
  11. class OrderController extends OnAuthController
  12. {
  13. public $modelClass = '';
  14. /**
  15. *
  16. * 不用进行登录验证的方法
  17. *
  18. * 例如: ['index', 'update', 'create', 'view', 'delete']
  19. * 默认全部需要验证
  20. *
  21. * @var array
  22. */
  23. protected $authOptional = [
  24. 'get-confirm-receive-data'
  25. ];
  26. /**
  27. * 订单预览
  28. * @Author bing
  29. * @DateTime 2021-09-24 19:46:46
  30. * @return void
  31. * @copyright: Copyright (c) 2020 广东七件事集团
  32. */
  33. public function actionPreview()
  34. {
  35. $request = Yii::$app->request;
  36. try {
  37. if ($request->isPost) {
  38. $post = $request->post();
  39. $res = Yii::$app->services->validate->validate($post, [
  40. [['level', 'district_id'], 'integer'],
  41. ]);
  42. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  43. $post['mall_id'] = $this->mall_id;
  44. $post['user_id'] = $this->user_id;
  45. $data = (new OrderService())->preview($post);
  46. return $this->success('操作成功', $data);
  47. }
  48. }catch (\Exception $e){
  49. return $this->error($e->getMessage());
  50. }
  51. }
  52. /**
  53. * 创建订单
  54. * @Author bing
  55. * @DateTime 2021-09-22 09:31:22
  56. * @return void
  57. * @copyright: Copyright (c) 2020 广东七件事集团
  58. */
  59. public function actionCreate()
  60. {
  61. $request = Yii::$app->request;
  62. try {
  63. if ($request->isPost) {
  64. $post = $request->post();
  65. $res = Yii::$app->services->validate->validate($post, [
  66. [['level', 'district_id'], 'integer'],
  67. ]);
  68. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  69. $post['mall_id'] = $this->mall_id;
  70. $post['user_id'] = $this->user_id;
  71. $data = (new OrderService())->created($post);
  72. return $this->success('操作成功', $data);
  73. }
  74. }catch (\Exception $e){
  75. return $this->error($e->getMessage());
  76. }
  77. }
  78. }