TaskLogRepository.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\TaskLog;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. use Prettus\Repository\Criteria\RequestCriteria;
  6. /**
  7. * Class MemberRepositoryEloquent.
  8. *
  9. * @package namespace App\Repositories;
  10. */
  11. class TaskLogRepository extends BaseRepository
  12. {
  13. /**
  14. * Specify Model class name
  15. *
  16. * @return string
  17. */
  18. public function model()
  19. {
  20. return TaskLog::class;
  21. }
  22. /**
  23. * Boot up the repository, pushing criteria
  24. */
  25. public function boot()
  26. {
  27. $this->pushCriteria(app(RequestCriteria::class));
  28. }
  29. public function getTaskLog($uid, $task, $utype)
  30. {
  31. return $this->model->where(['uid'=>$uid,'task_id'=>$task->id,'utype'=>$utype])->first();
  32. }
  33. public function getTaskLogCount($uid, $task_id, $utype)
  34. {
  35. return $this->model->where(['uid'=>$uid,'task_id'=>$task_id,'utype'=>$utype])->where('created_at', '>=', date('Y-m-d 00:00:00'))->where('created_at', '<=', date('Y-m-d 23:59:59'))->count();
  36. }
  37. public function addNew($data)
  38. {
  39. return $this->model->create($data);
  40. }
  41. /**
  42. * 获取今日的积分。
  43. */
  44. public function getTodayPoints($uid, $utype)
  45. {
  46. return $this->model->where(['uid'=>$uid,'utype'=>$utype])->where('created_at', '>=', date('Y-m-d 00:00:00'))->where('created_at', '<=', date('Y-m-d 23:59:59'))->sum('points');
  47. }
  48. /**
  49. * 获取单次的积分。
  50. */
  51. public function getSinglePoints($uid, $utype)
  52. {
  53. return $this->model->where(['uid'=>$uid,'utype'=>$utype,'once'=>1])->sum('points');
  54. }
  55. /**
  56. * 获取当天日常的积分。
  57. */
  58. public function getDayPoints($uid, $utype)
  59. {
  60. return $this->model->where(['uid'=>$uid,'utype'=>$utype,'once'=>0])->where('created_at', '>=', date('Y-m-d 00:00:00'))->where('created_at', '<=', date('Y-m-d 23:59:59'))->sum('points');
  61. }
  62. public function getTlog($uid, $task_id, $utype)
  63. {
  64. return $this->model->where(['uid'=>$uid,'task_id'=>$task_id,'utype'=>$utype])->first();
  65. }
  66. }