TypeAudit.php 4.4 KB

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