123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\data\controller;
- use app\data\service\PaymentService;
- use app\data\service\UserService;
- use think\admin\Controller;
- use think\admin\extend\CodeExtend;
- /**
- * 支付参数通道
- * Class ShopPayment
- * @package app\data\controller
- */
- class ShopPayment extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- private $table = 'ShopPayment';
- /**
- * 支付参数类型
- * @var array
- */
- protected $types = PaymentService::TYPES;
- /**
- * 支付参数管理
- * @auth true
- * @menu true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function index()
- {
- $this->title = '支付参数管理';
- $query = $this->_query($this->table);
- $query->where(['deleted' => 0])->order('sort desc,id desc');
- $query->equal('type,status')->like('name')->dateBetween('create_at')->page();
- }
- /**
- * 添加支付参数
- * @auth true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function add()
- {
- $this->title = '添加支付参数';
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑支付参数
- * @auth true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function edit()
- {
- $this->title = '编辑支付参数';
- $this->_form($this->table, 'form');
- }
- /**
- * 数据表单处理
- * @param array $data
- */
- protected function _form_filter(array &$data)
- {
- if (empty($data['code'])) {
- $data['code'] = CodeExtend::uniqidNumber(14, 'M');
- }
- if ($this->request->isGet()) {
- $this->payments = [];
- foreach ($this->types as $k => $vo) {
- $allow = [];
- foreach ($vo['bind'] as $api) if (isset(UserService::TYPES[$api])) {
- $allow[$api] = UserService::TYPES[$api]['name'];
- }
- $this->payments[$k] = array_merge($vo, ['allow' => join('、', $allow)]);
- }
- $data['content'] = json_decode($data['content'] ?? '[]', true) ?: [];
- } else {
- if (empty($data['type'])) $this->error('请选择支付参数并配置支付参数!');
- $data['content'] = json_encode($this->request->post() ?: [], JSON_UNESCAPED_UNICODE);
- }
- }
- /**
- * 表单结果处理
- * @param boolean $state
- */
- protected function _form_result(bool $state)
- {
- if ($state) {
- $this->success('支付参数保存成功!', 'javascript:history.back()');
- }
- }
- /**
- * 修改支付参数状态
- * @auth true
- * @throws \think\db\exception\DbException
- */
- public function state()
- {
- $this->_save($this->table, $this->_vali([
- 'status.in:0,1' => '状态值范围异常!',
- 'status.require' => '状态值不能为空!',
- ]));
- }
- /**
- * 删除支付参数
- * @auth true
- * @throws \think\db\exception\DbException
- */
- public function remove()
- {
- $this->_delete($this->table);
- }
- }
|