CustomClockin.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php namespace App\Models\Score;
  2. use Illuminate\Database\Eloquent\Factories\HasFactory;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Facades\Servers\Redis\Redis;
  5. use App\Models\Score\ClockinActive;
  6. use App\Models\CustomScore;
  7. use App\Models\CustomCoupon;
  8. use App\Models\CustomClockinRecord;
  9. use Illuminate\Support\Carbon;
  10. use Illuminate\Support\Facades\DB;
  11. /**
  12. * 用户连续打卡记录
  13. *
  14. */
  15. class CustomClockin extends Model
  16. {
  17. use HasFactory;
  18. // 与模型关联的表名
  19. protected $table = 'custom_clockin';
  20. // 是否主动维护时间戳
  21. public $timestamps = false;
  22. /**
  23. * 添加数据
  24. *
  25. */
  26. public function add($data)
  27. {
  28. // 时间
  29. $data['insert_time'] = time();
  30. $data['update_time'] = time();
  31. // 写入数据表
  32. $id = $this->query()->insertGetId($data);
  33. // 如果操作失败
  34. if( !$id ) return ['error'=>'新增失败'];
  35. // 返回结果
  36. return $id;
  37. }
  38. /**
  39. * 添加数据
  40. *
  41. */
  42. public function edit($id,$data)
  43. {
  44. // 更新时间
  45. $data['update_time'] = time();
  46. // 写入数据表
  47. $result = $this->query()->where(['id'=>$id])->update($data);
  48. // 如果操作失败
  49. if( !$result ) return ['error'=>'修改失败'];
  50. // 返回结果
  51. return $result;
  52. }
  53. }