Template.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 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\setting\payment;
  13. use think\response\Json;
  14. use app\store\controller\Controller;
  15. use app\store\model\PaymentTemplate as PaymentTemplateModel;
  16. use think\db\exception\DbException;
  17. /**
  18. * 支付模板设置
  19. * Class Template
  20. * @package app\store\controller\setting
  21. */
  22. class Template extends Controller
  23. {
  24. /**
  25. * 支付模板列表
  26. * @return Json
  27. * @throws DbException
  28. */
  29. public function list(): Json
  30. {
  31. $model = new PaymentTemplateModel;
  32. $list = $model->getList();
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 获取全部支付模板
  37. * @return Json
  38. * @throws DbException
  39. */
  40. public function all(): Json
  41. {
  42. $model = new PaymentTemplateModel;
  43. $list = $model->getAll();
  44. return $this->renderSuccess(compact('list'));
  45. }
  46. /**
  47. * 支付模板详情
  48. * @param int $templateId
  49. * @return Json
  50. */
  51. public function detail(int $templateId): Json
  52. {
  53. $detail = PaymentTemplateModel::detail($templateId);
  54. return $this->renderSuccess(compact('detail'));
  55. }
  56. /**
  57. * 添加支付模板
  58. * @return Json
  59. * @throws \cores\exception\BaseException
  60. */
  61. public function add(): Json
  62. {
  63. // 新增记录
  64. $model = new PaymentTemplateModel;
  65. if ($model->add($this->postData())) {
  66. return $this->renderSuccess('添加成功');
  67. }
  68. return $this->renderError($model->getError() ?: '添加失败');
  69. }
  70. /**
  71. * 编辑支付模板
  72. * @param int $templateId
  73. * @return Json
  74. * @throws \cores\exception\BaseException
  75. */
  76. public function edit(int $templateId): Json
  77. {
  78. // 模板详情
  79. $model = PaymentTemplateModel::detail($templateId);
  80. // 更新记录
  81. if ($model->edit($this->postData())) {
  82. return $this->renderSuccess('更新成功');
  83. }
  84. return $this->renderError($model->getError() ?: '更新失败');
  85. }
  86. /**
  87. * 删除模板
  88. * @param int $templateId
  89. * @return Json
  90. */
  91. public function delete(int $templateId): Json
  92. {
  93. // 模板详情
  94. $model = PaymentTemplateModel::detail($templateId);
  95. if (!$model->setDelete()) {
  96. return $this->renderError($model->getError() ?: '删除失败');
  97. }
  98. return $this->renderSuccess('删除成功');
  99. }
  100. }