PostLogic.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * PostLogic.php UTF-8
  4. * 资讯
  5. *
  6. * @date : 2018/1/23 14:59
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : linjiebin <ljb@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace web\pc\logic;
  13. use huo\model\common\CommonModel;
  14. use huo\model\posts\PostsModel;
  15. class PostLogic extends CommonModel {
  16. public function getList($where = [], $page = '1,10', $order = '') {
  17. $_rdata = [
  18. 'count' => 0,
  19. 'list' => []
  20. ];
  21. $_map = [];
  22. if (!empty($where['gameid'])) {
  23. $_map['app_id'] = $where['gameid'];
  24. }
  25. if (!empty($where['catalog'])) {
  26. $_map['post_type'] = $where['catalog'];
  27. }
  28. $_param['where'] = $_map;
  29. $_param['page'] = $page;
  30. $_param['order'] = $order;
  31. $_posts = new PostsModel();
  32. $_rdata['count'] = $_posts->where($_map)->count();
  33. if (empty($_rdata['count'])) {
  34. return $_rdata;
  35. }
  36. $_field= 'id,post_title,app_id,published_time,more,user_id,comment_count,post_like,post_type,post_content';
  37. $_datas = $_posts->field($_field)->where($_map)->order($order)->page($page)->select();
  38. // $_param['field'] = 'id,post_title,app_id,published_time,more,user_id,comment_count,post_like,post_type,post_content';
  39. // $_datas = $_posts->getDatas($_param);
  40. $_list = [];
  41. foreach ($_datas as $_data) {
  42. $_post = [];
  43. $_post['id'] = $_data['id'];
  44. $_post['title'] = $_data['post_title'];
  45. $_post['gameid'] = $_data['app_id'];
  46. $_post['pubdate'] = $_data['published_time'];
  47. $_post['img'] = isset($_data['more']['thumbnail']) ? $_data['more']['thumbnail'] : '';
  48. $_post['author'] = $_data['user_id'];
  49. $_post['commentcnt'] = $_data['comment_count'];
  50. $_post['likecnt'] = $_data['post_like'];
  51. $_post['type'] = $_data['post_type'];
  52. $_post['post_content'] = strip_tags($_data['post_content']);
  53. $_list[] = $_post;
  54. }
  55. $_rdata['list'] = $_list;
  56. return $_rdata;
  57. }
  58. /**
  59. * @param int $post_id
  60. *
  61. * @return int
  62. */
  63. public function getDetail($post_id = 0) {
  64. if (empty($post_id)) {
  65. return 2000;
  66. }
  67. $_param['field'] = 'id,post_title,post_content,app_id,post_excerpt,published_time,more,user_id,comment_count,post_like,post_type';
  68. $_param['id'] = $post_id;
  69. $_posts = new PostsModel();
  70. $_data = $_posts->getDatas($_param);
  71. if (empty($_data)) {
  72. return 2000;
  73. }
  74. $_post['id'] = $_data['id'];
  75. $_post['title'] = $_data['post_title'];
  76. $_post['gameid'] = $_data['app_id'];
  77. $_post['pubdate'] = $_data['published_time'];
  78. $_post['img'] = isset($_data['more']['thumbnail']) ? $_data['more']['thumbnail'] : '';
  79. $_post['author'] = $_data['user_id'];
  80. $_post['type'] = $_data['post_type'];
  81. $_post['excerpt'] = $_data['post_excerpt'];
  82. $_post['content'] = $_data['post_content'];
  83. return $_post;
  84. }
  85. }