UserUnmoneyService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\UserUnmoneyModel;
  4. use app\common\model\YsBankListModel;
  5. use utils\RedisCache;
  6. /**
  7. * 用户利润 by wes
  8. * Class UserUnmoneyService
  9. * @package app\common\service
  10. */
  11. class UserUnmoneyService
  12. {
  13. protected static $instance = null;
  14. protected $model = null;
  15. public function __construct()
  16. {
  17. $this->model = new UserUnmoneyModel();
  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 $params 查询参数
  33. * @param int $pageSize
  34. * @param string $field
  35. * @param string $cache
  36. * @return array|mixed
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function getList($params, $pageSize = 10, $field = '', $cache=true)
  42. {
  43. $page = request()->post('page', 1);
  44. $cacheKey = "caches:temp:profitLogs:{$page}_{$pageSize}_" . md5(json_encode($params));
  45. $data = RedisCache::get($cacheKey);
  46. if ($data && $cache) {
  47. return $data;
  48. }
  49. $typeArr = config('type.profit');
  50. $where = [];
  51. $type = isset($params['type'])? intval($params['type']) : 0;
  52. if($type){
  53. $where['type'] = $type;
  54. }
  55. $uid = isset($params['uid'])? intval($params['uid']) : 0;
  56. if($uid){
  57. $where['uid'] = $uid;
  58. }
  59. $field = $field ? $field : 'id,uid,money,status,state,type,create_time as create_at,remark';
  60. $data = $this->model->where($where)->where(function ($query) use ($params) {
  61. $time = isset($params['time']) ? trim($params['time']) : '';
  62. })
  63. ->field($field)
  64. ->withAttr('type', function ($value, $data) use ($typeArr) {
  65. return isset($typeArr[$value]) ? $typeArr[$value] : '未知类型';
  66. })
  67. ->order('id desc')
  68. ->page($page, $pageSize)->select();
  69. $data = $data? $data->toArray() : [];
  70. if($data && $cache){
  71. RedisCache::set($cacheKey, $data, rand(3,5));
  72. }
  73. return $data;
  74. }
  75. }