瀏覽代碼

1. 封禁功能
2. 订单记录

ith5 6 月之前
父節點
當前提交
543c6d1469

+ 24 - 0
app/v1/controller/customer/AccountController.php

@@ -74,4 +74,28 @@ class AccountController extends BaseController
         $data = $this->logic->updateReal($data);
         return $this->success();
     }
+
+    /**
+     * 封禁列表
+     */
+    public function getBanList(Request $request){
+        $where = $request->more([
+            ['action', '']
+        ]);
+        $query = $this->logic->search($where);
+        $data = $this->logic->getBanList($query);
+        return $this->success($data);
+    }
+
+    /**
+     * 添加/解除封禁
+     */
+    public function saveBan(Request $request): Response
+    {
+        $data = $request->post();
+        $info = getCurrentInfo();
+        $data['auth_id'] = $info['id'];
+        $data = $this->logic->saveBan($data);
+        return $this->success();
+    }
 }

+ 72 - 0
app/v1/controller/customer/SdkOrderController.php

@@ -0,0 +1,72 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\controller\customer;
+
+use plugin\saiadmin\basic\BaseController;
+use app\v1\logic\customer\SdkOrderLogic;
+use app\v1\validate\customer\SdkOrderValidate;
+use support\Request;
+use support\Response;
+
+/**
+ * 用户订单记录控制器
+ */
+class SdkOrderController extends BaseController
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->logic = new SdkOrderLogic();
+        $this->validate = new SdkOrderValidate;
+        parent::__construct();
+    }
+
+    /**
+     * 数据列表
+     * @param Request $request
+     * @return Response
+     */
+    public function index(Request $request): Response
+    {
+        $where = $request->more([
+            ['orderid', ''],
+            ['tradeid', ''],
+            ['game_id', ''],
+            ['user_name', ''],
+            ['role_id', ''],
+            ['pay_date', ''],
+            ['orderBy', ''],
+            ['orderType', ''],
+            ['page',''],
+            ['limit','']
+        ]);
+        // 账号名|订单号|交易订单号 不能同时为空
+        if(empty($where['user_name']) && empty($where['orderid']) && empty($where['tradeid'])){
+            return $this->fail('账号名|订单号|交易订单号 不能同时为空');
+        }
+        // $query = $this->logic->search($where);
+        // $data = $this->logic->getList($query);
+        $data = $this->logic->getOrderList($where);
+        return $this->success($data);
+    }
+
+    /**
+     * 补发
+     * @param Request $request
+     * @return Response
+     */
+
+    public function send(Request $request): Response
+    {
+        $orderid = $request->input('orderid');
+        $data = $this->logic->send($orderid);
+        return $this->success($data);
+    }
+
+}

+ 59 - 0
app/v1/logic/customer/AccountLogic.php

@@ -10,12 +10,15 @@ use plugin\saiadmin\basic\BaseLogic;
 use plugin\saiadmin\exception\ApiException;
 use plugin\saiadmin\utils\Helper;
 use app\v1\model\customer\Account;
+
+use support\Redis;
 use support\think\Db;
 
 /**
  * 账号信息逻辑层
  */
 class AccountLogic extends BaseLogic
