123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- declare (strict_types = 1);
- namespace app\store\controller\card;
- use app\common\service\Export as ExportService;
- use app\store\controller\Controller;
- use app\store\model\card\GenRealRiceCards;
- use app\store\model\card\RealRiceCardList;
- use app\store\model\coupon\CouponRedeemCodes;
- use think\facade\Validate;
- /**
- * 实体米卡管理控制器
- * Class RealRiceCard
- * @package app\store\controller\card
- */
- class RealRiceCard extends Controller
- {
- /**
- * 生成优惠券的兑换码
- * @return array
- */
- public function genCardCodes(){
- $post = $this->postForm();
- $post['type'] = $post['type']??3;
- $validate = Validate::rule('riceCardId', 'require|number|gt:0')
- ->rule([
- 'amount' => 'require|number|gt:0',
- 'saleChannel' => 'require|max:25',
- 'type' => 'require|number|between:3,4'
- ]);
- if (!$validate->check($post)) {
- return $this->renderError($validate->getError());
- }
- $m = new GenRealRiceCards();
- //兑换码匹配汉字数字字母
- /* $pattern = "/^[a-zA-Z0-9\x{4e00}-\x{9fa5}]+$/u";
- if(!preg_match($pattern,$post['code'])){
- return $this->renderError('兑换码格式不正确');
- }*/
- if( $m->addCodes($post)){
- return $this->renderSuccess([],'成功');
- }
- return $this->renderError('系统繁忙');
- }
- /**
- * 实体米卡列表
- * @return array
- */
- public function list(){
- $param = $this->request->param();
- $m = new GenRealRiceCards();
- $list = $m->getAllList($param);
- return $this->renderSuccess(compact('list'),'成功');
- }
- /**
- * 实体米卡明细
- * @return array
- */
- public function listDetail(){
- $param = $this->request->param();
- if (empty($param['genId'])){
- return $this->renderError('参数有误');
- }
- $m = new RealRiceCardList();
- $list = $m->getAllList($param);
- return $this->renderSuccess(compact('list'),'成功');
- }
- /**
- * 激活码导出功能
- * @return array
- * @Time: 2021/10/15 13:43
- */
- public function redeemCodesExport()
- {
- $param = $this->request->param();
- $model = new RealRiceCardList;
- if(isset($param['id']) && $param['id'] > 0){
- $data = $model->redeemCodesExport($param,true);
- //return $this->renderError('请勾选兑换码后再导出');
- }else{
- $data = $model->redeemCodesExport($param);
- }
- //dd($param['ids']);
- if (!$data['data'] || !count($data['data'])){
- return $this->renderError('没有数据哟');
- }
- $res = ExportService::export($data['data'],$data['header'],$data['filename'],'兑换码列表');
- //更新已导出状态
- $model->updateBeenExported($param);
- return $this->renderSuccess($res,'导出成功');
- }
- /**
- * 冻结、解冻实体米卡
- * @return array
- */
- public function freezeCard(){
- $param = $this->request->param();
- if (empty($param['id']) || !isset($param['status']) || !in_array($param['status'],[0,1])){
- return $this->renderError('参数有误');
- }
- $m = new RealRiceCardList();
- $m->updateFrozenStatus($param);
- return $this->renderSuccess([],'成功');
- }
- }
|