PayConfig.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model;
  20. use app\common\enum\PayEnum;
  21. use app\common\service\FileService;
  22. class PayConfig extends BaseModel
  23. {
  24. protected $name = 'dev_pay';
  25. // 设置json类型字段
  26. // protected $json = ['config'];
  27. // 设置JSON数据返回数组
  28. // protected $jsonAssoc = true;
  29. function setConfigAttr($config)
  30. {
  31. return json_encode($config, JSON_UNESCAPED_UNICODE);
  32. }
  33. function getConfigAttr($config, $data)
  34. {
  35. $config = (array) json_decode($config, true);
  36. switch ($data['pay_way']) {
  37. case PayEnum::WECHAT_PAY:
  38. $config['interface_version'] = $config['interface_version'] ?? '';
  39. $config['merchant_type'] = $config['merchant_type'] ?? '';
  40. $config['mch_id'] = $config['mch_id'] ?? '';
  41. $config['pay_sign_key'] = $config['pay_sign_key'] ?? '';
  42. $config['apiclient_cert'] = $config['apiclient_cert'] ?? '';
  43. $config['apiclient_key'] = $config['apiclient_key'] ?? '';
  44. $config['wechat_public_serial'] = $config['wechat_public_serial'] ?? '';
  45. $config['wechat_public_cert'] = $config['wechat_public_cert'] ?? '';
  46. break;
  47. case PayEnum::ALI_PAY:
  48. $config['mode'] = $config['mode'] ?? 'normal_mode';
  49. $config['merchant_type'] = $config['merchant_type'] ?? 'ordinary_merchant';
  50. $config['app_id'] = $config['app_id'] ?? '';
  51. $config['private_key'] = $config['private_key'] ?? '';
  52. $config['ali_public_key'] = $config['ali_public_key'] ?? '';
  53. break;
  54. }
  55. return $config;
  56. }
  57. /**
  58. * @notes 支付图标获取器 - 路径添加域名
  59. * @param $value
  60. * @return string
  61. * @author ljj
  62. * @date 2021/7/28 2:12 下午
  63. */
  64. public function getIconAttr($value)
  65. {
  66. return empty($value) ? '' : FileService::getFileUrl($value);
  67. }
  68. /**
  69. * @notes 支付方式名称获取器
  70. * @param $value
  71. * @param $data
  72. * @return string|string[]
  73. * @author ljj
  74. * @date 2021/7/31 2:24 下午
  75. */
  76. public function getPayWayNameAttr($value,$data)
  77. {
  78. return PayEnum::getPayDesc($data['pay_way']);
  79. }
  80. }