|
@@ -1,6 +1,7 @@
|
|
|
package com.ydd.app.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baidu.aip.ocr.AipOcr;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.ydd.api.DeliveryService;
|
|
@@ -10,9 +11,12 @@ import com.ydd.app.dto.ShopReq;
|
|
|
import com.ydd.app.dto.StoreDto;
|
|
|
import com.ydd.app.dto.StoreStatusDto;
|
|
|
import com.ydd.app.service.ApiStoreService;
|
|
|
+import com.ydd.common.constant.BillingConstant;
|
|
|
+import com.ydd.common.core.domain.ResponseResult;
|
|
|
import com.ydd.common.enums.DeliveryTypeEnums;
|
|
|
import com.ydd.common.enums.ResponseResultCodeEnum;
|
|
|
import com.ydd.common.utils.SnCodeUtils;
|
|
|
+import com.ydd.common.utils.StringUtils;
|
|
|
import com.ydd.ecloud.core.utils.JsonMapper;
|
|
|
import com.ydd.module.domain.*;
|
|
|
import com.ydd.module.dto.StoreDeliveryDto;
|
|
@@ -23,6 +27,8 @@ import com.ydd.module.enums.StatusEnum;
|
|
|
import com.ydd.module.expection.CustomAppException;
|
|
|
import com.ydd.module.service.*;
|
|
|
import com.ydd.system.service.ISysConfigService;
|
|
|
+import com.ydd.third.common.utils.AddressLngLatExchanger;
|
|
|
+import com.ydd.third.common.utils.CoordinateUtils;
|
|
|
import com.ydd.third.common.vo.ResObject;
|
|
|
import com.ydd.third.common.vo.shop.ShopResultVo;
|
|
|
import com.ydd.third.common.vo.shop.ShopVo;
|
|
@@ -33,6 +39,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -69,24 +76,49 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public JSONObject saveShop(Long loginId, StoreDto shopReq, boolean isMerchant) {
|
|
|
+ public ResponseResult saveShop(Long loginId, StoreDto shopReq, boolean isMerchant) {
|
|
|
JSONObject resp = new JSONObject();
|
|
|
- resp.put("code",0);
|
|
|
Member member = iMemberService.getById(loginId);
|
|
|
-// if (member.getMerchantId() == null) {
|
|
|
-// resp.put("code",-1);
|
|
|
-// resp.put("msg","门店分类不存在");
|
|
|
-// return resp;
|
|
|
-// throw new CustomAppException("请先申请成为商家!");
|
|
|
-// }
|
|
|
+ Map<String, Object> map = AddressLngLatExchanger.addressToLngAndLag(shopReq.getAddress());
|
|
|
+ double distance = CoordinateUtils.getDistance(Double.parseDouble(map.get("lng") + ""), Double.parseDouble(map.get("lat") + ""), Double.parseDouble(shopReq.getLongitude()), Double.parseDouble(shopReq.getLatitude()));
|
|
|
+ if (distance > 50) {
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_ADDRESS_ERROR);
|
|
|
+ }
|
|
|
+ AipOcr client = new AipOcr("23831014", "BELGCxGTPOlcZzeZ85OLyIpD", "pLt8IG1PoXZBaDonLfFM9EkXndI1OBxh");
|
|
|
+ String idCardName = "";
|
|
|
+ if (StringUtils.isNotBlank(shopReq.getIdcardFront())) {
|
|
|
+ //百度ocr校验
|
|
|
+ org.json.JSONObject json = client.idcard(shopReq.getIdcardFront(), "front", new HashMap<String, String>());
|
|
|
+ if(json.getJSONObject("words_result")!=null){
|
|
|
+ String idCardNo = json.getJSONObject("words_result").getJSONObject("公民身份号码").getString("words");
|
|
|
+ idCardName = json.getJSONObject("words_result").getJSONObject("姓名").getString("words");
|
|
|
+ if(!idCardNo.equals(shopReq.getIdcardNo())){
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.ID_CARD_VERIFY_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(shopReq.getBizLicense())) {
|
|
|
+ //百度ocr校验
|
|
|
+ org.json.JSONObject json = client.businessLicense(shopReq.getIdcardFront(), new HashMap<String, String>());
|
|
|
+ if(json.getJSONObject("words_result")!=null){
|
|
|
+ String bizNo = json.getJSONObject("words_result").getJSONObject("社会信用代码").getString("words");
|
|
|
+ String name = json.getJSONObject("words_result").getJSONObject("法人").getString("words");
|
|
|
+ if(!bizNo.equals(shopReq.getBizLicenseNo())){
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.BUSINESS_LICENCSE_VERIFY_FAIL);
|
|
|
+ }
|
|
|
+ if(!idCardName.equals(name)){
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.BUSINESS_LICENCSE_AND_FAREN_VERIFY_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
Merchant merchant = iMerchantService.getById(member.getMerchantId());
|
|
|
if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
|
|
|
- resp.put("code", ResponseResultCodeEnum.MERCHANT_DISABLE);
|
|
|
- return resp;
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.MERCHANT_DISABLE);
|
|
|
}
|
|
|
if (merchant.getStatus().equals(MerchantStatusEnum.TO_BE_CERTIFIED.status)) {
|
|
|
- resp.put("code", ResponseResultCodeEnum.MERCHANT_IS_AUDIT);
|
|
|
- return resp;
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.MERCHANT_IS_AUDIT);
|
|
|
}
|
|
|
Long categoryId = merchant.getCategoryId();
|
|
|
if (null != shopReq.getCategoryId()) {
|
|
@@ -94,22 +126,20 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
}
|
|
|
MerchantCategory category = iMerchantCategoryService.getById(categoryId);
|
|
|
if (category == null) {
|
|
|
- resp.put("code", ResponseResultCodeEnum.SHOP_CATEGORY_NOT_EXIST);
|
|
|
- return resp;
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_CATEGORY_NOT_EXIST);
|
|
|
}
|
|
|
- Shop existShop = iShopService.getOne(new QueryWrapper<Shop>().eq("name",shopReq.getShopName()));
|
|
|
- if(existShop!=null){
|
|
|
- resp.put("code", ResponseResultCodeEnum.SHOP_EXIST);
|
|
|
- return resp;
|
|
|
+ Shop existShop = iShopService.getOne(new QueryWrapper<Shop>().eq("name", shopReq.getShopName()));
|
|
|
+ if (existShop != null) {
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_EXIST);
|
|
|
}
|
|
|
Shop shop = new Shop();
|
|
|
- shop = shopBean(shop,shopReq);
|
|
|
+ shop = shopBean(shop, shopReq);
|
|
|
shop.setCategoryId(categoryId);
|
|
|
shop.setCode(SnCodeUtils.createShopSn());
|
|
|
shop.setMerchantId(member.getMerchantId());
|
|
|
// 如果商家打印二维码开启,新增门店也打开
|
|
|
if (merchant.getOpenQrCode() == 1) {
|
|
|
- shop.setOpenQrCode(1);
|
|
|
+ shop.setOpenQrCode(1);
|
|
|
}
|
|
|
iShopService.save(shop);
|
|
|
//绑定最新门店到账户
|
|
@@ -173,26 +203,26 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
}
|
|
|
iShopDeliveryService.save(delivery);
|
|
|
// 存lb_shop_third表中
|
|
|
- saveShopThird(shop,delivery.getDeliveryId());
|
|
|
+ saveShopThird(shop, delivery.getDeliveryId());
|
|
|
}
|
|
|
|
|
|
- resp.put("shopCode",shop.getCode());
|
|
|
- return resp;
|
|
|
+ resp.put("shopCode", shop.getCode());
|
|
|
+ return ResponseResult.success(resp);
|
|
|
}
|
|
|
|
|
|
- private Shop shopBean(Shop shop,StoreDto shopReq){
|
|
|
+ private Shop shopBean(Shop shop, StoreDto shopReq) {
|
|
|
shop.setProvinceName(shopReq.getProvinceName());
|
|
|
shop.setCityName(shopReq.getCityName());
|
|
|
shop.setDistrictName(shopReq.getDistrictName());
|
|
|
shop.setAddress(shopReq.getAddress());
|
|
|
shop.setContactName(shopReq.getContactName());
|
|
|
- shop.setDoorHeadPhoto(shopReq.getHouseNumber());
|
|
|
+ // shop.setDoorHeadPhoto(shopReq.getHouseNumber());
|
|
|
shop.setLat(shopReq.getLatitude());
|
|
|
shop.setLng(shopReq.getLongitude());
|
|
|
// shop.setCityCode(shopReq.getCityCode());
|
|
|
shop.setMobile(shopReq.getContactPhone());
|
|
|
shop.setName(shopReq.getShopName());
|
|
|
- shop.setStreet(shopReq.getAddress());
|
|
|
+ shop.setStreet(shopReq.getHouseNumber());
|
|
|
shop.setBizLicense(shopReq.getBizLicense());
|
|
|
shop.setBizLicenseNo(shopReq.getBizLicenseNo());
|
|
|
//shop.setLegalPerson(shopReq.getLegalPerson());
|
|
@@ -202,9 +232,10 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
// shop.setBizLicenseIdcard(shopReq.getBizLicenseIdcard());
|
|
|
shop.setPoiAddress(shopReq.getPoiAddress());
|
|
|
|
|
|
- return shop;
|
|
|
+ return shop;
|
|
|
}
|
|
|
- private void saveShopThird(Shop shop,Long deliveryId){
|
|
|
+
|
|
|
+ private void saveShopThird(Shop shop, Long deliveryId) {
|
|
|
ShopThird shopThird = new ShopThird();
|
|
|
shopThird.setShopId(shop.getId());
|
|
|
shopThird.setAddress(shop.getAddress());
|
|
@@ -225,7 +256,7 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private ShopReq coverShopReq(Shop shop){
|
|
|
+ private ShopReq coverShopReq(Shop shop) {
|
|
|
ShopReq req = new ShopReq();
|
|
|
req.setAddress(shop.getAddress());
|
|
|
req.setContactName(shop.getContactName());
|
|
@@ -248,7 +279,7 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
req.setBizLicenseIdcard(shop.getBizLicenseIdcard());
|
|
|
req.setFoodLicensePic(shop.getFoodLicensePic());
|
|
|
req.setPoiAddress(shop.getPoiAddress());
|
|
|
- return req;
|
|
|
+ return req;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -267,20 +298,22 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject changeShopDelivery(Long loginId,StoreStatusDto storeStatusDto) {
|
|
|
- JSONObject json = new JSONObject();
|
|
|
+ public ResponseResult changeShopDelivery(Long loginId, StoreStatusDto storeStatusDto) {
|
|
|
Shop shop = iShopService.getByCode(storeStatusDto.getShopCode());
|
|
|
if (shop == null) {
|
|
|
- json.put("code", ResponseResultCodeEnum.SHOP_NOT_EXIST);
|
|
|
- return json;
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_NOT_EXIST);
|
|
|
}
|
|
|
String deliverIdStr = storeStatusDto.getDeliveryIdStr();
|
|
|
- List<String> deliverIds= Arrays.stream(deliverIdStr.split(",")).collect(Collectors.toList());
|
|
|
- if(StatusEnum.SHOW.getStatus()==storeStatusDto.getStatus()){
|
|
|
- iShopDeliveryDisableService.remove(new UpdateWrapper<ShopDeliveryDisable>().in("delivery_type",deliverIds).eq("shop_id",shop.getId()));
|
|
|
- }else{
|
|
|
+ List<String> deliverIds = Arrays.stream(deliverIdStr.split(",")).collect(Collectors.toList());
|
|
|
+ List<DspDelivery> list = iDspDeliveryService.list(new QueryWrapper<DspDelivery>().in("type", deliverIds).isNotNull("dsp_id"));
|
|
|
+ if (deliverIds.size() != list.size()) {
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_DELIVERY_NOT_EXIST);
|
|
|
+ }
|
|
|
+ if (StatusEnum.SHOW.getStatus() == storeStatusDto.getStatus()) {
|
|
|
+ iShopDeliveryDisableService.remove(new UpdateWrapper<ShopDeliveryDisable>().in("delivery_type", deliverIds).eq("shop_id", shop.getId()));
|
|
|
+ } else {
|
|
|
String[] ids = deliverIdStr.split(",");
|
|
|
- for(int i=0;i<ids.length;i++){
|
|
|
+ for (int i = 0; i < ids.length; i++) {
|
|
|
ShopDeliveryDisable bean = new ShopDeliveryDisable();
|
|
|
bean.setAppId(storeStatusDto.getAppId());
|
|
|
bean.setDeliveryType(Integer.valueOf(ids[i]));
|
|
@@ -288,65 +321,60 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
iShopDeliveryDisableService.save(bean);
|
|
|
}
|
|
|
}
|
|
|
- return json;
|
|
|
+ return ResponseResult.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject queryhopDelivery(Long loginId, StoreStatusDto storeStatusDto) {
|
|
|
+ public ResponseResult queryshopDelivery(Long loginId, StoreStatusDto storeStatusDto) {
|
|
|
JSONObject json = new JSONObject();
|
|
|
Shop shop = iShopService.getByCode(storeStatusDto.getShopCode());
|
|
|
if (shop == null) {
|
|
|
- json.put("code", ResponseResultCodeEnum.SHOP_NOT_EXIST);
|
|
|
- return json;
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_NOT_EXIST);
|
|
|
}
|
|
|
List<StoreDeliveryDto> list = iShopDeliveryDisableService.shopDelivery(shop.getId());
|
|
|
|
|
|
- json.put("shopCode",shop.getCode());
|
|
|
- json.put("list",list);
|
|
|
- return json;
|
|
|
+ json.put("shopCode", shop.getCode());
|
|
|
+ json.put("list", list);
|
|
|
+ return ResponseResult.success(json);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public JSONObject modify(Long loginId, StoreDto storeDto) {
|
|
|
+ public ResponseResult modify(Long loginId, StoreDto storeDto) {
|
|
|
JSONObject resp = new JSONObject();
|
|
|
- resp.put("code",0);
|
|
|
Shop shop = iShopService.getByCode(storeDto.getShopCode());
|
|
|
if (shop == null) {
|
|
|
-
|
|
|
- return resp;
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_NOT_EXIST);
|
|
|
}
|
|
|
- if(!shop.getName().equals(storeDto.getShopName())){
|
|
|
- Shop existShop = iShopService.getOne(new QueryWrapper<Shop>().eq("name",storeDto.getShopName()));
|
|
|
- if(existShop!=null){
|
|
|
- resp.put("code", ResponseResultCodeEnum.SHOP_EXIST);
|
|
|
- return resp;
|
|
|
+ if (!shop.getName().equals(storeDto.getShopName())) {
|
|
|
+ Shop existShop = iShopService.getOne(new QueryWrapper<Shop>().eq("name", storeDto.getShopName()));
|
|
|
+ if (existShop != null) {
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_EXIST);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- shop = shopBean(shop,storeDto);
|
|
|
- if (storeDto.getCategoryId() != null){
|
|
|
+ shop = shopBean(shop, storeDto);
|
|
|
+ if (storeDto.getCategoryId() != null) {
|
|
|
shop.setCategoryId(storeDto.getCategoryId());
|
|
|
}
|
|
|
iShopService.updateById(shop);
|
|
|
+ MerchantCategory category = iMerchantCategoryService.getById(storeDto.getCategoryId());
|
|
|
+ if (category == null) {
|
|
|
+ return ResponseResult.error(ResponseResultCodeEnum.SHOP_CATEGORY_NOT_EXIST);
|
|
|
+ }
|
|
|
+ Merchant merchant = new Merchant();
|
|
|
+ merchant.setCategoryName(category.getFnProductType());
|
|
|
+ merchant.setMtCcategoryName(category.getMtProductType());
|
|
|
+ merchant.setDdCcategory(category.getDadaProductType());
|
|
|
+ merchant.setSsProductType(category.getSsProductType());
|
|
|
+ Member member = iMemberService.getById(loginId);
|
|
|
// 提交审核
|
|
|
List<ShopDelivery> shopDeliveries = iShopDeliveryService.findByShopId(shop.getId());
|
|
|
for (ShopDelivery delivery : shopDeliveries) {
|
|
|
DspDelivery dspDelivery = iDspDeliveryService.getById(delivery.getDeliveryId());
|
|
|
- Member member = iMemberService.getById(loginId);
|
|
|
- Merchant merchant = iMerchantService.getById(member.getMerchantId());
|
|
|
- Long categoryId = merchant.getCategoryId();
|
|
|
- if (storeDto.getCategoryId() != null) {
|
|
|
- categoryId = storeDto.getCategoryId();
|
|
|
- }
|
|
|
- MerchantCategory category = iMerchantCategoryService.getById(categoryId);
|
|
|
- merchant.setCategoryName(category.getFnProductType());
|
|
|
- merchant.setMtCcategoryName(category.getMtProductType());
|
|
|
- merchant.setDdCcategory(category.getDadaProductType());
|
|
|
- merchant.setSsProductType(category.getSsProductType());
|
|
|
if (delivery.getThirdShopId() != null) {
|
|
|
// 更新
|
|
|
- ShopReq shopReq = new ShopReq();
|
|
|
+ ShopReq shopReq = coverShopReq(shop);
|
|
|
shopReq.setThirdShopId(delivery.getThirdShopId());
|
|
|
shopReq.setCode(shop.getCode());
|
|
|
ShopVo shopVo = ShopEditUtils.editShopVo(shopReq, dspDelivery, merchant);
|
|
@@ -379,9 +407,9 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
} else {
|
|
|
// 新增
|
|
|
Shop shop1 = new Shop();
|
|
|
- shop1 = shopBean(shop1,storeDto);
|
|
|
+ shop1 = shopBean(shop1, storeDto);
|
|
|
coverShopReq(shop1);
|
|
|
- shop1.setCategoryId(categoryId);
|
|
|
+ shop1.setCategoryId(storeDto.getCategoryId());
|
|
|
shop1.setMerchantId(member.getMerchantId());
|
|
|
// BeanUtils.copyProperties(shopReq, shop1);
|
|
|
ShopVo shopVo = ShopEntityUtils.createShopVo(shop1, dspDelivery, merchant);
|
|
@@ -412,11 +440,27 @@ public class ApiStoreServiceImpl implements ApiStoreService {
|
|
|
}
|
|
|
iShopDeliveryService.updateById(delivery);
|
|
|
}
|
|
|
- saveShopThird(shop,delivery.getDeliveryId());
|
|
|
+ saveShopThird(shop, delivery.getDeliveryId());
|
|
|
}
|
|
|
|
|
|
- resp.put("shopCode",shop.getCode());
|
|
|
- return resp;
|
|
|
+ resp.put("shopCode", shop.getCode());
|
|
|
+ return ResponseResult.success(resp);
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ AipOcr client = new AipOcr("23831014", "BELGCxGTPOlcZzeZ85OLyIpD", "pLt8IG1PoXZBaDonLfFM9EkXndI1OBxh");
|
|
|
+
|
|
|
+ //百度ocr校验
|
|
|
+ String image = "E:\\1.jpg";
|
|
|
+ org.json.JSONObject json = client.idcard(image, "front", new HashMap<String, String>());
|
|
|
+ // JSONObject json = JSONObject.parseObject(ss);
|
|
|
+ System.out.println(json.toString());
|
|
|
+// System.out.println(json.getJSONObject("words_result").getJSONObject("社会信用代码").getString("words"));
|
|
|
+// System.out.println(json.getJSONObject("words_result").getJSONObject("法人").getString("words"));
|
|
|
+ if(json.getJSONObject("words_result")!=null){
|
|
|
+ System.out.println(json.getJSONObject("words_result").getJSONObject("公民身份号码").getString("words"));
|
|
|
+ System.out.println(json.getJSONObject("words_result").getJSONObject("姓名").getString("words"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|