📖 File Reader
<?php
namespace app\admin\controller;
use app\admin\common\Common_index;
use app\common\Common_time;
use think\facade\Db;
use think\facade\View;
class Index extends Base
{
public function index()
{
return redirect('/admin/Login/login');
}
public function main()
{
return View::fetch();
}
/*菜单栏处理*/
public function menu()
{
$admin_info = db::name("admin")->alias("a")
->join("admin_role b","a.role_id = b.id")
->field("a.admin_id,b.jurisdiction,b.type as role_type")
->where("a.admin_id = $this->admin_id")
->find();
$jurisdiction = $admin_info["jurisdiction"];//权限
if (empty($jurisdiction)){
$jurisdiction = 0;
}
$where = 1;
if ($admin_info["role_type"] == 1){ //平台管理员
$where .= " and role_type in (0,1)";
}else if($admin_info["role_type"] == 2){ //店铺管理员
$where .= " and role_type in (0,2)";
}
/*定义菜单栏*/
$data_top_left = [
['title'=>'常规管理','icon'=>'fa fa-address-book','href'=>'','target'=>'_self','top_type'=>'1','child'=>[]],
];
foreach ($data_top_left as $k => $v){
//顶级分类
$list1 = db::name("config_menus")->where("id in ($jurisdiction) and is_show = 1 and superior_id = 0 and top_type = $v[top_type] and $where")->order("sort desc")->select()->toarray();
$arr1 = [];
foreach ($list1 as $k1 => $v1){
//子级分类
$list2 = db::name("config_menus")->where("id in ($jurisdiction) and is_show = 1 and superior_id = $v1[id] and is_left = 1 and $where")->order("sort desc")->select()->toarray();
$data2 = [];
foreach ($list2 as $k2 => $v2){
$data2[$k2] = [
'id'=>$v2["id"],
'title'=>$v2["title"],
'icon'=>$v2["icon"],
'href'=>$v2["url"],
'children'=>[],
"type"=>1,
"openType"=>"_iframe"
];
}
$data1=[
'id'=>$v1["id"],
"title"=>$v1["title"],
"icon"=>$v1["icon"],
"type"=>0,
"href"=>$v1["url"],
'children'=>$data2,
];
if (empty($list2)){ //当没有二级页面时,定义顶级可跳转
$data1["type"] = 1;
$data1["openType"] = "_iframe";
}
$arr1[$k1] = $data1;
}
}
return json($arr1);
}
public function index_v1()
{
/*订单趋势统计*/
$all = '';
$all_pay = '';
$all_obligation = '';
$time = '';
$yue_count = 7;
for ($i = 1; $i <= 6; $i++) {
$yue = $yue_count-$i;
if (!empty($yue)){
$time_month = Common_time::GetMonth('-' . $yue);//每月开始时间
$time_month2 = Common_time::GetMonth('-' . $yue+1);//每月结束时间
/*统计*/
$order_statistics = Common_index::order_statistics($time_month,$time_month2,$this->admin_info);
$time .= "'" . date("Y-m", $time_month) . "',";
$all .= $order_statistics["order_count"] . ',';
$all_pay .= $order_statistics["order_pay_count"] . ',';
$all_obligation .= $order_statistics["order_dpay_count"] . ',';
}
}
/*最新发布的公告*/
$article = db::name("article")->where("act_id = 1")->order("id desc")->limit("4")->select()->toArray();
foreach ($article as $k => $v){
$article[$k]["add_time"] = date("m月d日",$v["add_time"]);
}
View::assign([
'article'=>$article,
'time' => '[' . substr($time, 0, strlen($time) - 1) . ']',//月份
'all' => '[' . substr($all, 0, strlen($all) - 1) . ']',
'all_pay' => '[' . substr($all_pay, 0, strlen($all_pay) - 1) . ']',
'all_obligation' => '[' . substr($all_obligation, 0, strlen($all_obligation) - 1) . ']',
]);
return View::fetch();
}
public function index_404()
{
return View::fetch();
}
/*数据统计*/
public function statistics()
{
$time_info = Common_time::time_info();
$time_today = strtotime(date("Y-m-d 00:00:00", time()));//今日开始时间
$time_month = date("m", $time_info["b_time"]);
$where = 1;
/*角色权限*/
$admin_role_type = $this->admin_info["role_type"];
$admin_shop_id = $this->admin_info["shop_id"];
if($admin_role_type == 2){ //店铺管理员
$where .= " and shop_id = $admin_shop_id";
}
$where .= " and is_chai = 0";
//本月总收入
$order_money = db::name("order")->where("state in (1,2,3) and pay_time >= $time_info[e_time] and $where")->sum("price");
//今日订单
$order_count = db::name("order")->where("state in (1,2,3) and pay_time >= $time_today and $where")->count();
//今日访客
$visitor_count = db::name("user")->where("login_time >= $time_today")->count();
//活跃数量
$active_count = db::name("user")->where("login_time >= $time_info[b_time] and login_time <= $time_info[e_time]")->count();
$data = [
'order_money' => $order_money,
'order_count' => $order_count,
'visitor_count' => $visitor_count,
'time_month' => $time_month,
'active_count' => $active_count,
];
return $this->succeed_json("ok", $data);
}
}