+
 {
     /**
      * 构造函数
@@ -102,4 +105,60 @@ class AccountLogic extends BaseLogic
         $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['real_name' => $data['real_name'], 'id_card' => $data['id_card']]);
         return $result;
     }
+
+    /**
+     * 封禁列表 
+     */
+    public function getBanList($query)
+    {
+        $saiType = request()->input('saiType', 'list');
+        $page = request()->input('page', 1);
+        $limit = request()->input('limit', 10);
+        $orderBy = request()->input('orderBy', '');
+        $orderType = request()->input('orderType', $this->orderType);
+        if(empty($orderBy)) {
+            $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
+        }
+        if ($saiType === 'all') {
+            $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->select()->toArray();
+        }
+        $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->paginate($limit, false, ['page' => $page])->toArray();
+
+
+        $data['data'] = array_map(function($item) {
+            $item['action'] = $item['action'] == 1 ? '封禁' : '解封';
+            $item['type'] = $item['type'] == 1 ? 'UID' : ($item['type'] == 2 ? 'IP' : '设备');
+            return $item;
+        }, $data['data']);
+        $data['data'] = $this->trandformListColumn($data['data'],['auth']);
+       return $data;
+    }
+
+    /**
+     * 添加/解除封禁
+     */
+    public function saveBan($data)
+    {
+        $type = $data['type']; // 封禁类型
+        $value = $data['value']; // 封禁值
+        $action = $data['action']; // 操作
+        $reason = $data['reason']; // 理由
+        $auth_id = $data['auth_id']; // 操作人
+
+
+        $data = Db::connect('db_game_log')->table('ban_log')->insert([
+            'type' => $type,
+            'value' => $value,
+            'action' => $action,
+            'reason' => $reason,
+            'auth_id' => $auth_id,
+        ]);
+        // 如果成功插入,则更新redis
+        if($data){
+            $key = $type==1 ? 'ban_uid' : ($type==2 ? 'ban_ip' : ($type==3 ? 'ban_device' : ''));
+            $value = explode(',', $value);
+            $action == 1 ? Redis::sAdd($key, ...$value) : Redis::sRem($key, ...$value);
+        }
+        return $data;
+    }
 }

+ 152 - 0
app/v1/logic/customer/SdkOrderLogic.php

@@ -0,0 +1,152 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\logic\customer;
+
+use plugin\saiadmin\basic\BaseLogic;
+use plugin\saiadmin\exception\ApiException;
+use plugin\saiadmin\utils\Helper;
+use app\v1\model\customer\SdkOrder;
+use DateTime;
+use support\Redis;
+use support\think\Db;
+
+/**
+ * 用户订单记录逻辑层
+ */
+class SdkOrderLogic extends BaseLogic
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->model = new SdkOrder();
+    }
+
+    /**
+     * 获取年月
+     */
+    public function queryOrdersByDateRange($start, $end)
+    {
+            $start = new DateTime($start);
+            $end = new DateTime($end);
+            $end->modify('first day of next month');
+
+            $months = [];
+            while ($start < $end) {
+                $months[] = $start->format('Ym'); // 例如 202505
+                $start->modify('+1 month');
+            }
+            return $months;
+    }
+
+    /**
+     * 获取订单列表
+     */
+    public function getOrderList($where)
+    {
+    $startDate = $where['pay_date'][0];
+    $endDate = $where['pay_date'][1];
+    $page       = max(1, (int)($where['page'] ?? 1));
+    $limit      = max(1, (int)($where['limit'] ?? 10));
+    $offset     = ($page - 1) * $limit;
+    $orderBy =   $where['orderBy'] ? $where['orderBy'] : 'pay_date';
+    $orderType = $where['orderType'] ? $where['orderType'] : 'DESC';
+    $orderBy = $orderBy . ' ' . $orderType;
+
+       // 获取年月
+        $table_name_array = $this->queryOrdersByDateRange($startDate, $endDate);
+       
+        // 合并表 union all
+        
+        $where_sql = "";
+        if(!empty($where['game_id'])){
+            $where_sql .= " AND game_id IN({$where['game_id']})";
+        }
+        if(!empty($where['user_name'])){
+            $where_sql .= " AND user_name = '{$where['user_name']}'";
+        }
+        if(!empty($where['order_id'])){
+            $where_sql .= " AND order_id = '{$where['order_id']}'";
+        }
+        if(!empty($where['trade_id'])){
+            $where_sql .= " AND trade_id = '{$where['trade_id']}'";
+        }
+        if(!empty($where['role_id'])){
+            $where_sql .= " AND role_id = '{$where['role_id']}'";
+        }
+        if(!empty($where['role_name'])){
+            $where_sql .= " AND role_name = '{$where['role_name']}'";
+        }
+        if(!empty($where['pay_date'])){
+            $where_sql .= " AND pay_date BETWEEN '{$startDate} 00:00:00' AND '{$endDate} 23:59:59'";
+        }
+        $sql_parts = [];
+        foreach($table_name_array as $table_name){
+            // 安全过滤,避免 SQL 注入
+            if (!preg_match('/^\d{6}$/', $table_name)) {
+                continue;
+            }
+            $sql_parts[] = "SELECT * FROM sdk_order_{$table_name} WHERE 1=1 {$where_sql}";
+        }
+        if (empty($sql_parts)) {
+            return []; // 或抛异常,或返回空结果
+        }
+
+        $unionSql = implode(" UNION ALL ", $sql_parts);
+
+        // 外层包裹分页、排序
+        $finalSql = "
+            SELECT * FROM ( {$unionSql} ) AS all_orders
+            ORDER BY {$orderBy}
+            LIMIT {$offset}, {$limit}
+        ";
+
+        // 统计总数(用于分页)
+        $countSql = "
+            SELECT COUNT(*) AS total FROM ( {$unionSql} ) AS count_orders
+        ";
+
+        // 总金额查询
+        $sumSql = "
+            SELECT ROUND(SUM(money), 2) AS money_sum FROM (
+                {$unionSql}
+            ) AS sum_orders
+        ";
+    
+        $count = Db::connect('db_game_log')->query($countSql)[0]['total'] ?? 0;
+
+        $data = Db::connect('db_game_log')->query($finalSql);
+
+        $moneySum   = Db::connect('db_game_log')->query($sumSql)[0]['money_sum'] ?? 0;
+
+        $data = $this->trandformListColumn($data,['game','pay_channel']);
+
+
+        return [
+            'total'         => $count,
+            'current_page'  => $page,
+            'per_page'      => $limit,
+            'last_page'     => ceil($count / $limit),
+            'has_more'      => $page < ceil($count / $limit),
+            'data'          => $data,
+            'totalRow'     => $moneySum
+        ];
+   
+   
+   
+    }
+
+    /**
+     * 补发
+     */
+    public function send($orderid)
+    {
+      $res = Redis::lpush("request_cp_callback_queue", $orderid);
+      return $res;
+    }
+}

