| 
					
				 | 
			
			
				@@ -15,6 +15,7 @@ use support\Response; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use app\model\CardBatch; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use app\model\Card; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use app\admin\service\card\CardService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use app\admin\service\sys_manage\CategoryService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class CardBatchService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -31,6 +32,10 @@ class CardBatchService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 添加卡批次 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $model = new CardBatch(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (is_array($params['join_card_batch_category_id'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $params['join_card_batch_category_id'] = end($params['join_card_batch_category_id']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $model->join_card_batch_user_id = $params['join_card_batch_user_id']; // 批次创建用户 user_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $model->join_card_batch_category_id = $params['join_card_batch_category_id']; // 批次卡分类ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $model->card_batch_status = $params['card_batch_status']; // 批次状态 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -115,7 +120,11 @@ class CardBatchService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $model = $cardBatchModel::find($params['card_batch_id']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $model->card_batch_name = $params['card_batch_name']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $model->card_batch_remark = $params['card_batch_remark'] ?? ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $params['card_batch_status'] = $model->card_batch_status = $params['card_batch_status']; // 批次状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $params['card_batch_status'] && $model->card_batch_status = $params['card_batch_status']; // 批次状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 是否有激活的卡片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Card::where('join_card_batch_id', $params['card_batch_id'])->where('card_status', 'ACTIVED')->exists()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return json_fail('存在已激活卡片不可以修改状态'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if ($params['validtimes_status'] == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $model->card_batch_validtimes = 0; // 卡批次有效期 0=永久 天 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } elseif ($params['validtimes_status'] == 1) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -132,7 +141,7 @@ class CardBatchService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 // CardService::saveCardByCardBatchId($params['card_batch_id'], $params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 // 修改卡批次下面的卡信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $model = new Card(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $data['card_name'] = $params['card_batch_name']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $data['card_name'] = $params['card_batch_name']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $card_status = array_keys($model::CARD_STATUS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (in_array($params['card_batch_status'], $card_status)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -239,45 +248,42 @@ class CardBatchService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!empty($rows)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 查询所有分类信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $category = array_column($rows, 'join_card_batch_category_id'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $categoryInfos = CategoryService::getCategoryInfos($category) ?? []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $categoryInfos && $categoryInfos = array_column($categoryInfos, null, 'category_id'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 查询求和数据信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $card_batch_id_string = implode(',', array_column($rows, 'card_batch_id')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $sql = "select join_card_batch_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- INIT 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'INIT' THEN counts ELSE 0 END),0) as status_INIT_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'INIT' THEN amounts ELSE 0 END),0) as status_INIT_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'INIT' THEN addeds ELSE 0 END),0) as status_INIT_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- PRODUCTED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'PRODUCTED' THEN counts ELSE 0 END),0) as status_PRODUCTED_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'PRODUCTED' THEN amounts ELSE 0 END),0) as status_PRODUCTED_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'PRODUCTED' THEN addeds ELSE 0 END),0) as status_PRODUCTED_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- ENABLED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'ENABLED' THEN counts ELSE 0 END),0) as status_ENABLED_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'ENABLED' THEN amounts ELSE 0 END),0) as status_ENABLED_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'ENABLED' THEN addeds ELSE 0 END),0) as status_ENABLED_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- WAITING 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'WAITING' THEN counts ELSE 0 END),0) as status_WAITING_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'WAITING' THEN amounts ELSE 0 END),0) as status_WAITING_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'WAITING' THEN addeds ELSE 0 END),0) as status_WAITING_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- PENDING 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'PENDING' THEN counts ELSE 0 END),0) as status_PENDING_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'PENDING' THEN amounts ELSE 0 END),0) as status_PENDING_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'PENDING' THEN addeds ELSE 0 END),0) as status_PENDING_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- ACTIVED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'ACTIVED' THEN counts ELSE 0 END),0) as status_ACTIVED_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'ACTIVED' THEN amounts ELSE 0 END),0) as status_ACTIVED_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'ACTIVED' THEN addeds ELSE 0 END),0) as status_ACTIVED_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- DISABLED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'DISABLED' THEN counts ELSE 0 END),0) as status_DISABLED_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'DISABLED' THEN amounts ELSE 0 END),0) as status_DISABLED_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'DISABLED' THEN addeds ELSE 0 END),0) as status_DISABLED_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- EXPIRED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'EXPIRED' THEN counts ELSE 0 END),0) as status_EXPIRED_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'EXPIRED' THEN amounts ELSE 0 END),0) as status_EXPIRED_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'EXPIRED' THEN addeds ELSE 0 END),0) as status_EXPIRED_addeds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     -- PAUSED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     IFNULL(SUM(CASE WHEN card_status = 'PAUSED' THEN counts ELSE 0 END),0) as status_PAUSED_counts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'PAUSED' THEN amounts ELSE 0 END),0) as status_PAUSED_amounts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    IFNULL(SUM(CASE WHEN card_status = 'PAUSED' THEN addeds ELSE 0 END),0) as status_PAUSED_addeds 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    IFNULL(SUM(CASE WHEN card_status = 'PAUSED' THEN amounts ELSE 0 END),0) as status_PAUSED_amounts  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     from (select join_card_batch_id, card_status, COUNT(*) as counts, SUM(card_amount) as amounts, SUM(card_added) as addeds from app_card where join_card_batch_id in (" . $card_batch_id_string . ") group by join_card_batch_id, card_status) group_data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     group by join_card_batch_id"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -285,6 +291,7 @@ class CardBatchService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $card_status_total = array_column($card_status_total, null, 'join_card_batch_id'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             foreach ($rows as $key => &$value) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $value['card_batch_status_value'] = $cardBatchModel::CARD_BATCH_STATUS[$value['card_batch_status']]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $value['category_name'] = $categoryInfos[$value['join_card_batch_category_id']]['category_name'] ?? ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if ($value['card_batch_validtimes'] == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     $value['card_batch_validtimes_value'] = "永久"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 |