📖 File Reader
<?php
namespace app\api\controller;
use app\api\model\ModGoodsAct;
use app\BaseController;
use app\common\Common_pdf;
use app\common\Common_time;
use app\api\common\Common_config;
use app\api\common\Common_index;
use app\api\common\Common_user;
use think\facade\Db;
use think\facade\View;
class Index extends BaseController
{
protected $page = 1;//默认页数
protected $limit = 20;//默认条数
// 初始化
protected function initialize()
{
$this->page = input('page')?:$this->page;
$this->limit = input('limit')?:$this->limit;
}
/*首页*/
public function index()
{
/*首页推荐专区*/
$goods_act = db::name("goods_act")->where("parent_id = 0 and is_show_home = 1")->order("sort desc id desc")->field("id,name")->select()->toArray();
foreach ($goods_act as $k => $v){
$list = db::name("goods")->where("state = 1 and is_sold = 1 and is_delete = 0 and find_in_set($v[id],act_id_str)")->order("sort desc,add_time desc")->limit(4)->select()->toArray();
$goods_act[$k]["goods_list"] = $list;
}
$data = [
"goods"=>$goods_act,
];
return $this->succeed_json("ok",$data);
}
/*产品分类(二层)*/
public function goods_act()
{
$act_id1 = input("param.act_id1");
//顶级分类
$act_list1 = db::name("goods_act")->where("parent_id = 0 and is_show = 1")->order("sort desc")->select()->toArray();
//二级分类
if (empty($act_id1)){
$act_id1 = $act_list1[0]["id"];
}
$act_list2 = db::name("goods_act")->where("parent_id = $act_id1 and is_show = 1")->order("sort desc")->select()->toArray();
$data = [
'act_id1'=>$act_id1,
'act_list1'=>$act_list1,
'act_list2'=>$act_list2,
];
return $this->succeed_json("ok",$data);
}
/*首页产品信息*/
public function goods_list()
{
$keyword = input("param.keyword");
$act_id = input("param.act_id");
$is_competitive = input("param.is_competitive");
$is_new = input("param.is_new");
$where = 1;
if (!empty($act_id)){
$sublevel_act_id = ModGoodsAct::sublevel_act_id($act_id,1);
if (!empty($sublevel_act_id)){
$where .= " and a.act_id in ($sublevel_act_id)";
}
}
if (!empty($is_competitive)){
$where.= " and a.is_competitive = $is_competitive";
}
if (!empty($is_new)){
$where.= " and a.is_new = $is_new";
}
if (!empty($keyword)){
$where.= " and (a.name like '%".$keyword."%' or a.describe like '%".$keyword."%')";
}
$list = db::name("goods")->alias("a")
->join("goods_act b","a.act_id = b.id","LEFT")
->field("a.*,b.name as cat_name")
->where("a.state = 1 and a.is_sold = 1 and a.is_delete = 0 and $where")
->order("a.sort desc,a.add_time desc")
->page($this->page,$this->limit)
->select()
->toArray();
//总页数
$count = db::name("goods")->alias("a")
->join("goods_act b","a.act_id = b.id","LEFT")
->where("a.state = 1 and a.is_sold = 1 and a.is_delete = 0 and $where")
->count();
$pages = $this->vue_pages($count,$this->limit);
$data = [
'list'=>$list,
'pages'=>$pages,
];
return $this->succeed_json("ok",$data);
}
/*配置信息获取*/
public function config()
{
$field = input("param.field");
$field_name = "";
if (!empty($field)){
$field_arr = explode(',',$field);
foreach ($field_arr as $k => $v){
$field_name .= "'".$v."',";
}
$field_name = substr($field_name,0,strlen($field_name)-1);
}
$config = Common_config::config($field_name);
return $this->succeed_json("ok",$config);
}
/*文章信息*/
public function article_list()
{
$keyword = input("param.keyword");
$act_id = input("param.act_id");
$where = 1;
if (!empty($act_id)){
$where .= " and a.act_id = $act_id";
}
if (!empty($keyword)){
$where .= " and a.title like '%".$keyword."%'";
}
$list = db::name("article")->alias("a")
->join("article_act b","a.act_id = b.id","LEFT")
->field("a.id,a.title,a.img,a.describe,a.browse_sum,a.add_time, b.name as act_name")
->where("a.is_show = 1 and $where")
->order("a.add_time desc")
->page($this->page,$this->limit)
->select()
->toarray();
foreach ($list as $k => $v){
$list[$k]["add_time"] = date("Y-m-d",$v["add_time"]);
}
//获取总页数
$count = db::name("article")->alias("a")
->join("article_act b","a.act_id = b.id","LEFT")
->field("a.id,a.title,a.img,a.describe,a.browse_sum,a.add_time, b.name as act_name")
->where("a.is_show = 1 and $where")
->count();
$pages = $this->vue_pages($count,$this->limit);
$data = [
'list'=>$list,
'pages'=>$pages,
];
return $this->succeed_json("ok",$data);
}
/*文章详情*/
public function article_info()
{
$article_id = input("param.article_id");
if (empty($article_id)){
return $this->error_json("参数错误");
}
$article_info = db::name("article")->where("id = $article_id")->find();
$article_info["add_time"] = date("Y-m-d",$article_info["add_time"]);
//更改浏览量
$info["browse_sum"] = $article_info["browse_sum"]+1;
db::name("article")->where("id = $article_id")->data($info)->update();
$data = [
'article_info'=>$article_info,
];
return $this->succeed_json("ok",$data);
}
/*店面活动*/
public function activity_dianmian()
{
$time = time();
$list = db::name("activity_dianmian")->where("time_ks <= $time and time_js >= $time and is_show = 1")->order("id desc")->page($this->page,$this->limit)->select()->toArray();
foreach ($list as $k => $v){
$list[$k]["add_time"] = date("Y.m.d",$v["add_time"]);
$list[$k]["time_ks"] = date("m-d H:i",$v["time_ks"]);
$list[$k]["time_js"] = date("m-d H:i",$v["time_js"]);
}
//获取总页数
$count =db::name("activity_dianmian")->where("time_ks <= $time and time_js >= $time and is_show = 1")->count();
$pages = $this->vue_pages($count,$this->limit);
$data = [
'list'=>$list,
'pages'=>$pages,
];
return $this->succeed_json("ok",$data);
}
/*html生成pdf*/
public function pdf_generate(Common_pdf $common_pdf)
{
$html = '
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
html生成pdf
</body>
</html>';
$data[] = [
'type' => 'text',
'content' => $html
];
$title = 'geshi1_';
$info = $common_pdf->createPDF($data, $title);
}
}