lip 8 ore fa
parent
commit
2a2df53beb
6 ha cambiato i file con 214 aggiunte e 181 eliminazioni
  1. 0 38
      .dockerignore
  2. 0 51
      Dockerfile
  3. 70 0
      app/Console/Commands/LhcSettlement.php
  4. 144 0
      app/Services/LhcSettlementService.php
  5. 0 36
      docker-compose.yml
  6. 0 56
      nginx.conf

+ 0 - 38
.dockerignore

@@ -1,38 +0,0 @@
-# 排除版本控制目录
-.git/
-.gitignore
-
-# 排除依赖目录
-vendor/
-node_modules/
-
-# 排除环境文件
-.env
-.env.local
-.env.*.local
-
-# 排除日志文件
-storage/logs/
-
-# 排除缓存文件
-bootstrap/cache/
-
-# 排除编译后的文件
-public/js/
-public/css/
-public/mix-manifest.json
-
-# 排除测试文件
-tests/
-phpunit.xml
-
-# 排除IDE配置文件
-.idea/
-.vscode/
-*.swp
-*.swo
-
-# 排除大型文件和目录
-storage/app/public/lottery/
-storage/app/public/avatars/
-storage/app/public/images/

+ 0 - 51
Dockerfile

@@ -1,51 +0,0 @@
-FROM php:8.4-fpm-alpine
-
-# 安装系统依赖
-RUN apk add --no-cache \
-    libpng-dev \
-    libjpeg-turbo-dev \
-    freetype-dev \
-    libzip-dev \
-    gmp-dev \
-    curl \
-    fontconfig \
-    tzdata \
-    && docker-php-ext-configure gd --with-freetype --with-jpeg \
-    && docker-php-ext-install -j$(nproc) \
-    gd \
-    gmp \
-    bcmath \
-    fileinfo \
-    zip \
-    pdo_mysql \
-    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
-    && echo "Asia/Shanghai" > /etc/timezone
-
-# 注意:openssl和curl是PHP内置扩展,不需要单独安装
-
-# 设置工作目录
-WORKDIR /var/www/html
-
-# 复制项目文件
-COPY . .
-
-# 创建bootstrap/cache目录并设置权限
-RUN mkdir -p bootstrap/cache && chmod -R 755 bootstrap/cache
-
-# 安装Composer
-RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
-
-# 安装项目依赖
-RUN composer install --no-dev
-
-# 创建存储软链接
-RUN php artisan storage:link
-
-# 创建队列表
-RUN php artisan queue:table
-
-# 暴露端口
-EXPOSE 9000
-
-# 启动PHP-FPM
-CMD ["php-fpm"]

+ 70 - 0
app/Console/Commands/LhcSettlement.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\LhcOrder;
+use App\Services\LhcSettlementService;
+
+class LhcSettlement extends Command
+{
+    /**
+     * 命令名称和签名
+     *
+     * @var string
+     */
+    protected $signature = 'lhc:settlement';
+    
+    /**
+     * 命令描述
+     *
+     * @var string
+     */
+    protected $description = '六合彩结算方法';
+    /**
+     * 执行命令
+     *
+     * @return int
+     */
+    public function handle(LhcSettlementService $service)
+    {
+
+        $issue = $this->argument('issue');
+        $this->info("开始结算期号: {$issue}...");
+        
+        $result = $service->settle($issue);
+        
+        $this->info($result);
+    }
+
+    public function sportOrderSettlement(){
+        $where = [
+            'status' => 1,
+            'pay_status' => 1,
+            'return_status' => 0,
+            'settlement_status' => 0,
+        ];
+        $list = Order::alias('o')
+                ->join('sport s', 'o.data_id', '=', 's.data_id')
+                ->where('s.state', 2)
+                ->where($where)
+                ->select('o.*', 's.score','s.half_score')
+                ->get()->toArray();
+        foreach($list as $item) {
+            $detail = json_decode($item['detail'], true);
+            $odd_id = $detail['odds'][0]['id'];
+            $function = SportOdds::where('id',$odd_id)->value('function_name');
+            $params = [
+                'score' => $item['score'], 
+                'half_score' => $item['half_score'],
+                'data_id' => $item['data_id'],
+                'home_team_id' => $item['home_team_id'],
+                'guest_team_id' => $item['guest_team_id'],
+            ];
+            $result = $function($item['amount'], $detail, $params);
+            print_r($result);die;
+        }
+    }
+
+
+}

