WithdrawAccountService.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\WithdrawAccountModel;
  4. use app\common\model\YsBankListModel;
  5. use utils\RedisCache;
  6. /**
  7. * 提现账号 by wes
  8. * Class WithdrawAccountService
  9. * @package app\common\service
  10. */
  11. class WithdrawAccountService
  12. {
  13. protected static $instance = null;
  14. protected $model = null;
  15. public function __construct()
  16. {
  17. $this->model = new WithdrawAccountModel();
  18. }
  19. /**
  20. * 静态化入口
  21. * @return static|null
  22. */
  23. public static function make()
  24. {
  25. if (!self::$instance) {
  26. self::$instance = new static();
  27. }
  28. return self::$instance;
  29. }
  30. /**
  31. * 获取银行卡列表
  32. * @param $uid 查询参数
  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, $type=0, $field = '', $cache=true)
  41. {
  42. $cacheKey = "caches:temp:withdrawAccount:{$uid}_{$type}" . md5($field);
  43. $data = RedisCache::get($cacheKey);
  44. if ($data && $cache) {
  45. return $data;
  46. }
  47. $where = ['uid'=> $uid];
  48. if($type){
  49. $where['type'] = $type;
  50. }
  51. $field = $field ? $field : 'id,name,number,bank_subname,create_time';
  52. $data = $this->model->where($where)->where(['is_del' => 2])
  53. ->field($field)
  54. ->select();
  55. $data = $data? $data->toArray() : [];
  56. if($data && $cache){
  57. RedisCache::set($cacheKey, $data, 5,10);
  58. }
  59. return $data;
  60. }
  61. }