Browse Source

fix:邀请记录

super-yimizi 11 hours ago
parent
commit
731ad13a1a

+ 4 - 4
application/api/controller/Withdraw.php

@@ -17,7 +17,7 @@ class Withdraw extends Base
     {
         $params = $this->request->param();
         
-        // 使用验证器验证查询参数:status, page, page_size
+        // 使用验证器验证查询参数:status, page, page_size, year_month
         $validate = new WithdrawValidate();
         if (!$validate->scene('index')->check($params)) {
             $this->error($validate->getError());
@@ -26,10 +26,10 @@ class Withdraw extends Base
         $user = auth_user();
         $withdrawService = new WithdrawService($user);
         
-        // 通过服务获取提现记录列表
-        $withdraws = $withdrawService->getWithdrawList($params);
+        // 通过服务获取提现记录列表,包含年月筛选和总金额统计
+        $result = $withdrawService->getWithdrawList($params);
 
-        $this->success('获取成功', $withdraws);
+        $this->success('获取成功', $result);
     }
 
 

+ 0 - 2
application/api/controller/third/Wechat.php

@@ -153,8 +153,6 @@ class Wechat extends Base
     {
         $mp = $this->wechat->getApp();
         $path = $this->payload['path'];
-        
-        // 这里要处理下 如果没有穿$path  默认 pages/me/edit  spm的参数是 
         list($page, $scene) = explode('?', $path);
         $content = $mp->app_code->getUnlimit($scene, [
             'page' => substr($page, 1),

+ 5 - 5
application/api/validate/User.php

@@ -11,7 +11,7 @@ class User extends Validate
     public function __construct(array $rules = [], $message = [], $field = [])
     {
         // 动态设置枚举值
-        $this->rule['gender'] = 'require|in:' .implode(',', UserEnum::getGenderList());
+        $this->rule['gender'] = 'in:' .implode(',', UserEnum::getGenderList());
         parent::__construct($rules, $message, $field);
     }
     /**
@@ -20,9 +20,9 @@ class User extends Validate
     protected $rule = [
         'account'   => 'require|length:3,30',
         'username'  => 'length:3,30',
-        'nickname'  => 'require|length:3,30',
-        'password'  => 'require|length:6,30',
-        'mobile'    => 'require|regex:/^1\d{10}$/',
+        'nickname'  => 'length:3,30',
+        'password'  => 'length:6,30',
+        'mobile'    => 'regex:/^1\d{10}$/',
         'email'     => 'email',
         // 验证头像  验证文件后缀
 
@@ -37,7 +37,7 @@ class User extends Validate
         'balance'   => 'float|egt:0',
         'score'     => 'integer|egt:0',
         'level'     => 'integer|egt:0',
-        'age'       => 'require|integer|egt:0|elt:200', 
+        'age'       => 'integer|egt:0|elt:200', 
         'captcha'   => 'require|length:4,6'
     ];
 

+ 38 - 1
application/api/validate/Withdraw.php

@@ -14,6 +14,7 @@ class Withdraw extends Validate
         'status' => 'integer|in:-3,-2,-1,0,1,2',
         'page' => 'integer|egt:1',
         'page_size' => 'integer|between:1,100',
+        'year_month' => 'checkYearMonth',
     ];
 
     protected $message = [
@@ -32,13 +33,49 @@ class Withdraw extends Validate
         'page.egt' => '页码必须大于等于1',
         'page_size.integer' => '分页大小必须为整数',
         'page_size.between' => '分页大小必须在1-100之间',
+        'year_month.checkYearMonth' => '年月格式错误,请使用YYYY-MM格式,如2025-08',
     ];
 
     protected $scene = [
-        'index' => ['status', 'page', 'page_size'],
+        'index' => ['status', 'page', 'page_size', 'year_month'],
         'apply' => ['type', 'amount', 'account_id'],
         'transfer' => ['type', 'withdraw_sn'],
         'retry' => ['type', 'withdraw_sn'],
         'cancel' => ['type', 'withdraw_sn'],
     ];
+    
+    /**
+     * 验证年月格式 (YYYY-MM)
+     * @param string $value
+     * @param string $rule
+     * @param array $data
+     * @return bool|string
+     */
+    protected function checkYearMonth($value, $rule, $data)
+    {
+        if (empty($value)) {
+            return true; // 允许为空
+        }
+        
+        // 验证格式 YYYY-MM
+        if (!preg_match('/^\d{4}-\d{2}$/', $value)) {
+            return '年月格式错误,请使用YYYY-MM格式,如2025-08';
+        }
+        
+        list($year, $month) = explode('-', $value);
+        $year = (int)$year;
+        $month = (int)$month;
+        
+        // 验证年份范围(不限制具体范围,只要是4位数字即可)
+        if ($year < 1000 || $year > 9999) {
+            return '年份必须是4位数字';
+        }
+        
+        // 验证月份范围
+        if ($month < 1 || $month > 12) {
+            return '月份必须在01-12之间';
+        }
+        
+        return true;
+    }
 }

+ 62 - 7
application/common/Service/Withdraw.php

@@ -45,23 +45,63 @@ class Withdraw
     /**
      * 获取用户提现记录列表
      * @param array $params 查询参数
-     * @return \think\Paginator
+     * @return array 包含列表数据和统计信息
      */
     public function getWithdrawList($params = [])
     {
-        // 构建查询条件
-        $where = ['user_id' => $this->user->id];
+        // 构建查询条件数组
+        $arrWhere = ['user_id' => $this->user->id];
         
         // 状态筛选
         if (isset($params['status']) && $params['status'] !== '') {
-            $where['status'] = (int)$params['status'];
+            $arrWhere['status'] = (int)$params['status'];
+        }
+        
+        // 年月筛选 (支持YYYY-MM格式)
+        $timeWhere = [];
+        if (isset($params['year_month']) && !empty($params['year_month'])) {
+            $yearMonth = trim($params['year_month']);
+            
+            // 解析年月字符串 (YYYY-MM)
+            if (preg_match('/^(\d{4})-(\d{2})$/', $yearMonth, $matches)) {
+                $year = (int)$matches[1];
+                $month = (int)$matches[2];
+                
+                // 按年月筛选
+                $startTime = mktime(0, 0, 0, $month, 1, $year);
+                $endTime = mktime(23, 59, 59, $month + 1, 0, $year);
+                
+                $timeWhere = [
+                    'createtime' => ['between', [$startTime, $endTime]]
+                ];
+            }
+        }
+        
+        // 合并查询条件
+        $finalWhere = array_merge($arrWhere, $timeWhere);
+        
+        // 计算筛选条件下的总金额(使用BC数学函数)
+        $totalAmount = '0.00';
+        $totalChargeAmount = '0.00';
+        $totalActualAmount = '0.00';
+        $totalCount = 0;
+        
+        // 执行统计查询
+        $statsRecords = WithdrawModel::where($finalWhere)->field(['amount', 'charge_fee'])->select();
+        
+        foreach ($statsRecords as $record) {
+            $totalAmount = BcMath::add($totalAmount, $record->amount, 2);
+            $totalChargeAmount = BcMath::add($totalChargeAmount, $record->charge_fee, 2);
+            $actualAmount = BcMath::sub($record->amount, $record->charge_fee, 2);
+            $totalActualAmount = BcMath::add($totalActualAmount, $actualAmount, 2);
+            $totalCount++;
         }
         
         // 分页参数
         $page_size = isset($params['page_size']) ? (int)$params['page_size'] : 10;
         
-        // 查询提现记录
-        $withdraws = WithdrawModel::where($where)
+        // 查询提现记录(使用相同的查询条件)
+        $withdraws = WithdrawModel::where($finalWhere)
             ->order('id desc')
             ->paginate($page_size)
             ->each(function ($withdraw) {
@@ -69,7 +109,22 @@ class Withdraw
                 $withdraw->hidden(['withdraw_info']);
             });
 
-        return $withdraws;
+        // 组装返回数据
+        $result = [
+            'list' => $withdraws,
+            'summary' => [
+                'total_count' => $totalCount,
+                'total_amount' => $totalAmount,
+                'total_charge_amount' => $totalChargeAmount,  
+                'total_actual_amount' => $totalActualAmount,
+                'filter_info' => [
+                    'year_month' => isset($params['year_month']) ? $params['year_month'] : null,
+                    'status' => isset($params['status']) ? (int)$params['status'] : null,
+                ]
+            ]
+        ];
+
+        return $result;
     }
 
     /**

+ 1 - 87
application/common/model/user/Share.php

@@ -33,93 +33,7 @@ class Share extends Model
         return ShareEnum::getFromText($value);
     }
 
-    public static function log(Object $user, $params)
-    {
-
-        // 错误的分享参数
-        if (empty($params['spm'])) {
-            return false;
-        }
-
-        $shareId = $params['shareId'];
-        // 分享用户为空
-        if ($shareId <= 0) {
-            return false;
-        }
-
-        // 不能分享给本人
-        if ($shareId == $user->id) {
-            return false;
-        }
-
-        // 新用户不能分享给老用户 按需打开
-        // if($user->id < $shareId) {
-        //   return false;
-        // }
-
-        $shareUser = UserModel::where('id', $shareId)->find();
-        // 分享人不存在
-        if (!$shareUser) {
-            return false;
-        }
-
-        // 5分钟内相同的分享信息不保存,防止冗余数据
-        $lastShareLog = self::where([
-            'user_id' => $user->id
-        ])->where('createtime', '>', time() - 300)->order('id desc')->find();
-
-        if ($lastShareLog && $lastShareLog->spm === $params['spm']) {
-            return $lastShareLog;
-        }
-
-        $memoText = '通过' . ShareEnum::getFromText($params['from']) . '访问了';
-        if ($params['page'] == '/pages/index/index') {
-            $memoText .= '首页';
-        }
-        if ($params['page'] === '/pages/goods/index') {
-            $memoText .= '商品';
-            $goodsId = $params['query']['id'];
-        }
-        if ($params['page'] === '/pages/goods/groupon') {
-            $memoText .= '拼团商品';
-            $goodsId = $params['query']['id'];
-        }
-        if ($params['page'] === '/pages/goods/seckill') {
-            $memoText .= '秒杀商品';
-            $goodsId = $params['query']['id'];
-        }
-        if ($params['page'] === '/pages/activity/groupon/detail') {
-            $memoText .= '拼团活动';
-        }
-
-        if (!empty($goodsId)) {
-            $goods = GoodsModel::find($goodsId);
-            if ($goods) {
-                $memoText .= "[{$goods->title}]";
-            }
-        }
-
-        $ext = [
-            'image' => $goods->image ?? "",
-            'memo' => $memoText
-        ];
-
-        $shareInfo = self::create([
-            'user_id' => $user->id,
-            'share_id' => $shareId,
-            'spm' => $params['spm'],
-            'page' => $params['page'],
-            'query' => http_build_query($params['query']),
-            'platform' => $params['platform'],
-            'from' => $params['from'],
-            'ext' => $ext
-        ]);
-
-        $data = ['shareInfo' => $shareInfo];
-        \think\Hook::listen('user_share_after', $data);
-
-        return $shareInfo;
-    }
+ 
 
 
     // -- commission code start --