222 lines
8.6 KiB
PHP
Executable File
222 lines
8.6 KiB
PHP
Executable File
<?php
|
|
namespace app\index\controller;
|
|
|
|
use think\Loader;
|
|
use think\Cookie;
|
|
use think\Config;
|
|
use think\Db;
|
|
|
|
|
|
class Blog extends BaseController {
|
|
|
|
public function index() {
|
|
$data = $this->request->param();
|
|
$arg_where = ['siteid' => $this->siteid,'stat' => 1, 'country_code' => $this->country_code,'public_time'=>['<=',date("Y-m-d")]];
|
|
|
|
$search = array();
|
|
if (isset($data['name']) && $data['name'] != ''){
|
|
$arg_where['title'] = ['like', "%$data[name]%"];
|
|
$search['name'] = $data['name'];
|
|
|
|
}
|
|
|
|
$arg_order = ['is_top'=>'desc','id' => 'desc'];
|
|
$arg_field = ['*'];
|
|
|
|
$dataObject = Loader::model('blog')->getBlogLists($arg_where, $arg_order, $arg_field, 12);
|
|
//echo Loader::model('blog')->getLastsql();
|
|
//echo "<pre>====22222222======"; print_r($dataObject);die;
|
|
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
|
|
];
|
|
$value['seo_title'] = config('article_seo_title')? : config('website_seo_title_us');
|
|
$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);
|
|
$this->assign('search',$search);
|
|
return $this->fetch();
|
|
}
|
|
|
|
|
|
public function blog() {
|
|
$data = $this->request->param();
|
|
$arg_where = ['siteid' => $this->siteid,'stat' => 1, 'country_code' => $this->country_code,'public_time'=>['<=',date("Y-m-d")]];
|
|
|
|
$search = array();
|
|
if (isset($data['name']) && $data['name'] != ''){
|
|
$arg_where['title'] = ['like', "%$data[name]%"];
|
|
$search['name'] = $data['name'];
|
|
|
|
}
|
|
|
|
$arg_order = ['is_top'=>'desc','id' => 'desc'];
|
|
$arg_field = ['*'];
|
|
|
|
$dataObject = Loader::model('blog')->getBlogLists($arg_where, $arg_order, $arg_field, 12);
|
|
//echo Loader::model('blog')->getLastsql();
|
|
//echo "<pre>====22222222======"; print_r($dataObject);die;
|
|
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
|
|
];
|
|
$value['seo_title'] = config('article_seo_title')? : config('website_seo_title_us');
|
|
$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);
|
|
$this->assign('search',$search);
|
|
return $this->fetch();
|
|
}
|
|
|
|
|
|
public function detail($id = 0) {
|
|
if ($id > 0) {
|
|
$blog = Loader::model('Blog')->getRow($id);
|
|
if (empty($blog)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
//echo "<pre>====6666======".$id; print_r($blog); die;
|
|
|
|
$arg_where = ['blog_remark.b_id' => $id, 'blog_remark.stat' => 1];
|
|
$arg_order = ['blog_remark.id' => 'desc'];
|
|
$arg_field = ['blog_remark.*'];
|
|
$dataObject = Loader::model('blog')->getRemarkList($arg_where, $arg_order, $arg_field, 10);
|
|
|
|
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
|
|
$value['total'] = $dataObject->total();
|
|
$value['page'] = $dataObject->render();
|
|
|
|
|
|
|
|
$value['seo_title'] = $blog['seo_title']? : $blog['title'] . '-' . config('website_seo_title');
|
|
$value['seo_keyword'] = $blog['seo_keyword']? : config('website_seo_keyword');
|
|
$value['seo_description'] = $blog['seo_description']? : config('website_seo_description');
|
|
$this->assign($value);
|
|
$this->assign('blog', $blog);
|
|
$this->viewcount($id);
|
|
//return $this->fetch($template);
|
|
|
|
$disCount = $dataObject->isEmpty() ? null : count($dataObject->items());
|
|
|
|
if($disCount) {
|
|
$counts = get_rand_number(1,10,$disCount);
|
|
$this->assign('counts', $counts);
|
|
}
|
|
|
|
|
|
$curUrl = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
|
$this->assign('curUrl', $curUrl);
|
|
|
|
return $this->fetch();
|
|
} else {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
}
|
|
|
|
public function details($id = 0) {
|
|
if ($id > 0) {
|
|
$blog = Loader::model('Blog')->getRow($id);
|
|
if (empty($blog)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
|
|
$jssdk=new \JsSdk\JsSdk('wx0d4ac6d59abca442','c482b3f5d1354533e9e14ad294016551');
|
|
//$jssdk=new \JsSdk\JsSdk('wxe44444f1f65fe4a6','a8c6a5a40572829da61a9c945ae6a0cd'); //测试账户
|
|
$signPackage = $jssdk->getSignPackage();
|
|
$this->assign('singpackage',$signPackage);
|
|
|
|
|
|
$arg_where = ['blog_remark.b_id' => $id, 'blog_remark.stat' => 1];
|
|
$arg_order = ['blog_remark.id' => 'desc'];
|
|
$arg_field = ['blog_remark.*'];
|
|
$dataObject = Loader::model('blog')->getRemarkList($arg_where, $arg_order, $arg_field, 10);
|
|
|
|
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
|
|
$value['total'] = $dataObject->total();
|
|
$value['page'] = $dataObject->render();
|
|
|
|
|
|
|
|
$value['seo_title'] = $blog['seo_title']? : $blog['title'] . '-' . config('website_seo_title');
|
|
$value['seo_keyword'] = $blog['seo_keyword']? : config('website_seo_keyword');
|
|
$value['seo_description'] = $blog['seo_description']? : config('website_seo_description');
|
|
$this->assign($value);
|
|
$this->assign('blog', $blog);
|
|
$this->viewcount($id);
|
|
//return $this->fetch($template);
|
|
|
|
$disCount = $dataObject->isEmpty() ? null : count($dataObject->items());
|
|
|
|
if($disCount) {
|
|
$counts = get_rand_number(1,10,$disCount);
|
|
$this->assign('counts', $counts);
|
|
}
|
|
|
|
|
|
$curUrl = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
|
$this->assign('curUrl', $curUrl);
|
|
|
|
return $this->fetch();
|
|
} else {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected function viewcount($id) {
|
|
$view = Cookie::get('blogview', 'history'); //print_r($history);exit;
|
|
if (empty($view) || $view != $id) {
|
|
Loader::model('blog')->where(['id' => $id])->setInc('visit_count');
|
|
Cookie::set('blogview', $id, ['prefix' => 'history', 'expire' => 3600]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//添加评论 2021-06-01 Martin
|
|
public function addcomment()
|
|
{
|
|
|
|
$data = $this->request->post();
|
|
if (empty($data) || !is_array($data))
|
|
return $this->json(403, 'Data error ');
|
|
|
|
if (trim($data['name']) == '')
|
|
return $this->json(403-2, 'Name cannot be empty');
|
|
if (trim($data['email']) == '')
|
|
return $this->json(403-4, 'Email cannot be empty');
|
|
if (trim($data['comment']) == '')
|
|
return $this->json(403-5, 'Comment cannot be empty');
|
|
// if ($data['buy_source'] == '')
|
|
// return $this->json(-5, '购买渠道不能为空');
|
|
|
|
/*if ($data['customer_telephone'] != '' && !preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['customer_telephone']))
|
|
return $this->json(-6, 'Phone format error ');*/
|
|
if ($data['email'] != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['email']))
|
|
return $this->json(403-6, 'Email Address format error');
|
|
|
|
$insert_data = [
|
|
'b_id' => trim($data['b_id']),
|
|
'name' => trim($data['name']),
|
|
'email' => trim($data['email']),
|
|
'content' => trim($data['comment']),
|
|
'add_time' => date("Y-m-d H:i:s",time()),
|
|
'siteid' => $this->siteid,
|
|
'country_code' => $this->country_code,
|
|
];
|
|
|
|
$result = model('blog_remark')->insert($insert_data);
|
|
if (!$result)
|
|
return $this->json(201, 'Failure to submit');
|
|
|
|
return $this->json(200, 'ok');
|
|
}
|
|
|
|
|
|
}
|