ShopPayment.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\data\controller;
  3. use app\data\service\PaymentService;
  4. use app\data\service\UserService;
  5. use think\admin\Controller;
  6. use think\admin\extend\CodeExtend;
  7. /**
  8. * 支付参数通道
  9. * Class ShopPayment
  10. * @package app\data\controller
  11. */
  12. class ShopPayment extends Controller
  13. {
  14. /**
  15. * 绑定数据表
  16. * @var string
  17. */
  18. private $table = 'ShopPayment';
  19. /**
  20. * 支付参数类型
  21. * @var array
  22. */
  23. protected $types = PaymentService::TYPES;
  24. /**
  25. * 支付参数管理
  26. * @auth true
  27. * @menu true
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function index()
  33. {
  34. $this->title = '支付参数管理';
  35. $query = $this->_query($this->table);
  36. $query->where(['deleted' => 0])->order('sort desc,id desc');
  37. $query->equal('type,status')->like('name')->dateBetween('create_at')->page();
  38. }
  39. /**
  40. * 添加支付参数
  41. * @auth true
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\DbException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. */
  46. public function add()
  47. {
  48. $this->title = '添加支付参数';
  49. $this->_form($this->table, 'form');
  50. }
  51. /**
  52. * 编辑支付参数
  53. * @auth true
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function edit()
  59. {
  60. $this->title = '编辑支付参数';
  61. $this->_form($this->table, 'form');
  62. }
  63. /**
  64. * 数据表单处理
  65. * @param array $data
  66. */
  67. protected function _form_filter(array &$data)
  68. {
  69. if (empty($data['code'])) {
  70. $data['code'] = CodeExtend::uniqidNumber(14, 'M');
  71. }
  72. if ($this->request->isGet()) {
  73. $this->payments = [];
  74. foreach ($this->types as $k => $vo) {
  75. $allow = [];
  76. foreach ($vo['bind'] as $api) if (isset(UserService::TYPES[$api])) {
  77. $allow[$api] = UserService::TYPES[$api]['name'];
  78. }
  79. $this->payments[$k] = array_merge($vo, ['allow' => join('、', $allow)]);
  80. }
  81. $data['content'] = json_decode($data['content'] ?? '[]', true) ?: [];
  82. } else {
  83. if (empty($data['type'])) $this->error('请选择支付参数并配置支付参数!');
  84. $data['content'] = json_encode($this->request->post() ?: [], JSON_UNESCAPED_UNICODE);
  85. }
  86. }
  87. /**
  88. * 表单结果处理
  89. * @param boolean $state
  90. */
  91. protected function _form_result(bool $state)
  92. {
  93. if ($state) {
  94. $this->success('支付参数保存成功!', 'javascript:history.back()');
  95. }
  96. }
  97. /**
  98. * 修改支付参数状态
  99. * @auth true
  100. * @throws \think\db\exception\DbException
  101. */
  102. public function state()
  103. {
  104. $this->_save($this->table, $this->_vali([
  105. 'status.in:0,1' => '状态值范围异常!',
  106. 'status.require' => '状态值不能为空!',
  107. ]));
  108. }
  109. /**
  110. * 删除支付参数
  111. * @auth true
  112. * @throws \think\db\exception\DbException
  113. */
  114. public function remove()
  115. {
  116. $this->_delete($this->table);
  117. }
  118. }