This commit is contained in:
2024-10-29 14:04:59 +08:00
commit 48bf3e6f33
2839 changed files with 762707 additions and 0 deletions

156
app/mobile/controller/Blog.php Executable file
View File

@@ -0,0 +1,156 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\Db;
class Blog extends BaseController {
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('数据有误,请检查后再操作');
}
$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);
//echo "<pre>====6666======".$id; print_r($dataObject); die;
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]);
}
}
protected function historyarticle($id) {
/*$article = Cookie::get('article', 'history'); //print_r($history);exit;
if (isset($article) && !empty($article)) {
$article_ids = explode(',', $article);
if ($article_ids[0] != $id) {
array_unshift($article_ids, $id);
$article_ids = array_unique($article_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$article_ids = array_slice($article_ids, 0, $num);
while (count($article_ids) > $num) {
array_pop($article_ids);
}
Cookie::set('article', implode(',', $article_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('article', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}*/
}
//添加评论 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');
}
}