|
@@ -4,6 +4,7 @@ namespace app\admin\service\goods;
|
|
|
|
|
|
use app\common\Tree;
|
|
|
use app\model\Appointment;
|
|
|
+use app\model\Coupon;
|
|
|
use app\model\Goods;
|
|
|
use app\model\GoodsComponent;
|
|
|
use app\model\GoodsDetail;
|
|
@@ -11,6 +12,7 @@ use app\model\GoodsLabel;
|
|
|
use app\model\GoodsRunning;
|
|
|
use app\model\GoodsSku;
|
|
|
use app\model\OrderSheet;
|
|
|
+use app\model\Supplier;
|
|
|
use app\model\SysCategory;
|
|
|
use app\model\SysDept;
|
|
|
use app\model\SysSerial;
|
|
@@ -153,7 +155,9 @@ class GoodsService
|
|
|
$goodsName = $request->get('goods_name', '');
|
|
|
$categoryId = $request->get('join_goods_category_id', null);
|
|
|
$goodsCategory = $request->get('goods_category', null);
|
|
|
- $type = $request->get('type','');
|
|
|
+ $goodsSupplierId = $request->get('join_goods_supplier_id', null);
|
|
|
+ $goodsStatus = $request->get('goods_status', null);
|
|
|
+ $type = $request->get('type', '');
|
|
|
if ($categoryId != null) {
|
|
|
$categoryPath = SysCategory::where('category_id', $categoryId)->value('category_super_path');
|
|
|
$categoryPath .= '#' . $categoryId . '#';
|
|
@@ -179,7 +183,7 @@ class GoodsService
|
|
|
'user' => function ($query) {
|
|
|
$query->select('user_id', 'user_name');
|
|
|
}
|
|
|
- ])->leftJoin('goods_running','goods_running.join_running_goods_id','=','goods.goods_id')
|
|
|
+ ])->leftJoin('goods_running', 'goods_running.join_running_goods_id', '=', 'goods.goods_id')
|
|
|
->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id', 'creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_attribute_json', 'goods_addtimes', 'goods_updatetimes')
|
|
|
->when($goodsName != '', function ($query) use ($goodsName) {
|
|
|
$query->where(function ($q) use ($goodsName) {
|
|
@@ -197,10 +201,14 @@ class GoodsService
|
|
|
} else if ($classify != 'GOODS' && empty($categoryId)) {
|
|
|
$query->where('goods_classify', $classify);
|
|
|
}
|
|
|
- })->when( !empty($type),function ($query) use ($type){
|
|
|
- if ($type == 'storageWarning'){
|
|
|
- $query->where('goods_running.goods_running_storage','<=',2);
|
|
|
+ })->when(!empty($type), function ($query) use ($type) {
|
|
|
+ if ($type == 'storageWarning') {
|
|
|
+ $query->where('goods_running.goods_running_storage', '<=', 2);
|
|
|
}
|
|
|
+ })->when(!empty($goodsSupplierId), function ($query) use ($goodsSupplierId) {
|
|
|
+ $query->where('join_goods_supplier_id', $goodsSupplierId);
|
|
|
+ })->when(!empty($goodsStatus), function ($query) use ($goodsStatus) {
|
|
|
+ $query->where('goods_status', $goodsStatus);
|
|
|
})
|
|
|
->orderBy('goods_sort', 'DESC')
|
|
|
->orderBy('goods_addtimes', 'DESC')
|
|
@@ -208,26 +216,30 @@ class GoodsService
|
|
|
->get()
|
|
|
->toArray();
|
|
|
|
|
|
- $total = Goods::leftJoin('goods_running','goods_running.join_running_goods_id','=','goods.goods_id')
|
|
|
- ->when($goodsName != '', function ($query) use ($goodsName) {
|
|
|
- $query->where(function ($q) use ($goodsName) {
|
|
|
- $q->where('goods_name', 'like', '%' . $goodsName . '%')
|
|
|
- ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
|
|
|
- });
|
|
|
- })->when($categoryId != null, function ($query) use ($categoryId) {
|
|
|
- $query->whereIn('join_goods_category_id', $categoryId);
|
|
|
- })->when($goodsCategory != null, function ($query) use ($goodsCategory) {
|
|
|
- $query->where('goods_category', $goodsCategory);
|
|
|
- })->when($classify != '', function ($query) use ($classify, $categoryId) {
|
|
|
- if ($classify == 'GOODS' && empty($categoryId)) {
|
|
|
- $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
|
|
|
- } else if ($classify != 'GOODS' && empty($categoryId)) {
|
|
|
- $query->where('goods_classify', $classify);
|
|
|
- }
|
|
|
- })->when( !empty($type),function ($query) use ($type){
|
|
|
- if ($type == 'storageWarning'){
|
|
|
- $query->where('goods_running.goods_running_storage','<=',2);
|
|
|
+ $total = Goods::leftJoin('goods_running', 'goods_running.join_running_goods_id', '=', 'goods.goods_id')
|
|
|
+ ->when($goodsName != '', function ($query) use ($goodsName) {
|
|
|
+ $query->where(function ($q) use ($goodsName) {
|
|
|
+ $q->where('goods_name', 'like', '%' . $goodsName . '%')
|
|
|
+ ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
|
|
|
+ });
|
|
|
+ })->when($categoryId != null, function ($query) use ($categoryId) {
|
|
|
+ $query->whereIn('join_goods_category_id', $categoryId);
|
|
|
+ })->when($goodsCategory != null, function ($query) use ($goodsCategory) {
|
|
|
+ $query->where('goods_category', $goodsCategory);
|
|
|
+ })->when($classify != '', function ($query) use ($classify, $categoryId) {
|
|
|
+ if ($classify == 'GOODS' && empty($categoryId)) {
|
|
|
+ $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
|
|
|
+ } else if ($classify != 'GOODS' && empty($categoryId)) {
|
|
|
+ $query->where('goods_classify', $classify);
|
|
|
+ }
|
|
|
+ })->when(!empty($type), function ($query) use ($type) {
|
|
|
+ if ($type == 'storageWarning') {
|
|
|
+ $query->where('goods_running.goods_running_storage', '<=', 2);
|
|
|
}
|
|
|
+ })->when(!empty($goodsSupplierId), function ($query) use ($goodsSupplierId) {
|
|
|
+ $query->where('join_goods_supplier_id', $goodsSupplierId);
|
|
|
+ })->when(!empty($goodsStatus), function ($query) use ($goodsStatus) {
|
|
|
+ $query->where('goods_status', $goodsStatus);
|
|
|
})
|
|
|
->count();
|
|
|
|
|
@@ -516,58 +528,78 @@ class GoodsService
|
|
|
|
|
|
public static function selectCascaderList(Request $request)
|
|
|
{
|
|
|
- $categoryIds = $request->get('category_id','');
|
|
|
- $categorySuperId = $request->get('category_super_id','');
|
|
|
- $joinGoodsCategoryId = $request->get('join_goods_category_id','');
|
|
|
- if (!$categoryIds && !$categorySuperId && !$joinGoodsCategoryId){
|
|
|
+ $categoryIds = $request->get('category_id', '');
|
|
|
+ $categorySuperId = $request->get('category_super_id', '');
|
|
|
+ $joinGoodsCategoryId = $request->get('join_goods_category_id', '');
|
|
|
+ $type = $request->get('type', '');
|
|
|
+ if (!$categoryIds && !$categorySuperId && !$joinGoodsCategoryId) {
|
|
|
return json_fail('参数异常');
|
|
|
}
|
|
|
$data = [];
|
|
|
$categorys = [];
|
|
|
- if (!empty($categoryIds)){
|
|
|
- $categorys = SysCategory::whereIn('category_id',$categoryIds)
|
|
|
- ->where('category_status','ACTIVED')
|
|
|
- ->select('category_id as id','category_name as name','category_super_id as pid','category_super_path')
|
|
|
- ->orderBy('category_sort','DESC')
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
- $data = array_merge($data,$categorys);
|
|
|
- }else if(!empty($categorySuperId)){
|
|
|
- $categorys = SysCategory::where('category_super_id',$categorySuperId)
|
|
|
- ->where('category_status','ACTIVED')
|
|
|
- ->select('category_id as id','category_name as name','category_super_id as pid','category_super_path')
|
|
|
- ->orderBy('category_sort','DESC')
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
- $data = array_merge($data,$categorys);
|
|
|
+ if (!empty($categoryIds)) {
|
|
|
+ $categorys = SysCategory::whereIn('category_id', $categoryIds)
|
|
|
+ ->where('category_status', 'ACTIVED')
|
|
|
+ ->select('category_id as id', 'category_name as name', 'category_super_id as pid', 'category_super_path')
|
|
|
+ ->orderBy('category_sort', 'DESC')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $data = array_merge($data, $categorys);
|
|
|
+ } else if (!empty($categorySuperId)) {
|
|
|
+ $categorys = SysCategory::where('category_super_id', $categorySuperId)
|
|
|
+ ->where('category_status', 'ACTIVED')
|
|
|
+ ->select('category_id as id', 'category_name as name', 'category_super_id as pid', 'category_super_path')
|
|
|
+ ->orderBy('category_sort', 'DESC')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $data = array_merge($data, $categorys);
|
|
|
}
|
|
|
|
|
|
- foreach ($categorys as $category){
|
|
|
+ foreach ($categorys as $category) {
|
|
|
// if(empty($category['category_super_path'])){
|
|
|
- $category['category_super_path'] = '#'.$category['id'].'#';
|
|
|
+ $category['category_super_path'] = '#' . $category['id'] . '#';
|
|
|
// }
|
|
|
- $subCategory = SysCategory::where('category_super_path','like','%'.$category['category_super_path'].'%')
|
|
|
- ->where('category_status','ACTIVED')
|
|
|
- ->select('category_id as id','category_name as name','category_super_id as pid','category_super_path')
|
|
|
- ->orderBy('category_sort','DESC')
|
|
|
+ $subCategory = SysCategory::where('category_super_path', 'like', '%' . $category['category_super_path'] . '%')
|
|
|
+ ->where('category_status', 'ACTIVED')
|
|
|
+ ->select('category_id as id', 'category_name as name', 'category_super_id as pid', 'category_super_path')
|
|
|
+ ->orderBy('category_sort', 'DESC')
|
|
|
->get()
|
|
|
->toArray();
|
|
|
- $data = array_merge($data,$subCategory);
|
|
|
+ $data = array_merge($data, $subCategory);
|
|
|
}
|
|
|
- if (empty($data) && !empty($joinGoodsCategoryId)){
|
|
|
+ if (empty($data) && !empty($joinGoodsCategoryId)) {
|
|
|
$goodsCategoryIds = $joinGoodsCategoryId;
|
|
|
- }else{
|
|
|
- $goodsCategoryIds = array_column($data,'id');
|
|
|
+ } else {
|
|
|
+ $goodsCategoryIds = array_column($data, 'id');
|
|
|
}
|
|
|
$goods = Goods::with('sku')
|
|
|
- ->whereIn('join_goods_category_id',$goodsCategoryIds)
|
|
|
- ->where('goods_status','ON')
|
|
|
- ->select('goods_id','goods_id as id','goods_name as name','join_goods_category_id as pid','goods_attribute_json','goods_classify')
|
|
|
- ->orderBy('goods_sort','DESC')
|
|
|
- ->orderBy('goods_addtimes','DESC')
|
|
|
+ ->leftJoin('goods_running', 'goods_running.join_running_goods_id', '=', 'goods.goods_id')
|
|
|
+ ->where('goods_running.goods_running_storage', '>', 0)
|
|
|
+ ->whereIn('join_goods_category_id', $goodsCategoryIds)
|
|
|
+ ->where('goods_status', 'ON');
|
|
|
+
|
|
|
+ if ($type == 'dishes') {
|
|
|
+ $uid = JwtToken::getCurrentId();
|
|
|
+ $user = SysUser::where('user_id', $uid)->first();
|
|
|
+ $restaurant = SysDept::where('dept_category', '餐厅')->where(function ($query) use ($user) {
|
|
|
+ $query->where('dept_id', $user->join_user_dept_id)->orWhere('dept_super_id', $user->join_user_dept_id);
|
|
|
+ })->first();
|
|
|
+ $supplier = Supplier::where('join_supplier_dept_id', $restaurant->dept_id)->first();
|
|
|
+ if ($supplier) {
|
|
|
+ $goods = $goods->where('join_goods_supplier_id', $supplier->supplier_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $goods = $goods->select('goods_id', 'goods_id as id', 'goods_name as name', 'join_goods_category_id as pid', 'goods_attribute_json', 'goods_classify', 'goods_sales_price', 'goods_cover', 'goods_running.goods_running_storage')
|
|
|
+ ->orderBy('goods_sort', 'DESC')
|
|
|
+ ->orderBy('goods_addtimes', 'DESC')
|
|
|
->get()
|
|
|
->toArray();
|
|
|
foreach ($goods as &$good) {
|
|
|
+ $good['goods_cover'] = getenv('STORAGE_DOMAIN') . $good['goods_cover'];
|
|
|
+ $good['goods_running_storage'] = intval($good['goods_running_storage']);
|
|
|
+ $good['nbr'] = 0;
|
|
|
if (!empty($good['sku'])) {
|
|
|
foreach ($good['sku'] as $key => $sku) {
|
|
|
if (!empty($sku['goods_sku_specs_json'])) {
|
|
@@ -575,14 +607,14 @@ class GoodsService
|
|
|
|
|
|
$skuName = '';
|
|
|
foreach ($good['sku'][$key]['goods_sku_specs_json'] as $specsKey => $skuSpecs) {
|
|
|
- $keyStr = ($specsKey == '规格') ? '' : ($specsKey.':');
|
|
|
+ $keyStr = ($specsKey == '规格') ? '' : ($specsKey . ':');
|
|
|
if (is_array($skuSpecs)) {
|
|
|
- $skuName = $skuName .$keyStr . ' ' . implode(' ', $skuSpecs) . '; ';
|
|
|
+ $skuName = $skuName . $keyStr . ' ' . implode(' ', $skuSpecs) . '; ';
|
|
|
} else {
|
|
|
- $skuName = $skuName .$keyStr . ' ' . $skuSpecs . '; ';
|
|
|
+ $skuName = $skuName . $keyStr . ' ' . $skuSpecs . '; ';
|
|
|
}
|
|
|
}
|
|
|
- $good['sku'][$key]['sku_name'] = rtrim($skuName,'; ');
|
|
|
+ $good['sku'][$key]['sku_name'] = rtrim($skuName, '; ');
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -602,11 +634,55 @@ class GoodsService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $data = array_merge($data,$goods);
|
|
|
-
|
|
|
+ $data = array_merge($data, $goods);
|
|
|
$tree = new Tree($data);
|
|
|
+ $cascaderData = $tree->getTree();
|
|
|
+
|
|
|
+ foreach ($cascaderData as $key1 => $cascader1) {
|
|
|
+ if (isset($cascader1['children'])) {
|
|
|
+ foreach ($cascader1['children'] as $key2 => $cascader2) {
|
|
|
+ if (isset($cascader2['children'])) {
|
|
|
+ foreach ($cascader2['children'] as $key3 => $cascader3) {
|
|
|
+ if (isset($cascader3['children'])) {
|
|
|
+ foreach ($cascader3['children'] as $key4 => $cascader4) {
|
|
|
+ if (!isset($cascader4['goods_id'])) {
|
|
|
+ unset($cascaderData[$key1]['children'][$key2]['children'][$key3]['children'][$key4]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (!isset($cascader3['goods_id'])) {
|
|
|
+ unset($cascaderData[$key1]['children'][$key2]['children'][$key3]);
|
|
|
+ }
|
|
|
+ if (isset($cascader3['children']) && count($cascaderData[$key1]['children'][$key2]['children']) == 0) {
|
|
|
+ unset($cascaderData[$key1]['children'][$key2]);
|
|
|
+ }
|
|
|
+ if (isset($cascader3['children']) && count($cascaderData[$key1]['children'][$key2]['children'][$key3]['children']) > 0) {
|
|
|
+ $cascaderData[$key1]['children'][$key2]['children'][$key3]['children'] = array_values($cascaderData[$key1]['children'][$key2]['children'][$key3]['children']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (!isset($cascader2['goods_id'])) {
|
|
|
+ unset($cascaderData[$key1]['children'][$key2]);
|
|
|
+ }
|
|
|
+ if (isset($cascader2['children']) && count($cascaderData[$key1]['children'][$key2]['children']) == 0) {
|
|
|
+ unset($cascaderData[$key1]['children'][$key2]);
|
|
|
+ }
|
|
|
+ if (isset($cascader2['children']) && isset($cascaderData[$key1]['children'][$key2]) && count($cascaderData[$key1]['children'][$key2]['children']) > 0) {
|
|
|
+ $cascaderData[$key1]['children'][$key2]['children'] = array_values($cascaderData[$key1]['children'][$key2]['children']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (!isset($cascader1['goods_id'])) {
|
|
|
+ unset($cascaderData[$key1]);
|
|
|
+ }
|
|
|
+ if (isset($cascader1['children']) && count($cascaderData[$key1]['children']) == 0) {
|
|
|
+
|
|
|
+ unset($cascaderData[$key1]);
|
|
|
+ }
|
|
|
+ if (isset($cascader1['children']) && isset($cascaderData[$key1]) && count($cascaderData[$key1]['children']) > 0) {
|
|
|
+ $cascaderData[$key1]['children'] = array_values($cascaderData[$key1]['children']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $cascaderData = array_values($cascaderData);
|
|
|
|
|
|
- return json_success('success', $tree->getTree());
|
|
|
+ return json_success('success', $cascaderData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -664,7 +740,7 @@ class GoodsService
|
|
|
$running = [];
|
|
|
}
|
|
|
// Sku表
|
|
|
- $skus = GoodsSku::where('join_sku_goods_id', $goodsId)->get();
|
|
|
+ $skus = GoodsSku::where('join_sku_goods_id', $goodsId)->where('goods_sku_status','ON')->get();
|
|
|
if (!empty($skus)) {
|
|
|
$skus = $skus->toArray();
|
|
|
$submitList = [];
|
|
@@ -700,8 +776,17 @@ class GoodsService
|
|
|
$skus = [];
|
|
|
}
|
|
|
|
|
|
+ // 供应商表
|
|
|
+ $supplier = [];
|
|
|
+ if (isset($main['join_goods_supplier_id']) && !empty($main['join_goods_supplier_id'])) {
|
|
|
+ $supplierModel = Supplier::where('supplier_id', $main['join_goods_supplier_id'])->select('supplier_id', 'supplier_name')->first();
|
|
|
+ if (!empty($supplierModel)) {
|
|
|
+ $supplier = $supplierModel->toArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 合并数据
|
|
|
- $data = array_merge($main, $detail, $label, $running, ['sku' => $skus]);
|
|
|
+ $data = array_merge($main, $detail, $label, $running, ['sku' => $skus], ['supplier' => $supplier]);
|
|
|
$data['goods_sku_json_label'] = [];
|
|
|
|
|
|
$data['goods_label'] = !empty($data['goods_label']) ? explode(',', $data['goods_label']) : [];
|
|
@@ -748,6 +833,9 @@ class GoodsService
|
|
|
$data['goods_service_premises'] = $extendJson['service_premises_id'];
|
|
|
}
|
|
|
}
|
|
|
+ if (!empty($extendJson['coupon'])) {
|
|
|
+ $data['coupon_list'] = $extendJson['coupon'];
|
|
|
+ }
|
|
|
|
|
|
$data['express_json'] = [];
|
|
|
if (!empty($data['goods_express_json'])) {
|
|
@@ -938,7 +1026,7 @@ class GoodsService
|
|
|
if (empty($item['join_component_goods_id'])) {
|
|
|
continue;
|
|
|
}
|
|
|
- $skus = GoodsSku::where('join_sku_goods_id', $item['join_component_goods_id'])
|
|
|
+ $skus = GoodsSku::where('join_sku_goods_id', $item['join_component_goods_id'])->where('goods_sku_status','ON')
|
|
|
->select('goods_sku_id', 'join_sku_goods_id', 'goods_sku_specs_json', 'goods_sku_sales_price')
|
|
|
->get()
|
|
|
->toArray();
|
|
@@ -1122,7 +1210,7 @@ class GoodsService
|
|
|
$goods->goods_attribute_json = json_encode($attributeJson);
|
|
|
}
|
|
|
$goods->save();
|
|
|
- $sku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->first();
|
|
|
+ $sku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->where('goods_sku_status','ON')->first();
|
|
|
$sku->goods_sku_status = $params['goods_status'];
|
|
|
$sku->goods_sku_specs_json = json_encode(['规格' => $params['goods_sales_price'] . '元']);
|
|
|
$sku->goods_sku_market_price = $params['goods_sales_price'];
|
|
@@ -1607,6 +1695,28 @@ class GoodsService
|
|
|
$attributeJson['time'] = $attributeJsonTime;
|
|
|
$model->goods_attribute_json = json_encode($attributeJson);
|
|
|
}
|
|
|
+ if (!empty($params['coupon_id']) && !empty($params['coupon_nbr'])) {
|
|
|
+ if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
|
|
|
+ $attributeJson = json_decode($model->goods_attribute_json, true);
|
|
|
+ } elseif (empty($model->goods_attribute_json)) {
|
|
|
+ $attributeJson = [];
|
|
|
+ }
|
|
|
+ $coupons = Coupon::whereIn('coupon_id', $params['coupon_id'])
|
|
|
+ ->select('coupon_id', 'coupon_name')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $couponList = [];
|
|
|
+ foreach ($coupons as $coupon) {
|
|
|
+ if (isset($params['coupon_nbr'][$coupon['coupon_id']])) {
|
|
|
+ $couponList[$coupon['coupon_id']] = [
|
|
|
+ 'num' => $params['coupon_nbr'][$coupon['coupon_id']],
|
|
|
+ 'name' => $coupon['coupon_name']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $attributeJson['coupon'] = $couponList;
|
|
|
+ $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
|
|
|
+ }
|
|
|
if ($model->save()) {
|
|
|
return $model->goods_id;
|
|
|
}
|
|
@@ -1962,6 +2072,27 @@ class GoodsService
|
|
|
$attributeJson['month'] = $months;
|
|
|
$data['goods_attribute_json'] = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
|
|
|
}
|
|
|
+ if (!empty($params['coupon_id']) && !empty($params['coupon_nbr'])) {
|
|
|
+ $attributeJson = [];
|
|
|
+ if (!empty($row->goods_attribute_json)) {
|
|
|
+ $attributeJson = json_decode($row->goods_attribute_json, true);
|
|
|
+ }
|
|
|
+ $coupons = Coupon::whereIn('coupon_id', $params['coupon_id'])
|
|
|
+ ->select('coupon_id', 'coupon_name')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $couponList = [];
|
|
|
+ foreach ($coupons as $coupon) {
|
|
|
+ if (isset($params['coupon_nbr'][$coupon['coupon_id']])) {
|
|
|
+ $couponList[$coupon['coupon_id']] = [
|
|
|
+ 'num' => $params['coupon_nbr'][$coupon['coupon_id']],
|
|
|
+ 'name' => $coupon['coupon_name']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $attributeJson['coupon'] = $couponList;
|
|
|
+ $data['goods_attribute_json'] = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
|
|
|
+ }
|
|
|
if (!empty($params['goods_premisses'])) {
|
|
|
if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
|
|
|
if (is_json($data['goods_attribute_json'])) {
|
|
@@ -2301,14 +2432,14 @@ class GoodsService
|
|
|
$specsJson = json_encode($skuArr);
|
|
|
$skuTitle = str_replace('-', ',', $item['sku']) . $params['goods_name'];
|
|
|
if ($operation == 'update' && !empty($item['sku_id'])) {
|
|
|
- $model = GoodsSku::where('goods_sku_id', $item['sku_id'])->first();
|
|
|
+ $model = GoodsSku::where('goods_sku_id', $item['sku_id'])->where('goods_sku_status','ON')->first();
|
|
|
if (!$model) {
|
|
|
$model = new GoodsSku();
|
|
|
} else {
|
|
|
unset($skusOldIds[$model->goods_sku_id]);
|
|
|
}
|
|
|
} else {
|
|
|
- $model = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->where('goods_sku_title', $skuTitle)->first();
|
|
|
+ $model = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->where('goods_sku_status','ON')->where('goods_sku_title', $skuTitle)->first();
|
|
|
if (!$model) {
|
|
|
$model = new GoodsSku();
|
|
|
} else {
|
|
@@ -2329,7 +2460,8 @@ class GoodsService
|
|
|
}
|
|
|
}
|
|
|
if ($operation == 'update' && !empty($skusOldIds)) {
|
|
|
- GoodsSku::whereIn('goods_sku_id', $skusOldIds)->delete();
|
|
|
+ // GoodsSku::whereIn('goods_sku_id', $skusOldIds)->delete();
|
|
|
+ GoodsSku::whereIn('goods_sku_id', $skusOldIds)->update(['goods_sku_status' => 'DISABLED']);
|
|
|
}
|
|
|
|
|
|
Db::commit();
|