From c03acdb57ab94a48743fb25d02ad92df51664df8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 12 Jun 2024 15:05:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86WorkbenchCon?= =?UTF-8?q?troller=E5=92=8CWorkbenchLogic=E7=B1=BB=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E6=A0=B9=E6=8D=AE=E6=97=B6=E9=97=B4=E6=AE=B5?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=95=86=E5=93=81=E7=BB=9F=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/WorkbenchController.php | 50 +----- app/admin/logic/WorkbenchLogic.php | 176 +++---------------- 2 files changed, 37 insertions(+), 189 deletions(-) diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index 8fd11a57d..fdf23eb00 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -232,48 +232,16 @@ class WorkbenchController extends BaseAdminController */ public function get_basic() { - $data = [ - "browse" => [ - "num" => 11353, - "percent" => "330.03" - ], - "user" => [ - "num" => 538, - "percent" => "47.39" - ], - "cart" => [ - "num" => 1181, - "percent" => "43.67" - ], - "order" => [ - "num" => 105753, - "percent" => "-68.07" - ], - "pay" => [ - "num" => 2476, - "percent" => "-99.24" - ], - "payPrice" => [ - "num" => 163490.54, - "percent" => "-87.50" - ], - "cost" => [ - "num" => 72147.8, - "percent" => "-93.33" - ], - "refundPrice" => [ - "num" => 2321.81, - "percent" => "1447.87" - ], - "refund" => [ - "num" => 39, - "percent" => "8.33" - ], - "payPercent" => [ - "num" => "15.61", - "percent" => "-6.58" - ] + $startTime=$this->request->get('start_time');//开始时间 + $endTime=$this->request->get('end_time');//结束时间 + if(empty($startTime)){//如果没有传开始时间,则默认获取最近7天的数据 + $startTime=strtotime(date('Y-m-d')); + $endTime=$startTime+86400; + } + $where=[ + ['create_time','between',[$startTime,$endTime]] ]; + $data=WorkbenchLogic::get_basic($where); return $this->data($data); } diff --git a/app/admin/logic/WorkbenchLogic.php b/app/admin/logic/WorkbenchLogic.php index 297ad05b9..8bf3df71d 100644 --- a/app/admin/logic/WorkbenchLogic.php +++ b/app/admin/logic/WorkbenchLogic.php @@ -16,6 +16,8 @@ namespace app\admin\logic; use app\common\logic\BaseLogic; +use app\common\model\store_order\StoreOrder; +use app\common\model\store_visit\StoreVisit; use app\common\service\ConfigService; use app\common\service\FileService; @@ -37,162 +39,40 @@ class WorkbenchLogic extends BaseLogic public static function index() { return [ - // 版本信息 - 'version' => self::versionInfo(), - // 今日数据 - 'today' => self::today(), + // 常用功能 - 'menu' => self::menu(), - // 近15日访客数 - 'visitor' => self::visitor(), - // 服务支持 - 'support' => self::support() + ]; } + //-------------------------------商品统计---------------------------------------// /** - * @notes 常用功能 - * @return array[] - * @author 乔峰 - * @date 2021/12/29 16:40 + * 商品概况 */ - public static function menu(): array + public static function get_basic($where) { + $browse=StoreVisit::where($where)->count(); + $user=0; + $cart=0; + $order=StoreOrder::where($where)->count(); + $pay=StoreOrder::where($where)->where('paid',1)->count(); + $payPrice=StoreOrder::where($where)->where('paid',1)->count('pay_price'); + $cost=StoreOrder::where($where)->where('paid',1)->sum('cost'); + $refundPrice=StoreOrder::where($where)->where('status','in',[-1,-2])->sum('refund_price'); + $refund=StoreOrder::where($where)->where('status','in',[-1,-2])->count(); + $payPercent=0; return [ - [ - 'name' => '管理员', - 'image' => FileService::getFileUrl(config('project.default_image.menu_admin')), - 'url' => '/permission/admin' - ], - [ - 'name' => '角色管理', - 'image' => FileService::getFileUrl(config('project.default_image.menu_role')), - 'url' => '/permission/role' - ], - [ - 'name' => '部门管理', - 'image' => FileService::getFileUrl(config('project.default_image.menu_dept')), - 'url' => '/organization/department' - ], - [ - 'name' => '素材中心', - 'image' => FileService::getFileUrl(config('project.default_image.menu_file')), - 'url' => '/material/index' - ], - [ - 'name' => '菜单权限', - 'image' => FileService::getFileUrl(config('project.default_image.menu_auth')), - 'url' => '/permission/menu' - ], - [ - 'name' => '网站信息', - 'image' => FileService::getFileUrl(config('project.default_image.menu_web')), - 'url' => '/setting/website/information' - ], + 'browse'=>['num'=>$browse,'title'=>'浏览量'],//浏览量 + 'user'=>['num'=>$user,'title'=>'访客数'],//访客数 + 'cart'=>['num'=>$cart,'title'=>'加购人数'],//加购人数 + 'order'=>['num'=>$order,'title'=>'订单量'],//订单量 + 'pay'=>['num'=>$pay,'title'=>'支付订单量'],//支付订单量 + 'payPrice'=>['num'=>$payPrice,'title'=>'支付金额'],//支付金额 + 'cost'=>['num'=>$cost,'title'=>'成本'],//成本 + 'refundPrice'=>['num'=>$refundPrice,'title'=>'退款金额'],//退款金额 + 'refund'=>['num'=>$refund,'title'=>'退款订单量'],//退款订单量 + 'payPercent'=>['num'=>$payPercent,'title'=>'支付转化率'],//支付转化率 ]; } - - - /** - * @notes 版本信息 - * @return array - * @author 乔峰 - * @date 2021/12/29 16:08 - */ - public static function versionInfo(): array - { - return [ - 'version' => config('project.version'), - 'website' => config('project.website.url'), - 'name' => ConfigService::get('website', 'name'), - 'based' => 'vue3.x、ElementUI、MySQL', - 'channel' => [ - 'website' => 'https://gitee.com/MuZJun/gather-admin.git', - 'gitee' => 'https://gitee.com/MuZJun/gather-vue.git', - ] - ]; - } - - - /** - * @notes 今日数据 - * @return int[] - * @author 乔峰 - * @date 2021/12/29 16:15 - */ - public static function today(): array - { - return [ - 'time' => date('Y-m-d H:i:s'), - // 今日销售额 - 'today_sales' => 100, - // 总销售额 - 'total_sales' => 1000, - - // 今日访问量 - 'today_visitor' => 10, - // 总访问量 - 'total_visitor' => 100, - - // 今日新增用户量 - 'today_new_user' => 30, - // 总用户量 - 'total_new_user' => 3000, - - // 订单量 (笔) - 'order_num' => 12, - // 总订单量 - 'order_sum' => 255 - ]; - } - - - /** - * @notes 访问数 - * @return array - * @author 乔峰 - * @date 2021/12/29 16:57 - */ - public static function visitor(): array - { - $num = []; - $date = []; - for ($i = 0; $i < 15; $i++) { - $where_start = strtotime("- " . $i . "day"); - $date[] = date('Y/m/d', $where_start); - $num[$i] = rand(0, 100); - } - - return [ - 'date' => $date, - 'list' => [ - ['name' => '访客数', 'data' => $num] - ] - ]; - } - - - /** - * @notes 服务支持 - * @return array[] - * @author 乔峰 - * @date 2022/7/18 11:18 - */ - public static function support() - { - return [ - [ - 'image' => FileService::getFileUrl(config('project.default_image.qq_group')), - 'title' => '官方公众号', - 'desc' => '关注官方公众号', - ], - [ - 'image' => FileService::getFileUrl(config('project.default_image.customer_service')), - 'title' => '添加企业客服微信', - 'desc' => '想了解更多请添加客服', - ] - ]; - } - -} \ No newline at end of file +}