From 1d51fe072ae60eac6634f1e98b9b55abb6825bf5 Mon Sep 17 00:00:00 2001 From: manghe Date: Fri, 14 Mar 2025 14:42:09 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- app/admin/controller/Statistics.php | 30 +- app/admin/controller/Upload.php | 6 + app/admin/route/app.php | 5 + app/admin/view/Danye/edit.html | 89 ++-- app/admin/view/Statistics/userstatistics.html | 472 ++++++++++++++++++ app/admin/view/view_kM6dcB.tar.gz | Bin 4160 -> 0 bytes app/command/UserStatisticsDay.php | 169 +++++++ app/command/UserStatisticsHour.php | 59 --- app/common.php | 291 ++++++++--- config/console.php | 1 + config/menu.php | 4 + 12 files changed, 951 insertions(+), 180 deletions(-) create mode 100644 app/admin/view/Statistics/userstatistics.html delete mode 100755 app/admin/view/view_kM6dcB.tar.gz create mode 100644 app/command/UserStatisticsDay.php delete mode 100644 app/command/UserStatisticsHour.php diff --git a/README.md b/README.md index d65a9d2..d7f941e 100755 --- a/README.md +++ b/README.md @@ -61,4 +61,7 @@ putenv composer install php think run -composer require phpoffice/phpspreadsheet \ No newline at end of file +composer require phpoffice/phpspreadsheet + +php think UserStatisticsHour + diff --git a/app/admin/controller/Statistics.php b/app/admin/controller/Statistics.php index ca52b4d..ae4db18 100644 --- a/app/admin/controller/Statistics.php +++ b/app/admin/controller/Statistics.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\common\model\Order as OrderModel; use app\common\model\OrderList; use app\common\model\OrderListRecovery; +use app\common\model\UserStatistics; use app\common\model\User; use app\admin\controller\Base; use app\common\model\Category; @@ -16,7 +17,7 @@ use think\facade\Db; use app\common\model\Shang; use app\common\model\ProfitExpenses; use app\common\model\ProfitRvenue; - + class Statistics extends Base { @@ -89,7 +90,7 @@ class Statistics extends Base // 传递数据给视图 View::assign([ - + 'sum_dingdan' => $orderTotals->order_total_all, 'sum_shiji' => $orderTotals->order_zhe_total_all, 'sum_chuhuo' => $goodslistMoneyAll, @@ -163,31 +164,31 @@ class Statistics extends Base // 计算利润 $lirun = round($orderStats->order_zhe_total - $goodslistMoney, 2); $liruns = round(($orderStats->count_price + $orderStats->count_yue + $orderStats->use_integral + $orderStats->use_score + $orderStats->use_coupon) - $goodslistMoney, 2); - + return [ 'order_count' => round($orderStats->count, 2), - 'count_price' =>round($orderStats->count_price, 2), - 'order_total' =>round( $orderStats->order_total, 2), + 'count_price' => round($orderStats->count_price, 2), + 'order_total' => round($orderStats->order_total, 2), 'count_yue' => round($orderStats->count_yue, 2), 'count_use_integral' => round($orderStats->use_integral, 2), 'count_use_score' => round($orderStats->use_score, 2), 'count_use_coupon' => round($orderStats->use_coupon, 2), 'count_heji' => round($orderStats->count_price + $orderStats->count_yue + $orderStats->use_integral + $orderStats->use_score + $orderStats->use_coupon, 2), - 'order_zhe_total'=>round($orderStats->order_zhe_total, 2), + 'order_zhe_total' => round($orderStats->order_zhe_total, 2), // 订单列表数量 'count_OrderList' => OrderList::where($whe2)->count(), // ✅ 添加这一行 - + // 订单总价验证 // 'count_heji_yanzheng' => $count_OrderList * $value['price'], // ✅ 使用 count_OrderList - + 'goodslist_price' => round($goodslistMoney, 2), 'lirun' => $lirun, 'liruns' => $liruns, 'lirulv' => $goodslistMoney == 0 ? 0 : round(($lirun / $goodslistMoney) * 100, 2), 'lirulvs' => $goodslistMoney == 0 ? 0 : round(($liruns / $goodslistMoney) * 100, 2), ]; - - + + } @@ -384,4 +385,13 @@ class Statistics extends Base } + public function UserStatistics() + { + + $list = UserStatistics::order('id desc')->limit(30)->select(); + View::assign('list', $list); + return View::fetch('Statistics/userstatistics'); + } + + } diff --git a/app/admin/controller/Upload.php b/app/admin/controller/Upload.php index c5cc270..dedcb45 100755 --- a/app/admin/controller/Upload.php +++ b/app/admin/controller/Upload.php @@ -169,6 +169,12 @@ class Upload extends Base } } + public function uploadimage(){ + + // return + + return '{"imageActionName":"uploadimage","imageFieldName":"upfile","imageMaxSize":51200000,"imageAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp",".php"],"imageCompressEnable":true,"imageCompressBorder":600,"imageInsertAlign":"none","imageUrlPrefix":"","imagePathFormat":"\/ueditor\/php\/upload\/image\/{yyyy}{mm}{dd}\/{time}{rand:6}","scrawlActionName":"uploadscrawl","scrawlFieldName":"upfile","scrawlPathFormat":"\/ueditor\/php\/upload\/image\/{yyyy}{mm}{dd}\/{time}{rand:6}","scrawlMaxSize":51200000,"scrawlUrlPrefix":"","scrawlInsertAlign":"none","snapscreenActionName":"uploadimage","snapscreenPathFormat":"\/ueditor\/php\/upload\/image\/{yyyy}{mm}{dd}\/{time}{rand:6}","snapscreenUrlPrefix":"","snapscreenInsertAlign":"none","catcherLocalDomain":["127.0.0.1","localhost","img.baidu.com"],"catcherActionName":"catchimage","catcherFieldName":"source","catcherPathFormat":"\/ueditor\/php\/upload\/image\/{yyyy}{mm}{dd}\/{time}{rand:6}","catcherUrlPrefix":"","catcherMaxSize":51200000,"catcherAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp"],"videoActionName":"uploadvideo","videoFieldName":"upfile","videoPathFormat":"\/ueditor\/php\/upload\/video\/{yyyy}{mm}{dd}\/{time}{rand:6}","videoUrlPrefix":"","videoMaxSize":102400000,"videoAllowFiles":[".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".php",".wav",".mid"],"fileActionName":"uploadfile","fileFieldName":"upfile","filePathFormat":"\/ueditor\/php\/upload\/file\/{yyyy}{mm}{dd}\/{time}{rand:6}","fileUrlPrefix":"","fileMaxSize":51200000,"fileAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp",".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".wav",".mid",".rar",".zip",".tar",".gz",".7z",".bz2",".cab",".php",".iso",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pdf",".txt",".md",".xml"],"imageManagerActionName":"listimage","imageManagerListPath":"\/ueditor\/php\/upload\/image\/","imageManagerListSize":20,"imageManagerUrlPrefix":"","imageManagerInsertAlign":"none","imageManagerAllowFiles":[".png",".jpg",".jpeg",".gif",".php",".bmp"],"fileManagerActionName":"listfile","fileManagerListPath":"\/ueditor\/php\/upload\/file\/","fileManagerUrlPrefix":"","fileManagerListSize":20,"fileManagerAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp",".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".php",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".wav",".mid",".rar",".zip",".tar",".gz",".7z",".bz2",".cab",".iso",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pdf",".txt",".md",".xml"]}'; + } /** * 阿里云oss上传 diff --git a/app/admin/route/app.php b/app/admin/route/app.php index e3d14f6..f49914e 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -288,3 +288,8 @@ Route::rule('rvenue_del', 'Profit/rvenue_del', 'POST'); Route::rule('user_invite', 'user/user_invite', 'GET'); +Route::rule('user_statistics', 'Statistics/UserStatistics', 'GET'); + + + +Route::rule('ueditor_uploadimage', 'Upload/uploadimage', 'GET|POST'); diff --git a/app/admin/view/Danye/edit.html b/app/admin/view/Danye/edit.html index 3dc6cd1..3b2b575 100755 --- a/app/admin/view/Danye/edit.html +++ b/app/admin/view/Danye/edit.html @@ -1,66 +1,81 @@ {include file="Public:header2"/} + -
-
-
-
-
-
-
-
- -
- +
+
+
+
+
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
-
- -
- -
-
-
-
- - -
-
-
- + +
-
-{include file="Public:footer"/} + {include file="Public:footer"/} + + + + +
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+ +
+
+
+ 备注:总收入=订单支付+其他收入;
+ 备注:总支出=订单出货+其他支出;
+ 备注:利润=总收入-总支出;
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+ {include file="Public:footer"/} + + + + \ No newline at end of file diff --git a/app/admin/view/view_kM6dcB.tar.gz b/app/admin/view/view_kM6dcB.tar.gz deleted file mode 100755 index d29ce36ee74082baafd991c88e115d95830c9731..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4160 zcmV-G5WnvqiwFS!*_&hl1MM7ZbK6w5pYtn(2y1)rJ4v%Rab|Yl1I#S53^V(IVLBbf zy0%4S$w+b@7|*moY3VaON=xa|2HGvKLt1uA32kWqOk}&C_zQdPy|OIHk}RijNZWfd z6IoaHaUS=cdvzXqS#8u+C39e$kOi2XnZeiG>`c~q?ZJWE^z_us%xvypZu&qrmz_B{ zbAX!}D^?aXbVJZM?!fZ$a%jC_&!13unaUrDl98?&HF+FkU;!VTo(_qou+3W!>I}T*L@Qlm9DJdnnAtJ6U$*9P`(O8tFQlW|j5ovio)0&uHRK-c~M&GwW(;;9h!ZZc)`>@YJGe7-|j1sjqOlDoY~w zJet9ObF!o$8;z-#phwq@x`ec{tS%S0sw9d?nFDk<0`q!ZP-p)RFS6#fbrxDd?ep`@%TMoO37LqN|o z-1nF@H8u5|RI96+At(k6zrA&-{oyt98W$ZN=GXbM*rWZfnI;UnRWcy3t|VI^R)Q?P^#q!sy)UV?i{fh=l6T9VeX zu!v-z_N1I&FxSp@Zr+~HklP5|4Im>a^@aie@g$Cb59x%o;f&QftOo&i}X7|>w-3OnW z$8S)=cur^-YDultWn@5~Drg%Y{G%|EPV&dCGFD->@1E@5`K^6_ef$2e?Q2{6M5;AG zIb7GI(x7DRCnHPOL+P_6W~!3+m5lx6yEEB3$$Pd0+rIKi`@+fgm8)^{`VWaeQM5{< zwurQza8bF8O8DG$SQJ(VgzS1sgbfFuBA<&SberNoSE|pYQlXMfrG|GvuETcQ8yDLb z?A_K9OIP@-;<6B&*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_TLq7r?&%@a%m5VZbEDzW>0!|F9R|e;6gK-g?VtAA8s* zB6NK0VWjK`_C1GvCB_|y(EZtlr&d@`)HfP-n6$q?KFYw-6{1&R=?WZ6S8zXK=?Z-s zS-JvCR~ST*r7N&>g^-vamaV|D6&SdI+W+4~B?PN;OrHTC;rrjSx$G3S|7Q=*vhRQI z1-Ruuo-~jl`5)8MdF%V%v$NB)xje{!I+x8e|Ic0k%l~-V^FM5V&;CdO*&|*?P5216 z(TtMmF-lL5k>YXX$L-%AcE0$2N8|21y~F(VzmGBQRMc^&e8%lQJkh>#b@;e;O3COm z_pzrb%OKgu86-5edAG7ig2IkjA_>>a`?zd=dZ~Tsm!at-e`3lBRo~%tsN#u~a5Ah8 zo`UYg6yLnHrzkf?kxEA}0#9r@OX&XQ-OX^pN z&je8%R84Ht0sKP=fD=k)S4dbE?6Z3y0gl5(WCC^xJyFuJZWJS+*gJgx8O)k$W_o?>K@JwtZ(?Xlj-AxIAJeg-AWnXdn3WZY zAyIOfp0fO`5hueqaLGn{d|{ zShi0^?iK?E3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM7%*VKfB^#r3>YwYcH#e1 KwqsZTpa1}!w>=;L diff --git a/app/command/UserStatisticsDay.php b/app/command/UserStatisticsDay.php new file mode 100644 index 0000000..3c569fe --- /dev/null +++ b/app/command/UserStatisticsDay.php @@ -0,0 +1,169 @@ +setName('UserStatisticsHour')->setDescription('用户每天数据统计'); + } + + protected function execute(Input $input, Output $output) + { + + //# 统计表 user_statistics + // ELECT `id`, `login_count`, `register_count`, `created_at`, `updated_at`, `record_date` FROM `user_statistics` + //# 用户登录记录表 user_account,last_login_time 最后登录时间(时间戳int(11) )。user_id 用户id + //SELECT `id`, `user_id`, `account_token`, `token_num`, `token_time`, `last_login_time`, `last_login_ip`, `last_login_ip1`, `ip_adcode`, `ip_province`, `ip_city` FROM `user_account` + $userList = User::where('istest', '>=', 1)->field('id')->select(); + $userNotArray = array_column($userList->toArray(), 'id'); + // 获取当天日期 + $today = date('Y-m-d'); + + // 检查当天的统计记录是否存在 + $existingRecord = UserStatistics::where('record_date', $today) + ->find(); + + $today_start = strtotime($today); + $today_end = strtotime($today . ' +1 day'); + // 查询当天的登录人数 + $loginCount = UserAccount::where('last_login_time', '>=', $today_start) + ->where('last_login_time', '<', $today_end) + ->count('DISTINCT user_id'); + //当天注册人数 + $registerCount = User::where('addtime', '>=', $today_start) + ->count('id'); + // 本日充值金额 + $order_today_price = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userNotArray) + ->whereBetweenTime( + 'addtime', + $today_start, + $today_end + )->sum('price'); + + // 消费人数统计 + $consume_today = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userNotArray) + ->whereBetweenTime( + 'addtime', + $today_start, + $today_end + ) + ->field('user_id')->group('user_id')->count('user_id'); + + // 消费RMB人数统计 + $consume_today_price = OrderModel::where('status', '=', 1) + ->where('price', '>', '0') + ->whereNotIn('user_id', $userNotArray) + ->whereBetweenTime( + 'addtime', + $today_start, + $today_end + ) + ->field('user_id')->group('user_id')->count('user_id'); + + //今日余额消费 + $money_today = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userNotArray) + ->whereBetweenTime( + 'addtime', + $today_start, + $today_end + )->sum('use_money'); + + //今日消费 + $order_zhe_total = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userNotArray) + ->whereBetweenTime( + 'addtime', + $today_start, + $today_end + )->sum('order_zhe_total'); + //今日消费 + $consume_order_count = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userNotArray) + ->whereBetweenTime( + 'addtime', + $today_start, + $today_end + )->count(); + + //发放价值 + $shipment_money = OrderList::whereBetweenTime('addtime', $today_start, $today_end)->whereNotIn('user_id', $userNotArray)->sum('goodslist_money'); + + //回收价值 + $shipment_money1 = OrderList::where('status', '=', 1)->whereBetweenTime('choice_time', $today_start, $today_end)->whereNotIn('user_id', $userNotArray)->sum('goodslist_money'); + + $send_money = OrderList::where('status', '=', 2)->whereBetweenTime('choice_time', $today_start, $today_end)->whereNotIn('user_id', $userNotArray)->sum('goodslist_money'); + $profit_expenses = ProfitExpenses::getTotalAmountByDate(date('Y-m-d')); + $profit_rvenue = ProfitRvenue::getTotalAmountByDate(date('Y-m-d')); + + $profit_money = $order_zhe_total - $shipment_money; + //今日余额发放 + $money_recovery_today = OrderListRecovery:: + whereBetweenTime( + 'addtime', + $today_start, + $today_end + )->whereNotIn('user_id', $userNotArray)->sum('money'); + if ($existingRecord) { + // 更新记录 + UserStatistics::where('record_date', $today) + ->update([ + 'login_count' => $loginCount, + 'register_count' => $registerCount, + 'recharge_amount' => $order_today_price, + 'consume_user_count' => $consume_today, + 'balance_consume' => $money_today, + 'balance_issue' => $money_recovery_today, + 'consume_rmb_count' => $consume_today_price, + 'recharge_sum' => $order_zhe_total, + 'consume_order_count' => $consume_order_count, + 'shipment_money' => $shipment_money, + 'send_money' => $send_money, + 'recycle_money' => $shipment_money1, + 'profit_money' => $profit_money, + 'all_shipment_money' => $shipment_money + $profit_expenses, + 'all_recycle_money' => $order_zhe_total + $profit_rvenue, + 'all_money' => round(($order_zhe_total + $profit_rvenue) - ($shipment_money + $profit_expenses), 2), + 'updated_at' => date('Y-m-d H:i:s') + ]); + } else { + // 插入新记录 + UserStatistics::insert([ + 'login_count' => $loginCount, + 'register_count' => $registerCount, // 假设注册人数统计在其他地方处理 + 'record_date' => $today, + 'recharge_amount' => $order_today_price, + 'balance_consume' => $money_today, + 'balance_issue' => $money_recovery_today, + 'consume_user_count' => $consume_today, + 'consume_rmb_count' => $consume_today_price, + 'recharge_sum' => $order_zhe_total, + 'consume_order_count' => $consume_order_count, + 'shipment_money' => $shipment_money, + 'send_money' => $send_money, + 'recycle_money' => $shipment_money1, + 'profit_money' => $profit_money, + 'all_shipment_money' => $shipment_money + $profit_expenses, + 'all_recycle_money' => $order_zhe_total + $profit_rvenue, + 'all_money' => round(($order_zhe_total + $profit_rvenue) - ($shipment_money + $profit_expenses), 2), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s') + ]); + } + + } +} diff --git a/app/command/UserStatisticsHour.php b/app/command/UserStatisticsHour.php deleted file mode 100644 index 63b3dc4..0000000 --- a/app/command/UserStatisticsHour.php +++ /dev/null @@ -1,59 +0,0 @@ -setName('UserStatisticsHour')->setDescription('用户登录数据统计'); - } - - protected function execute(Input $input, Output $output) - { - - //# 统计表 user_statistics - // ELECT `id`, `login_count`, `register_count`, `created_at`, `updated_at`, `record_date` FROM `user_statistics` - //# 用户登录记录表 user_account,last_login_time 最后登录时间(时间戳int(11) )。user_id 用户id - //SELECT `id`, `user_id`, `account_token`, `token_num`, `token_time`, `last_login_time`, `last_login_ip`, `last_login_ip1`, `ip_adcode`, `ip_province`, `ip_city` FROM `user_account` - - // 获取当天日期 - $today = date('Y-m-d'); - - // 查询当天的登录人数 - $loginCount = UserAccount::where('last_login_time', '>=', strtotime($today)) - ->where('last_login_time', '<', strtotime($today . ' +1 day')) - ->count('DISTINCT user_id'); - - // 检查当天的统计记录是否存在 - $existingRecord = UserStatistics::where('record_date', $today) - ->find(); - - if ($existingRecord) { - // 更新记录 - UserStatistics::where('record_date', $today) - ->update(['login_count' => $loginCount, 'updated_at' => date('Y-m-d H:i:s')]); - } else { - // 插入新记录 - UserStatistics::insert([ - 'login_count' => $loginCount, - 'register_count' => 0, // 假设注册人数统计在其他地方处理 - 'record_date' => $today, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ]); - } - - } -} diff --git a/app/common.php b/app/common.php index 49aab54..c6d5303 100755 --- a/app/common.php +++ b/app/common.php @@ -12,18 +12,99 @@ if (!function_exists('getRandStr')) { function getRandStr($len = 30, $special = false) { $chars = array( - "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", - "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", - "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", - "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", - "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", - "3", "4", "5", "6", "7", "8", "9" + "a", + "b", + "c", + "d", + "e", + "f", + "g", + "h", + "i", + "j", + "k", + "l", + "m", + "n", + "o", + "p", + "q", + "r", + "s", + "t", + "u", + "v", + "w", + "x", + "y", + "z", + "A", + "B", + "C", + "D", + "E", + "F", + "G", + "H", + "I", + "J", + "K", + "L", + "M", + "N", + "O", + "P", + "Q", + "R", + "S", + "T", + "U", + "V", + "W", + "X", + "Y", + "Z", + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9" ); if ($special) { $chars = array_merge($chars, array( - "!", "@", "#", "$", "?", "|", "{", "/", ":", ";", - "%", "^", "&", "*", "(", ")", "-", "_", "[", "]", - "}", "<", ">", "~", "+", "=", ",", "." + "!", + "@", + "#", + "$", + "?", + "|", + "{", + "/", + ":", + ";", + "%", + "^", + "&", + "*", + "(", + ")", + "-", + "_", + "[", + "]", + "}", + "<", + ">", + "~", + "+", + "=", + ",", + "." )); } $charsLen = count($chars) - 1; @@ -86,14 +167,14 @@ if (!function_exists('imageUrl')) { if ($url == '') { return ''; } - + if (strpos($url, 'http') !== false) { $path = $url; - } + } // else if (strpos($pre, '192.168') !== false) {#测试环境 // $path = $pre . "ceshi/public/" . $url; // } - else{ + else { $pre = request()->domain(); if ($url === '0') { $path = $pre; @@ -101,7 +182,7 @@ if (!function_exists('imageUrl')) { $path = $pre . $url; } } - + $path = str_replace('\\', '/', $path); return $path; @@ -117,11 +198,16 @@ if (!function_exists('contentUrl')) { function contentUrl($content) { $url = request()->domain() . '/'; + // $url="https://mh.shhuanmeng.com/"; // if (strpos($url, '192.168') !== false) {#测试环境 // $url = $url . "ceshi/public/"; // } - $pregRule = "/<[img|IMG].*?src=[\‘|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\‘|\"].*?[\/]?>/"; - $content = preg_replace($pregRule, '', htmlspecialchars_decode($content)); + $pregRule = "/]*src=[\"'](?!http|https)([^\"']+\.(?:jpg|jpeg|png|gif|bmp))[\"'][^>]*>/i"; + + // 替换相对路径的图片 + $content = preg_replace_callback($pregRule, function ($matches) use ($url) { + return ''; + }, htmlspecialchars_decode($content)); return $content; } } @@ -198,12 +284,68 @@ if (!function_exists('getPrizeCode')) { function getPrizeCode($len = 10, $special = false) { $chars = array( - "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", - "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", - "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", - "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", - "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", - "3", "4", "5", "6", "7", "8", "9" + "a", + "b", + "c", + "d", + "e", + "f", + "g", + "h", + "i", + "j", + "k", + "l", + "m", + "n", + "o", + "p", + "q", + "r", + "s", + "t", + "u", + "v", + "w", + "x", + "y", + "z", + "A", + "B", + "C", + "D", + "E", + "F", + "G", + "H", + "I", + "J", + "K", + "L", + "M", + "N", + "O", + "P", + "Q", + "R", + "S", + "T", + "U", + "V", + "W", + "X", + "Y", + "Z", + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9" ); $charsLen = count($chars) - 1; shuffle($chars); //打乱数组顺序 @@ -366,7 +508,7 @@ if (!function_exists('expressWuliu')) { $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); list($header, $body) = explode("\r\n\r\n", $out_put, 2); if ($httpCode == 200) { -// print("正常请求计费(其他均不计费)
"); + // print("正常请求计费(其他均不计费)
"); // print($body); $body = json_decode($body, true); if ($body['status'] == 0 && $body['msg'] == 'ok') { @@ -376,34 +518,34 @@ if (!function_exists('expressWuliu')) { } } else { if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) { -// print("参数错误"); + // print("参数错误"); return ['code' => 0, 'msg' => '参数错误']; } elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) { -// print("AppCode错误"); + // print("AppCode错误"); return ['code' => 0, 'msg' => 'AppCode错误']; } elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) { -// print("请求的 Method、Path 或者环境错误"); + // print("请求的 Method、Path 或者环境错误"); return ['code' => 0, 'msg' => '请求的 Method、Path 或者环境错误']; } elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) { -// print("服务未被授权(或URL和Path不正确)"); + // print("服务未被授权(或URL和Path不正确)"); return ['code' => 0, 'msg' => '服务未被授权(或URL和Path不正确)']; } elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) { -// print("套餐包次数用完"); + // print("套餐包次数用完"); return ['code' => 0, 'msg' => '套餐包次数用完']; } elseif ($httpCode == 500) { -// print("API网关错误"); + // print("API网关错误"); return ['code' => 0, 'msg' => 'API网关错误']; } elseif ($httpCode == 0) { -// print("URL错误"); + // print("URL错误"); return ['code' => 0, 'msg' => 'URL错误']; } else { -// print("参数名错误 或 其他错误"); + // print("参数名错误 或 其他错误"); // print($httpCode); return ['code' => 0, 'msg' => '参数名错误 或 其他错误']; $headers = explode("\r\n", $header); @@ -412,7 +554,7 @@ if (!function_exists('expressWuliu')) { $value = explode(':', $head); $headList[$value[0]] = $value[1]; } - print($headList['x-ca-error-message']); + print ($headList['x-ca-error-message']); } } } @@ -492,7 +634,7 @@ if (!function_exists('time_jian')) { * @param $url 图片路径 * @return int */ - function time_jian($star_time,$end_time) + function time_jian($star_time, $end_time) { // 计算两个时间戳之间的差值(单位:秒) $timeDiff = $end_time - $star_time; @@ -503,16 +645,16 @@ if (!function_exists('time_jian')) { $hours = floor(($timeDiff / (60 * 60)) % 24); $days = floor($timeDiff / (60 * 60 * 24)); $str = ''; - if ($days){ + if ($days) { $str .= "{$days}天"; } - if ($hours){ + if ($hours) { $str .= "{$hours}小时"; } - if ($minutes){ + if ($minutes) { $str .= "{$minutes}分钟"; } - if ($seconds){ + if ($seconds) { $str .= "{$seconds}秒"; } return $str; @@ -520,45 +662,47 @@ if (!function_exists('time_jian')) { } // 订单支付日志 -function writelog($filename,$content){ +function writelog($filename, $content) +{ $date = date('Y-m-d'); - $file = "./pay_log/".$date; - if(!is_dir($file)){ + $file = "./pay_log/" . $date; + if (!is_dir($file)) { mkdir($file); } - $file = $file."/".$filename.".txt"; - $content = "【收到信息".date("Y-m-d H:i:s",time())."】".$content."\r\n\r\n"; - $open=fopen($file,"a" ); - fwrite($open,$content); + $file = $file . "/" . $filename . ".txt"; + $content = "【收到信息" . date("Y-m-d H:i:s", time()) . "】" . $content . "\r\n\r\n"; + $open = fopen($file, "a"); + fwrite($open, $content); fclose($open); } //广告 -function tencent_ad_attribution($click_id,$money,$account_id,$access_token,$user_action_set_id){ -// $access_token = '80a2138abe0227598ea9ae8a2a55ba69'; +function tencent_ad_attribution($click_id, $money, $account_id, $access_token, $user_action_set_id) +{ + // $access_token = '80a2138abe0227598ea9ae8a2a55ba69'; // $user_action_set_id = 1200995945; $interface = 'user_actions/add'; $url = 'https://api.e.qq.com/v1.1/' . $interface; - $common_parameters = array ( + $common_parameters = array( 'access_token' => $access_token, 'timestamp' => time(), 'nonce' => md5(uniqid('', true)) ); - $parameters = array ( + $parameters = array( 'account_id' => $account_id, 'user_action_set_id' => $user_action_set_id, 'actions' => - array ( + array( 0 => - array ( + array( 'url' => 'ruiou.ruiouyifanshang.com', - 'external_action_id' => strtolower(md5(rand(100000,999999))) . '_complete_order_1492991000_30569088_1200995945', + 'external_action_id' => strtolower(md5(rand(100000, 999999))) . '_complete_order_1492991000_30569088_1200995945', 'action_time' => time(), 'action_type' => 'COMPLETE_ORDER', -// 'custom_action' => 'my_type', + // 'custom_action' => 'my_type', 'trace' => [ 'click_id' => $click_id, ], @@ -569,7 +713,7 @@ function tencent_ad_attribution($click_id,$money,$account_id,$access_token,$user ), ), ); - // dd($parameters); + // dd($parameters); // dump($common_parameters); $parameters = json_encode($parameters); @@ -594,29 +738,30 @@ function tencent_ad_attribution($click_id,$money,$account_id,$access_token,$user throw new \Exception($error_msg, $error_no); } curl_close($curl); - \think\facade\Log::write($response,'warning'); + \think\facade\Log::write($response, 'warning'); return $response; - + } - function getData($url,$header){ +function getData($url, $header) +{ - $ch = curl_init(); - - curl_setopt($ch,CURLOPT_URL,$url); - - curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1); - - curl_setopt($ch,CURLOPT_HTTPHEADER,$header); - - curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); - - curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,3); - - $handles = curl_exec($ch); - - curl_close($ch); - - return $handles; - } \ No newline at end of file + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); + + $handles = curl_exec($ch); + + curl_close($ch); + + return $handles; +} \ No newline at end of file diff --git a/config/console.php b/config/console.php index 314b903..8a87421 100755 --- a/config/console.php +++ b/config/console.php @@ -4,5 +4,6 @@ return [ 'RankWeek' => 'app\command\RankWeek',#周榜定榜 'RankMonth' => 'app\command\RankMonth',#月榜定榜 'Zd' => 'app\command\Zd',#自动发货 + 'UserStatisticsDay' => 'app\command\UserStatisticsDay',#自动发货 ], ]; diff --git a/config/menu.php b/config/menu.php index 98bd45f..1c83981 100755 --- a/config/menu.php +++ b/config/menu.php @@ -84,6 +84,10 @@ return [ 'url' => '/admin/ProfitRvenue', 'name' => '其它收入', ], + [ + 'url' => '/admin/user_statistics', + 'name' => '数据统计', + ], ], ], [