| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\market\classes\XrFlClass;
- use biz\shop\classes\ShopClass;
- use bizGhs\custom\classes\CustomClass;
- use bizHd\hb\classes\HbManageClass;
- use bizHd\recharge\classes\RechargeShbClass;
- use common\components\util;
- use bizHd\hb\classes\HbClass;
- use Yii;
- class HbController extends BaseController
- {
- public $guestAccess = [];
- //获取新人红包福利 ssh 20211026
- public function actionGetNewGift()
- {
- $ghsId = Yii::$app->request->get('ghsId', 0);
- $ghs = GhsClass::getById($ghsId, true);
- GhsClass::valid($ghs, $this->shopId);
- $ghsShopId = $ghs->shopId ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- $xrFl = $ghsShop->xrFl ?? 0;
- if ($xrFl == 0) {
- util::fail('活动已结束');
- }
- $sendNewGift = $ghs->sendNewGift ?? 0;
- if ($sendNewGift == 1) {
- util::fail('已经领过了');
- }
- $new = $ghs->new ?? 0;
- if ($new == 0) {
- util::fail('新人才能领取哦');
- }
- $customId = $ghs->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- XrFlClass::giveGift($ghs, $custom);
- util::complete('领取成功');
- }
- /**
- * 获取红包列表
- */
- public function actionHbList()
- {
- $where = ['shopId' => $this->shopId];
- $customId = Yii::$app->request->get('customId', '');
- if (!empty($customId)) {
- $where['customId'] = $customId;
- }
- $status = Yii::$app->request->get('status', '');
- if (isset($status) && $status != '') {
- if($status == -1){ // 已失效包含:1作废 与 过期(0未使用但endTime<当前时间) --- 所以当操作作废时,status改为-1,同时将endTime改为当前时间
- $where['endTime<'] = time();
- }else{
- $where['status'] = $status;
- }
- }
- $list = HbClass::getList('*', $where, 'id desc', 'custom');
- if (!empty($list['list'])) {
- foreach ($list['list'] as &$v) {
- $v['customName'] = $v['custom']['name'];
- }
- }
- util::success($list);
- }
- // 单个门店下所有可用红包
- public function actionAvailableHb()
- {
- $get = Yii::$app->request->get();
-
- $where = [];
- $where['customId'] = $get['customId'];
- $where['status'] = 0;
- $where['endTime>'] = time();
- $list = HbClass::getAllByCondition($where, 'id DESC');
- util::success($list);
- }
- /**
- * 获取红包详情
- */
- public function actionHbDetail()
- {
- $hbId = Yii::$app->request->get('hbId');
- $hb = HbClass::getById($hbId);
- util::success($hb);
- }
- /**
- * 创建红包
- */
- public function actionCreateHb()
- {
- // TODO
- // $form = new \hd\models\hb\CreateHbForm();
- // $form->load(Yii::$app->request->post(), '');
- // if (!$form->validateForm()) {
- // return;
- // }
- // $data = $form->attributes;
- $post = Yii::$app->request->post();
- $duration = intval($post['days']);
- $count = $post['count'] ?? 1;
- $beginTime = time();
- $endTime = $beginTime + $duration * 86400;
- $data = [
- 'mainId' => $this->mainId,
- 'shopId' => $this->shopId,
- 'userId' => $post['userId'],
- 'customId' => $post['customId'],
- 'amount' => $post['amount'],
- 'minConsume' => $post['minConsume'],
- 'beginTime' => $beginTime,
- 'endTime' => $endTime,
- 'willTime' => $endTime,
- 'duration' => $duration,
- 'getType' => 1, //取得方式 0新人领取 1门店发放 2充值赠送
- 'remark' => $post['remark'],
- ];
- $manageData = [
- 'getType' => 1, //取得方式 0新人领取 1门店发放 2充值赠送
- 'getTargetId' => 0,
- 'createStaffId' => $this->shopAdminId,
- 'createStaffName' => $this->shopAdminName,
- 'remark' => $data['remark'],
- ];
- for ($i = 0; $i < $count; $i++) {
- $hb = HbClass::add($data);
- $manageData['hbId'] = $hb['id'];
- $hbManage = HbManageClass::add($manageData);
- }
- $arr = [];
- if(!empty($hb) && !empty($hbManage)){
- $arr = array_merge($hb, $hbManage);
- }
- util::success($arr);
- }
- /**
- * 更新红包
- */
- public function actionUpdateHb()
- {
- // TODO
- // $hbId = Yii::$app->request->get('hbId');
- // $form = new \hd\models\hb\UpdateHbForm();
- // $form->load(Yii::$app->request->post(), '');
- // if (!$form->validateForm()) {
- // return;
- // }
- // $data = $form->attributes;
- $data = Yii::$app->request->post();
- $id = $data['id'];
- $hb = HbClass::getById($id, true);
- //检测是否是本门店的红包
- if($hb->shopId != $this->shopId){
- util::fail('不是本门店的红包');
- }
- foreach($data as $key => $val){
- $hb->$key = $val;
- }
- // 当操作作废时,status改为-1,同时将endTime改为当前时间
- if($hb->status == -1){
- $hb->endTime = time();
- //记录作废人
- $updateData = [
- 'cancelStaffId' => $this->shopAdminId,
- 'cancelStaffName' => $this->shopAdminName,
- 'cancelTime' => date('Y-m-d H:i:s'),
- ];
- HbManageClass::updateByCondition(['hbId'=>$id], $updateData);
- }
- $hb->save();
- util::success($hb->attributes);
- }
- /**
- * 充值送红包规则列表
- */
- public function actionHbRules()
- {
- $list = RechargeShbClass::getList('*', ['shopId'=>$this->shopId]);
- util::success($list);
- }
- /**
- * 充值送红包规则创建
- */
- public function actionSendHbRules()
- {
- $data = Yii::$app->request->post();
- //var_dump($data); die;
- $hbRules = RechargeShbClass::setRules($this->shopId, $this->mainId, $data);
- util::success($hbRules);
- }
- /**
- *
- */
- public function actionDeleteHbRule()
- {
- $id = Yii::$app->request->post('id');
- var_dump($id); die;
- $re = RechargeShbClass::deleteById($id);
- if($re == 1){
- util::complete();
- }else{
- util::fail('删除失败');
- }
- }
- }
|