123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- <?php
- /**
- *
- * User: anyluck
- * Date: 2020/5/28
- * Time: 12:13
- */
- namespace app\admin\controller;
- use app\common\controller\Aliyunoss;
- use think\facade\Db;
- use app\common\controller\Backend;
- use think\facade\Request;
- use think\facade\View;
- class Friendship extends Backend
- {
- // 上传图片
- public function upimage()
- {
- // $file = request()->file('image');
- $file = $_FILES["file"];
- // $file = $_FILES;
- // dump($file);
- // die();
- if (!$file) json_result(400, '请上传图片', '');
- $Aliyun = new Aliyunoss();
- $aa = $Aliyun->uploadFile($file);
- json_result(200, '发送成功', $aa);
- }
- // 主页
- public function index()
- {
- // 查询友情链接数量
- $links=Db::name("links")->count();
- $banner=Db::name("banner")->count();
- $user_count=Db::name("admin")->count();
- // 查询浏览量
- $liull=Db::name("browse")->where(["type"=>0])->count();
- $liull_zt=Db::name("browse")->where(["type"=>0])->whereDay("add_time")->count();
- $user=0;// 独立用户
- $zhixing=0;// 最终咨询
- $view = [
- 'info' => [
- "liull"=>$liull,
- "liull_zt"=>$liull_zt/($liull-$liull_zt)*100,
- "user"=>$user,
- "zhixing"=>$zhixing,
- "links"=>$links,
- "banner"=>$banner,
- "admin"=>$user_count,
- ],
- 'title' => lang('add'),
- // 'userLevel'=>$userLevel,
- ];
- View::assign($view);
- return View::fetch();
- }
- // 友情链接列表
- public function links()
- {
- if (Request::isPost()) {
- $page = input("page") ?: 1;
- $limit = input("limit") ?: 10;
- $name = input("name");
- $where = [];
- if ($name) {
- $where["name"] = ["like", "%" . $name . "%"];
- }
- $list = Db::name("links")->where($where)->order("pai desc")->paginate(["list_rows" => $limit, "page" => $page])->toArray();
- return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
- } else {
- return View::fetch();
- }
- }
- //添加或修改友情链接
- public function add_links()
- {
- if (Request::isPost()) {
- $id = input("id");
- $name = input("name");
- $url = input("url");
- $add["name"] = $name;
- $add["url"] = $url;
- if ($id) {
- Db::name("links")->where(["id" => $id])->update($add);
- } else {
- Db::name("links")->insert($add);
- }
- $this->success(lang('add success'), url('links'));
- return;
- // json_result(200,"操作成功");
- }
- $id = input("id");
- $info = "";
- if ($id) {
- $info = Db::name("links")->where(["id" => $id])->find();
- }
- $view = [
- 'info' => $info,
- 'title' => lang('add'),
- // 'userLevel'=>$userLevel,
- ];
- View::assign($view);
- return View::fetch();
- }
- // 修改状态
- public function update_links()
- {
- $id = input("id");
- $status = input("status") ?: 0;
- Db::name("links")->where(["id" => $id])->update(["status" => $status]);
- json_result(1, "设置成功");
- }
- // 修改排序
- public function update_pai_links()
- {
- $id = input("id");
- $value = input("value");
- $field = input("field");
- Db::name("links")->where(["id" => $id])->update([$field => $value]);
- json_result(1, "设置成功");
- }
- //删除友情链接
- public function del_links()
- {
- $id = input("id");
- Db::name("links")->where(["id" => $id])->delete();
- json_result(1, "删除成功");
- }
- // 导航管理列表
- public function dh_list()
- {
- if (Request::isPost()) {
- $page = input("page") ?: 1;
- $limit = input("limit") ?: 10;
- $name = input("name");
- $type = input("type");
- $where = [];
- if ($name) {
- $where["name"] = ["like", "%" . $name . "%"];
- }
- if ($type) {
- $where["type"] = $type;
- }
- $list = Db::name("dh")->where($where)->order("pai desc")->paginate(["list_rows" => $limit, "page" => $page])->each(function ($item){
- if ($item["type"]==1){
- $item["type"]="商城系统";
- }elseif ($item["type"]==2){
- $item["type"]="解决方案";
- }else{
- $item["type"]="";
- }
- return $item;
- })->toArray();
- return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
- } else {
- return View::fetch();
- }
- }
- // 修改数据
- public function update_pai_dh()
- {
- $id = input("id");
- $value = input("value");
- $field = input("field");
- Db::name("dh")->where(["id" => $id])->update([$field => $value]);
- json_result(1, "设置成功");
- }
- // 修改导航栏状态
- public function update_dh_status()
- {
- $id = input("id");
- $status = input("status") ?: 0;
- Db::name("dh")->where(["id" => $id])->update(["status" => $status]);
- json_result(1, "设置成功");
- }
- // 删除导航
- public function del_dh()
- {
- $id = input("id");
- Db::name("dh")->where(["id" => $id])->delete();
- json_result(1, "删除成功");
- }
- // 添加导航
- public function add_dh()
- {
- if (Request::isPost()) {
- $id = input("id");
- $name = input("name");
- $type = input("type");
- $status = input("status");
- $add["name"] = $name;
- $add["type"] = $type;
- $add["status"] = $status;
- if ($id) {
- Db::name("dh")->where(["id" => $id])->update($add);
- } else {
- Db::name("dh")->insert($add);
- }
- $this->success(lang('add success'), url('dh_list'));
- return;
- // json_result(200,"操作成功");
- }
- $id = input("id");
- $info = "";
- if ($id) {
- $info = Db::name("dh")->where(["id" => $id])->find();
- }
- $view = [
- 'info' => $info,
- 'title' => lang('add'),
- // 'userLevel'=>$userLevel,
- ];
- View::assign($view);
- return View::fetch();
- }
- // 轮播图列表
- public function banner()
- {
- if (Request::isPost()) {
- $page = input("page") ?: 1;
- $limit = input("limit") ?: 10;
- $name = input("name");
- $type = input("type");
- $where = [];
- if ($name) {
- $where["name"] = ["like", "%" . $name . "%"];
- }
- if ($type) {
- $where["type"] = $type;
- }
- $list = Db::name("banner")->where($where)->order("pai desc")->paginate(["list_rows" => $limit, "page" => $page])->each(function ($item){
- return $item;
- })->toArray();
- return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
- } else {
- return View::fetch();
- }
- }
- // 修改数据轮播图
- public function update_pai_banner()
- {
- $id = input("id");
- $value = input("value");
- $field = input("field");
- Db::name("banner")->where(["id" => $id])->update([$field => $value]);
- json_result(1, "设置成功");
- }
- // 修改轮播图栏状态
- public function update_banner_status()
- {
- $id = input("id");
- $status = input("status") ?: 0;
- Db::name("banner")->where(["id" => $id])->update(["status" => $status]);
- json_result(1, "设置成功");
- }
- //添加或修改轮播图
- public function add_banner()
- {
- if (Request::isPost()) {
- $id = input("id");
- $name = input("name");
- $image = input("image");
- $url = input("url");
- $status = input("status");
- $add["name"] = $name;
- $add["image"] =$image;
- $add["url"] =$url;
- $add["status"] = $status;
- if ($id) {
- Db::name("banner")->where(["id" => $id])->update($add);
- } else {
- Db::name("banner")->insert($add);
- }
- $this->success(lang('add success'), url('banner'));
- return;
- // json_result(200,"操作成功");
- }
- $id = input("id");
- $info = "";
- if ($id) {
- $info = Db::name("banner")->where(["id" => $id])->find();
- }
- $view = [
- 'info' => $info,
- 'title' => lang('add'),
- // 'userLevel'=>$userLevel,
- ];
- View::assign($view);
- return View::fetch();
- }
- // 删除轮播图
- public function del_banner()
- {
- $id = input("id");
- Db::name("banner")->where(["id" => $id])->delete();
- json_result(1, "删除成功");
- }
- // 统计数据
- public function statistics()
- {
- if (Request::isPost()) {
- $type=input("type")?:0;//0 日指标 1 浏览量 2 独立用户 3 最终咨询
- $day=input("day");// 选中天数
- $start_time=input("start_time");// 开始时间
- $end_time=input("end_time");// 结束时间
- $where=[];
- $where[]=["type","=",$type];
- if ($type==0){// 日指标
- $list=Db::name("browse")->where($where)->whereDay('add_time')->field("add_time,FROM_UNIXTIME(add_time,'%H') as posttime,sum(num) as zong")->group('posttime')->select();
- // 处理数据
- $data=[];
- foreach ($list as $k=>$v){
- $data["day"][$k]=$v["posttime"]."点";
- $data["data"][$k]=$v["zong"];
- }
- json_result(200,"日指标",$data);
- }elseif ($type==1){// 浏览量
- if ($day){
- $start_time=date("Y-m-d",time()).' 23:59:59';
- $end_time=date('Y-m-d',strtotime('-'.($day).' days')).' 23:59:59';;
- }
- $start_time=strtotime($start_time);
- $end_time=strtotime($end_time);
- $list=Db::name("browse")->where(["type"=>0])->where("add_time",">",$end_time)->where("add_time","<",$start_time)->where(["type"=>0])->field("add_time,FROM_UNIXTIME(add_time,'%Y-%m-%d') as posttime,sum(num) as zong")->group('posttime')->select();
- // json_result($start_time,$end_time,$list);
- $data=[];
- foreach ($list as $k=>$v){
- $data["day"][$k]=date("m.d",strtotime($v["posttime"]));
- $data["data"][$k]=$v["zong"];
- }
- json_result(200,"浏览量",$data);
- }
- $data["data"]=[];
- $data["day"]=[];
- json_result(200,"浏览量22",$data);
- }
- // 查询浏览量
- $liull=Db::name("browse")->where(["type"=>0])->count();
- $liull_zt=Db::name("browse")->where(["type"=>0])->whereDay("add_time")->count();
- $user=0;// 独立用户
- $zhixing=0;// 最终咨询
- $view = [
- 'info' => [
- "liull"=>$liull,
- "liull_zt"=>$liull_zt/($liull-$liull_zt)*100,
- "user"=>$user,
- "zhixing"=>$zhixing,
- ],
- 'title' => lang('add'),
- // 'userLevel'=>$userLevel,
- ];
- View::assign($view);
- return View::fetch();
- }
- }
|