| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace app\common\model\user;
- use app\common\model\BaseModel;
- use think\Exception;
- class AwardLakeLog extends BaseModel
- {
- public static function tablePk(): ?string
- {
- return 'id';
- }
- public static function tableName(): string
- {
- return 'award_integral_price';
- }
- public static function income($lake_id, $type, $num, $link_id = 0, $mark = '')
- {
- $lake = AwardLake::find($lake_id);
- if (!$lake) throw new Exception('invalid lake');
- $pm = 1;
- $add_time = time();
- $res = self::create(compact('lake_id', 'type', 'num', 'link_id', 'mark', 'pm', 'add_time'));
- $res = $res && AwardLake::where('id', $lake_id)->inc('num', $num)->update();
- return $res;
- }
- public static function expend($lake_id, $type, $num, $link_id = 0, $mark = '')
- {
- $lake = AwardLake::find($lake_id);
- if (!$lake) throw new Exception('invalid lake');
- if ($lake->num < $num) {
- throw new Exception('lake num not enough');
- }
- $pm = 0;
- $add_time = time();
- $res = self::create(compact('lake_id', 'type', 'num', 'link_id', 'mark', 'pm', 'add_time'));
- $res = $res && AwardLake::where('id', $lake_id)->dec('num', $num)->update();
- return $res;
- }
- }
|