Plan.php 2.8 KB

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