Award.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\CoinRate;
  4. use think\Model;
  5. use function GuzzleHttp\Psr7\str;
  6. /**
  7. * 释放日志
  8. */
  9. class Award Extends Model
  10. {
  11. // 表名
  12. protected $name = 'award';
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'create_time';
  17. protected $updateTime = 'update_time';
  18. // 追加属性
  19. protected $append = [
  20. ];
  21. /**
  22. * 获取配置值
  23. * @param $code
  24. * @return bool|\PDOStatement|string|\think\Collection
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. * @throws \think\exception\DbException
  28. */
  29. public static function getValueByCode($code)
  30. {
  31. return self::where(['code'=> $code])
  32. ->find('id,title,code,value,last_time');
  33. }
  34. /**
  35. * 累计增加奖池金额
  36. * @return float|int|mixed
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @throws \think\exception\DbException
  40. */
  41. public static function getAddAward(){
  42. $award = self::where(['code'=> 'award_add_total'])
  43. ->field('id,title,code,value,last_time')
  44. ->find();
  45. if(empty($award)){
  46. $data = ['title'=>'累计增加奖池金额/USDT','code'=>'award_add_total','value'=>0,'last_time'=>time(),'update_time'=>time(),'create_time'=>time()];
  47. self::insertGetId($data);
  48. return 0;
  49. }
  50. // 今日未增加过则自动计算增加
  51. $lastTIme = isset($award['last_time'])? $award['last_time'] : '';
  52. $awardAddTotal = isset($award['value'])? $award['value'] : 0;
  53. if(empty($lastTIme) || strtotime($lastTIme) < strtotime(date('Y-m-d'))){
  54. // 总营业额业绩
  55. $total = Trade::where(['status'=> 3,'on_resale'=>2])
  56. ->where('pay_time','>=',strtotime(date('Y-m-d')) - 86400)
  57. ->where('pay_time','<', strtotime(date('Y-m-d')))
  58. ->sum('endnums');
  59. $config = Config::getConfigByGroup('trade');
  60. $awardRate = isset($config['award_rate'])? floatval($config['award_rate']['value']) : 0;
  61. $addAward = round($total*$awardRate/100, 2);
  62. $usdt = CoinRate::transfer($addAward);
  63. $award->value += $usdt;
  64. $award->last_time = date('Y-m-d H:i:s');
  65. $award->remark = '累计增加奖池,营业额:'.$total.',增加金额:'.$addAward.'/'.$usdt.'usdt,时间:'.date('Y-m-d H:i:s');
  66. $award->save();
  67. if($award->save()){
  68. $awardAddTotal += $usdt;
  69. }
  70. }
  71. return $awardAddTotal;
  72. }
  73. }