浏览代码

修改拼团活动后台

jun 5 月之前
父节点
当前提交
e28f8bc4c9
共有 2 个文件被更改,包括 24 次插入4 次删除
  1. 16 0
      app/Http/Controllers/Admin/RegimentActive.php
  2. 8 4
      app/Http/Controllers/Api/Product.php

+ 16 - 0
app/Http/Controllers/Admin/RegimentActive.php

@@ -2,6 +2,7 @@
 
 use App\Http\Requests\Admin\RegimentActive as Request;
 use App\Models\RegimentActive as Model;
+use App\Models\Regiment;
 use App\Models\Product as Product;
 use Illuminate\Support\Facades\DB;
 
@@ -91,6 +92,21 @@ class RegimentActive extends Auth{
             $id						        = $Model->add($data);
             // 如果操作失败
             if( !$id ) 				        return json_send(['code'=>'error','msg'=>'新增失败']);
+            //商户开团
+            if ($data['automatic'] == 1){
+                $regimentData  =   [
+                    'custom_uid'    =>  0,
+                    'active_id'     =>  $id,
+                    'product_id'    =>  $data['product_id'],
+                    'status'        =>  0,
+                    'start_time'    =>  $data['start_time'],
+                    'end_time'      =>  $data['start_time'] + $data['expiration']*60*60,
+                    'update_time'   =>  time(),
+                    'insert_time'   =>  time(),
+                ];
+                $regimentRes            =   Regiment::query()->where($where)->insert($regimentData);
+                if (!$regimentRes)      return json_send(['code'=>'error','msg'=>'商户开团失败']);
+            }
             // 记录行为
             $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,1,[],$data);
             // 告知结果

+ 8 - 4
app/Http/Controllers/Api/Product.php

@@ -76,10 +76,14 @@ class Product extends Api{
             $regiment = $RegimentActive::query()->where($regimentWhere)->first();
             if ( $regiment ){
                 $value['regiment_number']   = $regiment['number'];
-                $value['regiment_id']       = $regiment['id'];
-                $value['regiment_title']    = $regiment['number'].'人团';
+                $value['regiment_active_id']       = $regiment['id'];
+                if ($regiment['automatic'] == 1){
+                    $value['regiment_title']    = '多人团';
+                }else{
+                    $value['regiment_title']    = $regiment['number'].'人团';
+                }
             }else{
-                $value['regiment_id'] = null;
+                $value['regiment_active_id'] = null;
             }
 			// 重组数据
 			$data['data'][$key]		= $value;
@@ -171,7 +175,7 @@ class Product extends Api{
             $data['regiment_active']        = $regimentActive;
             $data['automatic_info']         = [];
             if ($regimentActive['automatic'] == 1){
-                $data['regiment_title']         = '多人团';
+                $data['regiment_title']     = '多人团';
                 $automaticInfo              = $Regiment::query()->where([['status','=',1],['active_id','=',$regimentActive['id']],['start_time','<=',$time],['end_time','>=',$time]])->first();
                 $data['automatic_info']     = $automaticInfo;
                 $data['regiment_type']      = 1;