| 
					
				 | 
			
			
				@@ -9,6 +9,7 @@ use app\model\Coupon; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use app\model\CouponGoods; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use app\model\Device; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use app\model\Member; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use app\model\SysDept; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use app\model\SysSerial; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use support\Db; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use support\exception\BusinessException; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -48,7 +49,8 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $model = $this->model->with([ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'category' => function ($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $query->select('category_id', 'category_name'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'user' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         foreach ($where as $column => $value) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (is_array($value)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -267,7 +269,7 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Db::beginTransaction(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             [$id, $data] = $this->updateInput($request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->updateCouponGoods($request->post('goodsContentList'),$id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $this->updateCouponGoods($request->post('goodsContentList'), $id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $this->doUpdate($id, $data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Db::commit(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -285,13 +287,13 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public function updateCouponGoods($goods, $couponId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        try{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $couponGoodsIds = CouponGoods::where('join_goods_coupon_id',$couponId)->pluck('join_coupon_goods_id')->toArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $goodsIds = array_column($goods,'goods_id'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $couponGoodsIds = CouponGoods::where('join_goods_coupon_id', $couponId)->pluck('join_coupon_goods_id')->toArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $goodsIds = array_column($goods, 'goods_id'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 新的差集 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $goodsDiff = array_diff($goodsIds,$couponGoodsIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $goodsDiff = array_diff($goodsIds, $couponGoodsIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 旧的差集 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $couponDiff = array_diff($couponGoodsIds,$goodsIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $couponDiff = array_diff($couponGoodsIds, $goodsIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             foreach ($goods as $good) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 // 更新两个中都有的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (in_array($good['goods_id'], $couponGoodsIds)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -307,12 +309,12 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!empty($couponDiff)){   // 去掉的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                foreach ($couponDiff as $item){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!empty($couponDiff)) {   // 去掉的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                foreach ($couponDiff as $item) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     CouponGoods::where('join_goods_coupon_id', $couponId)->where('join_coupon_goods_id', $item)->delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }catch (\Exception $e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (\Exception $e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new BusinessException('关联产品更新失败'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -335,10 +337,10 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ($params['coupon_use_member'] == 'member' && isset($params['member_list'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $couponJson['member']['list'] = $params['member_list']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (isset($couponJson['member']['range'])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (isset($couponJson['member']['range'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $couponJson['member']['range'] = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (isset($couponJson['member']['where'])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (isset($couponJson['member']['where'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $couponJson['member']['where'] = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else if ($params['coupon_use_member'] == 'condition') { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -352,14 +354,14 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $couponJson['member']['range'] = '会员'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $couponJson['member']['where'] = urlencode(" `member_classify` = 'MEMBER'"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (isset($couponJson['member']['list'])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (isset($couponJson['member']['list'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $couponJson['member']['list'] = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else if ($params['coupon_use_member'] == 'all') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $couponJson['member']['range'] = '不限'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $couponJson['member']['where'] = urlencode(" 1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (isset($couponJson['member']['list'])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (isset($couponJson['member']['list'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $couponJson['member']['list'] = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -411,6 +413,7 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (isset($couponGood['goods'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $content['goods_name'] = $couponGood['goods']['name']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $content['goods_classify'] = $couponGood['goods']['goods_classify']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $content['goods_cover'] = getenv('STORAGE_DOMAIN').$couponGood['goods']['goods_cover']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (isset($couponGood['sku']) && isset($couponGood['sku']['goods_sku_specs_json'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                $skuSpecsJson = json_decode($couponGood['sku']['goods_sku_specs_json'], true); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -444,6 +447,8 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 选中的会员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $memberLists = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 可用门店 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $premises = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!empty($coupon->coupon_json)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $couponJson = json_decode($coupon->coupon_json, true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (isset($couponJson['member']) && isset($couponJson['member']['list']) && !empty($couponJson['member']['list'])) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -476,12 +481,19 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (isset($couponJson['premises']) && !empty($couponJson['premises'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $premises = SysDept::whereIn('dept_id', $couponJson['premises']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ->select('dept_id', 'dept_name') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ->get() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ->toArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $data = [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'goods_ids' => $goodsIds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'goods_content' => $goodsContent, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            'member_lists' => $memberLists 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'member_lists' => $memberLists, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'premises_list' => $premises 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return json_success('', $data); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -499,13 +511,13 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Db::beginTransaction(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 删除优惠券关联的产品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            foreach ($ids as $id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                CouponGoods::where('join_goods_coupon_id',$id)->delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            foreach ($ids as $id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                CouponGoods::where('join_goods_coupon_id', $id)->delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $this->doDelete($ids); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Db::commit(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return json_success('success'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }catch (\Exception $e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (\Exception $e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Db::rollBack(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return json_fail('删除失败'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 |