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.

133 lines
3.3 KiB

<?php
namespace app\integral\logic;
use app\integral\model\IntegralLog;
use app\integral\model\IntegralMy;
class Integral extends Base
{
/**
* 获取我的积分数据
* @date 2022-11-17
*/
public function getMyIntegral()
{
$my_model = new IntegralMy();
// 获取当前用户积分
$my = $my_model->getOneData([
['uid', '=', $this->mid],
['user_id', '=', $this->userId]
], 'integral,total_integral');
// 如果还没数据
if (empty($my)) {
$my = [
'integral' => 0,
'total_integral' => 0
];
}
return sendSuccessArray([
// 我的积分和累计积分
'my' => $my
]);
}
/**
* 获取我的积分数据
* @date 2022-11-21
*/
public function getMyRank()
{
$my_model = new IntegralMy();
// 获取当前用户积分
$my = $my_model->getOneData([
['uid', '=', $this->mid],
['user_id', '=', $this->userId]
], 'id,integral,total_integral,total_integral_change_time');
if (empty($my)) {
$my['total_integral'] = 0;
$rank = '暂无数据';
} else {
$map1 = [
['uid', '=', $this->mid],
['total_integral', '>', $my['total_integral']]
];
$map2 = [
['uid', '=', $this->mid],
['total_integral', '=', $my['total_integral']],
['total_integral_change_time', '<', $my['total_integral_change_time']]
];
$map3 = [
['uid', '=', $this->mid],
['total_integral', '=', $my['total_integral']],
['total_integral_change_time', '=', $my['total_integral_change_time']],
['id', '<', $my['id']]
];
$number = $my_model->whereOr([$map1, $map2, $map3])->count();
$rank = $number + 1;
}
return sendSuccessArray([
'total_integral' => $my['total_integral'],
'rank' => $rank
]);
}
/**
* 我的积分记录
* @param int $index 类型 0--全部 1--收入 2--支出
* @param int $page 第X页
* @date 2022-11-01
*/
public function listLog($index, $page)
{
$log_model = new IntegralLog();
$where = [
['uid', '=', $this->mid],
['user_id', '=', $this->userId]
];
if ($index == 1) {
$where[] = ['integral', '>', 0];
} else if ($index == 2) {
$where[] = ['integral', '<', 0];
}
$field = 'id,user_id,show_text,integral,after_integral,create_time';
$list = $log_model->listLogWithPage($where, $page, $field, 'id desc', 50);
return sendSuccessArray([
// 积分明细
'list' => $list
]);
}
/**
* 获取排行榜
* @date 2022-11-21
*/
public function listRank()
{
$my_model = new IntegralMy();
$rank_list = $my_model->listRank([
['uid', '=', $this->mid]
], 'user_id,total_integral', 'total_integral desc,total_integral_change_time asc,id asc', 20);
return sendSuccessArray([
// 排行榜列表
'rank_list' => $rank_list
]);
}
}