| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\common\model;
- use app\common\library\CoinRate;
- use think\Model;
- use function GuzzleHttp\Psr7\str;
- /**
- * 释放日志
- */
- class Award Extends Model
- {
- // 表名
- protected $name = 'award';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- // 追加属性
- protected $append = [
- ];
- /**
- * 获取配置值
- * @param $code
- * @return bool|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getValueByCode($code)
- {
- return self::where(['code'=> $code])
- ->find('id,title,code,value,last_time');
- }
- /**
- * 累计增加奖池金额
- * @return float|int|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getAddAward(){
- $award = self::where(['code'=> 'award_add_total'])
- ->field('id,title,code,value,last_time')
- ->find();
- if(empty($award)){
- $data = ['title'=>'累计增加奖池金额/USDT','code'=>'award_add_total','value'=>0,'last_time'=>time(),'update_time'=>time(),'create_time'=>time()];
- self::insertGetId($data);
- return 0;
- }
- // 今日未增加过则自动计算增加
- $lastTIme = isset($award['last_time'])? $award['last_time'] : '';
- $awardAddTotal = isset($award['value'])? $award['value'] : 0;
- if(empty($lastTIme) || strtotime($lastTIme) < strtotime(date('Y-m-d'))){
- // 总营业额业绩
- $total = Trade::where(['status'=> 3,'on_resale'=>2])
- ->where('pay_time','>=',strtotime(date('Y-m-d')) - 86400)
- ->where('pay_time','<', strtotime(date('Y-m-d')))
- ->sum('endnums');
-
- $config = Config::getConfigByGroup('trade');
- $awardRate = isset($config['award_rate'])? floatval($config['award_rate']['value']) : 0;
- $addAward = round($total*$awardRate/100, 2);
- $usdt = CoinRate::transfer($addAward);
- $award->value += $usdt;
- $award->last_time = date('Y-m-d H:i:s');
- $award->remark = '累计增加奖池,营业额:'.$total.',增加金额:'.$addAward.'/'.$usdt.'usdt,时间:'.date('Y-m-d H:i:s');
- $award->save();
- if($award->save()){
- $awardAddTotal += $usdt;
- }
- }
- return $awardAddTotal;
- }
- }
|