|
@@ -36,6 +36,17 @@ class GoodsService
|
|
|
$pageSize = $request->get('pageSize');
|
|
|
$goodsName = $request->get('goods_name', '');
|
|
|
$categoryId = $request->get('join_goods_category_id', null);
|
|
|
+ $goodsCategory = $request->get('goods_category', null);
|
|
|
+ if ($categoryId != null) {
|
|
|
+ $categoryPath = SysCategory::where('category_id', $categoryId)->value('category_super_path');
|
|
|
+ $categoryPath .= '#' . $categoryId . '#';
|
|
|
+ $categoryIds = SysCategory::where('category_super_path', 'like', $categoryPath . '%')->pluck('category_id')->toArray();
|
|
|
+ if (!empty($categoryIds)) {
|
|
|
+ $categoryId = $categoryIds;
|
|
|
+ } else {
|
|
|
+ $categoryId = [$categoryId];
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$rows = Goods::with([
|
|
|
'category' => function ($query) {
|
|
@@ -54,7 +65,9 @@ class GoodsService
|
|
|
->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
|
|
|
});
|
|
|
})->when($categoryId != null, function ($query) use ($categoryId) {
|
|
|
- $query->where('join_goods_category_id', $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) {
|
|
|
if ($classify == 'GOODS') {
|
|
@@ -74,7 +87,9 @@ class GoodsService
|
|
|
->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
|
|
|
});
|
|
|
})->when($categoryId != null, function ($query) use ($categoryId) {
|
|
|
- $query->where('join_goods_category_id', $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) {
|
|
|
if ($classify == 'GOODS') {
|
|
|
$query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
|
|
@@ -455,7 +470,6 @@ class GoodsService
|
|
|
$data['goods_json'][$key]['color'] = rgbToHex($datum['color']);
|
|
|
}
|
|
|
} elseif (!empty($data['goods_json']) && $data['join_goods_category_id'] == 43) {
|
|
|
-// dump($data['goods_json']);
|
|
|
foreach ($data['goods_json'] as $key1 => $item1) {
|
|
|
$data['goods_json'][$key1]['title'] = $key1;
|
|
|
foreach ($item1['items'] as $key2 => $item2) {
|
|
@@ -851,17 +865,65 @@ class GoodsService
|
|
|
|
|
|
if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times'])) {
|
|
|
$times = [];
|
|
|
+ $attributeJsonTimeArr = [];
|
|
|
+ $personTotal = 0;
|
|
|
foreach ($params['appointment_times'] as $time) {
|
|
|
+ $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeStart']);
|
|
|
+ $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeEnd']);
|
|
|
+ $personTotal += $time['person'];
|
|
|
$times[$time['appointmentTimeStart']] = [
|
|
|
'person' => $time['person'],
|
|
|
'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
|
|
|
];
|
|
|
}
|
|
|
- $model->goods_attribute_json = json_encode([
|
|
|
+ $attributeJsonTime = date('H:i',min($attributeJsonTimeArr)).'至'.date('H:i',max($attributeJsonTimeArr));
|
|
|
+
|
|
|
+ $newDates = [];
|
|
|
+ foreach ($params['dates'] as $date) {
|
|
|
+ $key = self::$week[$date];
|
|
|
+ $newDates[$key] = $date;
|
|
|
+ }
|
|
|
+ ksort($newDates);
|
|
|
+
|
|
|
+
|
|
|
+ $currentDate = current($newDates);
|
|
|
+ $lastDate = end($newDates);
|
|
|
+
|
|
|
+ $attributeJsonDate = '';
|
|
|
+ if (self::$week[$lastDate] - self::$week[$currentDate] + 1 > count($newDates)) {
|
|
|
+ $attributeJsonDate = implode(',', $newDates);
|
|
|
+ } else if (self::$week[$lastDate] - self::$week[$currentDate] + 1 == count($newDates)) {
|
|
|
+ $attributeJsonDate = $currentDate . '至' . $lastDate;
|
|
|
+ }
|
|
|
+ $attributeJson = [
|
|
|
'icon' => '',
|
|
|
- 'dates' => $params['dates'] ?? [],
|
|
|
- 'times' => $times
|
|
|
- ]);
|
|
|
+ 'date' => $attributeJsonDate,
|
|
|
+ 'time' => $attributeJsonTime,
|
|
|
+ 'dates' => $newDates ? array_values($newDates) : [],
|
|
|
+ 'times' => $times,
|
|
|
+ 'person' => $personTotal
|
|
|
+ ];
|
|
|
+ if (!empty($params['appointment_label'])) {
|
|
|
+ $attributeJson['label'] = $params['appointment_label'];
|
|
|
+ }
|
|
|
+ if (!empty($params['address'])) {
|
|
|
+ $attributeJson['address'] = $params['address'];
|
|
|
+ $attributeJson['position'] = $params['position'];
|
|
|
+ }
|
|
|
+ $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
|
|
|
+
|
|
|
+// $times = [];
|
|
|
+// foreach ($params['appointment_times'] as $time) {
|
|
|
+// $times[$time['appointmentTimeStart']] = [
|
|
|
+// 'person' => $time['person'],
|
|
|
+// 'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
|
|
|
+// ];
|
|
|
+// }
|
|
|
+// $model->goods_attribute_json = json_encode([
|
|
|
+// 'icon' => '',
|
|
|
+// 'dates' => $params['dates'] ?? [],
|
|
|
+// 'times' => $times
|
|
|
+// ]);
|
|
|
}
|
|
|
if (!empty($params['goods_json']) && $params['join_goods_category_id'] == 65) {
|
|
|
$goodsJson = json_decode($params['goods_json'], true);
|
|
@@ -964,7 +1026,6 @@ class GoodsService
|
|
|
'goods_component_addtimes' => time()
|
|
|
];
|
|
|
}
|
|
|
- dump($data);
|
|
|
|
|
|
if ($data) {
|
|
|
GoodsComponent::insert($data);
|
|
@@ -1094,16 +1155,43 @@ class GoodsService
|
|
|
}
|
|
|
if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times'])) {
|
|
|
$times = [];
|
|
|
+ $attributeJsonTimeArr = [];
|
|
|
+ $personTotal = 0;
|
|
|
foreach ($params['appointment_times'] as $time) {
|
|
|
+ $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeStart']);
|
|
|
+ $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeEnd']);
|
|
|
+ $personTotal += $time['person'];
|
|
|
$times[$time['appointmentTimeStart']] = [
|
|
|
'person' => $time['person'],
|
|
|
'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
|
|
|
];
|
|
|
}
|
|
|
+ $attributeJsonTime = date('H:i',min($attributeJsonTimeArr)).'至'.date('H:i',max($attributeJsonTimeArr));
|
|
|
+
|
|
|
+ $newDates = [];
|
|
|
+ foreach ($params['dates'] as $date) {
|
|
|
+ $key = self::$week[$date];
|
|
|
+ $newDates[$key] = $date;
|
|
|
+ }
|
|
|
+ ksort($newDates);
|
|
|
+
|
|
|
+
|
|
|
+ $currentDate = current($newDates);
|
|
|
+ $lastDate = end($newDates);
|
|
|
+
|
|
|
+ $attributeJsonDate = '';
|
|
|
+ if (self::$week[$lastDate] - self::$week[$currentDate] + 1 > count($newDates)) {
|
|
|
+ $attributeJsonDate = implode(',', $newDates);
|
|
|
+ } else if (self::$week[$lastDate] - self::$week[$currentDate] + 1 == count($newDates)) {
|
|
|
+ $attributeJsonDate = $currentDate . '至' . $lastDate;
|
|
|
+ }
|
|
|
$attributeJson = [
|
|
|
'icon' => '',
|
|
|
- 'dates' => $params['dates'] ?? [],
|
|
|
- 'times' => $times
|
|
|
+ 'date' => $attributeJsonDate,
|
|
|
+ 'time' => $attributeJsonTime,
|
|
|
+ 'dates' => $newDates ? array_values($newDates) : [],
|
|
|
+ 'times' => $times,
|
|
|
+ 'person' => $personTotal
|
|
|
];
|
|
|
if (!empty($params['appointment_label'])) {
|
|
|
$attributeJson['label'] = $params['appointment_label'];
|
|
@@ -1112,7 +1200,7 @@ class GoodsService
|
|
|
$attributeJson['address'] = $params['address'];
|
|
|
$attributeJson['position'] = $params['position'];
|
|
|
}
|
|
|
- $data['goods_attribute_json'] = json_encode($attributeJson);
|
|
|
+ $data['goods_attribute_json'] = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
|
|
|
}
|
|
|
if (!empty($data['goods_json']) && $data['join_goods_category_id'] == 65) {
|
|
|
$goodsJson = json_decode($data['goods_json'], true);
|
|
@@ -1137,8 +1225,6 @@ class GoodsService
|
|
|
$data['goods_json'] = '[]';
|
|
|
}
|
|
|
|
|
|
- dump($data);
|
|
|
-
|
|
|
foreach ($data as $key => $val) {
|
|
|
$row->{$key} = $val;
|
|
|
}
|
|
@@ -1146,7 +1232,7 @@ class GoodsService
|
|
|
} catch (BusinessException $e) {
|
|
|
throw new BusinessException($e->getMessage());
|
|
|
} catch (\Exception $e) {
|
|
|
- dump($e->getMessage());
|
|
|
+ dump($e->getTrace());
|
|
|
throw new BusinessException('数据更新异常~1');
|
|
|
}
|
|
|
}
|
|
@@ -1197,12 +1283,11 @@ class GoodsService
|
|
|
{
|
|
|
try {
|
|
|
$data = self::inputFilter($params, new GoodsLabel());
|
|
|
- dump($data);
|
|
|
// 根据goods_id 查详情ID
|
|
|
$detail = GoodsLabel::where('join_label_goods_id', $params['goods_id'])->first();
|
|
|
if ($detail) {
|
|
|
self::doUpdate($detail->goods_label_id, $data, new GoodsLabel());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$data['join_label_goods_id'] = $params['goods_id'];
|
|
|
GoodsLabel::insert($data);
|
|
|
}
|
|
@@ -1295,7 +1380,7 @@ class GoodsService
|
|
|
// 删掉原有的
|
|
|
// GoodsSku::where('join_sku_goods_id', $params['goods_id'])->delete();
|
|
|
}
|
|
|
- if (empty($skusOldIds) && empty($params['goods_sku_json_value'])){
|
|
|
+ if (empty($skusOldIds) && empty($params['goods_sku_json_value'])) {
|
|
|
$skuData = [
|
|
|
'join_sku_goods_id' => $params['goods_id'],
|
|
|
'goods_sku_status' => 'ON',
|
|
@@ -1330,7 +1415,6 @@ class GoodsService
|
|
|
if (!$model) {
|
|
|
$model = new GoodsSku();
|
|
|
} else {
|
|
|
- dump($model->goods_sku_id);
|
|
|
unset($skusOldIds[$model->goods_sku_id]);
|
|
|
}
|
|
|
|
|
@@ -1463,4 +1547,14 @@ class GoodsService
|
|
|
$redis->del($key);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static $week = [
|
|
|
+ '周一' => 1,
|
|
|
+ '周二' => 2,
|
|
|
+ '周三' => 3,
|
|
|
+ '周四' => 4,
|
|
|
+ '周五' => 5,
|
|
|
+ '周六' => 6,
|
|
|
+ '周日' => 7,
|
|
|
+ ];
|
|
|
}
|