+ 144 - 0
app/Services/LhcSettlementService.php

@@ -0,0 +1,144 @@
+<?php
+
+
+namespace App\Services;
+
+use App\Models\LhcLottery;
+use App\Models\LhcOrder;
+use Illuminate\Support\Facades\DB;
+
+//六合彩开奖结算相关
+class LhcSettlementService
+{
+
+    //根据期号结算订单
+    public static function settle($issue)
+    {
+        // 1. 获取开奖结果
+        $lottery = LhcLottery::where('issue', $issue)->first();
+        if (!$lottery) throw new \Exception("未找到期号 {$issue} 的开奖数据");
+
+        $numbers = is_array($lottery->numbers) ? $lottery->numbers : json_decode($lottery->numbers, true);
+        $specialNum = (int)end($numbers); // 最后一个是特码
+        
+        // 预计算特码属性
+        $attr = [
+            'num'    => $specialNum,
+            'zodiac' => self::getZodiac($specialNum, date('Y', strtotime($lottery->open_time))),
+            'color'  => self::getColor($specialNum),
+            'ds'     => $specialNum % 2 === 0 ? '双' : '单',
+            'dx'     => $specialNum >= 25 ? '大' : '小', // 49通常算和局或按规则定义
+        ];
+
+        // 2. 批量获取待结算订单 (Chunk 处理防止内存溢出)
+        LhcOrder::where('issue', $issue)->where('lottery_status', 'pending')
+            ->chunk(100, function ($orders) use ($attr) {
+                foreach ($orders as $order) {
+                    $this->processOrder($order, $attr);
+                }
+            });
+    }
+
+    private function processOrder($order, $attr)
+    {
+        DB::transaction(function () use ($order, $attr) {
+            $isWin = false;
+
+            // 3. 根据玩法判断中奖
+            switch ($order->play_type) {
+                case 'tm_number': // 特码直选
+                    $isWin = (int)$order->bet_value === $attr['num'];
+                    break;
+                case 'tm_sx':     // 特码生肖
+                    $isWin = $order->bet_value === $attr['zodiac'];
+                    break;
+                case 'tm_bs':     // 特码波色
+                    $isWin = $order->bet_value === $attr['color'];
+                    break;
+                case 'tm_ds':     // 特码单双
+                    $isWin = $order->bet_value === $attr['ds'];
+                    break;
+                case 'tm_dx':     // 特码大小
+                    // 49 一般不计大小或算和,根据实际规则改写
+                    if ($attr['num'] === 49) {
+                        $this->refundOrder($order); // 49退本金
+                        return;
+                    }
+                    $isWin = $order->bet_value === $attr['dx'];
+                    break;
+            }
+
+            // 4. 执行结算
+            if ($isWin) {
+                $bonus = $order->amount * $order->odds;
+                $order->update(['lottery_status' => '2', 'win_amount' => $bonus]);
+                $order->user->increment('balance', $bonus); // 派奖
+            } else {
+                $order->update(['lottery_status' => '1']);
+            }
+        });
+    }
+
+    private function refundOrder($order) {
+        $order->update(['lottery_status' => '3', 'win_amount' => $order->amount]);
+        $order->user->increment('balance', $order->amount);
+    }
+
+    /**
+     * 获取特码对应的生肖
+     * 六合彩生肖逻辑:当年的生肖对应 01, 13, 25, 37, 49
+     * @param int $number 号码 (1-49)
+     * @param int $year 农历年份 (如 2024)
+     */
+    public static function getZodiac($number, $year = null)
+    {
+        $year = $year ?: date('Y');
+        
+        // 生肖对应索引 (固定顺序)
+        $zodiacList = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'];
+        
+        // 计算当年的本命生肖索引 (以 2024 龙年为例)
+        // 简易逻辑:(年份 - 4) % 12。2024 -> index 8 (龙)
+        $currentYearZodiacIndex = ($year - 4) % 12; 
+        
+        // 六合彩号码是从 1 开始逆推的
+        // 公式:(本命索引 - (号码 - 1) % 12 + 12) % 12
+        $targetIndex = ($currentYearZodiacIndex - ($number - 1) % 12 + 12) % 12;
+        
+        return $zodiacList[$targetIndex];
+    }
+
+    /**
+     * 获取号码对应的波色
+     */
+    public static function getColor($number)
+    {
+        $red = [1, 2, 7, 8, 12, 13, 18, 19, 23, 24, 29, 30, 34, 35, 40, 45, 46];
+        $blue = [3, 4, 9, 10, 14, 15, 20, 25, 26, 31, 36, 37, 41, 42, 47, 48];
+        $green = [5, 6, 11, 16, 17, 21, 22, 27, 28, 32, 33, 38, 39, 43, 44, 49];
+
+        if (in_array($number, $red)) return '红波';
+        if (in_array($number, $blue)) return '蓝波';
+        if (in_array($number, $green)) return '绿波';
+        return '未知';
+    }
+
+    /**
+     * 获取五行 (金木水火土)
+     */
+    public static function getElement($number)
+    {
+        // 五行通常每年也会微调,此处为通用映射逻辑(示意)
+        $elements = [
+            '金' => [1, 2, 15, 16, 23, 24, 31, 32, 45, 46],
+            '木' => [5, 6, 13, 14, 27, 28, 35, 36, 43, 44],
+            '水' => [11, 12, 19, 20, 33, 34, 41, 42, 49],
+            '火' => [7, 8, 21, 22, 29, 30, 37, 38],
+            '土' => [3, 4, 9, 10, 17, 18, 25, 26, 39, 40, 47, 48],
+        ];
+        foreach ($elements as $name => $nums) {
+            if (in_array($number, $nums)) return $name;
+        }
+    }
+
+}

