RealRiceCard.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\store\controller\card;
  4. use app\common\service\Export as ExportService;
  5. use app\store\controller\Controller;
  6. use app\store\model\card\GenRealRiceCards;
  7. use app\store\model\card\RealRiceCardList;
  8. use app\store\model\coupon\CouponRedeemCodes;
  9. use think\facade\Validate;
  10. /**
  11. * 实体米卡管理控制器
  12. * Class RealRiceCard
  13. * @package app\store\controller\card
  14. */
  15. class RealRiceCard extends Controller
  16. {
  17. /**
  18. * 生成优惠券的兑换码
  19. * @return array
  20. */
  21. public function genCardCodes(){
  22. $post = $this->postForm();
  23. $post['type'] = $post['type']??3;
  24. $validate = Validate::rule('riceCardId', 'require|number|gt:0')
  25. ->rule([
  26. 'amount' => 'require|number|gt:0',
  27. 'saleChannel' => 'require|max:25',
  28. 'type' => 'require|number|between:3,4'
  29. ]);
  30. if (!$validate->check($post)) {
  31. return $this->renderError($validate->getError());
  32. }
  33. $m = new GenRealRiceCards();
  34. //兑换码匹配汉字数字字母
  35. /* $pattern = "/^[a-zA-Z0-9\x{4e00}-\x{9fa5}]+$/u";
  36. if(!preg_match($pattern,$post['code'])){
  37. return $this->renderError('兑换码格式不正确');
  38. }*/
  39. if( $m->addCodes($post)){
  40. return $this->renderSuccess([],'成功');
  41. }
  42. return $this->renderError('系统繁忙');
  43. }
  44. /**
  45. * 实体米卡列表
  46. * @return array
  47. */
  48. public function list(){
  49. $param = $this->request->param();
  50. $m = new GenRealRiceCards();
  51. $list = $m->getAllList($param);
  52. return $this->renderSuccess(compact('list'),'成功');
  53. }
  54. /**
  55. * 实体米卡明细
  56. * @return array
  57. */
  58. public function listDetail(){
  59. $param = $this->request->param();
  60. if (empty($param['genId'])){
  61. return $this->renderError('参数有误');
  62. }
  63. $m = new RealRiceCardList();
  64. $list = $m->getAllList($param);
  65. return $this->renderSuccess(compact('list'),'成功');
  66. }
  67. /**
  68. * 激活码导出功能
  69. * @return array
  70. * @Time: 2021/10/15 13:43
  71. */
  72. public function redeemCodesExport()
  73. {
  74. $param = $this->request->param();
  75. $model = new RealRiceCardList;
  76. if(isset($param['id']) && $param['id'] > 0){
  77. $data = $model->redeemCodesExport($param,true);
  78. //return $this->renderError('请勾选兑换码后再导出');
  79. }else{
  80. $data = $model->redeemCodesExport($param);
  81. }
  82. //dd($param['ids']);
  83. if (!$data['data'] || !count($data['data'])){
  84. return $this->renderError('没有数据哟');
  85. }
  86. $res = ExportService::export($data['data'],$data['header'],$data['filename'],'兑换码列表');
  87. //更新已导出状态
  88. $model->updateBeenExported($param);
  89. return $this->renderSuccess($res,'导出成功');
  90. }
  91. /**
  92. * 冻结、解冻实体米卡
  93. * @return array
  94. */
  95. public function freezeCard(){
  96. $param = $this->request->param();
  97. if (empty($param['id']) || !isset($param['status']) || !in_array($param['status'],[0,1])){
  98. return $this->renderError('参数有误');
  99. }
  100. $m = new RealRiceCardList();
  101. $m->updateFrozenStatus($param);
  102. return $this->renderSuccess([],'成功');
  103. }
  104. }