TypeAudit.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class TypeAudit extends Model
  9. {
  10. /**
  11. * 获取列表
  12. * @param type $post
  13. * @param type $is_admin
  14. */
  15. public function getList($post,$is_admin=0){
  16. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  17. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  18. $where=[];
  19. if(is_numeric($post['status'])) {
  20. $where[]=["au.status","=",(int)$post['status']];
  21. }
  22. if(is_numeric($post['uid']) && $post['uid']>0) {
  23. $where[]=["au.uid","=",(int)$post['uid']];
  24. }else if(is_mobile($post['user_mobile'])){
  25. $udata = (new UserModel)->where("mobile",$post['user_mobile'])->find();
  26. if(!empty($udata)){
  27. $where[]=["au.uid","=",(int)$udata['uid']];
  28. }
  29. }
  30. // if(is_mobile($post['mobile'])) {
  31. // $where[]=["au.mobile","=",$post['mobile']];
  32. // }
  33. $startTime = "";
  34. $endTime = "";
  35. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  36. $startTime = strtotime($post['time'][0]);
  37. $endTime = strtotime($post['time'][1]);
  38. $where[]=["au.time","between","{$startTime},{$endTime}"];
  39. }
  40. // if(!empty($post['keyword'])){
  41. // $where[]=["au.name","=",$post['keyword']];
  42. // }
  43. $pageCount = $this->alias("au")->where($where)->count();
  44. $data = null;
  45. if($pageCount>0){
  46. $userField = $is_admin==1 ? ",u.mobile as user_mobile,u.nickname as user_nickname,u.avatar as user_avatar,a.name as admin_name" : "";
  47. $data = $this
  48. ->alias("au")
  49. ->field("au.*{$userField}")
  50. ->leftJoin("user u" , "u.uid = au.uid")//用户信息
  51. ->leftJoin("admin a" , "a.id = au.admin_id")//管理员
  52. ->where($where)
  53. ->order("au.id","desc")
  54. ->page((int)$post["page"], $post["pageSize"])
  55. ->select()
  56. ->toArray();
  57. }
  58. $data = empty($data) ? [] : $data;
  59. $serviceTypeModel = new ServiceTypeModel();
  60. foreach($data as $k=>$v){
  61. $data[$k]["time"] = date("Y-m-d H:i:s",$data[$k]["time"]);//添加时间
  62. $data[$k]["service_audit_imgs"] = getImageAr($data[$k]["service_audit_imgs"]);//认证图片
  63. $data[$k]["admin_time"] = empty($data[$k]["admin_time"])?"":date("Y-m-d H:i:s",$data[$k]["admin_time"]);
  64. }
  65. return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$pageCount];
  66. }
  67. /**
  68. *
  69. * @param type $id
  70. * @param type $type
  71. */
  72. public function getItem($post,$is_admin=0){
  73. if(empty($post)){
  74. return [];
  75. }
  76. $where=[];
  77. if(isset($post["status"]) && in_array((string)$post["status"], ["0","1","-1"])){
  78. $where[]=["au.status","=",(int)$post["status"]];
  79. }
  80. if(!empty($post["id"])){
  81. $where[]=["au.id","=",$post["id"]];
  82. }
  83. if(!empty($post["uid"])){
  84. $where[]=["au.uid","=",$post["uid"]];
  85. }
  86. //后台
  87. $userField = $is_admin==1 ? ",u.mobile as user_mobile,u.nickname as user_nickname,u.avatar as user_avatar,a.name as admin_name" : "";
  88. $data = $this
  89. ->alias("au")
  90. ->field("au.*{$userField}")
  91. ->leftJoin("user u" ,"u.uid = au.uid")//用户信息
  92. ->leftJoin("admin a" , "a.id = au.admin_id")//管理员
  93. ->where($where)
  94. ->order("au.id","desc")
  95. ->find();
  96. if(empty($data)){
  97. return [];
  98. }
  99. $data = $data->toArray();
  100. $data["time"] = date("Y-m-d H:i:s",$data["time"]);//添加时间
  101. $data["service_audit_imgs"] = getImageAr($data["service_audit_imgs"]);//我的证书
  102. if($is_admin==0){
  103. unset($data["admin_id"]);
  104. unset($data["admin_mono"]);
  105. unset($data["admin_time"]);
  106. unset($data["uid"]);
  107. }else{
  108. $data["admin_time"] = empty($data["admin_time"])?"":date("Y-m-d H:i:s",$data["admin_time"]);
  109. }
  110. return $data;
  111. }
  112. }