| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\common\model;
- use app\common\library\CoinRate;
- use think\Model;
- /**
- * 交易
- */
- class Trade Extends Model
- {
- // 表名
- protected $name = 'trade';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- // 追加属性
- protected $append = [
- ];
- /**
- * 奖金池
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getAwardTotal()
- {
- $config = Config::getConfigByGroup('trade');
- $awardBase = isset($config['award_base'])? floatval($config['award_base']['value']) : 0;
- // 计算增加比例
- $addAward = Award::getAddAward();
- $award = round($addAward + $awardBase, 2);
- $counts = [
- 'total_usdt'=> $award,
- 'award_add'=> $addAward,
- 'award_base'=> $awardBase,
- ];
- return $counts;
- }
- /**
- * 释放统计
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getReleaseTotal($userId)
- {
- //$total = Trade::where(['status'=> 4,'on_resale'=>1,'relevant_userid'=> $userId])->column('id');
- $totalUsdt = Trade::where(['status'=> 4,'on_resale'=>1,'relevant_userid'=> $userId])->sum('release_total_usdt');
- $releaseTotal = Trade::where(['status'=> 4,'on_resale'=>1,'relevant_userid'=> $userId])->sum('release_usdt');
- //$totalUsdt = round(CoinRate::transfer($total), 2);
- $counts = [
- 'total_usdt'=> $totalUsdt,
- 'release_usdt'=> round($releaseTotal, 2),
- 'surplus_usdt'=> round(max(0, $totalUsdt-$releaseTotal), 2),
- ];
- return $counts;
- }
- /**
- * 获取用户释放加速值
- * @param $userId
- * @return array|false
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getSpeedTotalByUser($userId)
- {
- $uids = User::getLowerIds($userId);
- if(empty($uids)){
- return false;
- }
- // 下线销售额,包括自己
- $total = Trade::where(['status'=> 4,'on_resale'=>2])->whereIn('userid', $uids)->sum('pre_price');
- // 加速参数
- $config = Config::getConfigByGroup('trade');
- $speedRate = isset($config['speed_rate'])? floatval($config['speed_rate']['value']) : 0;
- $speedTotal = round($total * $speedRate/100, 2);
- $counts = [
- 'total'=> $total,
- 'speed_rate'=> $speedRate,
- 'speed_usdt'=> CoinRate::transfer($speedTotal),
- 'speed_total'=> $speedTotal,
- 'rate'=> $speedRate,
- ];
- return $counts;
- }
- }
|