Plan.php 2.5 KB

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