Circle.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\system\controller\v1;
  4. use app\BaseController;
  5. use app\model\api\AdverPage;
  6. use app\model\api\Advert;
  7. use app\model\api\User as UserModel;
  8. use app\model\api\GoodsCate;
  9. use app\model\api\UserCircle;
  10. use app\Request;
  11. use library\services\UtilService;
  12. use think\facade\Db;
  13. // +----------------------------------------------------------------------
  14. // | [ WE CAN DO IT MORE SIMPLE ]
  15. // +----------------------------------------------------------------------
  16. // | Copyright (c) 2018-2020 rights reserved.
  17. // +----------------------------------------------------------------------
  18. // | [ 圈子管理 ]
  19. // +----------------------------------------------------------------------
  20. // | Date: 2020-09-06 21:53
  21. // +----------------------------------------------------------------------
  22. class Circle extends BaseController{
  23. /**
  24. * 动态列表
  25. * @param Request $request
  26. * @return type
  27. */
  28. public function list(Request $request) {
  29. $pageSize = 50;
  30. $post = UtilService::getMore([
  31. ['page',1],
  32. // ['title',''],
  33. ['nickname',''],
  34. ['status',''],
  35. ['uid',''],
  36. ['mobile',''],
  37. ['uip',''],
  38. ['time',[]],
  39. ],$request);
  40. $where = [];
  41. //创建时间
  42. $startTime="";
  43. $endTime="";
  44. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  45. $startTime = strtotime($post['time'][0]);
  46. $endTime = strtotime($post['time'][1]);
  47. $where[]=["c.time","between","{$startTime},{$endTime}"];
  48. }
  49. //用户
  50. if(!empty($post['uid'])){
  51. $where[]=["c.uid","=",$post['uid']];
  52. }else if (!empty($post['uip'])) {
  53. $m = Db::name("user")->where("uip",$post['uip'])->find();
  54. if(!empty($m)) {
  55. $where[]=["c.uid","=",$m['uid']];
  56. }
  57. }else if (!empty($post['mobile'])) {
  58. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  59. if(!empty($m)) {
  60. $where[]=["c.uid","=",$m['uid']];
  61. }
  62. }else if(!empty($post['nickname'])){
  63. $m = Db::name("user")->where("nickname",$post['nickname'])->find();
  64. if(!empty($m)) {
  65. $where[]=["c.uid","=",$m['uid']];
  66. }
  67. }
  68. // if (!empty($post["title"])){
  69. // $where[]=["c.title","like","%{$post['title']}%"];
  70. // }
  71. $where2 = $where;
  72. $where2[]=["c.status","=",0];//待审核
  73. if(in_array((string)$post["status"],['0','1','-1'])){
  74. $where[]=["c.status","=",(int)$post["status"]];
  75. }
  76. $data = (new UserCircle)
  77. ->field("c.*,u.nickname,g.imgs as pro_imgs,g.title as pro_title")
  78. ->alias("c")
  79. ->where($where)
  80. ->leftJoin("user u", "u.uid = c.uid")
  81. ->leftJoin("goods g", "g.id = c.pro_id")
  82. ->page((int)$post["page"], (int)$pageSize)
  83. ->order("c.id","desc")
  84. ->select()
  85. ->toArray();
  86. $pageCount = (new UserCircle)->alias("c")->where($where)->count();
  87. $waitCount = (new UserCircle)->alias("c")->where($where2)->count();
  88. $data = empty($data)?[]:$data;
  89. foreach($data as $k=>$v){
  90. $data[$k]["imgs"] = empty($v["imgs"])?[]:explode(",",$v["imgs"]);
  91. $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
  92. $data[$k]["pro_img"] = empty($v["pro_imgs"]) ? "" : explode(",", $v["pro_imgs"])[0];
  93. }
  94. return app('json')->success([
  95. 'list' => $data,
  96. 'pageCount' => $pageCount,
  97. 'pageSize' => $pageSize,
  98. 'page' => $post["page"],
  99. 'waitCount' => $waitCount,
  100. ]);
  101. }
  102. /**
  103. * 审核动态
  104. * @param Request $request
  105. */
  106. public function editStatus(Request $request) {
  107. [$id,$status] = UtilService::getMore([
  108. ['id',0,'empty','参数错误'],
  109. ['status','','empty','参数错误']
  110. ],$request,true);
  111. $data = (new UserCircle)->where("id",$id)->find();
  112. if(empty($data)){
  113. return app('json')->fail("数据不存在");
  114. }
  115. //禁用
  116. if($status==-1){
  117. (new UserCircle)->where("id",$id)->update(["status"=>-1]);
  118. }
  119. //删除
  120. if($status==-10){
  121. (new UserCircle)->where("id",$id)->delete();
  122. }
  123. //发布
  124. if($status==1){
  125. (new UserCircle)->where("id",$id)->update(["status"=>1]);
  126. }
  127. return app('json')->success("操作成功");
  128. }
  129. }