+ 42 - 0
app/v1/model/customer/SdkOrder.php

@@ -0,0 +1,42 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\model\customer;
+
+use plugin\saiadmin\basic\BaseNormalModel;
+
+/**
+ * 用户订单记录模型
+ */
+class SdkOrder extends BaseNormalModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 数据库表名称
+     * @var string
+     */
+    protected $table = 'sdk_order_202507';
+
+    /**
+     * 数据库连接
+     * @var string
+     */
+    protected $connection = 'db_game_log';
+
+    /**
+     * 支付时间 搜索
+     */
+    public function searchPayDateAttr($query, $value)
+    {
+        $query->whereTime('pay_date', 'between', $value);
+    }
+
+}

+ 122 - 0
app/v1/validate/customer/SdkOrderValidate.php

@@ -0,0 +1,122 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\validate\customer;
+
+use think\Validate;
+
+/**
+ * 用户订单记录验证器
+ */
+class SdkOrderValidate extends Validate
+{
+    /**
+     * 定义验证规则
+     */
+    protected $rule =   [
+        'orderid' => 'require',
+        'cp_orderid' => 'require',
+        'pay_channel' => 'require',
+        'money' => 'require',
+        'paid_amount' => 'require',
+        'game_id' => 'require',
+        'media_id' => 'require',
+        'auth_id' => 'require',
+        'agent_id' => 'require',
+        'site_id' => 'require',
+        'uid' => 'require',
+        'user_name' => 'require',
+        'user_ip' => 'require',
+        'server_id' => 'require',
+        'server_name' => 'require',
+        'role_name' => 'require',
+        'payname' => 'require',
+        'pay_date' => 'require',
+        'sync_status' => 'require',
+        'send_status' => 'require',
+        'product_name' => 'require',
+    ];
+
+    /**
+     * 定义错误信息
+     */
+    protected $message  =   [
+        'orderid' => '订单号必须填写',
+        'cp_orderid' => '研发订单号必须填写',
+        'pay_channel' => '充值方式必须填写',
+        'money' => '金额必须填写',
+        'paid_amount' => '净额必须填写',
+        'game_id' => '充值游戏必须填写',
+        'media_id' => '媒体ID必须填写',
+        'auth_id' => '负责人ID必须填写',
+        'agent_id' => '渠道ID必须填写',
+        'site_id' => '广告位ID必须填写',
+        'uid' => 'UID必须填写',
+        'user_name' => '充值账号必须填写',
+        'user_ip' => '充值IP必须填写',
+        'server_id' => '服务器ID必须填写',
+        'server_name' => '充值区服必须填写',
+        'role_name' => '角色名必须填写',
+        'payname' => '必须填写',
+        'pay_date' => '支付时间必须填写',
+        'sync_status' => '支付状态必须填写',
+        'send_status' => '发货状态必须填写',
+        'product_name' => '充值商品名必须填写',
+    ];
+
+    /**
+     * 定义场景
+     */
+    protected $scene = [
+        'save' => [
+            'orderid',
+            'cp_orderid',
+            'pay_channel',
+            'money',
+            'paid_amount',
+            'game_id',
+            'media_id',
+            'auth_id',
+            'agent_id',
+            'site_id',
+            'uid',
+            'user_name',
+            'user_ip',
+            'server_id',
+            'server_name',
+            'role_name',
+            'payname',
+            'pay_date',
+            'sync_status',
+            'send_status',
+            'product_name',
+        ],
+        'update' => [
+            'orderid',
+            'cp_orderid',
+            'pay_channel',
+            'money',
+            'paid_amount',
+            'game_id',
+            'media_id',
+            'auth_id',
+            'agent_id',
+            'site_id',
+            'uid',
+            'user_name',
+            'user_ip',
+            'server_id',
+            'server_name',
+            'role_name',
+            'payname',
+            'pay_date',
+            'sync_status',
+            'send_status',
+            'product_name',
+        ],
+    ];
+
+}

