Files
amb_wechatapp/application/api/controller/user/Assets.php
T

76 lines
1.9 KiB
PHP

<?php
namespace app\api\controller\user;
use app\common\controller\Api;
use app\common\model\ScoreLog;
use app\common\model\MoneyLog;
use think\Db;
/**
* 用户资产
*/
class Assets extends Api
{
// 无需登录的接口,*表示全部
// protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
$this->moneyLogModel = new MoneyLog();
$this->scoreLogModel = new ScoreLog();
}
/**
* 获取资产信息
* @return void
*/
public function getAssetsLog(){
$limit = input('limit',10);
$page = input('page',1);
$mode = input('mode',0);
$time = input('time',time());
$type = input('type','money');
$where = [
'user_id'=>$this->auth->id
];
$startOfMonth = strtotime(date('Y-m-01',$time)); // 获取当前月份的第一天的时间戳
$endOfMonth = strtotime(date('Y-m-t 23:59:59',$time)); // 获取当前月份的最后一天的时间戳
if($type=='money'){
$rows = $this->moneyLogModel;
}else{
$rows = $this->scoreLogModel;
}
if($mode == 1){
$rows->where('before', 'exp', Db::raw('> `after`'));
}else if($mode == 2){
$rows->where('before', 'exp', Db::raw('< `after`'));
}
$list = $rows
->where($where)
->limit($limit)->page($page)
->where('createtime', 'BETWEEN', [$startOfMonth, $endOfMonth])
->order('createtime','desc')
->select();
$data = [];
if(!empty($list)){
foreach ($list as $item){
$item['value'] = $type=='money' ? $item['money'] : $item['score'];
$item['value'] = $item['value'] > 0 ? '+'.$item['value'] : $item['value'];
}
}
$this->success('获取成功', $list);
}
}