|
@@ -122,6 +122,8 @@ class Coupon extends Auth{
|
|
|
$products = $FilesManager->excelToCode(request()->file('product_file'),$Product);
|
|
|
// 产品范围不存在
|
|
|
if( !$products ) return json_send(['code'=>'error','msg'=>'请上传可用的商品范围']);
|
|
|
+ // 去重
|
|
|
+ $products = array_values(array_unique($products));
|
|
|
// 商品数量
|
|
|
if( count($products) > 1000 ) return json_send(['code'=>'error','msg'=>'可用的商品范围请勿超过1000']);
|
|
|
}
|
|
@@ -276,6 +278,8 @@ class Coupon extends Auth{
|
|
|
$products = $FilesManager->excelToCode(request()->file('product_file'),$Product);
|
|
|
// 产品范围不存在
|
|
|
if( !$products ) return json_send(['code'=>'error','msg'=>'请上传可用的商品范围']);
|
|
|
+ // 去重
|
|
|
+ $products = array_values(array_unique($products));
|
|
|
// 商品数量
|
|
|
if( count($products) > 1000 ) return json_send(['code'=>'error','msg'=>'可用的商品范围请勿超过1000']);
|
|
|
}
|
|
@@ -329,11 +333,20 @@ class Coupon extends Auth{
|
|
|
if( $products ) {
|
|
|
// 循环商品
|
|
|
foreach ($products as $key => $value) {
|
|
|
+ // 重复的产品移除
|
|
|
+ $oldProduct = $CouponProduct->query()->where([['coupon_id','=',$id],['product_id','=',$value]])->value('product_id');
|
|
|
+ // 存在产品,移除
|
|
|
+ if( $oldProduct ) {
|
|
|
+ unset($products[$key]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
// 时间处理
|
|
|
- $value = ['coupon_id'=>$id,'product_id'=>$value,'insert_time'=>$time,'update_time'=>$time];
|
|
|
+ $value = ['coupon_id'=>$id,'product_id'=>$value,'insert_time'=>$time,'update_time'=>$time];
|
|
|
// 重组
|
|
|
$products[$key] = $value;
|
|
|
}
|
|
|
+ // 格式化
|
|
|
+ $products = array_values($products);
|
|
|
// 写入数据
|
|
|
$result = $CouponProduct->insert($products);
|
|
|
// 提示新增失败
|