| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace app\common\service;
- use app\common\model\MoneyLogModel;
- use utils\RedisCache;
- /**
- * 余额流水服务 by wes
- * Class MoneyLogService
- * @package app\common\service
- */
- class MoneyLogService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new MoneyLogModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 获取列表
- * @param $params 查询参数
- * @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 getList($params, $pageSize = 10, $field = '', $cache = true)
- {
- $page = request()->post('page', 1);
- $cacheKey = "caches:temp:profitLogs:{$page}_{$pageSize}_" . md5(json_encode($params));
- $data = RedisCache::get($cacheKey);
- if ($data && $cache) {
- return $data;
- }
- $typeArr = config('type.profit');
- $where = ['status' => 1];
- $type = isset($params['type']) ? intval($params['type']) : 0;
- if ($type) {
- $where['type'] = $type;
- }
- $field = $field ? $field : 'id,uid,money,status,state,type,create_at,remark';
- $data = $this->model->where($where)
- ->field($field)
- ->withAttr('type', function ($value, $data) use ($typeArr) {
- return isset($typeArr[$value]) ? $typeArr[$value] : '未知类型';
- })
- ->order('id desc')
- ->page($page, $pageSize)->select();
- $data = $data ? $data->toArray() : [];
- if ($data && $cache) {
- RedisCache::set($cacheKey, $data, rand(3, 5));
- }
- return $data;
- }
- }
|