Coupon.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\shop\controller\plus\coupon;
  3. use app\shop\controller\Controller;
  4. use app\shop\model\plus\coupon\Coupon as CouponModel;
  5. use app\shop\model\plus\coupon\UserCoupon as UserCouponModel;
  6. use app\shop\model\user\Grade as GradeModel;
  7. /**
  8. * 优惠券控制器
  9. */
  10. class Coupon extends Controller
  11. {
  12. /* @var CouponModel $model */
  13. private $model;
  14. /**
  15. * 构造方法
  16. */
  17. public function initialize()
  18. {
  19. $this->model = new CouponModel;
  20. }
  21. /**
  22. * 优惠券列表
  23. */
  24. public function index()
  25. {
  26. $list = $this->model->getList($this->postData());
  27. return $this->renderSuccess('', compact('list'));
  28. }
  29. /**
  30. * 添加优惠券
  31. */
  32. public function add()
  33. {
  34. $data = $this->postData();
  35. // 新增记录
  36. if ($this->model->add($data)) {
  37. return $this->renderSuccess('添加成功');
  38. }
  39. return $this->renderError('添加失败');
  40. }
  41. /**
  42. * 优惠券详情
  43. */
  44. public function couponDetail()
  45. {
  46. $coupon_id = $this->postData('coupon_id/i');
  47. // 优惠券详情
  48. $detail = CouponModel::detail($coupon_id)->toArray();
  49. if($detail['expire_type']==20){
  50. $detail['active_time'][0]=date('Y-m-d H:i:s',$detail['start_time']['value']);
  51. $detail['active_time'][1]=date('Y-m-d H:i:s',$detail['end_time']['value']);
  52. }
  53. return $this->renderSuccess('', compact('detail'));
  54. }
  55. /**
  56. * 更新优惠券
  57. */
  58. public function edit()
  59. {
  60. $data = $this->postData();
  61. unset($data['state']);
  62. $model = new CouponModel;
  63. // 更新记录
  64. if ($model->edit($data)) {
  65. return $this->renderSuccess('更新成功');
  66. }
  67. return $this->renderError('更新失败');
  68. }
  69. /**
  70. * 删除优惠券
  71. */
  72. public function delete($coupon_id)
  73. {
  74. $coupon_id = $this->postData('coupon_id/i');
  75. // 优惠券详情
  76. $model = new CouponModel;
  77. // 更新记录
  78. if ($model->setDelete(['coupon_id' => $coupon_id])) {
  79. return $this->renderSuccess('删除成功');
  80. }
  81. return $this->renderError('删除失败');
  82. }
  83. /**
  84. * 领取记录
  85. */
  86. public function receive()
  87. {
  88. $model = new UserCouponModel;
  89. $list = $model->getList($this->postData());
  90. return $this->renderSuccess('', compact('list'));
  91. }
  92. /**
  93. * 发送优惠券
  94. */
  95. public function SendCoupon()
  96. {
  97. if($this->request->isGet()){
  98. $model = new GradeModel;
  99. $list = $model->getLists();
  100. return $this->renderSuccess('', compact('list'));
  101. }
  102. $model = new UserCouponModel;
  103. if ($model->SendCoupon($this->postData())) {
  104. return $this->renderSuccess('发送成功');
  105. }
  106. return $this->renderError('发送失败');
  107. }
  108. }