Plan.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller\market\recharge;
  10. use app\store\controller\Controller;
  11. use app\store\model\recharge\Plan as PlanModel;
  12. /**
  13. * 充值套餐管理
  14. * Class Coupon
  15. * @package app\store\controller\market
  16. */
  17. class Plan extends Controller
  18. {
  19. /* @var PlanModel $model */
  20. private $model;
  21. /**
  22. * 构造方法
  23. * @throws \app\common\exception\BaseException
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. */
  28. public function _initialize()
  29. {
  30. parent::_initialize();
  31. $this->model = new PlanModel;
  32. }
  33. /**
  34. * 充值套餐列表
  35. * @return mixed
  36. * @throws \think\exception\DbException
  37. */
  38. public function index()
  39. {
  40. $list = $this->model->getList();
  41. return $this->fetch('index', compact('list'));
  42. }
  43. /**
  44. * 添加充值套餐
  45. * @return array|mixed
  46. */
  47. public function add()
  48. {
  49. if (!$this->request->isAjax()) {
  50. return $this->fetch('add');
  51. }
  52. // 新增记录
  53. if ($this->model->add($this->postData('plan'))) {
  54. return $this->renderSuccess('添加成功', url('market.recharge.plan/index'));
  55. }
  56. return $this->renderError($this->model->getError() ?: '添加失败');
  57. }
  58. /**
  59. * 更新充值套餐
  60. * @param $plan_id
  61. * @return array|mixed
  62. * @throws \think\exception\DbException
  63. */
  64. public function edit($plan_id)
  65. {
  66. // 充值套餐详情
  67. $model = PlanModel::detail($plan_id);
  68. if (!$this->request->isAjax()) {
  69. return $this->fetch('edit', compact('model'));
  70. }
  71. // 更新记录
  72. if ($model->edit($this->postData('plan'))) {
  73. return $this->renderSuccess('更新成功', url('market.recharge.plan/index'));
  74. }
  75. return $this->renderError($model->getError() ?: '更新失败');
  76. }
  77. /**
  78. * 删除充值套餐
  79. * @param $plan_id
  80. * @return array|mixed
  81. * @throws \think\exception\DbException
  82. */
  83. public function delete($plan_id)
  84. {
  85. // 套餐详情
  86. $model = PlanModel::detail($plan_id);
  87. // 更新记录
  88. if ($model->setDelete()) {
  89. return $this->renderSuccess('删除成功', url('market.recharge.plan/index'));
  90. }
  91. return $this->renderError($model->getError() ?: '删除成功');
  92. }
  93. }