| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\LedgerPowerChangeModel;
- use app\common\model\LedgerSmhChangeModel;
- use app\common\model\LedgerTokenChangeModel;
- use app\common\model\LedgerUsdtChangeModel;
- use app\common\model\OfflineRechargeRecordModel;
- use app\common\model\UserModel;
- use app\common\model\UserPathModel;
- use fast\Action;
- use fast\Date;
- use think\Db;
- use think\Model;
- class Team extends Api
- {
- /**
- * 团队算力收益的Action
- * @var array
- */
- private array $actionPower = [Action::PowerTeamAward, Action::PowerEqualAward];
- /**
- * 团队USDT收益的Action
- * @var array
- */
- private array $actionUsdt = [Action::UsdtWeightDividend];
- /**
- * 团队虚拟币收益的Action
- * @var array
- */
- private array $actionSmh = [Action::TokenAllocateEtc];
- /**
- * 团队页的几项数据
- * @return void
- */
- public function all()
- {
- $user = $this->auth->getUser();
- $resp = [
- 'team_power' => $user['team_power'],
- 'team_num' => $user['team_num'],
- 'direct_num' => $user['direct_num'],
- 'yesterday_profit' => $this->getYesterdayProfit($user['id']),
- ];
- $resp['list'] = (new UserModel())
- ->field('id,address,team_power,team_num,create_time')
- ->where('parent_id', $user['id'])
- ->order('id desc')
- ->select();
- foreach ($resp['list'] as $key => $item){
- //统计团队人数
- $resp['list'][$key]['user_power'] = (new OfflineRechargeRecordModel())
- ->where('user_id', $item['id'])
- ->where('status', OfflineRechargeRecordModel::StatusSuccess)
- ->sum('power');
- $resp['list'][$key]['address'] = substr($item['address'], 0, 4) . '****' . substr($item['address'], -4);
- unset($resp['list'][$key]['id']);
- }
- $this->success('', $resp);
- }
- /**
- * 获取用户昨日团队收益
- * @param int $uid 用户ID
- * @return array
- */
- private function getYesterdayProfit(int $uid): array
- {
- $yesterdayStart = Date::unixtime('day', -1); // 昨日0点0分0秒
- $yesterdayEnd = Date::unixtime() - 1; // 昨日23点59分59秒
- // 算力
- $sumPoser = (new LedgerPowerChangeModel())
- ->where('user_id', $uid)
- //->where('action', 'IN', $this->actionPower)
- ->where('create_time', ['>=', $yesterdayStart], ['<=', $yesterdayEnd], 'AND')
- ->where('change_amount', '>', 0)
- ->sum('change_amount');
- // USDT
- // $sumUsdt = (new LedgerUsdtChangeModel())
- // ->where('user_id', $uid)
- // ->where('action', 'IN', $this->actionUsdt)
- // ->where('create_time', ['>=', $yesterdayStart], ['<=', $yesterdayEnd], 'AND')
- // ->where('change_amount', '>', 0)
- // ->sum('change_amount');
- // SMH
- $sumSmh = (new LedgerSmhChangeModel())
- ->where('user_id', $uid)
- ->where('create_time', ['>=', $yesterdayStart], ['<=', $yesterdayEnd], 'AND')
- ->where('change_amount', '>', 0)
- ->sum('change_amount');
- //昨日团队业绩
- $yesterdayTeamPower = DB::table('team_rewards')
- ->where('user_id', $uid)
- ->where('date_time', date('Y-m-d', strtotime('-1 day')))
- ->value('team_power');
- // 转成字符串型
- return [
- 'power' => strval($sumPoser),
- //'usdt' => strval($sumUsdt),
- 'smh' => strval($sumSmh),
- 'team_power' => strval($yesterdayTeamPower) ? '' : 0,
- ];
- }
- /**
- * 团队收益列表
- * @return void
- */
- public function profitList()
- {
- $type = $this->request->post('query.type'); // 资产类型
- $model = new LedgerPowerChangeModel();
- $action = [];
- switch ($type) {
- case 1:
- $model = new LedgerPowerChangeModel();
- $action = $this->actionPower;
- break;
- case 2:
- $model = new LedgerUsdtChangeModel();
- $action = $this->actionUsdt;
- break;
- case 3:
- $model = new LedgerTokenChangeModel();
- $action = $this->actionToken;
- break;
- default:
- $this->error('资产类型错误');
- break;
- }
- $where = [
- 'user_id' => $this->auth->getTokenUserID(),
- 'action' => ['IN', $action],
- ];
- $paginator = $model->where($where)->order('id DESC')->paginate($this->pageSize);
- $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
- }
- }
|