Coupon.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 商城优惠
  7. * Class Coupon
  8. * @package app\store\controller
  9. */
  10. class Coupon extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'StoreCouponConfig';
  17. /**
  18. * 优惠券列表
  19. * @auth true
  20. * @menu true
  21. * @throws \think\Exception
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. * @throws \think\exception\PDOException
  26. */
  27. public function index()
  28. {
  29. $this->title = '优惠券';
  30. $query = $this->_query($this->table)->where('is_deleted',0)->like('title');
  31. $query->dateBetween('create_at')->order('sort desc , id desc')->page();
  32. }
  33. /**
  34. * 数据列表处理
  35. * @auth true
  36. * @menu true
  37. * @param array $data
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. protected function _index_page_filter(&$data)
  43. {
  44. foreach ($data as $k=>&$v){
  45. }
  46. }
  47. /**
  48. * 添加优惠券
  49. * @auth true
  50. * @menu true
  51. */
  52. public function add()
  53. {
  54. $this->title = '添加优惠券';
  55. $this->_form($this->table, 'form');
  56. }
  57. /**
  58. * 添加优惠券
  59. * @auth true
  60. * @menu true
  61. */
  62. public function edit()
  63. {
  64. $this->title = '编辑优惠券';
  65. $this->_form($this->table, 'form');
  66. }
  67. /**
  68. * 表单数据处理
  69. * @auth true
  70. * @menu true
  71. * @param array $data
  72. */
  73. protected function _form_filter(&$data)
  74. {
  75. }
  76. /**
  77. * @auth true
  78. * @menu true
  79. * 优惠券删除
  80. */
  81. public function del()
  82. {
  83. $this->_save($this->table, ['is_deleted' => '1']);
  84. }
  85. /**
  86. * @auth true
  87. * @menu true
  88. */
  89. public function user_coupon()
  90. {
  91. $coupon_id = input('id');
  92. $status_arr = ['','正常','已使用','过期','删除'];
  93. $this->assign('status_arr',$status_arr);
  94. $list =$this->_query('UserCouponList')
  95. ->alias('l')
  96. ->field('l.*,m.name as user_name , c.title as coupon_name')
  97. ->join('store_member m','m.id = l.user_id','LEFT')
  98. ->join('store_coupon_config c','l.coupon_id= m.id','LEFT')
  99. ->where(['l.coupon_id'=>$coupon_id])
  100. ->order('l.id desc')
  101. ->page();
  102. }
  103. }