| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace app\common\service;
- use app\common\model\UserBankSignModel;
- use utils\RedisCache;
- /**
- * 用户等级配置服务 by wes
- * Class UserBankSignService
- * @package app\common\service
- */
- class UserBankSignService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->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;
- }
- }
|