Info.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 信息管理
  7. */
  8. namespace app\citys\controller;
  9. use app\citys\controller\Common;
  10. use app\citys\model\Citys;
  11. use app\citys\model\CitysReply;
  12. use think\facade\Request;
  13. use think\helper\Time;
  14. use util\Util;
  15. class Info extends Common{
  16. public function initialize(){
  17. parent::initialize();
  18. $this->assign('pathMaps',[['name'=>'信息管理','url'=>url("citys/info/index")]]);
  19. }
  20. /**
  21. * 列表
  22. */
  23. public function index(int $types = 0){
  24. $condition = [];
  25. $time = Request::param('time/d',0);
  26. $starttime = Request::param('starttime/s');
  27. $endtime = Request::param('endtime/s');
  28. if($time){
  29. switch ($time) {
  30. case 2:
  31. list($start, $end) = Time::yesterday();
  32. break;
  33. case 30:
  34. list($start, $end) = Time::month();
  35. break;
  36. case 60:
  37. list($start, $end) = Time::lastMonth();
  38. break;
  39. default:
  40. list($start, $end) = Time::today();
  41. break;
  42. }
  43. $condition[] = ['create_time','>=',$start];
  44. $condition[] = ['create_time','<=',$end];
  45. }else{
  46. if($starttime){
  47. $condition[] = ['create_time','>=',strtotime($starttime)];
  48. }
  49. if($endtime){
  50. $condition[] = ['create_time','<=',strtotime($endtime)];
  51. }
  52. }
  53. $view['top_num'] = citys::where($this->mini_program)->where($condition)->sum("is_top");
  54. $view['views_num'] = citys::where($this->mini_program)->where($condition)->sum("views");
  55. $view['lock_num'] = citys::where($this->mini_program)->where($condition)->where(['is_lock' => 1])->sum("is_lock");
  56. $condition[] = ['is_lock','=',$types];
  57. $lists = citys::where($this->mini_program)->where($condition)->order('is_top desc,sort desc,id desc')->paginate(20,false,['query' => ['types' => $types,'starttime' => $starttime,'endtime' => $endtime,'time'=>$time]]);
  58. $view['types'] = $types;
  59. foreach ($lists as $key => $value) {
  60. $lists[$key]['howday'] = Util::ftime($value['create_time']);
  61. }
  62. $view['lists'] = $lists;
  63. $view['time'] = $time;
  64. $view['starttime'] = $starttime;
  65. $view['endtime'] = $endtime;
  66. return view()->assign($view);
  67. }
  68. /**
  69. * 查看回复
  70. * @param integer $id 用户ID
  71. */
  72. public function reply(int $id){
  73. $info = citys::where($this->mini_program)->where(['id'=> $id])->find();
  74. if(empty($info)){
  75. return $this->error('没有内容');
  76. }
  77. $info['create_time'] = Util::ftime($info['create_time']);
  78. $view['info'] = $info;
  79. $view['reply'] = $info->comments()->order('id desc')->paginate(10,false,['query'=>['id' => $id]]);
  80. $view['fields'] = $info->fields;
  81. if($info->is_get){
  82. $view['tabs'] = [
  83. ['name' =>'信息内容','url' =>url('citys/index/reply',['id' => $id]),'action' => 1],
  84. ['name' =>'订单列表','url' =>url('citys/order/index',['infoid' => $id])],
  85. ];
  86. }
  87. return view()->assign($view);
  88. }
  89. //删除
  90. public function delete(int $id){
  91. $result = citys::where($this->mini_program)->where(['id' => $id])->delete();
  92. if($result){
  93. CitysReply::where($this->mini_program)->where(['info_id' => $id])->delete();
  94. return json(['code'=>200,'msg'=>'操作成功']);
  95. }else{
  96. return json(['code'=>403,'msg'=>'删除失败,请查看是否包含子链接']);
  97. }
  98. }
  99. /**
  100. * 锁定
  101. * @param integer $id 用户ID
  102. */
  103. public function islock(int $id){
  104. $result = citys::lock($id,$this->member_miniapp_id);
  105. if(!$result){
  106. return json(['code'=>0,'message'=>'操作失败']);
  107. }else{
  108. return json(['code'=>200,'message'=>'操作成功']);
  109. }
  110. }
  111. /**
  112. * 指定
  113. * @param integer $id 用户ID
  114. */
  115. public function isTop(int $id){
  116. $result = citys::Top($id);
  117. if(!$result){
  118. return json(['code'=>0,'message'=>'操作失败']);
  119. }else{
  120. return json(['code'=>200,'message'=>'操作成功']);
  121. }
  122. }
  123. //删除
  124. public function delReply(){
  125. $id = input('get.id/d');
  126. $result = CitysReply::where($this->mini_program)->where(['id' => $id])->delete();
  127. if($result){
  128. return json(['code'=>200,'msg'=>'操作成功']);
  129. }else{
  130. return json(['code'=>403,'msg'=>'删除失败']);
  131. }
  132. }
  133. /**
  134. * 锁定
  135. * @param integer $id 用户ID
  136. */
  137. public function islockReply(int $id){
  138. $result = CitysReply::lock($id);
  139. if(!$result){
  140. return json(['code'=>0,'message'=>'操作失败']);
  141. }else{
  142. return json(['code'=>200,'message'=>'操作成功']);
  143. }
  144. }
  145. }