Xuniren.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Xuniren
  5. {
  6. # 获取几条数据
  7. public function getHome($limit = 10)
  8. {
  9. $where = array();
  10. $where['limit'] = '0,' . $limit;
  11. $data = Dever::db('content/xuniren')->getHome($where);
  12. if ($data) {
  13. foreach ($data as $k => $v) {
  14. $data[$k] = $this->getPic($v);
  15. $data[$k]['link'] = Dever::url('main/xnr-detail?id=' . $v['id']);
  16. $data[$k]['info'] = Dever::cut($v['info'], 50);
  17. }
  18. }
  19. return $data;
  20. }
  21. public function getDataByCreater($creater_id)
  22. {
  23. $where = array();
  24. //$where['creater_id'] = $creater_id;
  25. //$data = Dever::db('content/xuniren')->getDataByCreater($where);
  26. $where['cid'] = $creater_id;
  27. $data = Dever::db('content/creater_xuniren')->getAll($where);
  28. $result = array();
  29. if ($data) {
  30. foreach ($data as $k => $v) {
  31. $info = Dever::db('content/xuniren')->one($v['xid']);
  32. if ($info) {
  33. $info = $this->getPic($info);
  34. $info['sname'] = $info['name'];
  35. $info['link'] = Dever::url('main/xnr-detail?id=' . $info['id']);
  36. $info['info'] = '<span>简介</span> ' . $info['info'];
  37. $result[] = $info;
  38. }
  39. }
  40. }
  41. return $result;
  42. }
  43. private function getPic($data)
  44. {
  45. if (strstr($data['pic'], ',')) {
  46. $data['pic_list'] = explode(',', $data['pic']);
  47. $data['pic'] = $data['pic_list'][0];
  48. } else {
  49. $data['pic_list'][] = $data['pic'];
  50. }
  51. return $data;
  52. }
  53. public function getInfo($id)
  54. {
  55. $data = Dever::db('content/xuniren')->one(array('id' => $id));
  56. if ($data) {
  57. $data = $this->getPic($data);
  58. $data['news'] = Dever::array_decode($data['news']);
  59. /*
  60. if ($data['bdate']) {
  61. $data['age'] = $this->birthday($data['bdate']);
  62. if ($data['age'] <= 0) {
  63. $data['age'] = '不详';
  64. }
  65. } else {
  66. $data['age'] = '不详';
  67. }
  68. */
  69. if (!$data['age']) {
  70. $data['age'] = '不详';
  71. }
  72. if ($data['sex'] == 1) {
  73. $data['sex'] = '男';
  74. } elseif ($data['sex'] == 2) {
  75. $data['sex'] = '女';
  76. } else {
  77. $data['sex'] = '不详';
  78. }
  79. //$data['sname'] = $data['name'] . ' / ' . $data['ename'];
  80. $data['sname'] = $data['name'];
  81. //$data['pdate'] = date('Y/m/d', $data['pdate']);
  82. $data['pdate'] = $data['pdate_string'];
  83. $data['creater_name'] = '';
  84. $creater_name = array();
  85. $where['xid'] = $data['id'];
  86. $info = Dever::db('content/creater_xuniren')->getAll($where);
  87. if ($info) {
  88. foreach ($info as $k => $v) {
  89. $creater = Dever::db('content/creater')->one(array('id' => $v['cid']));
  90. if ($creater) {
  91. $url = Dever::url('main/zwz-detail?id=' . $creater['id']);
  92. $creater_name[] = '<a href="'.$url.'">' . $creater['name'] . '</a>';
  93. }
  94. }
  95. }
  96. if ($data['zwz']) {
  97. $temp = explode(',', $data['zwz']);
  98. $creater_name = array_merge($creater_name, $temp);
  99. }
  100. if ($creater_name) {
  101. $data['creater_name'] = implode(' & ', $creater_name);
  102. }
  103. }
  104. return $data;
  105. }
  106. public function birthday($age)
  107. {
  108. $temp = explode("-",date("Y-m-d",$age));
  109. $y1 = $temp[0];
  110. $m1 = $temp[1];
  111. $d1 = $temp[2];
  112. $temp = explode("-",date("Y-m-d"));
  113. $y2 = $temp[0];
  114. $m2 = $temp[1];
  115. $d2 = $temp[2];
  116. $age = $y2 - $y1;
  117. if((int)($m2.$d2) < (int)($m1.$d1))
  118. $age -= 1;
  119. return $age;
  120. }
  121. }