Coupon.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\controller\market;
  13. use app\store\controller\Controller;
  14. use app\store\model\Coupon as CouponModel;
  15. use app\store\model\UserCoupon as UserCouponModel;
  16. /**
  17. * 优惠券管理
  18. * Class Coupon
  19. * @package app\store\controller\market
  20. */
  21. class Coupon extends Controller
  22. {
  23. /**
  24. * 列表记录
  25. * @return array
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list()
  29. {
  30. $model = new CouponModel;
  31. $list = $model->getList($this->request->param());
  32. return $this->renderSuccess(compact('list'));
  33. }
  34. /**
  35. * 详情记录
  36. * @param int $couponId
  37. * @return array
  38. */
  39. public function detail(int $couponId)
  40. {
  41. $detail = CouponModel::detail($couponId);
  42. return $this->renderSuccess(compact('detail'));
  43. }
  44. /**
  45. * 添加优惠券
  46. * @return array|mixed
  47. */
  48. public function add()
  49. {
  50. // 新增记录
  51. $model = new CouponModel;
  52. if ($model->add($this->postForm())) {
  53. return $this->renderSuccess('添加成功');
  54. }
  55. return $this->renderError($model->getError() ?: '添加失败');
  56. }
  57. /**
  58. * 更新优惠券
  59. * @param $couponId
  60. * @return array|mixed
  61. */
  62. public function edit(int $couponId)
  63. {
  64. // 优惠券详情
  65. $model = CouponModel::detail($couponId);
  66. // 更新记录
  67. if ($model->edit($this->postForm())) {
  68. return $this->renderSuccess('更新成功');
  69. }
  70. return $this->renderError($model->getError() ?: '更新失败');
  71. }
  72. /**
  73. * 删除优惠券
  74. * @param $couponId
  75. * @return array|mixed
  76. */
  77. public function delete(int $couponId)
  78. {
  79. // 优惠券详情
  80. $model = CouponModel::detail($couponId);
  81. // 更新记录
  82. if ($model->setDelete()) {
  83. return $this->renderSuccess('删除成功');
  84. }
  85. return $this->renderError($model->getError() ?: '删除成功');
  86. }
  87. /**
  88. * 领取记录
  89. * @return array
  90. */
  91. public function receive()
  92. {
  93. // 获取列表记录
  94. $model = new UserCouponModel;
  95. $list = $model->getList($this->request->param());
  96. return $this->renderSuccess(compact('list'));
  97. }
  98. }