Payment.php 3.1 KB

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