+ 0 - 36
docker-compose.yml

@@ -1,36 +0,0 @@
-services:
-  app:
-    build: .
-    container_name: bot-28-app
-    volumes:
-      - .:/var/www/html
-      - /path/to/wkhtmltoimage:/usr/bin/wkhtmltoimage
-    networks:
-      - bot-28-network
-
-  web:
-    image: nginx:alpine
-    container_name: bot-28-web
-    volumes:
-      - .:/var/www/html
-      - ./nginx.conf:/etc/nginx/conf.d/default.conf
-    depends_on:
-      - app
-    networks:
-      - bot-28-network
-
-  queue:
-    build: .
-    container_name: bot-28-queue
-    command: php artisan queue:work --queue
-    volumes:
-      - .:/var/www/html
-      - /path/to/wkhtmltoimage:/usr/bin/wkhtmltoimage
-    depends_on:
-      - app
-    networks:
-      - bot-28-network
-
-networks:
-  bot-28-network:
-    driver: bridge

+ 0 - 56
nginx.conf

@@ -1,56 +0,0 @@
-server {
-    listen 80;
-    server_name bot28api.sp2509.cc;
-    root /var/www/html/public; # 必须指向 public 目录
-    index index.php index.html;
-
-
-
-    location / {
-        add_header 'Access-Control-Allow-Origin' '*';
-        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
-        add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
-        add_header 'Access-Control-Allow-Credentials' 'true';
-        add_header 'Access-Control-Max-Age' 3600;
-
-        if ($request_method = 'OPTIONS') {
-            # OPTIONS 请求直接返回 200
-            return 204;
-        }
-
-        #try_files $uri $uri/ /index.php?$query_string;        
-        if (!-e $request_filename) {
-            rewrite ^/index.php(.*)$ /index.php?s=$1 last;
-            rewrite ^(.*)$ /index.php?s=$1 last;
-            break;
-        }
-}
-
-    # ===== PHP 解析配置(强制指向 8.4,避免版本问题)=====
-    location ~ \.php$ {
-        fastcgi_pass app:9000; # 确认是 8.4 的 sock 文件
-        fastcgi_index index.php;
-        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
-        fastcgi_param DOCUMENT_ROOT $realpath_root;
-        include fastcgi_params;
-    }
-
-    # ===== 禁止访问敏感文件/目录(保留)=====
-    location ~ /\.(?!well-known).* {
-        deny all;
-    }
-    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env) {
-        return 404;
-    }
-
-    # ===== 静态文件缓存(保留,不影响接口)=====
-    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
-        expires 30d;
-        add_header Cache-Control "public, max-age=2592000";
-        access_log off;
-    }
-
-    # ===== 日志配置(保留)=====
-    access_log /var/log/nginx/bot28api.sp2509.cc.log;
-    error_log /var/log/nginx/bot28api.sp2509.cc.error.log;
-}