RiddleRecord.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php namespace App\Models\Lottery;
  2. use Illuminate\Database\Eloquent\Factories\HasFactory;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Models\Traits\Lottery\RewardType;
  5. use App\Models\Traits\Lottery\RecordState;
  6. /**
  7. * 中奖记录模型
  8. *
  9. */
  10. class RiddleRecord extends Model
  11. {
  12. use HasFactory,RewardType,RecordState;
  13. // 与模型关联的表名
  14. protected $table = 'lottery_riddle_record';
  15. // 是否主动维护时间戳
  16. public $timestamps = false;
  17. // 定义时间戳字段名
  18. // const CREATED_AT = 'insert_time';
  19. // const UPDATED_AT = 'update_time';
  20. /**
  21. * 添加数据
  22. *
  23. */
  24. public function add($data)
  25. {
  26. // 时间
  27. $data['insert_time'] = time();
  28. $data['update_time'] = time();
  29. // 写入数据表
  30. $id = $this->query()->insertGetId($data);
  31. // 如果操作失败
  32. if( !$id ) return $id;
  33. // 返回结果
  34. return $id;
  35. }
  36. /**
  37. * 添加数据
  38. *
  39. */
  40. public function edit($id,$data)
  41. {
  42. // 更新时间
  43. $data['update_time'] = time();
  44. // 写入数据表
  45. $result = $this->query()->where(['id'=>$id])->update($data);
  46. // 如果操作失败
  47. if( !$result ) return $result;
  48. // 返回结果
  49. return $result;
  50. }
  51. }