Ken 2 месяцев назад
Родитель
Сommit
484ff9f74d
3 измененных файлов с 32 добавлено и 12 удалено
  1. 4 2
      app/Http/Controllers/admin/Bet.php
  2. 11 4
      app/Models/Bet.php
  3. 17 6
      app/Services/BetService.php

+ 4 - 2
app/Http/Controllers/admin/Bet.php

@@ -14,7 +14,7 @@ class Bet extends Controller
     /**
      * @description: 分页数据
      * @return {*}
-     */    
+     */
     function index()
     {
         try {
@@ -22,7 +22,9 @@ class Bet extends Controller
                 'issue_no' => ['nullable', 'string'],
                 'member_id' => ['nullable', 'string'],
                 'id' => ['nullable', 'string'],
-                'status' => ['nullable', 'string'],
+                'status' => ['nullable', 'integer', 'in:1,2'],
+                'keywords' => ['nullable', 'string', 'min:1'],
+                'username' => ['nullable', 'string', 'min:1'],
             ]);
             $search = request()->all();
             $result = BetService::paginate($search);

+ 11 - 4
app/Models/Bet.php

@@ -18,12 +18,19 @@ class Bet extends Authenticatable
     use HasApiTokens, Notifiable;
     protected $table = 'bets';
     // protected $hidden = ['created_at', 'updated_at'];
-    protected $fillable = ['issue_no', 'keywords', 'amount' ,'odds' ,'status' ,'profit' ,'issue_id' ,'member_id' ,'user_id'];
+    protected $fillable = ['issue_no', 'keywords', 'amount', 'odds', 'status', 'profit', 'issue_id', 'member_id', 'user_id'];
 
     const STATUS_STAY = 1;
     const STATUS_SETTLED = 2;
     const STATUS_CANCEL = 3;
 
+
+    public function user()
+    {
+        return $this->belongsTo(User::class, 'member_id', 'member_id');
+    }
+
+
     public static $STATUS = [
         1 => '待结算',
         2 => '已结算',
@@ -33,16 +40,16 @@ class Bet extends Authenticatable
     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];
         }
     }

+ 17 - 6
app/Services/BetService.php

@@ -72,6 +72,8 @@ class BetService extends BaseService
         if (isset($search['status']) && !empty($search['status'])) {
             $where[] = ['status', '=', $search['status']];
         }
+
+
         return $where;
     }
 
@@ -103,7 +105,16 @@ class BetService extends BaseService
     public static function paginate(array $search = [])
     {
         $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = self::model()::where(self::getWhere($search))->paginate($limit);
+        $query = self::model()::where(self::getWhere($search));
+
+
+        if (isset($search['username']) && !empty($search['username'])) {
+            $username = $search['username'];
+            $query = $query->whereHas('user', function ($query) use ($username) {
+                $query->where('username', $username);
+            });
+        }
+        $paginator = $query->paginate($limit);
         return ['total' => $paginator->total(), 'data' => $paginator->items()];
     }
 
@@ -315,7 +326,7 @@ class BetService extends BaseService
     {
 
         $betFake = Config::where('field', 'bet_fake')->first()->val;
-        if($betFake){
+        if ($betFake) {
             // 期数验证
             $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
             if ($issueInfo) {
@@ -360,7 +371,7 @@ class BetService extends BaseService
 
             }
         }
-        
+
     }
 
     /**
@@ -444,13 +455,13 @@ class BetService extends BaseService
         $text = "历史注单 \n";
 
         foreach ($list as $k => $v) {
-            if($v->status == self::model()::STATUS_SETTLED){
+            if ($v->status == self::model()::STATUS_SETTLED) {
                 $phase = $v->profit - $v->amount;
 
-            }else{
+            } else {
                 $phase = '待开奖';
             }
-            
+
             $text .= "-------------------------------------\n";
             $text .= "期数:{$v->issue_no} \n";
             $text .= "内容:{$v->keywords} \n";