Переглянути джерело

【Mod】修复不自动开团时,无法发团的问题

liuxiangxin 5 місяців тому
батько
коміт
b316f59c70
1 змінених файлів з 15 додано та 25 видалено
  1. 15 25
      app/Http/Controllers/Api/Product.php

+ 15 - 25
app/Http/Controllers/Api/Product.php

@@ -66,28 +66,16 @@ class Product extends Api{
 		// 处理请求
 		foreach ( $data['data'] as $key => $value ) {
 			// 处理数据
-			$value['thumb'] 		= path_compat($value['thumb']);
-            $regimentWhere = [
-                ['status','=',1],
-                ['start_time','<=',$time],
-                ['end_time','>=',$time],
-                ['product_id','=',$value['id']]
-            ];
-            $regiment = $RegimentActive::query()->where($regimentWhere)->first();
-            if ( $regiment ){
-                $value['regiment_number']   = $regiment['number'];
-                $value['regiment_active_id']       = $regiment['id'];
-                if ($regiment['automatic'] == 1){
-                    $regimentInfo = Regiment::query()->where([['active_id','=',$regiment['id']],['start_time','<=',$time],['end_time','>=',$time]])->first();
-                    if ($regimentInfo){
-                        $value['regiment_title']    = '多人团';
-                    }
-                }else{
-                    $value['regiment_title']    = $regiment['number'].'人团';
-                }
-            }else{
-                $value['regiment_active_id'] = null;
-            }
+			$value['thumb'] 				= path_compat($value['thumb']);
+			$value['regiment_active_id'] 	= null;
+			$value['regiment_title'] 		= '';
+			// 查询产品拼团信息
+            $regiment 						= $RegimentActive::query()->where([['status','=',1],['start_time','<=',$time],['end_time','>=',$time],['product_id','=',$value['id']]])->first(['id as active_id','number','automatic']);
+			// 如果有拼团信息
+			if ( $regiment )				{
+				$value['regiment_active_id']= $regiment['id'];
+				$value['regiment_title']    = $regiment['automatic'] == 1 ? '多人团' : $regiment['number'].'人团';
+			}
 			// 重组数据
 			$data['data'][$key]		= $value;
 		}
@@ -180,10 +168,12 @@ class Product extends Api{
             if ($regimentActive['automatic'] == 1){
                 $automaticInfo              = $Regiment::query()->where([['status','=',1],['active_id','=',$regimentActive['id']],['start_time','<=',$time],['end_time','>=',$time]])->first();
                 if ($automaticInfo){
-                    $data['regiment_title']     = '多人团';
                     $data['automatic_info']     = $automaticInfo;
-                    $data['regiment_type']      = 1;
-                }
+					$data['regiment_type']      = 1;
+                }else{
+					$data['regiment_type']      = 2;
+				}
+				$data['regiment_title']     = '多人团';
             }else{
                 $data['regiment_title']     = $regimentActive['number'].'人团';
                 $data['regiment_type']      = 2;