|
|
@ -60,6 +60,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.data.domain.Page; |
|
|
import org.springframework.data.domain.Page; |
|
|
import org.springframework.data.domain.PageImpl; |
|
|
import org.springframework.data.domain.PageImpl; |
|
|
import org.springframework.data.domain.Pageable; |
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
@ -243,6 +244,57 @@ public class ShopController { |
|
|
return ResultUtil.success("编辑成功"); |
|
|
return ResultUtil.success("编辑成功"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/changeOwnerByMobile", method = RequestMethod.POST) |
|
|
|
|
|
@ResponseBody |
|
|
|
|
|
@Transactional |
|
|
|
|
|
@ApiOperation("根据手机号换绑店铺商家账号") |
|
|
|
|
|
public Result<Object> changeOwnerByMobile(@RequestParam String shopId, |
|
|
|
|
|
@RequestParam String mobile) { |
|
|
|
|
|
if (CharSequenceUtil.isBlank(shopId)) { |
|
|
|
|
|
return ResultUtil.error("店铺id不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
mobile = mobile == null ? "" : mobile.trim(); |
|
|
|
|
|
if (CharSequenceUtil.isBlank(mobile)) { |
|
|
|
|
|
return ResultUtil.error("手机号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
final Shop shop = shopService.get(shopId); |
|
|
|
|
|
if (shop == null) { |
|
|
|
|
|
return ResultUtil.error("店铺不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
final User targetUser = userService.findByMobile(mobile); |
|
|
|
|
|
if (targetUser == null) { |
|
|
|
|
|
return ResultUtil.error("未找到该手机号对应的用户,请商家先登录小程序并授权手机号"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final String oldOwnerId = shop.getShopOwnerId(); |
|
|
|
|
|
shop.setShopOwnerId(targetUser.getId()); |
|
|
|
|
|
shop.setShopMangerId(targetUser.getId()); |
|
|
|
|
|
shop.setContactPhone(mobile); |
|
|
|
|
|
shopService.update(shop); |
|
|
|
|
|
|
|
|
|
|
|
if (CharSequenceUtil.isNotBlank(oldOwnerId) && !oldOwnerId.equals(targetUser.getId())) { |
|
|
|
|
|
shopUserService.deleteAllByShopIdAndUserId(shop.getId(), oldOwnerId); |
|
|
|
|
|
} |
|
|
|
|
|
ShopUser shopUser = shopUserService.selectByUserIdAndShopId(targetUser.getId(), shop.getId()); |
|
|
|
|
|
if (shopUser == null) { |
|
|
|
|
|
shopUser = new ShopUser(); |
|
|
|
|
|
shopUser.setUser(targetUser); |
|
|
|
|
|
shopUser.setShop(shop); |
|
|
|
|
|
} |
|
|
|
|
|
shopUser.setUserName(targetUser.getUsername()); |
|
|
|
|
|
shopUser.setShopName(shop.getShopName()); |
|
|
|
|
|
shopUser.setType(ShopUserConstant.SHOP_ADMIN_COST[0]); |
|
|
|
|
|
if (shopUser.getId() == null) { |
|
|
|
|
|
shopUserService.save(shopUser); |
|
|
|
|
|
} else { |
|
|
|
|
|
shopUserService.update(shopUser); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ensureShopUserType(targetUser); |
|
|
|
|
|
shopService.refreshShopCache(shop.getId(), shop.getRegionId()); |
|
|
|
|
|
return ResultUtil.success("换绑成功"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@RequestMapping(value = "/bindPrinter", method = RequestMethod.POST) |
|
|
@RequestMapping(value = "/bindPrinter", method = RequestMethod.POST) |
|
|
@ResponseBody |
|
|
@ResponseBody |
|
|
@ApiOperation("绑定云打印机") |
|
|
@ApiOperation("绑定云打印机") |
|
|
@ -1162,6 +1214,23 @@ public class ShopController { |
|
|
return ResultUtil.data(shop); |
|
|
return ResultUtil.data(shop); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void ensureShopUserType(User user) { |
|
|
|
|
|
if (user == null || hasUserType(user.getType(), UserConstant.USER_TYPE_NORMAL)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
user.setType(CharSequenceUtil.isBlank(user.getType()) |
|
|
|
|
|
? UserConstant.USER_TYPE_NORMAL |
|
|
|
|
|
: user.getType() + "," + UserConstant.USER_TYPE_NORMAL); |
|
|
|
|
|
userService.save(user); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean hasUserType(String userType, String targetType) { |
|
|
|
|
|
if (CharSequenceUtil.isBlank(userType) || CharSequenceUtil.isBlank(targetType)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return Arrays.asList(userType.split(",")).contains(targetType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Data |
|
|
@Data |
|
|
public static class CloudPrinterBindForm { |
|
|
public static class CloudPrinterBindForm { |
|
|
private String shopId; |
|
|
private String shopId; |
|
|
|