Xuniren.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. $data['pic'] = str_replace('http://8.131.66.239/', 'http://www.virtualbeings.cn/', $data['pic']);
  46. if (strstr($data['pic'], ',')) {
  47. $data['pic_list'] = explode(',', $data['pic']);
  48. $data['pic'] = $data['pic_list'][0];
  49. } else {
  50. $data['pic_list'][] = $data['pic'];
  51. }
  52. return $data;
  53. }
  54. public function getInfo($id)
  55. {
  56. $data = Dever::db('content/xuniren')->one(array('id' => $id));
  57. if ($data) {
  58. $data = $this->getPic($data);
  59. $data['news'] = Dever::array_decode($data['news']);
  60. /*
  61. if ($data['bdate']) {
  62. $data['age'] = $this->birthday($data['bdate']);
  63. if ($data['age'] <= 0) {
  64. $data['age'] = '不详';
  65. }
  66. } else {
  67. $data['age'] = '不详';
  68. }
  69. */
  70. if (!$data['age']) {
  71. $data['age'] = '不详';
  72. }
  73. if ($data['sex'] == 1) {
  74. $data['sex'] = '男';
  75. } elseif ($data['sex'] == 2) {
  76. $data['sex'] = '女';
  77. } else {
  78. $data['sex'] = '不详';
  79. }
  80. //$data['sname'] = $data['name'] . ' / ' . $data['ename'];
  81. $data['sname'] = $data['name'];
  82. //$data['pdate'] = date('Y/m/d', $data['pdate']);
  83. $data['pdate'] = $data['pdate_string'];
  84. $data['creater_name'] = '';
  85. $creater_name = array();
  86. $where['xid'] = $data['id'];
  87. $info = Dever::db('content/creater_xuniren')->getAll($where);
  88. if ($info) {
  89. foreach ($info as $k => $v) {
  90. $creater = Dever::db('content/creater')->one(array('id' => $v['cid']));
  91. if ($creater) {
  92. $url = Dever::url('main/zwz-detail?id=' . $creater['id']);
  93. $creater_name[] = '<a href="'.$url.'">' . $creater['name'] . '</a>';
  94. }
  95. }
  96. }
  97. if ($data['zwz']) {
  98. $temp = explode(',', $data['zwz']);
  99. $creater_name = array_merge($creater_name, $temp);
  100. }
  101. if ($creater_name) {
  102. $data['creater_name'] = implode(' & ', $creater_name);
  103. }
  104. }
  105. return $data;
  106. }
  107. public function birthday($age)
  108. {
  109. $temp = explode("-",date("Y-m-d",$age));
  110. $y1 = $temp[0];
  111. $m1 = $temp[1];
  112. $d1 = $temp[2];
  113. $temp = explode("-",date("Y-m-d"));
  114. $y2 = $temp[0];
  115. $m2 = $temp[1];
  116. $d2 = $temp[2];
  117. $age = $y2 - $y1;
  118. if((int)($m2.$d2) < (int)($m1.$d1))
  119. $age -= 1;
  120. return $age;
  121. }
  122. }