PayChannel.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\pay;
  12. use app\dict\pay\PayDict;
  13. use app\service\admin\pay\PayChannelService;
  14. use core\base\BaseAdminController;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. use think\Response;
  19. class PayChannel extends BaseAdminController
  20. {
  21. /**
  22. * 支付渠道设置
  23. * @return Response
  24. */
  25. public function set($channel, $type)
  26. {
  27. $data = $this->request->params([
  28. ['is_default', 0],
  29. ['config', []],
  30. ['status', 0]
  31. ]);
  32. $data['config']['type'] = $type;
  33. $this->validate($data['config'], 'app\validate\pay\Pay.set');
  34. (new PayChannelService())->set($channel, $type, $data);
  35. return success('SET_SUCCESS');
  36. }
  37. /**
  38. * 支付渠道列表
  39. * @return Response
  40. */
  41. public function lists()
  42. {
  43. return success((new PayChannelService())->getChannelList());
  44. }
  45. /**
  46. * 通过渠道获取支付配置
  47. * @param $channel
  48. * @return Response
  49. * @throws DataNotFoundException
  50. * @throws DbException
  51. * @throws ModelNotFoundException
  52. */
  53. public function getListByChannel($channel)
  54. {
  55. return success((new PayChannelService())->getListByChannel($channel));
  56. }
  57. /**
  58. * 支付设置
  59. * @return Response
  60. */
  61. public function setTransfer()
  62. {
  63. $data = $this->request->params([
  64. ['wechatpay_config', []],
  65. ['alipay_config', []],
  66. ]);
  67. $this->validate(array_merge($data['wechatpay_config'], ['type' => PayDict::WECHATPAY]), 'app\validate\pay\Pay.set');
  68. $this->validate(array_merge($data['alipay_config'], ['type' => PayDict::ALIPAY]), 'app\validate\pay\Pay.set');
  69. (new PayChannelService())->setTransfer($data);
  70. return success('SET_SUCCESS');
  71. }
  72. /**
  73. * 多渠道支付设置
  74. * @return Response
  75. */
  76. public function setAll()
  77. {
  78. $data = $this->request->params([
  79. ['config', []],
  80. ]);
  81. // $this->validate(array_merge($data['wechatpay_config'], ['type' => PayDict::WECHATPAY]), 'app\validate\pay\Pay.set');
  82. // $this->validate(array_merge($data['alipay_config'], ['type' => PayDict::ALIPAY]), 'app\validate\pay\Pay.set');
  83. (new PayChannelService())->setAll($data['config']);
  84. return success('SET_SUCCESS');
  85. }
  86. /**
  87. * 获取全部支付方式
  88. * @return Response
  89. */
  90. public function getPayTypeList() {
  91. return success(data:PayDict::getPayType());
  92. }
  93. }