CouponConfig.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. $this->engineer_id = session('user.engineer_id');
  45. $query = $this->_query($this->table)->like('title')->equal('status,type');
  46. $query->where(['is_deleted' => '0'])->order('id desc')->page();
  47. }
  48. /**
  49. * 数据列表处理
  50. * @param array $data
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. */
  55. protected function _index_page_filter(&$data)
  56. {
  57. $type_arr = array('1'=>'发放券','2'=>'新人券','3'=>'推荐券');
  58. foreach ($data as &$value){
  59. $value['type_name'] = $type_arr[$value['type']];
  60. }
  61. }
  62. /**
  63. * 添加优惠券
  64. * @auth true
  65. * @throws \think\Exception
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. * @throws \think\exception\PDOException
  70. */
  71. public function add()
  72. {
  73. $this->title = '添加优惠券';
  74. $this->_form($this->table, 'form');
  75. }
  76. /**
  77. * 编辑优惠券
  78. * @auth true
  79. * @throws \think\Exception
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\ModelNotFoundException
  82. * @throws \think\exception\DbException
  83. * @throws \think\exception\PDOException
  84. */
  85. public function edit()
  86. {
  87. $this->title = '编辑优惠券';
  88. $this->_form($this->table, 'form');
  89. }
  90. /**
  91. * 表单数据处理
  92. * @param array $data
  93. * @throws \think\Exception
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. * @throws \think\exception\PDOException
  98. */
  99. protected function _form_filter(&$data)
  100. {
  101. if($this->request->isPost()){
  102. if($data['low_amount']<=0){
  103. $this->error('使用条件需大于零');
  104. }
  105. if($data['amount']>$data['low_amount']){
  106. $this->error('优惠金额不能大于限制金额');
  107. }
  108. if($data['low_day'] <= 0){
  109. $this->error('使用期限许大于零');
  110. }
  111. if($data['type'] == 2){
  112. $data['is_new'] = 1;
  113. }
  114. }else{
  115. }
  116. }
  117. /**
  118. * 禁用优惠券
  119. * @auth true
  120. * @throws \think\Exception
  121. * @throws \think\exception\PDOException
  122. */
  123. public function forbid()
  124. {
  125. $this->_save($this->table, ['status' => '0']);
  126. }
  127. /**
  128. * 启用优惠券
  129. * @auth true
  130. * @throws \think\Exception
  131. * @throws \think\exception\PDOException
  132. */
  133. public function resume()
  134. {
  135. $this->_save($this->table, ['status' => '1']);
  136. }
  137. /**
  138. * 删除优惠券
  139. * @auth true
  140. * @throws \think\Exception
  141. * @throws \think\exception\PDOException
  142. */
  143. public function remove()
  144. {
  145. $this->_delete($this->table);
  146. }
  147. }