| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\logic;
- use app\adminapi\logic\distribution\DistributionDataLogic;
- use app\common\enum\AfterSaleEnum;
- use app\common\enum\DistributionOrderGoodsEnum;
- use app\common\enum\OrderEnum;
- use app\common\enum\UserTerminalEnum;
- use app\common\enum\YesNoEnum;
- use app\common\logic\BaseLogic;
- use app\common\model\AfterSale;
- use app\common\model\DistributionOrderGoods;
- use app\common\model\Goods;
- use app\common\model\GoodsComment;
- use app\common\model\IndexVisit;
- use app\common\model\Order;
- use app\common\model\OrderGoods;
- use app\common\model\User;
- use app\common\service\ConfigService;
- use app\common\service\FileService;
- /**
- * 工作台
- * Class WorkbenchLogic
- * @package app\adminapi\logic
- */
- class WorkbenchLogic extends BaseLogic
- {
- /**
- * @notes 工作台
- * @return int[]
- * @author Tab
- * @date 2021/9/10 14:12
- */
- public static function index($adminInfo)
- {
- // 基本信息
- $shopInfo = self::shopInfo($adminInfo);
- // 今日数据
- $today = self::today();
- // 待办事项
- $pending = self::pending();
- // 近15日营业额
- $business15 = self::business15();
- // 近15日访客数
- $visitor15 = self::visitor15();
- return [
- 'shop_info' => $shopInfo,
- 'today' => $today,
- 'pending' => $pending,
- 'business15' => $business15,
- 'visitor15' => $visitor15,
- ];
- }
- public static function earningsData()
- {
- }
- /**
- * @notes 商城信息
- * @param $adminInfo
- * @return array
- * @author Tab
- * @date 2021/9/10 15:02
- */
- public static function shopInfo($adminInfo)
- {
- // 商城名称
- $name = ConfigService::get('shop', 'name');
- // 商城logo
- $logo = ConfigService::get('shop', 'logo');
- $logo = FileService::getFileUrl($logo);
- // 管理员名称
- $adminName = $adminInfo['name'];
- return [
- 'name' => $name,
- 'logo' => $logo,
- 'admin_name' => $adminName,
- ];
- }
- /**
- * @notes 今日数据
- * @return array
- * @author Tab
- * @date 2021/9/10 17:41
- */
- public static function today()
- {
- // 营业额
- $todayOrderAmount = Order::where('pay_status', YesNoEnum::YES)
- ->whereDay('create_time')
- ->sum('order_amount');
- // 成交订单数
- $todayOrderNum = Order::where('pay_status', YesNoEnum::YES)
- ->whereDay('create_time')
- ->count();
- // 访客数
- $visitor = IndexVisit::whereDay('create_time')->column('ip');
- $todayVisitor = count(array_unique($visitor));
- // 新增用户
- $todayNewUser = User::whereDay('create_time')->count();
- return [
- 'today_order_amount' => $todayOrderAmount,
- 'today_order_num' => $todayOrderNum,
- 'today_visitor' => $todayVisitor,
- 'today_new_user' => $todayNewUser,
- ];
- }
- /**
- * @notes 待办事项
- * @return array
- * @author Tab
- * @date 2021/9/10 17:57
- */
- public static function pending()
- {
- // 待发货订单数
- $waitShipped = Order::where('order_status', OrderEnum::STATUS_WAIT_DELIVERY)->count();
- // 待审核售后申请
- $waitAudit = AfterSale::where('sub_status', AfterSaleEnum::SUB_STATUS_WAIT_SELLER_AGREE)->count();
- // 待审核评价
- $waitProcess = GoodsComment::where(['status'=>YesNoEnum::NO])->count();
- // 售罄商品
- $noStockGoods = Goods::where('total_stock', 0)->count();
- return [
- 'wait_shipped' => $waitShipped,
- 'wait_audit' => $waitAudit,
- 'wait_process' => $waitProcess,
- 'no_stock_goods' => $noStockGoods
- ];
- }
- /**
- * @notes 近15天营业额
- * @return array
- * @author Tab
- * @date 2021/9/10 18:06
- */
- public static function business15()
- {
- $today = new \DateTime();
- $todayStr = $today->format('Y-m-d') . ' 23:59:59';
- $todayDec15 = $today->add(\DateInterval::createFromDateString('-14day'));
- $todayDec15Str = $todayDec15->format('Y-m-d');
- $field = [
- "FROM_UNIXTIME(create_time,'%Y%m%d') as date",
- "sum(order_amount) as today_amount"
- ];
- $lists = Order::field($field)
- ->whereTime('create_time', 'between', [$todayDec15Str,$todayStr])
- ->where('pay_status', YesNoEnum::YES)
- ->group('date')
- ->select()
- ->toArray();
- $lists = array_column($lists, 'today_amount', 'date');
- $amountData = [];
- $date = [];
- for($i = 0; $i < 15; $i ++) {
- $today = new \DateTime();
- $targetDay = $today->add(\DateInterval::createFromDateString('-'. $i . 'day'));
- $targetDay = $targetDay->format('Ymd');
- $date[] = $targetDay;
- $amountData[] = $lists[$targetDay] ?? 0;
- }
- return [
- 'date' => $date,
- 'list' => [
- ['name' => '营业额', 'data' => $amountData]
- ]
- ];
- }
- /**
- * @notes 近15天访客数
- * @return mixed
- * @author Tab
- * @date 2021/9/10 18:51
- */
- public static function visitor15()
- {
- $today = new \DateTime();
- $todayStr = $today->format('Y-m-d') . ' 23:59:59';
- $todayDec15 = $today->add(\DateInterval::createFromDateString('-14day'));
- $todayDec15Str = $todayDec15->format('Y-m-d');
- $field = [
- "FROM_UNIXTIME(create_time,'%Y%m%d') as date",
- "ip"
- ];
- $lists = IndexVisit::field($field)
- ->distinct(true)
- ->whereTime('create_time', 'between', [$todayDec15Str,$todayStr])
- ->select()
- ->toArray();
- // 集合一天的IP
- $temp1 = [];
- foreach ($lists as $item) {
- $temp1[$item['date']][] = $item['ip'];
- }
- // 统计数量
- $temp2 = [];
- foreach ($temp1 as $k => $v) {
- $temp2[$k] = count($v);
- }
- $userData = [];
- $date = [];
- for($i = 0; $i < 15; $i ++) {
- $today = new \DateTime();
- $targetDay = $today->add(\DateInterval::createFromDateString('-'. $i . 'day'));
- $targetDay = $targetDay->format('Ymd');
- $date[] = $targetDay;
- $userData[] = $temp2[$targetDay] ?? 0;
- }
- return [
- 'date' => $date,
- 'list' => [
- ['name' => '访客数', 'data' => $userData]
- ]
- ];
- }
- /**
- * @notes 商品排行榜 - 按销售额排序
- * @return mixed
- * @author Tab
- * @date 2021/9/10 19:40
- */
- public static function topGoods50($params)
- {
- $field = [
- 'g.id',
- 'g.name',
- 'g.image',
- 'sum(og.goods_num)' => 'total_num',
- 'sum(og.total_pay_price)' => 'total_pay_price',
- ];
- $lists = OrderGoods::alias('og')
- ->leftJoin('order o', 'o.id = og.order_id')
- ->leftJoin('goods g', 'g.id = og.goods_id')
- ->field($field)
- ->where('o.pay_status', YesNoEnum::YES)
- ->group('g.id,g.name,g.image')
- ->order('total_pay_price', 'desc')
- ->limit(50)
- ->page($params['page_no'], $params['page_size'])
- ->select()
- ->toArray();
- $count = OrderGoods::alias('og')
- ->leftJoin('order o', 'o.id = og.order_id')
- ->leftJoin('goods g', 'g.id = og.goods_id')
- ->field($field)
- ->where('o.pay_status', YesNoEnum::YES)
- ->group('g.id,g.name,g.image')
- ->order('total_pay_price', 'desc')
- ->limit(50)
- ->count();
- return [
- 'lists' => $lists,
- 'count' => $count,
- 'page_no' => $params['page_no'],
- 'page_size' => $params['page_size'],
- ];
- }
- /**
- * @notes 用户排行榜 - 按用户累计购买金额
- * @return mixed
- * @author Tab
- * @date 2021/9/10 19:50
- */
- public static function topUser50($params)
- {
- $field = [
- 'u.id',
- 'u.nickname',
- 'u.avatar',
- 'count(o.id)' => 'total_num',
- 'sum(o.order_amount)' => 'total_order_amount',
- ];
- $lists = Order::alias('o')
- ->leftJoin('user u', 'u.id = o.user_id')
- ->field($field)
- ->where('o.pay_status', YesNoEnum::YES)
- ->group('u.id,u.nickname,u.avatar')
- ->order('total_order_amount', 'desc')
- ->limit(50)
- ->page($params['page_no'], $params['page_size'])
- ->select()
- ->toArray();
- $count = Order::alias('o')
- ->leftJoin('user u', 'u.id = o.user_id')
- ->field($field)
- ->where('o.pay_status', YesNoEnum::YES)
- ->group('u.id,u.nickname,u.avatar')
- ->order('total_order_amount', 'desc')
- ->limit(50)
- ->count();
- return [
- 'lists' => $lists,
- 'count' => $count,
- 'page_no' => $params['page_no'],
- 'page_size' => $params['page_size'],
- ];
- }
- }
|