0, 'display' => 1]; if ($type) { $arg_where['typeid'] = $type; } if ($cid) { $arg_where['content_id'] = $cid; } $arg_order = ['id' => 'desc']; $arg_field = ['*']; $dataObject = Loader::model('Pinglun')->getPageList($arg_where, $arg_order, $arg_field, 12); //header('content-type:text/html;charset=utf-8;'); $value['list'] = $dataObject->isEmpty() ? null : $dataObject->items(); $value['page'] = $dataObject->render(); $value['total'] = $dataObject->total(); if ($this->request->isAjax()) { return $this->result($value, 'pinglun', true); } $value['cid'] = $cid; $value['type'] = ucfirst($type); $value['seo_title'] = config('article_seo_title')? : config('website_seo_title'); $value['seo_keyword'] = config('article_seo_keyword')? : config('website_seo_keyword'); $value['seo_description'] = config('article_seo_description')? : config('website_seo_description'); $this->assign($value); return $this->fetch('pinglun'); } public function add() { $data = $this->request->post(); if (empty($data) || !is_array($data)) { return $this->json(-3, '未知错误'); } // $row = Loader::model('Pinglun')->getRow(['customer_id' => $data['customer_id']], null, ['id' => 'desc']); // if ($row && $row['id']) { // $createtime = strtotime($row['createtime']); // if (time() - $createtime < 60) { // return $this->json(-2,'您已评论过了请不要重复评论'); // } // } // 验证.... $addtime = date('Y-m-d H:i:s'); $txarr = [1, 2, 3, 4, 5]; shuffle($txarr); $set = [ 'customer_id' => $data['customer_id'], 'cname' => $data['firstname'], 'typeid' => isset($data['typeid']) ? $data['typeid'] : 'Article', 'pid' => isset($data['pid']) ? $data['pid'] : 0, 'content_id' => isset($data['cid']) ? $data['cid'] : 0, 'content' => $data['content'], 'tx' => $txarr[0], 'stat' => 0, 'createtime' => $addtime, 'lasttime' => $addtime, ]; $model = Loader::model('Pinglun')->insert($set); if ($model) { isset($data['cid']) ? Loader::model('Article')->where(['id' => $data['cid']])->setInc('commentcount') : ''; return $this->json(1, '评论成功!'); } else { return $this->json(-5, '操作失败'); } } }