123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace Content\Lib;
- use Dever;
- class Xuniren
- {
- # 获取几条数据
- public function getHome($limit = 10)
- {
- $where = array();
- $where['limit'] = '0,' . $limit;
- $data = Dever::db('content/xuniren')->getHome($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $data[$k] = $this->getPic($v);
- $data[$k]['link'] = Dever::url('main/xnr-detail?id=' . $v['id']);
- $data[$k]['info'] = Dever::cut($v['info'], 50);
- }
- }
- return $data;
- }
- public function getDataByCreater($creater_id)
- {
- $where = array();
- //$where['creater_id'] = $creater_id;
- //$data = Dever::db('content/xuniren')->getDataByCreater($where);
- $where['cid'] = $creater_id;
- $data = Dever::db('content/creater_xuniren')->getAll($where);
- $result = array();
- if ($data) {
- foreach ($data as $k => $v) {
- $info = Dever::db('content/xuniren')->one($v['xid']);
- if ($info) {
- $info = $this->getPic($info);
- $info['sname'] = $info['name'];
- $info['link'] = Dever::url('main/xnr-detail?id=' . $info['id']);
- $info['info'] = '<span>简介</span> ' . $info['info'];
- $result[] = $info;
- }
- }
- }
- return $result;
- }
- private function getPic($data)
- {
- $data['pic'] = str_replace('http://8.131.66.239/', 'http://www.virtualbeings.cn/', $data['pic']);
- if (strstr($data['pic'], ',')) {
- $data['pic_list'] = explode(',', $data['pic']);
- $data['pic'] = $data['pic_list'][0];
- } else {
- $data['pic_list'][] = $data['pic'];
- }
- return $data;
- }
- public function getInfo($id)
- {
- $data = Dever::db('content/xuniren')->one(array('id' => $id));
- if ($data) {
- $data = $this->getPic($data);
- $data['news'] = Dever::array_decode($data['news']);
- /*
- if ($data['bdate']) {
- $data['age'] = $this->birthday($data['bdate']);
- if ($data['age'] <= 0) {
- $data['age'] = '不详';
- }
- } else {
- $data['age'] = '不详';
- }
- */
- if (!$data['age']) {
- $data['age'] = '不详';
- }
- if ($data['sex'] == 1) {
- $data['sex'] = '男';
- } elseif ($data['sex'] == 2) {
- $data['sex'] = '女';
- } else {
- $data['sex'] = '不详';
- }
- //$data['sname'] = $data['name'] . ' / ' . $data['ename'];
- $data['sname'] = $data['name'];
- //$data['pdate'] = date('Y/m/d', $data['pdate']);
- $data['pdate'] = $data['pdate_string'];
- $data['creater_name'] = '';
- $creater_name = array();
- $where['xid'] = $data['id'];
- $info = Dever::db('content/creater_xuniren')->getAll($where);
- if ($info) {
- foreach ($info as $k => $v) {
- $creater = Dever::db('content/creater')->one(array('id' => $v['cid']));
- if ($creater) {
- $url = Dever::url('main/zwz-detail?id=' . $creater['id']);
- $creater_name[] = '<a href="'.$url.'">' . $creater['name'] . '</a>';
- }
- }
- }
- if ($data['zwz']) {
- $temp = explode(',', $data['zwz']);
- $creater_name = array_merge($creater_name, $temp);
- }
- if ($creater_name) {
- $data['creater_name'] = implode(' & ', $creater_name);
- }
- }
- return $data;
- }
- public function birthday($age)
- {
- $temp = explode("-",date("Y-m-d",$age));
- $y1 = $temp[0];
- $m1 = $temp[1];
- $d1 = $temp[2];
- $temp = explode("-",date("Y-m-d"));
- $y2 = $temp[0];
- $m2 = $temp[1];
- $d2 = $temp[2];
- $age = $y2 - $y1;
- if((int)($m2.$d2) < (int)($m1.$d1))
- $age -= 1;
- return $age;
- }
- }
|