AwardLakeLog.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\common\model\user;
  3. use app\common\model\BaseModel;
  4. use think\Exception;
  5. class AwardLakeLog extends BaseModel
  6. {
  7. public static function tablePk(): ?string
  8. {
  9. return 'id';
  10. }
  11. public static function tableName(): string
  12. {
  13. return 'award_integral_price';
  14. }
  15. public static function income($lake_id, $type, $num, $link_id = 0, $mark = '')
  16. {
  17. $lake = AwardLake::find($lake_id);
  18. if (!$lake) throw new Exception('invalid lake');
  19. $pm = 1;
  20. $add_time = time();
  21. $res = self::create(compact('lake_id', 'type', 'num', 'link_id', 'mark', 'pm', 'add_time'));
  22. $res = $res && AwardLake::where('id', $lake_id)->inc('num', $num)->update();
  23. return $res;
  24. }
  25. public static function expend($lake_id, $type, $num, $link_id = 0, $mark = '')
  26. {
  27. $lake = AwardLake::find($lake_id);
  28. if (!$lake) throw new Exception('invalid lake');
  29. if ($lake->num < $num) {
  30. throw new Exception('lake num not enough');
  31. }
  32. $pm = 0;
  33. $add_time = time();
  34. $res = self::create(compact('lake_id', 'type', 'num', 'link_id', 'mark', 'pm', 'add_time'));
  35. $res = $res && AwardLake::where('id', $lake_id)->dec('num', $num)->update();
  36. return $res;
  37. }
  38. }