SkillTime.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\api\model\service;
  3. use think\Model;
  4. class SkillTime extends Model
  5. {
  6. // 表名
  7. protected $name = 'service_skill_time';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. /**
  14. * 获取服务人员最近时间
  15. * @param $id
  16. * @return float|mixed|string
  17. */
  18. public static function getSkillTime($id)
  19. {
  20. $time = self::where(['skill_id'=>$id,'state'=>0,'starttime'=>['>=',time()+1800]])
  21. ->order('starttime asc')
  22. ->value('starttime');
  23. return $time;
  24. }
  25. public static function getSettleTime($id)
  26. {
  27. $time = self::where(['skill_id'=>$id,'state'=>0,'starttime'=>['>=',time()+1800]])
  28. ->order('starttime asc')
  29. ->field('id,starttime')
  30. ->find();
  31. return $time;
  32. }
  33. /**
  34. * 服务者更新时间状态
  35. * @param $ids
  36. * @param $skill_id
  37. * @param $type
  38. * @return bool
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. */
  43. public static function updateTime($ids,$skill_id,$type='busy')
  44. {
  45. $idArr = explode(',',$ids);
  46. if(!$idArr)
  47. {
  48. return false;
  49. }
  50. foreach ($idArr as $val){
  51. $info = self::where(['skill_id'=>$skill_id,'id'=>$val])->field('id,state')->find();
  52. if($type == 'busy' && $info['state'] != 0){
  53. continue;
  54. }elseif($type == 'recover' && in_array($info['state'],[0,1])){
  55. continue;
  56. }
  57. $state = $type == 'busy'?2:0;
  58. self::where(['id'=>$val])->update(['state'=>$state]);
  59. }
  60. return true;
  61. }
  62. /**
  63. * 更新服务者时间状态
  64. * @param $params
  65. * @param $state
  66. * @return SkillTime
  67. */
  68. public static function updateSkillTime($params,$state)
  69. {
  70. return self::where(['skill_id'=>$params['skill_id'],'starttime'=>['between',[$params['starttime'],$params['actendtime']]]])->update(['state'=>$state
  71. ]);
  72. }
  73. }