Work.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\api\model\massager;
  3. use app\api\model\BaseModel;
  4. class Work extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'massager_work';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. function getLastRecord($m_id)
  14. {
  15. return $this->where("massager_id", $m_id)
  16. ->order("updatetime", "desc")
  17. ->find();
  18. }
  19. function sumByNowMonth($m_id, $y = null, $m = null)
  20. {
  21. $ym = ym($y, $m);
  22. return $this->where("massager_id", $m_id)
  23. ->where("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m') = '{$ym}'")
  24. ->sum("duration");
  25. }
  26. function sumDurationByMassager($m_id)
  27. {
  28. return $this->where("massager_id", $m_id)
  29. ->where("duration", ">", 0)
  30. ->sum("duration");
  31. }
  32. function fetchByMassager($m_id, $page, $size)
  33. {
  34. return $this->where("massager_id", $m_id)
  35. ->where("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')")
  36. ->order("updatetime", "desc")
  37. ->page($size)
  38. ->paginate($size);
  39. }
  40. }