UserBankSignService.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\UserBankSignModel;
  4. use utils\RedisCache;
  5. /**
  6. * 用户等级配置服务 by wes
  7. * Class UserBankSignService
  8. * @package app\common\service
  9. */
  10. class UserBankSignService
  11. {
  12. protected static $instance = null;
  13. protected $model = null;
  14. public function __construct()
  15. {
  16. $this->model = new UserBankSignModel();
  17. }
  18. /**
  19. * 静态化入口
  20. * @return static|null
  21. */
  22. public static function make()
  23. {
  24. if(!self::$instance){
  25. self::$instance = new static();
  26. }
  27. return self::$instance;
  28. }
  29. /**
  30. * 获取签名绑定的银行卡列表
  31. * @param $uid 用户ID
  32. * @param int $pageSize
  33. * @param string $field
  34. * @param string $cache
  35. * @return array|mixed
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function getListByUser($uid, $pageSize = 10, $field = '', $cache=true)
  41. {
  42. $page = request()->post('page', 1);
  43. $cacheKey = "caches:temp:ysBankList:{$page}_{$pageSize}_" . md5(json_encode($params));
  44. $data = RedisCache::get($cacheKey);
  45. if ($data && $cache) {
  46. return $data;
  47. }
  48. $field = $field ? $field : 'id,bank_no,bank_name,bank_sub,bank_type,bank_value,status';
  49. $data = $this->model->where(['status' => 1])->where(function ($query) use ($params) {
  50. $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
  51. if ($keyword) {
  52. $query->where('bank_name|bank_sub', 'like', "%{$keyword}%");
  53. }
  54. })
  55. ->field($field)
  56. ->order('id asc')
  57. ->page($page, $pageSize)->select();
  58. $data = $data? $data->toArray() : [];
  59. if($data && $cache){
  60. RedisCache::set($cacheKey, $data, 3600);
  61. }
  62. return $data;
  63. }
  64. /**
  65. * 验证该用户是否已签约该卡
  66. * @param $uid
  67. * @param $bankCard
  68. * @param int $status
  69. * @return array|mixed
  70. */
  71. public function checkHasSign($uid, $bankCard, $status = 4)
  72. {
  73. $cacheKey = "caches:userBankSign:check:u{$uid}_{$bankCard}_{$status}";
  74. $data = RedisCache::get($cacheKey);
  75. if($data){
  76. return $data;
  77. }
  78. $where = ['bank_card'=> $bankCard,'uid'=> $uid,'status'=>$status];
  79. $data = $this->model->where($where)->findOrEmpty();
  80. $data = $data? $data->toArray():[];
  81. if($data){
  82. RedisCache::set($cacheKey, $data, rand(5,10));
  83. }
  84. return $data;
  85. }
  86. /**
  87. * 按签约单号验证是否已经签约绑定
  88. * @param $signOrderId
  89. * @return array|mixed
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\DbException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. */
  94. public function checkHasBySignOrderId($signOrderId)
  95. {
  96. $cacheKey = "caches:userBankSign:check:so_{$signOrderId}";
  97. $data = RedisCache::get($cacheKey);
  98. if($data){
  99. return $data;
  100. }
  101. $where = ['signorder_id'=> $signOrderId];
  102. $data = $this->model->where($where)->findOrEmpty();
  103. $data = $data? $data->toArray():[];
  104. if($data){
  105. RedisCache::set($cacheKey, $data, rand(5,10));
  106. }
  107. return $data;
  108. }
  109. /**
  110. * 用户绑定银行卡信息
  111. * @param $id
  112. * @param int $uid
  113. * @return array|mixed
  114. */
  115. public function getCacheInfo($id, $uid=0)
  116. {
  117. $cacheKey = "caches:userBankSign:info:u{$uid}_{$id}";
  118. $data = RedisCache::get($cacheKey);
  119. if($data){
  120. return $data;
  121. }
  122. $where = ['id'=> $id];
  123. if($uid){
  124. $where['uid'] = $uid;
  125. }
  126. $data = $this->model->where($where)->findOrEmpty();
  127. $data = $data? $data->toArray():[];
  128. if($data){
  129. RedisCache::set($cacheKey, $data, rand(5,10));
  130. }
  131. return $data;
  132. }
  133. }