UserClock.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class UserClock extends Model
  9. {
  10. //
  11. /**
  12. * 打卡列表
  13. * @return type
  14. */
  15. public function getClockList($post)
  16. {
  17. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  18. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  19. $where=[];
  20. // if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
  21. // $where[]=["status","=",(int)$post["status"]];
  22. // }
  23. if(!empty($post["uid"])&&$post["uid"]>0){
  24. $where[]=["uid","=",$post["uid"]];
  25. }
  26. if(!empty($post["to_uid"])&&$post["to_uid"]>0){
  27. $where[]=["to_uid","=",$post["to_uid"]];
  28. }
  29. if(!empty($post["contract_id"])&&$post["contract_id"]>0){
  30. $where[]=["contract_id","=",$post["contract_id"]];
  31. }
  32. $totalCount = $this->where($where)->count();
  33. $data=null;
  34. if($totalCount>0){
  35. $data = $this
  36. // ->field($field)
  37. ->where($where)
  38. ->order("create_time", "desc")
  39. ->page($post["page"], $post["pageSize"])
  40. ->select();
  41. if(!empty($data)){
  42. $data = $data->toArray();
  43. foreach ($data as $k => $v){
  44. $data[$k]["uid_nickname"] = (new User())->where("uid", $v["uid"])->value("nickname");
  45. $data[$k]["uid_avatar"] = (new User())->where("uid", $v["uid"])->value("avatar");
  46. $data[$k]["to_uid_nickname"] = (new User())->where("uid", $v["to_uid"])->value("nickname");
  47. $data[$k]["to_uid_avatar"] = (new User())->where("uid", $v["to_uid"])->value("avatar");
  48. }
  49. }
  50. }
  51. $data = empty($data)?[]:$data;
  52. return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
  53. }
  54. }