123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
-
- namespace app\user\controller;
-
- use think\Db;
- use think\Config;
- use think\Page;
-
- class Ask extends Base
- {
-
- public function _initialize()
- {
- parent::_initialize();
- $this->ask_db = Db::name('ask');
- $this->ask_answer_db = Db::name('ask_answer');
- $this->ask_type_db = Db::name('ask_type');
-
- $functionLogic = new \app\common\logic\FunctionLogic;
- $functionLogic->validate_authorfile(2);
- }
-
-
-
- public function ask_index()
- {
-
-
- $field = 'a.ask_id, a.ask_title, a.click, a.replies, a.add_time, a.is_review, b.type_name';
-
-
-
- $where = [
- 'a.status' => ['IN', [0, 1]],
- 'a.users_id' => $this->users_id,
- ];
-
-
-
- $count = $this->ask_db->alias('a')->where($where)->count('ask_id');
- $pageObj = new Page($count, config('paginate.list_rows'));
-
-
-
- $result = $this->ask_db->field($field)
- ->alias('a')
- ->join('ask_type b', 'a.type_id = b.type_id', 'LEFT')
- ->where($where)
- ->order('a.add_time desc')
- ->limit($pageObj->firstRow . ',' . $pageObj->listRows)
- ->select();
-
-
- foreach ($result as $key => $value) {
-
- $result[$key]['AskUrl'] = url('home/Ask/details', ['ask_id' => $value['ask_id']]);
- }
-
-
- $show = $pageObj->show();
- $this->assign('page',$show);
- $this->assign('list',$result);
- $this->assign('pager',$pageObj);
-
- return $this->fetch('ask_index');
- }
-
-
-
- public function answer_index()
- {
-
-
- $field = 'a.*, b.ask_title';
-
-
-
- $where = [
- 'a.users_id' =>$this->users_id,
- ];
-
-
-
- $count = $this->ask_answer_db->alias('a')->where($where)->count('answer_id');
- $pageObj = new Page($count, config('paginate.list_rows'));
-
-
-
- $result = $this->ask_answer_db->field($field)
- ->alias('a')
- ->join('ask b', 'a.ask_id = b.ask_id', 'LEFT')
- ->where($where)
- ->order('a.add_time desc')
- ->limit($pageObj->firstRow . ',' . $pageObj->listRows)
- ->select();
-
-
- foreach ($result as $key => $value) {
-
- $result[$key]['AskUrl'] = url('home/Ask/details', ['ask_id' => $value['ask_id']]);
-
- if (isset($value['answer_id']) && !empty($value['answer_id'])) {
- $preg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
- $value['content'] = htmlspecialchars_decode($value['content']);
- $value['content'] = preg_replace($preg, '[图片]', $value['content']);
- $value['content'] = strip_tags($value['content']);
- $result[$key]['content'] = mb_strimwidth($value['content'], 0, 120, "...");
- }
- }
-
-
- $show = $pageObj->show();
- $this->assign('page',$show);
- $this->assign('list',$result);
- $this->assign('pager',$pageObj);
- return $this->fetch('answer_index');
- }
- }
|