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,check_password,api_url,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,check_password,api_url,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; } }