Ken 2 هفته پیش
والد
کامیت
23b2bd2316
7فایلهای تغییر یافته به همراه183 افزوده شده و 77 حذف شده
  1. 53 0
      app/Http/Controllers/api/BaseController.php
  2. 16 0
      app/Http/Controllers/api/Issue.php
  3. 17 4
      app/Models/Issue.php
  4. 6 36
      lang/en/messages.php
  5. 65 0
      lang/vi/messages.php
  6. 21 36
      lang/zh-CN/messages.php
  7. 5 1
      routes/api.php

+ 53 - 0
app/Http/Controllers/api/BaseController.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Http\Controllers\api;
+
+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Illuminate\Foundation\Bus\DispatchesJobs;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Routing\Controller;
+use Illuminate\Support\Facades\App;
+use Illuminate\Support\Facades\Lang;
+
+class BaseController extends Controller
+{
+    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+
+    protected $lang = 'en';
+
+    public function __construct()
+    {
+        $lang = request()->input('lang', 'en');
+        App::setLocale($lang);
+        $this->lang = $lang;
+    }
+
+    protected function success($data = [], $msg = 'messages.ok')
+    {
+        return response()->json([
+            'code' => 0,
+            'timestamp' => time(),
+            'msg' => Lang::get($msg),
+            'data' => $data
+        ]);
+    }
+
+    protected function error(string $msg = "请求错误", $data = [], int $code = -1)
+    {
+        $code = intval($code);
+        if ($code === 0) $code = -1;
+        $a = Lang::get("messages.{$msg}", $data);
+        if ($a == "messages." . $msg) {
+            $a = $msg;
+        }
+
+        return response()->json([
+            'code' => $code,
+            'timestamp' => time(),
+            'msg' => $a,
+            'data' => $data
+        ]);
+    }
+
+
+}

+ 16 - 0
app/Http/Controllers/api/Issue.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Http\Controllers\api;
+
+use App\Services\IssueService;
+
+class Issue extends BaseController
+{
+
+    public function index()
+    {
+        $res = IssueService::paginate();
+        return $this->success($res);
+    }
+
+}

+ 17 - 4
app/Models/Issue.php

@@ -2,6 +2,7 @@
 
 namespace App\Models;
 
+use App\Services\IssueService;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 use Illuminate\Notifications\Notifiable;
@@ -17,7 +18,18 @@ class Issue extends Authenticatable
     use HasApiTokens, Notifiable;
     protected $table = 'issues';
     // protected $hidden = ['created_at', 'updated_at'];
-    protected $fillable = ['issue_no', 'start_time', 'end_time' ,'winning_numbers' ,'status' ,'combo', 'extreme', 'image'];
+    protected $fillable = ['issue_no', 'start_time', 'end_time', 'winning_numbers', 'status', 'combo', 'extreme', 'image'];
+    protected $appends = [
+        'award'
+
+
+    ];
+
+    function getAwardAttribute()
+    {
+        return IssueService::award($this->winning_numbers);
+    }
+
 
     const STATUS_DRAFT = 0;
     const STATUS_BETTING = 1;
@@ -31,19 +43,20 @@ class Issue extends Authenticatable
         3 => '开奖',
     ];
 
