Site.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\common\controller\Backend;
  5. use lemo\helper\TreeHelper;
  6. use think\facade\Cache;
  7. use think\facade\Db;
  8. use think\facade\Request;
  9. use think\facade\View;
  10. use app\common\model\Laboratory;
  11. class Site extends Backend
  12. {
  13. // todo 场地管理
  14. // 场地列表
  15. public function index()
  16. {
  17. if (Request::isPost()){
  18. $page=input("page")?:1;
  19. $limit=input("limit")?:10;
  20. $name=input("name", '', 'trim');
  21. $list=Db::name("laboratory")->order("id desc")
  22. ->where("name","like","%".$name."%")
  23. ->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item){
  24. $subject_id="";
  25. if ($item["subject_id"]){
  26. // $where["id"]=["in",$item];
  27. $resul=Db::name("subject")->whereIn("id",$item["subject_id"])->column("name");
  28. foreach ($resul as $v){
  29. if ($subject_id){
  30. $subject_id.="/".$v;
  31. }else{
  32. $subject_id=$v;
  33. }
  34. }
  35. }
  36. $item["subject_id"]=$subject_id;
  37. return $item;
  38. })
  39. ->toArray();
  40. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  41. }
  42. return View::fetch();
  43. }
  44. public function text()
  45. {
  46. $name=input("name");
  47. // $list=Db::name("laboratory")->alias("la")->order("id desc")
  48. // ->leftJoin("subject su","su.id= in subject_id")
  49. //// ->where("la.name","like","%".$name."%")
  50. // ->paginate(['list_rows' => 10, 'page' => 1])
  51. // ->filed("la.* ,su.name")
  52. //// ->each(function ($item){
  53. //// $subject_id="";
  54. //// if ($item["subject_id"]){
  55. ////// $where["id"]=["in",$item];
  56. //// $resul=Db::name("subject")->whereIn("id",$item["subject_id"])->column("name");
  57. //// foreach ($resul as $v){
  58. //// if ($subject_id){
  59. //// $subject_id.="/".$v;
  60. //// }else{
  61. //// $subject_id=$v;
  62. //// }
  63. //// }
  64. //// }
  65. //// $item["subject_id"]=$subject_id;
  66. //// return $item;
  67. //// })
  68. // ->toArray();
  69. $list=Laboratory::with("subject")->where("name","like","%".$name."%")->order("id desc")->paginate(['list_rows' => 10, 'page' => 1]);
  70. // $sub=$list->subject;
  71. json_result(1,"",$list);
  72. }
  73. // 修改状态
  74. public function updata_status()
  75. {
  76. $id=input("id");
  77. $where["id"]=$id;
  78. $result=Db::name("laboratory")->where($where)->find();
  79. if ($result["status"]==1){
  80. $update["status"]=0;
  81. }else{
  82. $update["status"]=1;
  83. }
  84. $res=Db::name("laboratory")->where($where)->update($update);
  85. if ($res){
  86. json_result(1,"修改成功");
  87. }
  88. json_result(2,"修改失败");
  89. }
  90. // 科目
  91. public function sitetree()
  92. {
  93. // $list = Cache::get('SiteTree');
  94. $id=input("id");
  95. // if (!$list){
  96. $subject=Db::name("subject")->field("id,major_id,name")->order("major_id asc")->cache(3600)->select()->toArray();
  97. foreach ($subject as $k=>$v){
  98. $subject[$k]["title"]=$v["name"];
  99. $subject[$k]["pid"]=$v["major_id"];
  100. }
  101. $where["id"]=$id;
  102. $laboratory=Db::name("laboratory")->where($where)->value("subject_id");
  103. $list=TreeHelper::authChecked($subject,0,$laboratory);
  104. // Cache::set('SiteTree',$list,3600);
  105. // }
  106. $idList=Db::name("subject")->column("id");
  107. sort($idList);
  108. $view = [
  109. 'list' => $list,
  110. 'idList' => $idList,
  111. 'group_id' => $id,
  112. ];
  113. View::assign($view);
  114. return View::fetch();
  115. }
  116. public function urlk()
  117. {
  118. $list = Cache::get('SiteTree');
  119. json_result(1,"",$list);
  120. }
  121. // 修改权限
  122. public function teacher()
  123. {
  124. $rules = Request::post('rules');
  125. if (empty($rules)) {
  126. json_result(2,"请选择");
  127. }
  128. $data = Request::post();
  129. $rules = TreeHelper::authNormal($rules);
  130. $rls = '';
  131. foreach ($rules as $k=>$v){
  132. if ($rls){
  133. $rls.=",".$v['id'];
  134. }else{
  135. $rls.=$v['id'];
  136. }
  137. }
  138. $where['id'] = $data['group_id'];
  139. Db::name("laboratory")->where($where)->update(["subject_id"=>$rls]);
  140. json_result(1,"操作成功");
  141. }
  142. }