记得上下班打卡 | git大法好,push需谨慎

Commit b5d9dcb9 authored by 姜秀龙's avatar 姜秀龙

sqb admin 需要判断商品上下架状态

parent 4e23bb64
...@@ -35,4 +35,10 @@ public class GoblinAdminSqbGoodsVo implements Serializable { ...@@ -35,4 +35,10 @@ public class GoblinAdminSqbGoodsVo implements Serializable {
@ApiModelProperty(value = "单品库存") @ApiModelProperty(value = "单品库存")
private Integer skuStock; private Integer skuStock;
@ApiModelProperty(value = "是否允许关联演出(SPU+SKU 均上架且未删除)")
private Boolean linkable;
@ApiModelProperty(value = "上下架展示:上架 / 已下架 等")
private String shelfStatusLabel;
} }
...@@ -42,4 +42,10 @@ public class GoblinSqbPerfLinkedGoodsVo implements Serializable { ...@@ -42,4 +42,10 @@ public class GoblinSqbPerfLinkedGoodsVo implements Serializable {
@ApiModelProperty(value = "状态 0-禁用 1-启用") @ApiModelProperty(value = "状态 0-禁用 1-启用")
private Integer status; private Integer status;
@ApiModelProperty(value = "是否满足上架可售(与前台一致:SPU/SKU 上架且未删)")
private Boolean linkable;
@ApiModelProperty(value = "上下架展示文案")
private String shelfStatusLabel;
} }
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
<th>商品ID</th> <th>商品ID</th>
<th>商品头图</th> <th>商品头图</th>
<th>商品名称</th> <th>商品名称</th>
<th>状态</th>
<th>商品售价(元)</th> <th>商品售价(元)</th>
<th>换购价(元)</th> <th>换购价(元)</th>
<th>商品库存</th> <th>商品库存</th>
...@@ -59,7 +60,7 @@ ...@@ -59,7 +60,7 @@
</thead> </thead>
<tbody id="linkedGoodsBody"> <tbody id="linkedGoodsBody">
<tr id="emptyRow"> <tr id="emptyRow">
<td colspan="7" style="text-align:center;color:#999;">暂无关联商品</td> <td colspan="8" style="text-align:center;color:#999;">暂无关联商品</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
...@@ -129,7 +130,8 @@ ...@@ -129,7 +130,8 @@
var spu = item.spuTitle != null ? item.spuTitle : item.spuName; var spu = item.spuTitle != null ? item.spuTitle : item.spuName;
var sku = item.skuTitle != null ? item.skuTitle : item.skuName; var sku = item.skuTitle != null ? item.skuTitle : item.skuName;
var text = item.title || formatSqbSpuSkuLabel(spu, sku); var text = item.title || formatSqbSpuSkuLabel(spu, sku);
return { id: item.skuId, text: text, _raw: item }; var linkable = item.linkable !== false;
return { id: item.skuId, text: text, disabled: !linkable, _raw: item };
})}; })};
} }
} }
...@@ -138,6 +140,11 @@ ...@@ -138,6 +140,11 @@
// 选中即添加 // 选中即添加
$('#goodsSelect').on('select2:select', function (e) { $('#goodsSelect').on('select2:select', function (e) {
var raw = e.params.data._raw; var raw = e.params.data._raw;
if (raw && raw.linkable === false) {
layer.msg('该商品已下架,不可关联', { icon: 2 });
$(this).val(null).trigger('change');
return;
}
if (raw) { addLinked(raw); } if (raw) { addLinked(raw); }
// 清空选择框 // 清空选择框
$(this).val(null).trigger('change'); $(this).val(null).trigger('change');
...@@ -158,6 +165,8 @@ ...@@ -158,6 +165,8 @@
skuId: item.skuId, spuId: item.spuId, skuId: item.skuId, spuId: item.spuId,
spuName: item.spuName || '', skuName: item.skuName || '', spuName: item.spuName || '', skuName: item.skuName || '',
coverPic: item.coverPic || '', price: item.price, stock: item.stock, coverPic: item.coverPic || '', price: item.price, stock: item.stock,
shelfStatusLabel: item.shelfStatusLabel || '',
linkable: item.linkable !== false,
settlementPrice: (item.settlementPrice != null ? item.settlementPrice : ''), settlementPrice: (item.settlementPrice != null ? item.settlementPrice : ''),
persisted: true persisted: true
}; };
...@@ -170,7 +179,7 @@ ...@@ -170,7 +179,7 @@
function renderLinkedGoods() { function renderLinkedGoods() {
var tbody = document.getElementById('linkedGoodsBody'); var tbody = document.getElementById('linkedGoodsBody');
if (linkedGoods.length === 0) { if (linkedGoods.length === 0) {
tbody.innerHTML = '<tr id="emptyRow"><td colspan="7" style="text-align:center;color:#999;">暂无关联商品</td></tr>'; tbody.innerHTML = '<tr id="emptyRow"><td colspan="8" style="text-align:center;color:#999;">暂无关联商品</td></tr>';
return; return;
} }
var html = ''; var html = '';
...@@ -181,10 +190,13 @@ ...@@ -181,10 +190,13 @@
var imgHtml = item.coverPic var imgHtml = item.coverPic
? '<img src="' + item.coverPic + '" class="img-thumb" title="点击放大" alt="商品头图"/>' ? '<img src="' + item.coverPic + '" class="img-thumb" title="点击放大" alt="商品头图"/>'
: '<span style="color:#ccc;font-size:12px;">无图</span>'; : '<span style="color:#ccc;font-size:12px;">无图</span>';
var shelfTxt = item.shelfStatusLabel || (item.linkable === false ? '已下架' : '上架');
var shelfStyle = item.linkable === false ? 'color:#c00;font-weight:bold;' : 'color:#090;';
html += '<tr data-idx="' + idx + '">'; html += '<tr data-idx="' + idx + '">';
html += '<td><small>' + item.skuId + '</small></td>'; html += '<td><small>' + item.skuId + '</small></td>';
html += '<td>' + imgHtml + '</td>'; html += '<td>' + imgHtml + '</td>';
html += '<td>' + formatSqbSpuSkuLabel(item.spuName, item.skuName) + '</td>'; html += '<td>' + formatSqbSpuSkuLabel(item.spuName, item.skuName) + '</td>';
html += '<td style="' + shelfStyle + '">' + shelfTxt + '</td>';
html += '<td>' + priceYuan + '</td>'; html += '<td>' + priceYuan + '</td>';
html += '<td><input type="number" class="form-control settlement-input" value="' + settlementVal html += '<td><input type="number" class="form-control settlement-input" value="' + settlementVal
+ '" placeholder="不填按售价" onchange="updateSettlement(' + idx + ', this.value)" min="0" step="0.01"/></td>'; + '" placeholder="不填按售价" onchange="updateSettlement(' + idx + ', this.value)" min="0" step="0.01"/></td>';
...@@ -196,6 +208,10 @@ ...@@ -196,6 +208,10 @@
} }
function addLinked(item) { function addLinked(item) {
if (item.linkable === false) {
layer.msg('该商品已下架,不可关联', { icon: 2 });
return;
}
for (var i = 0; i < linkedGoods.length; i++) { for (var i = 0; i < linkedGoods.length; i++) {
if (linkedGoods[i].skuId === item.skuId) { if (linkedGoods[i].skuId === item.skuId) {
layer.msg('该商品已在关联列表中'); layer.msg('该商品已在关联列表中');
...@@ -209,6 +225,8 @@ ...@@ -209,6 +225,8 @@
coverPic: item.skuPic || item.coverPic || '', coverPic: item.skuPic || item.coverPic || '',
price: item.price, price: item.price,
stock: (item.skuStock != null ? item.skuStock : item.stock), stock: (item.skuStock != null ? item.skuStock : item.stock),
shelfStatusLabel: item.shelfStatusLabel || (item.linkable === false ? '已下架' : '上架'),
linkable: item.linkable !== false,
settlementPrice: null, autoOffline: 0, persisted: false settlementPrice: null, autoOffline: 0, persisted: false
}); });
renderLinkedGoods(); renderLinkedGoods();
......
...@@ -42,6 +42,23 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi ...@@ -42,6 +42,23 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
/** skuType=33 代表收钱吧商品 */ /** skuType=33 代表收钱吧商品 */
private static final int SQB_SKU_TYPE = 33; private static final int SQB_SKU_TYPE = 33;
/** 与前台 Goblin 一致:单品上架状态 3=上架 */
private static final String SHELVES_ON = "3";
private static boolean isSqbSkuAndSpuOnShelf(GoblinGoodsSku sku, GoblinGoods spu) {
if (sku == null || spu == null) {
return false;
}
if (!"0".equals(sku.getDelFlg()) || !"0".equals(spu.getDelFlg())) {
return false;
}
return SHELVES_ON.equals(sku.getShelvesStatus()) && SHELVES_ON.equals(spu.getShelvesStatus());
}
private static String shelfStatusLabel(boolean onShelf) {
return onShelf ? "上架" : "已下架";
}
private static String sqbSpuSkuDisplay(String spuTitle, String skuTitle) { private static String sqbSpuSkuDisplay(String spuTitle, String skuTitle) {
String s = spuTitle != null ? spuTitle.trim() : ""; String s = spuTitle != null ? spuTitle.trim() : "";
String k = skuTitle != null ? skuTitle.trim() : ""; String k = skuTitle != null ? skuTitle.trim() : "";
...@@ -117,17 +134,28 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi ...@@ -117,17 +134,28 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
GoblinGoodsSku sku = goblinGoodsSkuMapper.selectOne(skuQuery); GoblinGoodsSku sku = goblinGoodsSkuMapper.selectOne(skuQuery);
if (sku == null) { if (sku == null) {
log.warn("[演出商品关联] SKU不存在,skuId={}", skuId); log.warn("[演出商品关联] SKU不存在,skuId={}", skuId);
continue; return ResponseDto.failure("SKU不存在:" + skuId);
} }
int sortVal = item.getSort() != null ? item.getSort() : 0;
LambdaQueryWrapper<GoblinSqbPerformanceGoods> existQuery = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoblinSqbPerformanceGoods> existQuery = new LambdaQueryWrapper<>();
existQuery.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId) existQuery.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId)
.eq(GoblinSqbPerformanceGoods::getSkuId, skuId) .eq(GoblinSqbPerformanceGoods::getSkuId, skuId)
.last("LIMIT 1"); .last("LIMIT 1");
GoblinSqbPerformanceGoods existing = performanceGoodsMapper.selectOne(existQuery); GoblinSqbPerformanceGoods existing = performanceGoodsMapper.selectOne(existQuery);
if (sku.getSkuType() == null || sku.getSkuType() != SQB_SKU_TYPE) {
return ResponseDto.failure("仅可关联收钱吧商品(skuType=33),skuId=" + skuId);
}
if (existing == null) {
GoblinGoods spu = goblinGoodsMapper.selectOne(new LambdaQueryWrapper<GoblinGoods>()
.eq(GoblinGoods::getSpuId, sku.getSpuId()).last("LIMIT 1"));
if (!isSqbSkuAndSpuOnShelf(sku, spu)) {
return ResponseDto.failure("商品未上架或已下架,不可关联。请先让商户上架后再操作。skuId=" + skuId);
}
}
int sortVal = item.getSort() != null ? item.getSort() : 0;
if (existing != null) { if (existing != null) {
LambdaUpdateWrapper<GoblinSqbPerformanceGoods> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<GoblinSqbPerformanceGoods> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId) updateWrapper.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId)
...@@ -229,14 +257,17 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi ...@@ -229,14 +257,17 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<String, String> spuNameById = new HashMap<>(); Map<String, String> spuNameById = new HashMap<>();
Map<String, String> spuCoverById = new HashMap<>(); Map<String, String> spuCoverById = new HashMap<>();
Map<String, GoblinGoods> spuById = new HashMap<>();
if (!spuIdList.isEmpty()) { if (!spuIdList.isEmpty()) {
LambdaQueryWrapper<GoblinGoods> goodsQuery = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoblinGoods> goodsQuery = new LambdaQueryWrapper<>();
goodsQuery.in(GoblinGoods::getSpuId, spuIdList) goodsQuery.in(GoblinGoods::getSpuId, spuIdList)
.select(GoblinGoods::getSpuId, GoblinGoods::getName, GoblinGoods::getCoverPic); .select(GoblinGoods::getSpuId, GoblinGoods::getName, GoblinGoods::getCoverPic,
GoblinGoods::getShelvesStatus, GoblinGoods::getDelFlg);
for (GoblinGoods g : goblinGoodsMapper.selectList(goodsQuery)) { for (GoblinGoods g : goblinGoodsMapper.selectList(goodsQuery)) {
if (g.getSpuId() != null) { if (g.getSpuId() != null) {
spuNameById.put(g.getSpuId(), g.getName()); spuNameById.put(g.getSpuId(), g.getName());
spuCoverById.put(g.getSpuId(), g.getCoverPic()); spuCoverById.put(g.getSpuId(), g.getCoverPic());
spuById.put(g.getSpuId(), g);
} }
} }
} }
...@@ -257,6 +288,13 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi ...@@ -257,6 +288,13 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
vo.setCoverPic(pickSkuOrSpuCover(sku.getSkuPic(), spuCoverById.get(rel.getSpuId()))); vo.setCoverPic(pickSkuOrSpuCover(sku.getSkuPic(), spuCoverById.get(rel.getSpuId())));
vo.setPrice(sku.getPrice()); vo.setPrice(sku.getPrice());
vo.setStock(sku.getSkuStock()); vo.setStock(sku.getSkuStock());
GoblinGoods spu = spuById.get(rel.getSpuId());
boolean onShelf = isSqbSkuAndSpuOnShelf(sku, spu);
vo.setLinkable(onShelf);
vo.setShelfStatusLabel(shelfStatusLabel(onShelf));
} else {
vo.setLinkable(false);
vo.setShelfStatusLabel("已下架");
} }
goodsList.add(vo); goodsList.add(vo);
} }
...@@ -273,7 +311,7 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi ...@@ -273,7 +311,7 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
public ResponseDto<List<GoblinAdminSqbGoodsVo>> searchGoods(String keyword) { public ResponseDto<List<GoblinAdminSqbGoodsVo>> searchGoods(String keyword) {
try { try {
LambdaQueryWrapper<GoblinGoodsSku> skuQuery = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoblinGoodsSku> skuQuery = new LambdaQueryWrapper<>();
skuQuery.eq(GoblinGoodsSku::getSkuType, SQB_SKU_TYPE); skuQuery.eq(GoblinGoodsSku::getSkuType, SQB_SKU_TYPE).ne(GoblinGoodsSku::getDelFlg, "1");
if (StringUtils.hasText(keyword)) { if (StringUtils.hasText(keyword)) {
LambdaQueryWrapper<GoblinGoods> goodsQuery = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoblinGoods> goodsQuery = new LambdaQueryWrapper<>();
goodsQuery.select(GoblinGoods::getSpuId) goodsQuery.select(GoblinGoods::getSpuId)
...@@ -304,14 +342,17 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi ...@@ -304,14 +342,17 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<String, String> spuTitleById = new HashMap<>(); Map<String, String> spuTitleById = new HashMap<>();
Map<String, String> spuCoverById = new HashMap<>(); Map<String, String> spuCoverById = new HashMap<>();
Map<String, GoblinGoods> spuRowById = new HashMap<>();
if (!spuIdForTitle.isEmpty()) { if (!spuIdForTitle.isEmpty()) {
LambdaQueryWrapper<GoblinGoods> gq = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoblinGoods> gq = new LambdaQueryWrapper<>();
gq.in(GoblinGoods::getSpuId, spuIdForTitle) gq.in(GoblinGoods::getSpuId, spuIdForTitle)
.select(GoblinGoods::getSpuId, GoblinGoods::getName, GoblinGoods::getCoverPic); .select(GoblinGoods::getSpuId, GoblinGoods::getName, GoblinGoods::getCoverPic,
GoblinGoods::getShelvesStatus, GoblinGoods::getDelFlg);
for (GoblinGoods g : goblinGoodsMapper.selectList(gq)) { for (GoblinGoods g : goblinGoodsMapper.selectList(gq)) {
if (g.getSpuId() != null) { if (g.getSpuId() != null) {
spuTitleById.put(g.getSpuId(), g.getName()); spuTitleById.put(g.getSpuId(), g.getName());
spuCoverById.put(g.getSpuId(), g.getCoverPic()); spuCoverById.put(g.getSpuId(), g.getCoverPic());
spuRowById.put(g.getSpuId(), g);
} }
} }
} }
...@@ -325,7 +366,11 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi ...@@ -325,7 +366,11 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
String skuTitle = sku.getName() != null ? sku.getName() : ""; String skuTitle = sku.getName() != null ? sku.getName() : "";
vo.setSpuTitle(spuTitle); vo.setSpuTitle(spuTitle);
vo.setSkuTitle(skuTitle); vo.setSkuTitle(skuTitle);
vo.setTitle(sqbSpuSkuDisplay(spuTitle, skuTitle)); GoblinGoods spu = spuRowById.get(sku.getSpuId());
boolean onShelf = isSqbSkuAndSpuOnShelf(sku, spu);
vo.setLinkable(onShelf);
vo.setShelfStatusLabel(shelfStatusLabel(onShelf));
vo.setTitle(sqbSpuSkuDisplay(spuTitle, skuTitle) + (onShelf ? "" : "(已下架)"));
vo.setSkuPic(pickSkuOrSpuCover(sku.getSkuPic(), spuCoverById.get(sku.getSpuId()))); vo.setSkuPic(pickSkuOrSpuCover(sku.getSkuPic(), spuCoverById.get(sku.getSpuId())));
vo.setPrice(sku.getPrice()); vo.setPrice(sku.getPrice());
vo.setSkuStock(sku.getSkuStock()); vo.setSkuStock(sku.getSkuStock());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment