Prechádzať zdrojové kódy

【Mod】下发增加订单的产品列表

liuxiangxin 2 mesiacov pred
rodič
commit
d659c000ae
1 zmenil súbory, kde vykonal 20 pridanie a 15 odobranie
  1. 20 15
      app/Http/Controllers/Api/Redpacket/Active.php

+ 20 - 15
app/Http/Controllers/Api/Redpacket/Active.php

@@ -9,6 +9,7 @@ use App\Models\Redpacket\ActiveReward;
 use App\Models\Redpacket\Active as Model;
 use App\Models\WeiBan\Tags as WeiBanTags;
 use App\Models\OrdersProduct;
+use App\Models\Product;
 
 /**
  * 红包活动
@@ -22,7 +23,7 @@ class Active extends Api{
 	 * 获取抽奖配置		/api/redpacket_active/get_detail
 	 * 
 	 * */
-	public function get_detail(Model $Model,Custom $Custom,ActiveReward $ActiveReward,ActiveRecord $ActiveRecord,WeiBanTags $WeiBanTags,OrdersProduct $OrdersProduct){
+	public function get_detail(Model $Model,Custom $Custom,ActiveReward $ActiveReward,ActiveRecord $ActiveRecord,WeiBanTags $WeiBanTags,OrdersProduct $OrdersProduct,Product $Product){
 		// 接口验签
 		// $this->verify_sign();
 		// 检查登录
@@ -48,17 +49,6 @@ class Active extends Api{
 			// 如果客户注册时间不在活动期间
 			if( $data['custom_start_time'] > $custom['insert_time'] || $data['custom_end_time'] < $custom['insert_time'] ) return json_send(['code'=>'error','msg'=>'账号不在活动范围','data'=>['error'=>'不在活动时间内注册']]);
 		}
-		// 如果限制下单
-		if( $data['is_order'] )		{
-			// 查询结果
-			$query							= $OrdersProduct->query()->where([['custom_uid','=',$uid],['status','=',1],['insert_time','>=',$data['order_start_time']],['insert_time','<=',$data['order_end_time']]]);
-			// 如果商品存在
-			if( $data['product_scope'] )	$query = $query->whereIn('product_id',explode(',',$data['product_scope']));
-			// 获取时间段内下单数量
-			$orderTotal						= $query->groupBy('order_id')->count();
-			// 如果没有下单数据
-			if( !$orderTotal )				return json_send(['code'=>'error','msg'=>'不符合下单条件','data'=>['error'=>'不符合订单条件']]);
-		}
 		// 是否需要获取用户标签
 		$tags							= $data['tag_scope'] || $data['tag_except'] ? $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']) : [];
 		// 获取用户的标签
@@ -87,6 +77,23 @@ class Active extends Api{
 			// 如果存在交集,在排除范围,即不可参与
 			if( $intersect )			return json_send(['code'=>'error','msg'=>'账号不在范围','data'=>['error'=>'在标签排除范围内']]);
 		}
+		// 默认可以参加活动
+		$data['allow_join']				= 1;
+		// 获取商品
+		$data['product_list']			= [];
+		// 如果限制下单
+		if( $data['is_order'] )			{
+			// 查询结果
+			$query						= $OrdersProduct->query()->where([['custom_uid','=',$uid],['status','=',1],['insert_time','>=',$data['order_start_time']],['insert_time','<=',$data['order_end_time']]]);
+			// 如果商品存在
+			if( $data['product_scope'] )$query = $query->whereIn('product_id',explode(',',$data['product_scope']));
+			// 获取时间段内下单数量
+			$orderTotal					= $query->groupBy('order_id')->count();
+			// 如果没有下单数据
+			if( !$orderTotal )			$data['allow_join']	= 0;
+			// 获取产品列表
+			if( $data['product_scope'] ) $data['product_list'] = $Product->getListByIds(explode(',',$data['product_scope']));
+		}
 		// 奖品
 		$reward 						= $ActiveReward->getListByLottery($data['id']);
 		// 活动暂无奖品
@@ -104,7 +111,7 @@ class Active extends Api{
 		// 查询用户已参与次数
         $data['join_num']				= (int)$ActiveRecord->query()->where([['custom_uid','=',$uid],['active_id','=',$id]])->where($map)->count();
         // 计算剩余次数
-        $data['number']					= $data['lucky_num'] - $data['join_num'];
+        $data['number']					= $data['allow_join'] ? ($data['lucky_num'] - $data['join_num']) : 0;
 		// 最少为0,避免显示异常
 		$data['number']				    = $data['number'] < 0 ? 0 : $data['number'];
 		// 时间处理
@@ -118,8 +125,6 @@ class Active extends Api{
 			// 奖项
 			$data['reward_list'][]		= ['id'=>$value['id'],'money'=>$value['money']];
 		}
-		// 默认可以参加活动
-		$data['allow_join']				= 1;
 		// 返回结果
 		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
 	}