+ 7 - 1
plugin/saiadmin/basic/BaseLogic.php

@@ -270,7 +270,7 @@ class BaseLogic
      * @param $fields
      * @return mixed
      */
-    public function trandformListColumn($data, $fields=['site', 'agent', 'game', 'auth', 'media', 'package']){
+    public function trandformListColumn($data, $fields=['site', 'agent', 'game', 'auth', 'media', 'package', 'pay_channel']){
 
         if(in_array('site', $fields)){
             $agentSiteList = Db::connect('db_advert')->table('agent_site')->field('id,name')->select()->toArray();
@@ -301,6 +301,11 @@ class BaseLogic
             $packageList = array_column($packageList, 'name', 'id');
         }
 
+        if(in_array('pay_channel', $fields)){
+            $payChannelList = Db::connect('db_center')->table('pay_channel')->field('id,name')->where('status',1)->select()->toArray();
+            $payChannelList = array_column($payChannelList, 'name', 'id');
+        }
+
 
         foreach ($data as $key => $value) {
     
@@ -310,6 +315,7 @@ class BaseLogic
             $data[$key]['auth_name'] = !empty($authList) ? $authList[$value['auth_id']] ?? '':'';
             $data[$key]['media_name'] = !empty($mediaList) ? $mediaList[$value['media_id']] ?? '':'';
             $data[$key]['package_name'] = !empty($packageList) ? $packageList[$value['package_id']] ?? '':'';
+            $data[$key]['pay_channel_name'] = !empty($payChannelList) ? $payChannelList[$value['pay_channel']] ?? '':'';
         }
         return $data;
     }