request->get(); $merchantId = $this->merchantId; $query = xhCoupon::find(); $query->where(['merchantId' => $merchantId]); if (isset($get['mobile']) && !empty($get['mobile'])) { $query->andWhere(['mobile' => $get['mobile']]); } if (isset($get['id']) && !empty($get['id'])) { $query->andWhere(['id' => $get['id']]); } if (isset($get['status']) && $get['status'] != -1) { $query->andWhere(['status' => $get['status']]); } $countQuery = clone $query; $query->orderBy('id desc'); $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]); $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); $userInfoList = []; if (!empty($models)) { $userIdList = array_column($models, 'userId'); $userInfoList = UserService::getByIds($userIdList, null, 'id'); CouponService::setDeadline($models); } $now = time(); return $this->render('all', ['models' => $models, 'pages' => $pages, 'now' => $now, 'userInfoList' => $userInfoList]); } public function actionList() { $get = Yii::$app->request->get(); $merchantId = $this->merchantId; $query = xhCoupon::find(); $query->where(['merchantId' => $merchantId]); if (isset($get['number']) && !empty($get['number'])) { $query->andWhere(['number' => $get['number']]); } if (isset($get['useStatus']) && $get['useStatus'] != -1) { $query->andWhere(['useStatus' => $get['useStatus']]); } $countQuery = clone $query; $query->orderBy('id desc'); $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]); $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); return $this->render('list', ['models' => $models, 'pages' => $pages, 'now' => time()]); } public function actionUse() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $coupon = xhCouponService::getById($id); if ($this->merchantId != $coupon['merchantId']) { util::failInfo('不是您的客户,没有操作权限'); } if ($coupon['useStatus'] == 1) { util::failInfo('这个代金劵已经用过了'); } $now = time(); if ($now > $coupon['deadline']) { util::failInfo('代金劵已经过期'); } if ($now < $coupon['beginTime']) { util::failInfo('活动还未开始,代金劵不能使用'); } $id = $coupon['id']; $userId = $coupon['userId']; xhCouponService::updateById($id, $userId, ['useStatus' => 1]); util::successInfo('操作成功'); } /** * 用户的所有代金劵 */ public function actionUserList() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $userInfo = xhUserService::getById($id); if ($this->merchantId != $userInfo['merchantId']) { util::stop('您没有权限操作'); } $models = xhCouponService::getUserCoupon($id); return $this->render('userList', ['models' => $models, 'userInfo' => $userInfo]); } /** * 代金劵的明细 */ public function actionDetail() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $coupon = xhCouponService::getById($id); if ($coupon['merchantId'] != $this->merchantId) { util::stop('非法访问'); } $userId = $coupon['userId']; $user = xhUserService::getById($userId); return $this->render('detail', ['coupon' => $coupon, 'user' => $user]); } //添加分类 public function actionAddModel() { $post = Yii::$app->request->post(); $ret = CouponModelService::addModel($post); if ($ret == false) { util::sendFail($this->error->getError()); } util::sendSuccess(); } //卷管理 shish 2019.8.16 public function actionModel() { $where['merchantId'] = $this->merchantId; $order = 'level desc'; $return = CouponModelService::getBackendList('*', $where, $order); $pages = $return['pages']; $list = $return['list']; $categoryList = CategoryRelateService::getCategoryData(); $usageList = UsageRelationService::getMyUsage(); return $this->render('model', ['list' => $list, 'pages' => $pages, 'categoryList' => $categoryList, 'usageList' => $usageList]); } //保存卷模板 shish 2019.8.17 public function actionSaveModel() { $post = Yii::$app->request->post(); $data = $post['globalCoupon']; $ret = CouponModelService::replaceModel($data); if ($ret == false) { util::sendFail($this->error->getError()); } util::sendSuccess(); } //获取优惠卷信息 shish 2019.8.18 public function actionGetDetail() { $id = Yii::$app->request->get('id'); $info = CouponModelService::getCouponInfo($id); if ($this->error->hasError) { util::sendFail($this->error->getError()); } util::sendJson($info); } //发卷人列表 shish 2019.8.18 public function actionRight() { $where['merchantId'] = $this->merchantId; $order = 'addTime desc'; $return = CouponRightService::getBackendList('*', $where, $order); $pages = $return['pages']; $list = $return['list']; $userInfo = []; if (!empty($list)) { $userIds = array_column($list, 'userId'); $userIds = array_unique(array_filter($userIds)); $userInfo = UserService::getByIds($userIds, null, 'id'); } $categoryList = CategoryRelateService::getCategoryData(); $usageList = UsageRelationService::getMyUsage(); return $this->render('right', ['list' => $list, 'pages' => $pages, 'userInfo' => $userInfo, 'categoryList' => $categoryList, 'usageList' => $usageList]); } //兑奖列表 shish 2019.8.18 public function actionReward() { $get = Yii::$app->request->get(); $where['merchantId'] = $this->merchantId; if (isset($get['mobile']) && !empty($get['mobile'])) { $where['mobile'] = $get['mobile']; } if (isset($get['couponId']) && !empty($get['couponId'])) { $where['couponId'] = $get['couponId']; } if (isset($get['status']) && $get['status'] != -1) { $where['status'] = $get['status']; } $return = CouponRewardService::getBackendList('*', $where, 'addTime desc'); $pages = $return['pages']; $list = $return['list']; $userInfo = []; if (!empty($list)) { $userIdList = array_column($list, 'userId'); $invitedUserIdList = array_column($list, 'invitedUserId'); $ids = array_merge($userIdList, $invitedUserIdList); $ids = array_unique(array_filter($ids)); $userInfo = UserService::getByIds($ids, null, 'id'); } return $this->render('reward', ['list' => $list, 'pages' => $pages, 'userInfo' => $userInfo]); } //确认发放奖品 shish 2019.8.25 public function actionGrantReward() { $this->errorExportJson(); $get = Yii::$app->request->get(); CouponRewardService::grantReward($get); util::ok(); } //客户到店使用优惠卷 shish 2019.8.25 public function actionUseCoupon() { $this->errorExportJson(); $get = Yii::$app->request->get(); CouponService::destroyToGetReward($get); util::ok(); } }