| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\common\service;
- use app\common\model\PayConfigModel;
- use utils\RedisCache;
- /**
- * 支付配置服务 by wes
- * Class PayConfigService
- * @package app\common\service
- */
- class PayConfigService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new PayConfigModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 按渠道获取支付配置参数
- * @param $channel 渠道
- * @param string $field
- * @param bool $cache
- * @return array|mixed
- */
- public function getInfoByChannel($channel, $scene=1, $paySource=1, $cache=true)
- {
- $cacheKey = "caches:temp:payConfig:info:c_{$channel}_{$scene}_{$paySource}";
- $data = RedisCache::get($cacheKey);
- if($data && $cache){
- return $data;
- }
- $field = 'app_id,title,pay_code,sign_key,scene,pay_source,private_key,public_key,app_cert_path,pay_root_cert,pay_cert_path,mchid';
- $data = $this->model->where(['channel'=> $channel,'status'=>1])->field($field)->findOrEmpty();
- $data = $data? $data->toArray() : [];
- if($data && $cache){
- RedisCache::set($cacheKey, $data, 7200);
- }
- return $data;
- }
- /**
- * 获取开启的支付渠道配置
- * @param int $scene 支付场景:1-所有,4-商城,6-服务商
- * @param int $paySource 支付来源:1-所有,2-安卓,3-苹果
- * @param bool $cache
- * @return array|mixed
- */
- public function getChannelList($scene=1, $paySource=1, $cache=true)
- {
- $cacheKey = "caches:temp:payConfig:channelList:s_{$scene}_{$paySource}";
- $data = RedisCache::get($cacheKey);
- if($data && $cache){
- return $data;
- }
- $where = ['status'=>1];
- if($scene>0){
- $where['scene'] = $scene;
- }
- if($paySource>0){
- $where['pay_source'] = $paySource;
- }
- $field = 'app_id,title,pay_code,sign_key,scene,pay_source,private_key,icon,public_key,app_cert_path,pay_root_cert,pay_cert_path,mchid';
- $data = $this->model->where($where)->withAttr('icon',function($value){
- return getWebUrl().$value;
- })->order('sort asc,id asc')->column($field,'channel');
- if($data && $cache){
- RedisCache::set($cacheKey, $data, 7200);
- }
- return $data;
- }
- }
|