LalaRatio.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\models\lala;
  3. use app\models\system\SystemMoney;
  4. use app\models\user\User;
  5. use app\models\user\UserMoney;
  6. use Exception;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. use crmeb\traits\ModelTrait;
  11. use crmeb\basic\BaseModel;
  12. /**
  13. * TODO 文章Model
  14. * Class Article
  15. * @package app\models\article
  16. */
  17. class LalaRatio extends BaseModel
  18. {
  19. /**
  20. * 数据表主键
  21. * @var string
  22. */
  23. protected $pk = 'id';
  24. /**
  25. * 模型名称
  26. * @var string
  27. */
  28. protected $name = 'lala_ratio';
  29. use ModelTrait;
  30. public static function initRatio($date)
  31. {
  32. $ratio_value = 0;
  33. $date = $date ?: date('Y-m-d');
  34. $ratio = self::where('date', $date)->find();
  35. if (!$ratio && $date == date('Y-m-d')) {
  36. $r = self::order('id', 'desc')->value('ratio');
  37. $r = $r - 3;
  38. $ratio = self::create(['date' => $date, 'ratio' => ($r >= 0 ? $r : 0)]);
  39. }
  40. return $ratio->ratio ?? $ratio_value;
  41. }
  42. }