| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- // +----------------------------------------------------------------------
- // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: thinkphp <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\api\model;
- use app\common\model\UserInfo as UserInfoModel;
- use app\store\model\Setting as SettingModel;
- use think\facade\Cache;
- /**
- * 用户资料模型类
- * Class UserInfo
- * @package app\api\model
- */
- class UserInfo extends UserInfoModel
- {
- protected $globalScope = [''];
- /**
- * 隐藏字段
- * @var array
- */
- protected $hidden = [
- 'store_id',
- 'update_time'
- ];
- /**
- * 获取用户信息
- * @param $where
- * @param array $with
- * @return static|array|false|null
- */
- public static function detail($where, array $with = [])
- {
- $filter = [];
- if (is_array($where)) {
- $filter = array_merge($filter, $where);
- } else {
- $filter['user_id'] = (int)$where;
- }
- return static::get($filter, $with);
- }
- /**
- * 分配每日解锁用户
- * @param $userId
- * @return false
- */
- public static function dayLockedUser($userId)
- {
- $cacheKey = "caches:locked:day:{$userId}";
- if(Cache::get($cacheKey)){
- return false;
- }
- $info = self::where(['user_id'=> $userId])->field('day_locked_time,day_locked_uids')->find();
- $dayLockedTime = isset($info['day_locked_time'])? intval($info['day_locked_time']) : 0;
- if($dayLockedTime && date('Y-m-d', $dayLockedTime) == date('Y-m-d')){
- Cache::set($cacheKey, ['user_id'=> $userId,'ids'=> $info['day_locked_uids'],'date'=> date('Y-m-d H:i:s')], rand(300, 3600));
- return false;
- }
- $platform = SettingModel::getItem('platform');
- $locked = isset($platform['locked'])? $platform['locked'] : [];
- $lockNum = isset($locked['lock_num'])? $locked['lock_num'] : 0;
- $lockNum = $lockNum? $lockNum : 3;
- $uids = self::alias('a')
- ->leftJoin('user u','u.user_id=a.user_id')
- ->where(['u.user_type'=>1,'u.is_delete'=>0,'u.status'=>1])
- ->orderRaw('rand()')
- ->limit($lockNum)
- ->column('a.user_id');
- if($uids){
- self::where(['user_id'=> $userId])->save(['day_locked_time'=>time(),'day_locked_uids'=> implode(',', $uids)]);
- }
- Cache::set($cacheKey, ['user_id'=> $userId,'ids'=> $uids,'date'=> date('Y-m-d H:i:s')], rand(300, 3600));
- }
- }
|