Information.php 5.8 KB

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