| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\controllers;
- use app\models\Coupon;
- use app\models\SaasCoupon;
- use app\modules\alliance\models\CouponForm;
- use yii\base\BaseObject;
- class CouponController extends BaseController
- {
- public function behaviors()
- {
- return parent::behaviors();
- }
- /**
- * 领取优惠券
- * @return \yii\web\Response
- */
- public function actionReceive()
- {
- $form = new CouponForm();
- $form->saas_id = get_saas_user_id();
- $form->store_id = get_store_id();
- $form->id = post_params('id');
- return $this->asJson($form->sendCoupon());
- }
- /**
- * saas领取优惠券
- * @return \yii\web\Response
- */
- public function actionSaasReceive()
- {
- $form = new CouponForm();
- $form->saas_id = get_saas_user_id();
- $form->id = get_params('id');
- $form->send_type = get_params('send_type');
- return $this->asJson($form->sendSaasCoupon());
- }
- /**
- * 我的优惠券列表
- * @return \yii\web\Response
- */
- public function actionIndex()
- {
- $form = new CouponForm();
- $form->attributes = get_params();
- //$form->store_id = get_store_id();
- $form->saas_id = get_saas_user_id();
- return $this->asJson($form->search());
- }
- /**
- * 优惠券详情
- * @return \yii\web\Response
- */
- public function actionDetail()
- {
- $form = new CouponForm();
- $form->saas_id = get_saas_user_id();
- $form->id = get_params('user_coupon_id');
- $form->coupon_id = get_params('coupon_id');
- return $this->asJson($form->detail());
- }
- /**
- * 分享领取优惠券
- */
- public function actionShareReceive() {
- $user_id = get_saas_user_id();
- $user_coupon_id = post_params('id');
- $user_coupon = SaasCoupon::findOne(['id' => $user_coupon_id, 'is_delete' => 0, 'give_user_id' => 0]);
- if (!$user_coupon) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '优惠券已转赠或不存在'
- ]);
- }
- if ($user_id == $user_coupon->saas_id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '不能领取自己的优惠券'
- ]);
- }
- $user_coupon->give_user_id = $user_coupon->saas_id;
- $user_coupon->saas_id = $user_id;
- if (!$user_coupon->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '领取失败'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '领取成功'
- ]);
- }
- }
|