Index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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\allwin\controller\info;
  9. use app\allwin\controller\Common;
  10. use app\allwin\model\AllwinInfo;
  11. use app\allwin\model\AllwinInfoReply;
  12. use think\facade\Request;
  13. use think\helper\Time;
  14. use util\Util;
  15. class index extends Common{
  16. public function initialize(){
  17. parent::initialize();
  18. $this->assign('pathMaps',[['name'=>'信息管理','url'=>url("info.index/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'] = AllwinInfo::where($this->mini_program)->where($condition)->sum("is_top");
  54. $view['views_num'] = AllwinInfo::where($this->mini_program)->where($condition)->sum("views");
  55. $view['lock_num'] = AllwinInfo::where($this->mini_program)->where($condition)->where(['is_lock' => 1])->sum("is_lock");
  56. $condition[] = ['is_lock','=',$types];
  57. $lists = AllwinInfo::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. $lists[$key]['images'] = json_decode($value['images'],true);
  62. }
  63. $view['lists'] = $lists;
  64. $view['time'] = $time;
  65. $view['starttime'] = $starttime;
  66. $view['endtime'] = $endtime;
  67. return view()->assign($view);
  68. }
  69. /**
  70. * 查看回复
  71. * @param integer $id 用户ID
  72. */
  73. public function reply(int $id){
  74. $info = AllwinInfo::where($this->mini_program)->where(['id'=> $id])->find();
  75. if(empty($info)){
  76. return $this->error('没有内容');
  77. }
  78. $info['images'] = empty($info['images']) ? [] :json_decode($info['images']);
  79. $info['create_time'] = Util::ftime($info['create_time']);
  80. $view['info'] = $info;
  81. $view['reply'] = $info->comments()->order('id desc')->paginate(10,false,['query'=>['id' => $id]]);
  82. $view['fields'] = json_decode($info->fields,true);
  83. if($info->is_get){
  84. $view['tabs'] = [
  85. ['name' =>'信息内容','url' =>url('info.index/reply',['id' => $id]),'action' => 1],
  86. ['name' =>'订单列表','url' =>url('info.order/index',['infoid' => $id])],
  87. ];
  88. }
  89. return view()->assign($view);
  90. }
  91. //删除
  92. public function delete(){
  93. $id = input('get.id/d');
  94. $result = AllwinInfo::where($this->mini_program)->where(['id' => $id])->delete();
  95. if($result){
  96. AllwinInfoReply::where($this->mini_program)->where(['info_id' => $id])->delete();
  97. return json(['code'=>200,'msg'=>'操作成功']);
  98. }else{
  99. return json(['code'=>403,'msg'=>'删除失败,请查看是否包含子链接']);
  100. }
  101. }
  102. /**
  103. * 锁定
  104. * @param integer $id 用户ID
  105. */
  106. public function islock(int $id){
  107. $result = AllwinInfo::lock($id,$this->member_miniapp_id);
  108. if(!$result){
  109. return json(['code'=>0,'message'=>'操作失败']);
  110. }else{
  111. return json(['code'=>200,'message'=>'操作成功']);
  112. }
  113. }
  114. /**
  115. * 指定
  116. * @param integer $id 用户ID
  117. */
  118. public function isTop(int $id){
  119. $result = AllwinInfo::Top($id);
  120. if(!$result){
  121. return json(['code'=>0,'message'=>'操作失败']);
  122. }else{
  123. return json(['code'=>200,'message'=>'操作成功']);
  124. }
  125. }
  126. //删除
  127. public function delReply(){
  128. $id = input('get.id/d');
  129. $result = AllwinInfoReply::where($this->mini_program)->where(['id' => $id])->delete();
  130. if($result){
  131. return json(['code'=>200,'msg'=>'操作成功']);
  132. }else{
  133. return json(['code'=>403,'msg'=>'删除失败']);
  134. }
  135. }
  136. /**
  137. * 锁定
  138. * @param integer $id 用户ID
  139. */
  140. public function islockReply(int $id){
  141. $result = AllwinInfoReply::lock($id);
  142. if(!$result){
  143. return json(['code'=>0,'message'=>'操作失败']);
  144. }else{
  145. return json(['code'=>200,'message'=>'操作成功']);
  146. }
  147. }
  148. }