model = new UserBankSignModel(); } /** * 静态化入口 * @return static|null */ public static function make() { if(!self::$instance){ self::$instance = new static(); } return self::$instance; } /** * 获取签名绑定的银行卡列表 * @param $uid 用户ID * @param int $pageSize * @param string $field * @param string $cache * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getListByUser($uid, $pageSize = 10, $field = '', $cache=true) { $page = request()->post('page', 1); $cacheKey = "caches:temp:ysBankList:{$page}_{$pageSize}_" . md5(json_encode($params)); $data = RedisCache::get($cacheKey); if ($data && $cache) { return $data; } $field = $field ? $field : 'id,bank_no,bank_name,bank_sub,bank_type,bank_value,status'; $data = $this->model->where(['status' => 1])->where(function ($query) use ($params) { $keyword = isset($params['keyword']) ? trim($params['keyword']) : ''; if ($keyword) { $query->where('bank_name|bank_sub', 'like', "%{$keyword}%"); } }) ->field($field) ->order('id asc') ->page($page, $pageSize)->select(); $data = $data? $data->toArray() : []; if($data && $cache){ RedisCache::set($cacheKey, $data, 3600); } return $data; } /** * 验证该用户是否已签约该卡 * @param $uid * @param $bankCard * @param int $status * @return array|mixed */ public function checkHasSign($uid, $bankCard, $status = 4) { $cacheKey = "caches:userBankSign:check:u{$uid}_{$bankCard}_{$status}"; $data = RedisCache::get($cacheKey); if($data){ return $data; } $where = ['bank_card'=> $bankCard,'uid'=> $uid,'status'=>$status]; $data = $this->model->where($where)->findOrEmpty(); $data = $data? $data->toArray():[]; if($data){ RedisCache::set($cacheKey, $data, rand(5,10)); } return $data; } /** * 按签约单号验证是否已经签约绑定 * @param $signOrderId * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function checkHasBySignOrderId($signOrderId) { $cacheKey = "caches:userBankSign:check:so_{$signOrderId}"; $data = RedisCache::get($cacheKey); if($data){ return $data; } $where = ['signorder_id'=> $signOrderId]; $data = $this->model->where($where)->findOrEmpty(); $data = $data? $data->toArray():[]; if($data){ RedisCache::set($cacheKey, $data, rand(5,10)); } return $data; } /** * 用户绑定银行卡信息 * @param $id * @param int $uid * @return array|mixed */ public function getCacheInfo($id, $uid=0) { $cacheKey = "caches:userBankSign:info:u{$uid}_{$id}"; $data = RedisCache::get($cacheKey); if($data){ return $data; } $where = ['id'=> $id]; if($uid){ $where['uid'] = $uid; } $data = $this->model->where($where)->findOrEmpty(); $data = $data? $data->toArray():[]; if($data){ RedisCache::set($cacheKey, $data, rand(5,10)); } return $data; } }