CouponController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\controllers;
  8. use app\models\Coupon;
  9. use app\models\SaasCoupon;
  10. use app\modules\alliance\models\CouponForm;
  11. use yii\base\BaseObject;
  12. class CouponController extends BaseController
  13. {
  14. public function behaviors()
  15. {
  16. return parent::behaviors();
  17. }
  18. /**
  19. * 领取优惠券
  20. * @return \yii\web\Response
  21. */
  22. public function actionReceive()
  23. {
  24. $form = new CouponForm();
  25. $form->saas_id = get_saas_user_id();
  26. $form->store_id = get_store_id();
  27. $form->id = post_params('id');
  28. return $this->asJson($form->sendCoupon());
  29. }
  30. /**
  31. * saas领取优惠券
  32. * @return \yii\web\Response
  33. */
  34. public function actionSaasReceive()
  35. {
  36. $form = new CouponForm();
  37. $form->saas_id = get_saas_user_id();
  38. $form->id = get_params('id');
  39. $form->send_type = get_params('send_type');
  40. return $this->asJson($form->sendSaasCoupon());
  41. }
  42. /**
  43. * 我的优惠券列表
  44. * @return \yii\web\Response
  45. */
  46. public function actionIndex()
  47. {
  48. $form = new CouponForm();
  49. $form->attributes = get_params();
  50. //$form->store_id = get_store_id();
  51. $form->saas_id = get_saas_user_id();
  52. return $this->asJson($form->search());
  53. }
  54. /**
  55. * 优惠券详情
  56. * @return \yii\web\Response
  57. */
  58. public function actionDetail()
  59. {
  60. $form = new CouponForm();
  61. $form->saas_id = get_saas_user_id();
  62. $form->id = get_params('user_coupon_id');
  63. $form->coupon_id = get_params('coupon_id');
  64. return $this->asJson($form->detail());
  65. }
  66. /**
  67. * 分享领取优惠券
  68. */
  69. public function actionShareReceive() {
  70. $user_id = get_saas_user_id();
  71. $user_coupon_id = post_params('id');
  72. $user_coupon = SaasCoupon::findOne(['id' => $user_coupon_id, 'is_delete' => 0, 'give_user_id' => 0]);
  73. if (!$user_coupon) {
  74. return $this->asJson([
  75. 'code' => 1,
  76. 'msg' => '优惠券已转赠或不存在'
  77. ]);
  78. }
  79. if ($user_id == $user_coupon->saas_id) {
  80. return $this->asJson([
  81. 'code' => 1,
  82. 'msg' => '不能领取自己的优惠券'
  83. ]);
  84. }
  85. $user_coupon->give_user_id = $user_coupon->saas_id;
  86. $user_coupon->saas_id = $user_id;
  87. if (!$user_coupon->save()) {
  88. return $this->asJson([
  89. 'code' => 1,
  90. 'msg' => '领取失败'
  91. ]);
  92. }
  93. return $this->asJson([
  94. 'code' => 0,
  95. 'msg' => '领取成功'
  96. ]);
  97. }
  98. }