diff --git a/app/app.zip b/app/app.zip
new file mode 100644
index 0000000..2b5f3df
Binary files /dev/null and b/app/app.zip differ
diff --git a/app/controller/PayManageController.php b/app/controller/PayManageController.php
index 12e224f..d024af5 100644
--- a/app/controller/PayManageController.php
+++ b/app/controller/PayManageController.php
@@ -74,4 +74,9 @@ class PayManageController extends BaseController
View::assign(['id' => $id]);
return View::fetch();
}
+ // 收款统计
+ public function payStatistics()
+ {
+ return View::fetch();
+ }
}
diff --git a/app/controller/api/PayManageController.php b/app/controller/api/PayManageController.php
index 0cdf5b6..391591c 100644
--- a/app/controller/api/PayManageController.php
+++ b/app/controller/api/PayManageController.php
@@ -7,6 +7,8 @@ namespace app\controller\api;
use app\BaseController;
use app\model\PayAccount;
use app\model\PayChannel;
+use app\model\Order;
+use think\facade\Db;
use \think\facade\Log;
class PayManageController extends BaseController
@@ -208,4 +210,73 @@ class PayManageController extends BaseController
return json(['code' => 1, 'msg' => $records['msg']]);
}
}
+
+ public function payStatisticsList()
+ {
+ $query = $this->request->get();
+ $limit = $query['limit'] ?? 10;
+ $page = $query['page'] ?? 1;
+ $start_time = $query['time_start'] ?? date('Y-m-d H:i:s', strtotime('today'));
+ $end_time = $query['time_end'] ?? date('Y-m-d H:i:s', strtotime('tomorrow') - 1);
+ // 确保日期时间格式正确
+ $start_time = date('Y-m-d H:i:s', strtotime($start_time));
+ $end_time = date('Y-m-d H:i:s', strtotime($end_time));
+
+ $accounts = Db::table('mpay_pay_account', 'PayAccount')
+ ->alias('PayAccount')
+ ->join('mpay_order Order', 'PayAccount.id = Order.aid AND Order.delete_time IS NULL AND Order.state = 1', 'LEFT')
+ ->field([
+ 'PayAccount.*',
+ 'SUM(CASE WHEN DATE(Order.pay_time) = CURDATE() THEN Order.really_price ELSE 0 END) as day',
+ 'SUM(CASE WHEN DATE(Order.pay_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY) THEN Order.really_price ELSE 0 END) as yesterday',
+ 'SUM(CASE WHEN YEARWEEK(Order.pay_time, 1) = YEARWEEK(CURDATE(), 1) THEN Order.really_price ELSE 0 END) as week',
+ 'SUM(CASE WHEN DATE_FORMAT(Order.pay_time, "%Y-%m") = DATE_FORMAT(CURDATE(), "%Y-%m") THEN Order.really_price ELSE 0 END) as month',
+ 'SUM(CASE WHEN YEAR(Order.pay_time) = YEAR(CURDATE()) THEN Order.really_price ELSE 0 END) as year',
+ 'SUM(IFNULL(Order.really_price, 0)) as total',
+ "SUM(CASE WHEN Order.pay_time BETWEEN '$start_time' AND '$end_time' THEN Order.really_price ELSE 0 END) as income"
+ ])
+ ->where('PayAccount.delete_time IS NULL')
+ ->group('PayAccount.id')
+ ->order('PayAccount.id', 'DESC')
+ ->paginate(['list_rows' => $limit, 'page' => $page]);
+
+ return json([
+ 'code' => 0,
+ 'msg' => 'OK',
+ 'count' => $accounts->total(),
+ 'data' => $accounts->items()
+ ]);
+ }
+
+ // 收款统计
+ // public function payStatisticsList()
+ // {
+ // $query = $this->request->get();
+ // // 定义统计字段
+ // $fields = [
+ // "SUM(IF(DATE(pay_time) = CURDATE(), really_price, 0)) as day",
+ // "SUM(IF(DATE(pay_time) = CURDATE() - INTERVAL 1 DAY, really_price, 0)) as yesterday",
+ // "SUM(IF(YEARWEEK(pay_time, 1) = YEARWEEK(CURDATE(), 1), really_price, 0)) as week",
+ // "SUM(IF(DATE_FORMAT(pay_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m'), really_price, 0)) as month",
+ // "SUM(IF(YEAR(pay_time) = YEAR(CURDATE()), really_price, 0)) as year",
+ // "SUM(really_price) as total"
+ // ];
+
+ // $where = ['state', 1;
+
+ // // 合并 pay_account 表字段和统计字段
+ // $allFields = array_merge([PayAccount::getTable() . '.*'], $fields);
+
+ // $accounts = PayAccount::hasWhere('order', $where, '*', 'LEFT')
+ // ->field($allFields)
+ // ->group(PayAccount::getTable() . '.id')
+ // ->order('id', 'desc')
+ // ->paginate(['list_rows' => $query['limit'] ?? 10, 'page' => $query['page'] ?? 1]);
+
+ // if ($accounts) {
+ // return json(['code' => 0, 'msg' => PayAccount::getLastSql(), 'count' => $accounts->total(), 'data' => $accounts->items()]);
+ // } else {
+ // return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]);
+ // }
+ // }
}
diff --git a/app/model/Order.php b/app/model/Order.php
index 82eef1d..19183d3 100644
--- a/app/model/Order.php
+++ b/app/model/Order.php
@@ -210,6 +210,6 @@ class Order extends BaseModel
// 模型多对一关联
public function payAccount()
{
- return $this->belongsTo(PayAccount::class, 'aid', 'id');
+ return $this->belongsTo(PayAccount::class, 'id', 'aid');
}
}
diff --git a/app/model/PayAccount.php b/app/model/PayAccount.php
index 41b8f3e..285f707 100644
--- a/app/model/PayAccount.php
+++ b/app/model/PayAccount.php
@@ -24,7 +24,25 @@ class PayAccount extends BaseModel
$select[] = [$key, '=', $value];
}
}
- return self::withCount(['payChannel' => 'channel'])->where($select);
+ return self::withCount(['payChannel' => 'channel_num'])->withSum(['order' => function ($query, &$alias) {
+ $query->whereDay('pay_time')->where('state', 1);
+ $alias = 'income';
+ }], 'really_price')->where($select);
+ }
+ public static function findAccount($query)
+ {
+ $select = [];
+ $allow_field = ['state', 'platform', 'account', 'pattern'];
+ foreach ($query as $key => $value) {
+ if (in_array($key, $allow_field) && isset($value)) {
+ if ($key === 'account') {
+ $select[] = [$key, 'like', '%' . $value . '%'];
+ continue;
+ }
+ $select[] = [$key, '=', $value];
+ }
+ }
+ return self::where($select);
}
// 获取账号配置
public static function getAccountConfig($aid, $pid = null): array|bool
@@ -86,4 +104,9 @@ class PayAccount extends BaseModel
{
return $this->hasMany(PayChannel::class, 'account_id', 'id');
}
+ // 一对多关联
+ public function order()
+ {
+ return $this->hasMany(Order::class, 'aid', 'id');
+ }
}
diff --git a/extend/Plugin.php b/extend/Plugin.php
index 93e9eda..027c675 100644
--- a/extend/Plugin.php
+++ b/extend/Plugin.php
@@ -64,9 +64,9 @@ class Plugin
{
$message = cache('message');
if ($message) return $message;
- $message = self::getHttpResponse(self::$siteUrl . '/MpayApi', ['action' => 'message']);
+ $message = self::getHttpResponse(self::$siteUrl . '/MpayApi', ['action' => 'message'], [], 3);
$info = json_decode($message, true);
- if($info === null) return [];
+ if ($info === null) return [];
if ($info['code'] === 0) cache('message', $info['data'], 36000);
return $info['data'];
}
diff --git a/public/files/qrcode/img_1747104593_6822b351cab62.jpg b/public/files/qrcode/img_1747104593_6822b351cab62.jpg
new file mode 100644
index 0000000..6e391c8
Binary files /dev/null and b/public/files/qrcode/img_1747104593_6822b351cab62.jpg differ
diff --git a/view/order/index.html b/view/order/index.html
index f5541fa..a339134 100644
--- a/view/order/index.html
+++ b/view/order/index.html
@@ -219,6 +219,11 @@
let platformName = platforms[d.platform] || '已卸载';
return `${platformName} [${d.aid}:${d.cid}]`;
}
+ const urlParams = new URLSearchParams(window.location.search);
+ const where = {};
+ urlParams.forEach((value, key) => {
+ where[key] = value;
+ });
// 表格列参数
let cols = [[
{ type: 'checkbox' },
@@ -239,6 +244,7 @@
id: 'orders-table',
elem: '#orders-table',
url: '/api/Order/getOrders',
+ where: where,
page: true,
cols: cols,
skin: 'line',
diff --git a/view/pay_manage/index.html b/view/pay_manage/index.html
index 5688522..2551f5f 100644
--- a/view/pay_manage/index.html
+++ b/view/pay_manage/index.html
@@ -106,10 +106,11 @@
+
+
+