| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace addons\ElectronCoupon\backend\controllers;
- use addons\ElectronCoupon\common\models\ElectronCoupon;
- use addons\ElectronCoupon\common\models\ElectronCouponUserCoupon;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- class UserCouponController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 会员电子券
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['page', 'user_id', 'coupon_type','e_coupon_id'], 'integer'],
- [['name', 'user_name', 'coupon_name'], 'string'],
- [['receive_time'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [
- ['=', 'mall_id', $this->mall_id],
- ['>=', 'status', StatusEnum::DISABLED],
- ];
- if ($params['user_id']) {
- $where[] = ['=', 'user_id', (int)$params['user_id']];
- }
- // 昵称、手机号
- if ($params['user_name']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $params['user_name'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $params['user_name'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 电子券名称
- if ($params['coupon_name']) {
- $coupon_ids = ElectronCoupon::find()
- ->where(['like', 'name', "%" . $params['coupon_name'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'e_coupon_id', $coupon_ids];
- }
- if(!empty($params['e_coupon_id']))$where[] = ['e_coupon_id'=>$params['e_coupon_id']];
- if ($params['coupon_type'] == 1) { // 免费券
- $where[] = ['=', 'price', 0];
- } else if ($params['coupon_type'] == 2) { // 激活券
- $where[] = ['>', 'price', 0];
- }
- // 领取时间
- $start_time = strtotime($params['receive_time'][0] ?? 0);
- $end_time = strtotime($params['receive_time'][1] ?? 0);
- if ($start_time > 0 && $end_time > 0 && $end_time >= $start_time) {
- $where[] = ['>=', 'last_receive_time', $start_time];
- $where[] = ['<=', 'last_receive_time', $end_time];
- }
- $condition = ['where' => $where, 'with' => ['user', 'properUser', 'giver', 'goods'], 'order' => 'id desc'];
- $page_data = ElectronCouponUserCoupon::getListPage($condition, $this->mall_id);
- $this->success('获取成功', compact('page_data'));
- } else {
- return $this->render('index');
- }
- }
- }
|