CouponConfig.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\store\controller;
  15. use app\store\service\ExtendService;
  16. use library\Controller;
  17. use library\tools\Data;
  18. use think\Db;
  19. /**
  20. * 优惠券配置
  21. * Class Config
  22. * @package app\store\controller
  23. */
  24. class CouponConfig extends Controller
  25. {
  26. /**
  27. * 绑定数据表
  28. * @var string
  29. */
  30. protected $table = 'StoreCouponConfig';
  31. /**
  32. * 优惠券管理
  33. * @auth true
  34. * @menu true
  35. * @throws \think\Exception
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. * @throws \think\exception\PDOException
  40. */
  41. public function index()
  42. {
  43. $this->title = '优惠券配置';
  44. $query = $this->_query($this->table)->like('title')->equal('status,type');
  45. $query->where(['is_deleted' => '0'])->order('id desc')->page();
  46. }
  47. /**
  48. * 数据列表处理
  49. * @param array $data
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. protected function _index_page_filter(&$data)
  55. {
  56. $type_arr = array('1'=>'发放券','2'=>'新人券','3'=>'推荐券');
  57. foreach ($data as &$value){
  58. $value['type_name'] = $type_arr[$value['type']];
  59. }
  60. }
  61. /**
  62. * 添加优惠券
  63. * @auth true
  64. * @throws \think\Exception
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @throws \think\exception\DbException
  68. * @throws \think\exception\PDOException
  69. */
  70. public function add()
  71. {
  72. $this->title = '添加优惠券';
  73. $this->_form($this->table, 'form');
  74. }
  75. /**
  76. * 编辑优惠券
  77. * @auth true
  78. * @throws \think\Exception
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @throws \think\exception\DbException
  82. * @throws \think\exception\PDOException
  83. */
  84. public function edit()
  85. {
  86. $this->title = '编辑优惠券';
  87. $this->_form($this->table, 'form');
  88. }
  89. /**
  90. * 表单数据处理
  91. * @param array $data
  92. * @throws \think\Exception
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @throws \think\exception\DbException
  96. * @throws \think\exception\PDOException
  97. */
  98. protected function _form_filter(&$data)
  99. {
  100. if($this->request->isPost()){
  101. if($data['low_amount']<=0){
  102. $this->error('使用条件需大于零');
  103. }
  104. if($data['amount']>$data['low_amount']){
  105. $this->error('优惠金额不能大于限制金额');
  106. }
  107. if($data['low_day'] <= 0){
  108. $this->error('使用期限许大于零');
  109. }
  110. if($data['type'] == 2){
  111. $data['is_new'] = 1;
  112. }
  113. }else{
  114. }
  115. }
  116. /**
  117. * 禁用优惠券
  118. * @auth true
  119. * @throws \think\Exception
  120. * @throws \think\exception\PDOException
  121. */
  122. public function forbid()
  123. {
  124. $this->_save($this->table, ['status' => '0']);
  125. }
  126. /**
  127. * 启用优惠券
  128. * @auth true
  129. * @throws \think\Exception
  130. * @throws \think\exception\PDOException
  131. */
  132. public function resume()
  133. {
  134. $this->_save($this->table, ['status' => '1']);
  135. }
  136. /**
  137. * 删除优惠券
  138. * @auth true
  139. * @throws \think\Exception
  140. * @throws \think\exception\PDOException
  141. */
  142. public function remove()
  143. {
  144. $this->_delete($this->table);
  145. }
  146. }