+
     public static function getStatus($val = -1)
     {
         $array = self::$STATUS;
-        if($val < 0){
+        if ($val < 0) {
             $arr = [];
-            foreach($array as $k => $v){
+            foreach ($array as $k => $v) {
                 $item = [];
                 $item['id'] = $k;
                 $item['title'] = $v;
                 $arr[] = $item;
             }
             return $arr;
-        }else{
+        } else {
             return $array[$val];
         }
     }

+ 6 - 36
lang/en/messages.php

@@ -3,42 +3,6 @@
 use App\Constants\HttpStatus;
 
 return [
-    'translate' => [
-        'Reading' => 'Reading',
-        'Traveling' => 'Traveling',
-        'Photography' => 'Photography',
-        'Music' => 'Music',
-        'Painting' => 'Painting',
-        'Yoga' => 'Yoga',
-        'Cooking' => 'Cooking',
-        'Calligraphy' => 'Calligraphy',
-        'Crafts' => 'Crafts',
-        'History' => 'History',
-        'Drinking' => 'Drinking',
-        'Coding' => 'Coding',
-        'Valuing family' => 'Valuing family',
-        'Skydiving' => 'Skydiving',
-        'Diving' => 'Diving',
-
-        '$50K to $100K' => '$50K to $100K',
-        '$100K to $500K' => '$100K to $500K',
-        '$500K to $1M' => '$500K to $1M',
-        '$1M to $5M' => '$1M to $5M',
-        '$5M to $10M' => '$5M to $10M',
-        'Over $10M' => 'Over $10M',
-
-        'Male' => 'Male',
-        'Female' => 'Female',
-
-        '邀请注册' => 'Invite to register',
-        '首次邀请注册' => 'First invitation to register',
-        '注册' => 'Register',
-        '邀请完善' => 'Invite to complete',
-        '完善信息' => 'Complete information',
-        '普通区抽奖' => 'Normal area lottery',
-        '金币区抽奖' => 'Gold area lottery',
-        '至尊区抽奖' => 'Supreme area lottery',
-    ],
     HttpStatus::CUSTOM_ERROR => '',
     HttpStatus::UNKNOWN_ERROR => 'Unknown error.',
     HttpStatus::OK => 'OK',
@@ -77,4 +41,10 @@ return [
     HttpStatus::VERIFY_ERROR => 'Verification failure',
     HttpStatus::PAY_VERIFY_ERROR =>'PAY_VERIFY_ERROR',
     HttpStatus::IM_SYSTEM_ERROR =>'Im system error',
+
+
+
+
+
+
 ];

+ 65 - 0
lang/vi/messages.php

@@ -0,0 +1,65 @@
+<?php
+
+use App\Constants\HttpStatus;
+
+return [
+    HttpStatus::CUSTOM_ERROR => '',
+    HttpStatus::UNKNOWN_ERROR => 'Không biết lỗi',
+    HttpStatus::OK => 'OK',
+    HttpStatus::USER_DOES_NOT_EXIST => "Người dùng không tồn tại",
+    HttpStatus::PASSWORDS_ERROR => "Mật khẩu lỗi",
+    HttpStatus::VERIFICATION_CODE_ERROR => 'Lỗi mã xác minh',
+    HttpStatus::VERIFICATION_CODE_EXPIRED => 'Captcha đã hết hạn',
+    HttpStatus::PASSWORD_INCONSISTENCY => 'Mật khẩu không phù hợp',
+    HttpStatus::USERNAME_ALREADY_EXISTS => 'Tên người dùng đã tồn tại, hãy đăng nhập trực tiếp',
+    HttpStatus::EMAIL_ALREADY_EXISTS => 'Hộp thư đã tồn tại, xin vui lòng đăng nhập trực tiếp',
+    HttpStatus::USERNAME_ERROR => 'Lỗi tên người dùng',
+    HttpStatus::VALIDATION_FAILED => 'Tham số xác nhận thất bại',
+    HttpStatus::SYSTEM_ERROR => 'Lỗi hệ thống',
+    HttpStatus::AUTHORIZATION_HEADER_NOT_FOUND => 'Xin vui lòng đăng nhập',
+    HttpStatus::NO_COLLECT_YOURSELF => 'Không thu thập của riêng bạn',
+    HttpStatus::NO_BASIC_INFO => 'Điền vào những thông tin cơ bản trước',
+    HttpStatus::NOT_FOUND => 'Tài nguyên không tồn tại',
+    HttpStatus::AVATAR_MUST_SQUARE => 'Xin vui lòng cắt ảnh và tải lên',
+    HttpStatus::PAIRING_FAILURE => 'Cặp không thành công',
+    HttpStatus::COLLECT_COUNT_REACH_MAX => 'Có thể tập hợp nhiều nhất',
+    HttpStatus::SEND_CODE_ERROR => 'Gửi thất bại',
+    HttpStatus::PHONE_ERROR => 'Số điện thoại là không đúng',
+    HttpStatus::POST_DOES_NOT_EXIST => 'Bài viết không tồn tại',
+    HttpStatus::FILE_UPLOAD_ERROR => 'Lỗi tải lên tập tin',
+    HttpStatus::INVITATION_CODE_ERROR => "Lỗi mã mời",
+    HttpStatus::USER_ANOTHER_DEVICE => "Người dùng đã đăng nhập vào các thiết bị khác",
+    HttpStatus::INSUFFICIENT => "Số còn lại là không đủ。",
+    HttpStatus::MAXIMUM_NUMBER_OF_ADDRESSES => 'Số địa chỉ đạt mức giới hạn',
+    HttpStatus::HTTP_POST_ERROR => 'Lỗi yêu cầu HTTP',
+    HttpStatus::IM_ERROR => 'Im Sai lầm',
+    HttpStatus::PHONE_ALREADY_EXISTS => 'Số điện thoại đã tồn tại, xin vui lòng đăng nhập trực tiếp',
+    HttpStatus::GOOGLE_ERROR => 'Lỗi đăng nhập Google',
+    HttpStatus::INSUFFICIENT_CHAT_BALANCE => 'Số dư trò chuyện là không đủ',
+    HttpStatus::INSUFFICIENT_WALLET => 'Ví không đủ cân bằng',
+    HttpStatus::FACEBOOK_ERROR => 'Facebook error',
+    HttpStatus::VERIFY_ERROR => 'Xác nhận thất bại',
+    HttpStatus::PAY_VERIFY_ERROR =>'Thanh toán xác nhận thất bại',
+    HttpStatus::IM_SYSTEM_ERROR =>'Lỗi hệ thống Im',
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+];

+ 21 - 36
lang/zh-CN/messages.php

@@ -3,42 +3,6 @@
 use App\Constants\HttpStatus;
 
 return [
-    'translate' => [
-        'Reading' => '阅读',
-        'Traveling' => '旅行',
-        'Photography' => '摄影',
-        'Music' => '音乐',
-        'Painting' => '绘画',
-        'Yoga' => '瑜伽',
-        'Cooking' => '烹饪',
-        'Calligraphy' => '书法',
-        'Crafts' => '手工艺',
-        'History' => '历史',
-        'Drinking' => '饮酒',
-        'Coding' => '编程',
-        'Valuing family' => '重视家庭',
-        'Skydiving' => '跳伞',
-        'Diving' => '潜水',
-
-        '$50K to $100K' => '5-10万',
-        '$100K to $500K' => '10-50万',
-        '$500K to $1M' => '50-100万',
-        '$1M to $5M' => '100-500万',
-        '$5M to $10M' => '500-1000万',
-        'Over $10M' => '1000万以上',
-
-        'Male' => '男',
-        'Female' => '女',
-
-        '邀请注册' => '邀请注册',
-        '首次邀请注册' => '首次邀请注册',
-        '注册' => '注册',
-        '邀请完善' => "邀请完善",
-        '完善信息' => '完善信息',
-        '普通区抽奖' => '普通区抽奖',
-        '金币区抽奖' => '金币区抽奖',
-        '至尊区抽奖' => '至尊区抽奖',
-    ],
     HttpStatus::CUSTOM_ERROR => '',
     HttpStatus::UNKNOWN_ERROR => '未知错误',
     HttpStatus::OK => 'OK',
@@ -77,4 +41,25 @@ return [
     HttpStatus::VERIFY_ERROR => '验证失败',
     HttpStatus::PAY_VERIFY_ERROR =>'支付验证失败',
     HttpStatus::IM_SYSTEM_ERROR =>'Im系统错误',
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 ];

+ 5 - 1
routes/api.php

@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Route;
 use App\Constants\HttpStatus;
 use App\Http\Controllers\api\TelegramWebHook;
 use App\Http\Controllers\api\Home;
-
+use App\Http\Controllers\api\Issue;
 
 Route::post("/onMessage", [TelegramWebHook::class, 'handle']);
 Route::get("/setWebHook", [Home::class, 'setWebHook']);
@@ -14,6 +14,10 @@ Route::get("/setMyCommands", [Home::class, 'setMyCommands']);
 Route::get("/setA", [Home::class, 'setA']);
 
 
+Route::prefix('/issue')->group(function () {
+    Route::get("/", [Issue::class, 'index']);
+});
+
 
 Route::get('/test', [Home::class, 'test']);