You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

<?php
namespace app\integral\model;
use app\base\model\user\UserInfo;
use think\model\concern\SoftDelete;
class IntegralMy extends Base
{
use SoftDelete;
/**
* API-获取我的积分
* @date 2021-06-01
*/
public function getMyIntegral($user_id)
{
// 获取当前用户积分
$my = $this->getOneData([
['uid', '=', $this->mid],
['user_id', '=', $user_id]
], 'integral,total_integral');
if (empty($my)) {
$my['integral'] = 0;
$my['total_integral'] = 0;
}
return $my;
}
/**
* 查找全部数据
* @date 2022-11-22
*/
public function listRank($where, $field = '*', $order = '', $limit = 0)
{
if (empty($order)) {
$order = 'id desc';
}
return $this->with(['userInfo'])->field($field)->where($where)->order($order)->limit($limit)->select()->each(function ($item){
unset($item['userInfo']);
});
}
/**
* 关联模型 一对一关联用户信息
* @date 2022-11-22
*/
public function userInfo()
{
return $this->hasOne(UserInfo::class, 'user_id', 'user_id')->bind([
'user_head_img'=>'head_img',
'user_nick_name'=>'nick_name',
]);
}
}