123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace app\data\controller\base;
- use app\data\service\PaymentService;
- use app\data\service\UserAdminService;
- use think\admin\Controller;
- use think\admin\extend\CodeExtend;
- class Payment extends Controller
- {
-
- private $table = 'DataBasePayment';
-
- protected $types = PaymentService::TYPES;
-
- public function index()
- {
- $this->title = '支付通道管理';
- $query = $this->_query($this->table);
- $query->where(['deleted' => 0])->order('sort desc,id desc');
- $query->like('name,code')->equal('type,status')->dateBetween('create_at')->page();
- }
-
- public function add()
- {
- $this->title = '添加支付通道';
- $this->_form($this->table, 'form');
- }
-
- public function edit()
- {
- $this->title = '编辑支付通道';
- $this->_form($this->table, 'form');
- }
-
- protected function _form_filter(array &$data)
- {
- if (empty($data['code'])) {
- $data['code'] = CodeExtend::uniqidNumber(20, 'M');
- }
- if ($this->request->isGet()) {
- $this->payments = [];
- foreach ($this->types as $k => $vo) {
- $allow = [];
- foreach ($vo['bind'] as $api) if (isset(UserAdminService::TYPES[$api])) {
- $allow[$api] = UserAdminService::TYPES[$api]['name'];
- }
- if (empty($allow)) continue;
- $this->payments[$k] = array_merge($vo, ['allow' => join('、', $allow)]);
- }
- $data['content'] = json_decode($data['content'] ?? '[]', true) ?: [];
- } else {
- if (empty($data['type'])) $this->error('请选择支付通道并配置参数!');
- if (empty($data['cover'])) $this->error('请上传支付方式图标!');
- $data['content'] = json_encode($this->request->post() ?: [], JSON_UNESCAPED_UNICODE);
- }
- }
-
- protected function _form_result(bool $state)
- {
- if ($state) {
- $this->success('支付通道保存成功!', 'javascript:history.back()');
- }
- }
-
- public function state()
- {
- $this->_save($this->table, $this->_vali([
- 'status.in:0,1' => '状态值范围异常!',
- 'status.require' => '状态值不能为空!',
- ]));
- }
-
- public function remove()
- {
- $this->_delete($this->table);
- }
- }
|