Information.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * User: Qinii
  4. * Date: 2020-10-12
  5. * Time: 09:41
  6. */
  7. namespace app\controller\admin\information;
  8. use think\App;
  9. use app\common\repositories\information\InformationRepository as repository;
  10. use app\validate\api\InformationValidate as validate;
  11. use crmeb\basic\BaseController;
  12. class Information extends BaseController
  13. {
  14. /**
  15. * @var repository
  16. */
  17. protected $repository;
  18. /**
  19. * StoreBrand constructor.
  20. * @param App $app
  21. * @param repository $repository
  22. */
  23. public function __construct(App $app, repository $repository)
  24. {
  25. parent::__construct($app);
  26. $this->repository = $repository;
  27. }
  28. /**
  29. *发布资讯
  30. *@title 标题
  31. *@content 内容
  32. *@images 图片
  33. *@uid 用户id
  34. */
  35. public function postinfo()
  36. {
  37. $data = $this->request->params(['title', 'content','images']);
  38. $data['uid'] = $this->request->uid();
  39. $res=$this->repository->postinfo($data);
  40. if ($res) {
  41. return app('json')->success('发布成功');
  42. }else{
  43. return app('json')->fail('发布失败');
  44. }
  45. }
  46. /**
  47. *我发布的资讯
  48. *@title 搜索标题
  49. *@uid 用户id
  50. *@pid 父id
  51. *@id id
  52. */
  53. public function userlist()
  54. {
  55. [$page, $limit] = $this->getPage();
  56. $title =input('title/s',"");
  57. if ($title){
  58. $where['title'] =["like","%".$title."%"];
  59. }
  60. $where['uid'] = $this->request->uid();
  61. $where["pid"]=0;
  62. $res=$this->repository->getlist($where,$page,$limit);
  63. if ($res) {
  64. return app('json')->success($res);
  65. }else{
  66. return app('json')->fail('暂无数据');
  67. }
  68. }
  69. /**
  70. *编辑我发布的资讯
  71. *@title 标题
  72. *@content 内容
  73. *@images 图片
  74. *@id id
  75. *@uid 用户id
  76. */
  77. public function editinfo(){
  78. $data = $this->request->params(['title', 'content','images','id']);
  79. $where['uid'] = $this->request->uid();
  80. $where["pid"]=0;
  81. $res=$this->repository->editinfo($data,$where);
  82. if ($res) {
  83. return app('json')->success('编辑成功');
  84. }else{
  85. return app('json')->fail('保存失败');
  86. }
  87. }
  88. /**
  89. *删除我发布的资讯
  90. *@id id
  91. *@uid 用户id
  92. */
  93. public function delinfo(){
  94. $where = $this->request->params(['id']);
  95. if(empty($where["id"])) return app('json')->fail('请上传id');
  96. $where['uid'] = $this->request->uid();
  97. $res=$this->repository->delinfo($where);
  98. if ($res) {
  99. return app('json')->success('编辑成功');
  100. }else{
  101. return app('json')->fail('保存失败');
  102. }
  103. }
  104. /**
  105. * 资讯列表
  106. * @id id
  107. * page
  108. * limit
  109. * uid
  110. * pid
  111. * order 排序
  112. */
  113. public function list()
  114. {
  115. [$page, $limit] = $this->getPage();
  116. $title = input('title/s',"");
  117. if ($title){
  118. $where["title"]=["like","%".$title."%"];
  119. }
  120. $where["pid"]=0;
  121. $where["status"]=1;
  122. $order="is_top desc,update_time desc";
  123. $res=$this->repository->getlist($where,$page,$limit,$order);
  124. if ($res) {
  125. return app('json')->success($res);
  126. }else{
  127. return app('json')->fail('暂无数据');
  128. }
  129. }
  130. /**
  131. * 发布评论
  132. * content评论内容
  133. * pid 评论对象id
  134. */
  135. public function postcomment()
  136. {
  137. $data = $this->request->params(['content','pid']);
  138. $data['uid'] = $this->request->uid();
  139. $res=$this->repository->postinfo($data);
  140. if ($res) {
  141. return app('json')->success('发布成功');
  142. }else{
  143. return app('json')->fail('发布失败');
  144. }
  145. }
  146. /**
  147. * 评论列表
  148. * id 评论对象id
  149. */
  150. public function getcomment()
  151. {
  152. [$page, $limit] = $this->getPage();
  153. $id = input('id/d');
  154. $uid= $this->request->uid();
  155. if(empty($id)) return app('json')->fail('请上传id');
  156. $where["pid"]=$id;
  157. $res=$this->repository->getcommentlist($where,$page,$limit,$uid);
  158. if ($res) {
  159. return app('json')->success($res);
  160. }else{
  161. return app('json')->fail('暂无评论');
  162. }
  163. }
  164. /**
  165. * 赞 取消赞
  166. * pid 赞的对象id
  167. */
  168. public function fabulous()
  169. {
  170. $data = $this->request->params(['pid']);
  171. $data['uid'] = $this->request->uid();
  172. $data['type']=0;
  173. if(empty($data["pid"])) return app('json')->fail('请上传pid');
  174. $res=$this->repository->fabulous($data);
  175. if ($res) {
  176. return app('json')->success($res);
  177. }else{
  178. return app('json')->fail('失败');
  179. }
  180. }
  181. /**
  182. * 举报
  183. * pid 举报的对象id
  184. * cotent 举报内容
  185. */
  186. public function report()
  187. {
  188. $data = $this->request->params(['pid',"cotent"]);
  189. $data['uid'] = $this->request->uid();
  190. $data['type']=1;
  191. if(empty($data["pid"])) return app('json')->fail('请上传pid');
  192. $res=$this->repository->report($data);
  193. if ($res) {
  194. return app('json')->success($res);
  195. }else{
  196. return app('json')->fail('失败');
  197. }
  198. }
  199. /**
  200. * 评论管理
  201. * $uid 用户id
  202. */
  203. public function get_comment_list(){
  204. $uid = $this->request->uid();
  205. $res=$this->repository->comment_list($uid);
  206. if ($res) {
  207. return app('json')->success($res);
  208. }else{
  209. return app('json')->fail('暂无数据');
  210. }
  211. }
  212. }