del(self::CACHE_KEY_ID.$id); //Host没有时取ID的 if(empty($host)){ $host = $this->where('id',$id)->value('pay_host'); } //平台Id没有事取ID的 if(empty($platform_id)){ $platform_id = $this->where('id',$id)->value('platform_id'); } //删除Host $redis->del(self::CACHE_KEY_HOST.$host); //删除平台ID $redis->del(self::CACHE_KEY_DEFAULT.$platform_id); //删除支付列表 $redis->del(self::CACHE_KEY_PAYHOST); } /** * 删除Wxpay平台缓存 * @param null $platform_id */ public function delCacheByPlatformId($platform_id){ $redis = Redis::instance(); //删除平台ID $redis->del(self::CACHE_KEY_DEFAULT.$platform_id); } /** * 删除Wxpay平台缓存 */ public function delCachePayHost(){ $redis = Redis::instance(); //删除平台ID $redis->del(self::CACHE_KEY_PAYHOST); } /** * 删除Wxpay平台缓存 * @param null $host */ public function delCacheByHost($host){ $redis = Redis::instance(); //删除平台ID $redis->del(self::CACHE_KEY_HOST.$host); } /** * 获取支付信息 * @param $platform_id * @param null $id 表id * @return array|null */ public function getInfo($platform_id,$id=null){ if(empty($platform_id)) { return null; } $redis = Redis::instance(); if(empty($id)){ //获取当前平台下默认的支付信息 $modulename = request()->module(); if($modulename == 'admin' && PHP_SAPI != 'cli') { //如果是后台 $arr = $this->where(['platform_id'=>$platform_id,'isdefault'=>'1','status'=>1])->find(); if($arr){ $arr = $arr->toArray(); } }else{ $key = self::CACHE_KEY_DEFAULT.$platform_id; if($redis->exists($key)){ $arr = $redis->hgetall($key); }else{ $arr = $this->where(['platform_id'=>$platform_id,'isdefault'=>'1','status'=>1])->find(); if($arr){ $arr = $arr->toArray(); $redis->hmset($key,$arr); $redis->expire($key,86400); } } } }else{ //获取指定的支付信息 $modulename = request()->module(); if($modulename == 'admin' && PHP_SAPI != 'cli' ) { //如果是后台 $arr = $this->where('id',$id)->find(); if($arr){ $arr = $arr->toArray(); } }else{ $arr = $this->getInfoById($id); } } return $arr; } /** * 通过支付域名去相关支付信息 * @param $domain * @return array|null * @throws \think\Exception */ public function getInfoByDomain($domain){ $info = $this->where('pay_host',$domain)->find(); if(!empty($info)){ return $info->toArray(); }else{ return null; } } /** * 根据host获取支付域名信息 * @param $host * @return array|false|\PDOStatement|string|Model */ public function getInfoByHost($host){ $redis = Redis::instance(); $key = self::CACHE_KEY_HOST.$host; if($redis->exists($key)){ $payhost = $redis->hgetall($key); }else{ if($payhost = $this->where('pay_host',$host)->find()){ $payhost = $payhost->toArray(); $redis->hmset($key,$payhost); $redis->expire($key,3600); } } return $payhost; } public function getInfoById($id){ $redis = Redis::instance(); $key = self::CACHE_KEY_ID.$id; $wxpay = null; if (Cache::has($key)) { Log::info("获取缓存:$key filecache命中"); $wxpay = Cache::get($key); } if (!$wxpay) { if ($redis->exists($key)) { $wxpay = $redis->hgetall($key); Log::info("获取缓存:$key redis命中"); Cache::set($key, $wxpay, 10); } } if (!$wxpay) { $wxpay = $this->where('id', $id)->find(); if ($wxpay) { Log::info("获取缓存:$key mysql命中"); $wxpay = $wxpay->toArray(); $redis->hmset($key, $wxpay); $redis->expire($key, 3600); } } return $wxpay; } public function getListByBusiness($business){ $redis = Redis::instance(); $key = 'WPLS:'.intval($business); if($redis->exists($key)){ $result = json_decode($redis->get($key), true); }else{ $result = $this->where("find_in_set($business,business_line)")->where('status','1')->select(); if($result){ $result = collection($result)->toArray(); } $redis->setex($key, 60, json_encode($result, JSON_UNESCAPED_UNICODE)); } return $result; } //获取所有可用的支付域名 全部支付域名 public function getHosts(){ $redis = Redis::instance(); if ($ret = $redis->get(self::CACHE_KEY_PAYHOST)) { $res = json_decode($ret, true); }else{ $res = collection($this->column('pay_host'))->toArray(); $redis->setex(self::CACHE_KEY_PAYHOST,86400,json_encode($res)); } return $res; } public function platform() { return $this->belongsTo('Platform', 'platform_id')->setEagerlyType(0); } /** * 获取平台支付列表 * @param $business 业务线 * @param $platform_id * @param null $ophost_id 根据OpHost域名过滤 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getListFormatByPlatformId($business = null,$platform_id = null,$ophost_id = null){ $result = []; $map['status'] = '1'; if($platform_id){ $map['platform_id'] = ['in',$platform_id]; } if($business !== null){ $map[] = ['exp',"FIND_IN_SET({$business},business_line)"]; } if($ophost_id){ $host = model('Ophost')->where('id',$ophost_id)->value('host'); $map['pay_host'] = ['like','%'.$host]; } if($list = $this->where($map)->select()){ foreach($list as $val){ $platform_name = model('Platform')->where('id',$val['platform_id'])->value('name'); array_push($result,['fufen'=>$val['fufen'],'id'=>$val['id'],'platform_id'=>$val['platform_id'],'text'=>$platform_name.'--'.$val['name'].'--'.$val['p_desc']]); } } return $result; } public function getStatusList() { return ['0' => __('Status 0'),'1' => __('Status 1')]; } public function getFufenList() { return ['0' => __('Fufen 0'),'1' => __('Fufen 1')]; } public function getIsdefaultList() { return ['0' => __('Isdefault 0'),'1' => __('Isdefault 1')]; } public function getPaymentMethodList() { return ApiConstants::$allPaymentMethods; } public function getIsclosureList() { return ['0' => __('IsClosure 0'),'1' => __('IsClosure 1')]; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : $data['status']; $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getFufenTextAttr($value, $data) { $value = $value ? $value : $data['fufen']; $list = $this->getFufenList(); return isset($list[$value]) ? $list[$value] : ''; } public function getIsdefaultTextAttr($value, $data) { $value = $value ? $value : $data['isdefault']; $list = $this->getIsdefaultList(); return isset($list[$value]) ? $list[$value] : ''; } public function getIsClosureTextAttr($value, $data) { $value = $value ? $value : $data['is_closure']; $list = $this->getIsclosureList(); return isset($list[$value]) ? $list[$value] : ''; } public function getQuartetIsSplit() { return ApiConstants::$quartetIsSplit; } //获取点众分账子账户 public function getDzPamlpaySubaccountList() { return model('palmpay_sub_account')->alias('psub')->join('palmpay_company pc','pc.id=psub.palmpay_company_id')->where('psub.sub_account_type',PayConstents::PALMPAY_ACCOUNT_DZ)->field('psub.id,psub.nickname,pc.name')->select(); } public function getQuartetIsSplitList() { return ['1' => __('Quartet_is_split 1'),'2' => __('Quartet_is_split 2')]; } }