|
|
|
@ -1,6 +1,9 @@ |
|
|
|
package org.jeecg.api.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.aliyun.oss.OSS; |
|
|
|
import com.aliyun.oss.OSSClientBuilder; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
@ -9,8 +12,12 @@ import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; |
|
|
|
import lombok.extern.log4j.Log4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.jeecg.api.service.ApiRiceService; |
|
|
|
import org.jeecg.bean.HttpClientUtil; |
|
|
|
import org.jeecg.bean.PageBean; |
|
|
|
import org.jeecg.bean.WxQrCodeVo; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.config.shiro.ShiroRealm; |
|
|
|
import org.jeecg.modules.commonAddress.entity.CommonAddress; |
|
|
|
@ -21,6 +28,7 @@ import org.jeecg.modules.commonCat.entity.CommonCat; |
|
|
|
import org.jeecg.modules.commonCat.service.ICommonCatService; |
|
|
|
import org.jeecg.modules.commonClass.entity.CommonClass; |
|
|
|
import org.jeecg.modules.commonClass.service.ICommonClassService; |
|
|
|
import org.jeecg.modules.commonConfig.entity.CommonConfig; |
|
|
|
import org.jeecg.modules.commonConfig.service.ICommonConfigService; |
|
|
|
import org.jeecg.modules.commonIconImage.entity.CommonIconImage; |
|
|
|
import org.jeecg.modules.commonIconImage.service.ICommonIconImageService; |
|
|
|
@ -45,11 +53,22 @@ import org.jeecg.modules.riceNews.entity.RiceNews; |
|
|
|
import org.jeecg.modules.riceNews.service.IRiceNewsService; |
|
|
|
import org.jeecg.modules.riceVip.entity.RiceVip; |
|
|
|
import org.jeecg.modules.riceVip.service.IRiceVipService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.web.bind.annotation.RequestHeader; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.transaction.Transactional; |
|
|
|
import java.io.*; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@ -205,6 +224,126 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//再次支付 |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Result<?> createOrderTwo(String token,String orderId){ |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
//查询订单是否存在 |
|
|
|
CommonOrder commonOrder = commonOrderService.getById(orderId); |
|
|
|
if (commonOrder==null){ |
|
|
|
return Result.error("订单不存在"); |
|
|
|
} |
|
|
|
if (commonOrder.getState()==1){ |
|
|
|
return Result.error("订单已支付"); |
|
|
|
} |
|
|
|
//查询订单是否shopState不等于2 |
|
|
|
if (commonOrder.getShopState()==2){ |
|
|
|
return Result.error("非首页订单"); |
|
|
|
} |
|
|
|
|
|
|
|
//根据配置列表查询每人限制数量 |
|
|
|
CommonConfig commonConfig = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName,"pay_num") |
|
|
|
.one(); |
|
|
|
//得到配置的数值转为int类型 |
|
|
|
int payNum = Integer.parseInt(commonConfig.getKeyContent()); |
|
|
|
//根据商品信息是否是体验装进行判断 |
|
|
|
if (commonOrder.getShopState()==0){ |
|
|
|
//查询用户是否存在该订单 |
|
|
|
List<CommonOrder> byUserIdAndShopId = commonOrderService.lambdaQuery() |
|
|
|
.eq(CommonOrder::getUserId,hanHaiMember.getId()) |
|
|
|
.eq(CommonOrder::getShopId,commonOrder.getShopId()) |
|
|
|
.eq(CommonOrder::getShopState,0) |
|
|
|
.eq(CommonOrder::getState,1) |
|
|
|
.list(); |
|
|
|
if (byUserIdAndShopId.size()+1>payNum){ |
|
|
|
return Result.error("已超过体验商品购买次数限制!请勿重复购买"); |
|
|
|
} |
|
|
|
|
|
|
|
//查询用户是否存在该订单 |
|
|
|
List<CommonOrder> payNumList = commonOrderService.lambdaQuery() |
|
|
|
.eq(CommonOrder::getUserId,hanHaiMember.getId()) |
|
|
|
.eq(CommonOrder::getShopId,commonOrder.getShopId()) |
|
|
|
.eq(CommonOrder::getShopState,0) |
|
|
|
.eq(CommonOrder::getState,0) |
|
|
|
.list(); |
|
|
|
if (payNumList.size()>1){ |
|
|
|
return Result.error("您有相同订单未付款!请先付款"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建订单标识 |
|
|
|
String newOrderId = IdWorker.getIdStr(); |
|
|
|
//老的订单数据复制给新创建的订单对象 |
|
|
|
CommonOrder commonOrder1 = new CommonOrder(); |
|
|
|
commonOrder1.setId(newOrderId); |
|
|
|
commonOrder1.setShopState(commonOrder.getShopState()); |
|
|
|
commonOrder1.setUserId(hanHaiMember.getId()); |
|
|
|
commonOrder1.setTitle(commonOrder.getTitle()); |
|
|
|
commonOrder1.setImage(commonOrder.getImage()); |
|
|
|
commonOrder1.setPrice(commonOrder.getPrice()); |
|
|
|
commonOrder1.setNum(commonOrder.getNum()); |
|
|
|
commonOrder1.setShopId(commonOrder.getShopId()); |
|
|
|
commonOrder1.setPayNo(commonOrder.getPayNo()); |
|
|
|
commonOrder1.setAddressId(commonOrder.getAddressId()); |
|
|
|
commonOrder1.setAddressDetails(commonOrder.getAddressDetails()); |
|
|
|
commonOrder1.setAddress(commonOrder.getAddress()); |
|
|
|
commonOrder1.setName(commonOrder.getName()); |
|
|
|
commonOrder1.setPhone(commonOrder.getPhone()); |
|
|
|
commonOrder1.setSku(commonOrder.getSku()); |
|
|
|
commonOrder1.setCreateTime(new Date()); |
|
|
|
commonOrderService.save(commonOrder1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据订单标识查询订单详情对象 |
|
|
|
CommonOrderSku commonOrderSku = new CommonOrderSku(); |
|
|
|
commonOrderSku.setOrderId(newOrderId); |
|
|
|
commonOrderSku.setUserId(hanHaiMember.getId()); |
|
|
|
commonOrderSku.setTitle(commonOrder.getTitle()); |
|
|
|
commonOrderSku.setImage(commonOrder.getImage()); |
|
|
|
commonOrderSku.setPrice(commonOrder.getPrice()); |
|
|
|
commonOrderSku.setNum(commonOrder.getNum()); |
|
|
|
commonOrderSku.setShopId(commonOrder.getShopId()); |
|
|
|
commonOrderSku.setSku(commonOrder.getSku()); |
|
|
|
commonOrderSku.setCreateTime(new Date()); |
|
|
|
commonOrderSkuService.save(commonOrderSku); |
|
|
|
|
|
|
|
//删除原订单 |
|
|
|
commonOrderService.removeById(orderId); |
|
|
|
//查询订单关联的订单详情 |
|
|
|
CommonOrderSku one = commonOrderSkuService.lambdaQuery().eq(CommonOrderSku::getOrderId, orderId) |
|
|
|
.one(); |
|
|
|
//删除该订单详情 |
|
|
|
commonOrderSkuService.removeById(one); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//吊起微信支付 |
|
|
|
String s = commonOrder1.getPrice().multiply(new BigDecimal(100)).toString(); |
|
|
|
int i1 = Double.valueOf(s).intValue(); |
|
|
|
Object appOrder = mpWxPayService.createOrder( |
|
|
|
"购买"+ commonOrder1.getTitle() , |
|
|
|
"127.0.0.1", |
|
|
|
orderId, |
|
|
|
i1, |
|
|
|
orderId, |
|
|
|
hanHaiMember.getAppletOpenid(), |
|
|
|
commonOrder.toString()); |
|
|
|
|
|
|
|
return Result.OK("支付成功",appOrder); |
|
|
|
} |
|
|
|
|
|
|
|
//创建订单 |
|
|
|
@Override |
|
|
|
public Result<?> createOrder(String token,String productId,Integer num,String addressId) { |
|
|
|
@ -232,10 +371,45 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
if (commonAddress==null){ |
|
|
|
return Result.error("地址不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//根据配置列表查询每人限制数量 |
|
|
|
CommonConfig commonConfig = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName,"pay_num") |
|
|
|
.one(); |
|
|
|
//得到配置的数值转为int类型 |
|
|
|
int payNum = Integer.parseInt(commonConfig.getKeyContent()); |
|
|
|
//根据商品信息是否是体验装进行判断 |
|
|
|
if (commonShop.getType()==0){ |
|
|
|
//查询用户是否存在该订单 |
|
|
|
List<CommonOrder> byUserIdAndShopId = commonOrderService.lambdaQuery() |
|
|
|
.eq(CommonOrder::getUserId,hanHaiMember.getId()) |
|
|
|
.eq(CommonOrder::getShopId,productId) |
|
|
|
.eq(CommonOrder::getShopState,0) |
|
|
|
.eq(CommonOrder::getState,1) |
|
|
|
.list(); |
|
|
|
if (byUserIdAndShopId.size()+1>payNum){ |
|
|
|
return Result.error("已超过体验商品购买次数限制!请勿重复购买"); |
|
|
|
} |
|
|
|
|
|
|
|
//查询用户是否存在该订单 |
|
|
|
List<CommonOrder> payNumList = commonOrderService.lambdaQuery() |
|
|
|
.eq(CommonOrder::getUserId,hanHaiMember.getId()) |
|
|
|
.eq(CommonOrder::getShopId,productId) |
|
|
|
.eq(CommonOrder::getShopState,0) |
|
|
|
.eq(CommonOrder::getState,0) |
|
|
|
.list(); |
|
|
|
if (payNumList.size()>0){ |
|
|
|
return Result.error("您有相同订单未付款!请先付款"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//创建订单标识 |
|
|
|
String orderId = IdWorker.getIdStr(); |
|
|
|
//创建订单 |
|
|
|
BigDecimal price = commonShop.getPrice().multiply(new BigDecimal(num)); |
|
|
|
|
|
|
|
//生成订单信息 |
|
|
|
CommonOrder commonOrder = new CommonOrder(); |
|
|
|
|
|
|
|
@ -243,7 +417,7 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
commonOrder.setTitle(commonShop.getTitle()); |
|
|
|
commonOrder.setShopId(commonShop.getId()); |
|
|
|
commonOrder.setImage(commonShop.getImage()); |
|
|
|
commonOrder.setState(1); |
|
|
|
commonOrder.setState(0); |
|
|
|
commonOrder.setPrice(price); |
|
|
|
commonOrder.setNum(num); |
|
|
|
commonOrder.setSku(commonShop.getSku()); |
|
|
|
@ -251,8 +425,10 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
commonOrder.setPhone(commonAddress.getPhone()); |
|
|
|
commonOrder.setAddress(commonAddress.getAddress()); |
|
|
|
commonOrder.setAddressDetails(commonAddress.getAddressDetails()); |
|
|
|
|
|
|
|
commonOrder.setUserId(hanHaiMember.getId()); |
|
|
|
commonOrder.setAddressId(addressId); |
|
|
|
commonOrder.setShopState(commonShop.getType()); |
|
|
|
commonOrderService.save(commonOrder); |
|
|
|
|
|
|
|
//创建订单详情 |
|
|
|
@ -317,6 +493,13 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
//创建订单 |
|
|
|
BigDecimal price = commonShop.getPrice().multiply(new BigDecimal(sku.getNum())); |
|
|
|
|
|
|
|
|
|
|
|
//获取vip价格 |
|
|
|
if(hanHaiMember.getIsPay() == 1){ |
|
|
|
price = commonShop.getVipPrice().multiply(new BigDecimal(sku.getNum())); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sku.setOrderId(orderId); |
|
|
|
sku.setShopId(commonShop.getId()); |
|
|
|
sku.setTitle(commonShop.getTitle()); |
|
|
|
@ -349,8 +532,10 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
cityOrder.setName(commonAddress.getName()); |
|
|
|
cityOrder.setPhone(commonAddress.getPhone()); |
|
|
|
cityOrder.setAddressDetails(commonAddress.getAddressDetails()); |
|
|
|
cityOrder.setAddressId(addressId); |
|
|
|
cityOrder.setName("店铺订单"); |
|
|
|
cityOrder.setPrice(totalPrice); |
|
|
|
cityOrder.setShopState(2); |
|
|
|
|
|
|
|
cityOrder.setImage(null); |
|
|
|
cityOrder.setState(0); |
|
|
|
@ -379,13 +564,18 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
|
|
|
|
//商城-加入购物车之后一次下多个订单 - 再次下单 |
|
|
|
@Override |
|
|
|
public Result<?> createSumOrderAgain(String token,String list,String addressId,String order){ |
|
|
|
public Result<?> createSumOrderAgain(String token,String order){ |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
//根据订单标识查询订单是否存在 |
|
|
|
CommonOrder commonOrder = commonOrderService.getById(order); |
|
|
|
if (commonOrder==null){ |
|
|
|
CommonOrder oldOrder = commonOrderService.getById(order); |
|
|
|
if (oldOrder==null){ |
|
|
|
return Result.error("订单不存在"); |
|
|
|
} |
|
|
|
//储存地址标识 |
|
|
|
String addressId = oldOrder.getAddressId(); |
|
|
|
//创建订单标识 |
|
|
|
String orderId = IdWorker.getIdStr(); |
|
|
|
|
|
|
|
//根据订单标识查询订单详情列表 |
|
|
|
List<CommonOrderSku> commonOrderSkuList = commonOrderSkuService.lambdaQuery() |
|
|
|
.eq(CommonOrderSku::getOrderId,order) |
|
|
|
@ -393,9 +583,12 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
if (commonOrderSkuList==null || commonOrderSkuList.size()==0){ |
|
|
|
return Result.error("订单详情不存在"); |
|
|
|
} |
|
|
|
//循环修改订单标识 |
|
|
|
for (CommonOrderSku commonOrderSku : commonOrderSkuList) { |
|
|
|
commonOrderSku.setOrderId(orderId); |
|
|
|
commonOrderSkuService.updateById(commonOrderSku); |
|
|
|
} |
|
|
|
|
|
|
|
//如果集合存在循环删除 |
|
|
|
commonOrderSkuService.remove(new QueryWrapper<CommonOrderSku>().eq("order_id",order)); |
|
|
|
|
|
|
|
|
|
|
|
//用户地址不能为空 |
|
|
|
@ -407,83 +600,46 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
if (commonAddress==null){ |
|
|
|
return Result.error("地址不存在"); |
|
|
|
} |
|
|
|
//把list转为对象 list = [{"shopId":"1","num":1},{"shopId":"2","num":2}] |
|
|
|
List<CommonOrderSku> list1 = JSON.parseArray(list, CommonOrderSku.class); |
|
|
|
//创建订单标识 |
|
|
|
String orderId = IdWorker.getIdStr(); |
|
|
|
if(null!=list1 && list1.size()>0){ |
|
|
|
//订单总额 |
|
|
|
BigDecimal totalPrice = new BigDecimal(0); |
|
|
|
//订单商品数量 |
|
|
|
Integer totalNum = 0; |
|
|
|
|
|
|
|
//创建订单详情 |
|
|
|
for (CommonOrderSku sku : list1) { |
|
|
|
//查询商品信息 |
|
|
|
CommonShop commonShop = commonShopService.getById(sku.getShopId()); |
|
|
|
//商品不能为空 |
|
|
|
if (commonShop==null){ |
|
|
|
return Result.error("商品不存在"); |
|
|
|
} |
|
|
|
//创建订单 |
|
|
|
BigDecimal price = commonShop.getPrice().multiply(new BigDecimal(sku.getNum())); |
|
|
|
|
|
|
|
sku.setOrderId(orderId); |
|
|
|
sku.setShopId(commonShop.getId()); |
|
|
|
sku.setTitle(commonShop.getTitle()); |
|
|
|
sku.setImage(commonShop.getImage()); |
|
|
|
sku.setPrice(price); |
|
|
|
sku.setNum(sku.getNum()); |
|
|
|
sku.setSku(commonShop.getSku()); |
|
|
|
sku.setCreateTime(new Date()); |
|
|
|
sku.setPrice(price); |
|
|
|
|
|
|
|
sku.setImage(commonShop.getImage()); |
|
|
|
sku.setCreateTime(new Date()); |
|
|
|
sku.setOrderId(orderId); |
|
|
|
commonOrderSkuService.save(sku); |
|
|
|
|
|
|
|
//计算总价格 |
|
|
|
totalPrice = totalPrice.add(price); |
|
|
|
//创建主订单 |
|
|
|
CommonOrder cityOrder = new CommonOrder(); |
|
|
|
cityOrder.setId(orderId); |
|
|
|
cityOrder.setUserId(oldOrder.getUserId()); |
|
|
|
cityOrder.setShopId(null); |
|
|
|
cityOrder.setNum(oldOrder.getNum()); |
|
|
|
cityOrder.setAddress(oldOrder.getAddress()); |
|
|
|
cityOrder.setName(oldOrder.getName()); |
|
|
|
cityOrder.setPhone(oldOrder.getPhone()); |
|
|
|
cityOrder.setAddressDetails(oldOrder.getAddressDetails()); |
|
|
|
cityOrder.setAddressId(addressId); |
|
|
|
cityOrder.setName("店铺订单"); |
|
|
|
|
|
|
|
totalNum = totalNum + sku.getNum(); |
|
|
|
} |
|
|
|
cityOrder.setPrice(oldOrder.getPrice()); |
|
|
|
|
|
|
|
cityOrder.setImage(null); |
|
|
|
cityOrder.setState(0); |
|
|
|
cityOrder.setShopState(2); |
|
|
|
cityOrder.setCreateTime(new Date()); |
|
|
|
|
|
|
|
//创建主订单 |
|
|
|
CommonOrder cityOrder = new CommonOrder(); |
|
|
|
cityOrder.setId(orderId); |
|
|
|
cityOrder.setUserId(hanHaiMember.getId()); |
|
|
|
cityOrder.setShopId(null); |
|
|
|
cityOrder.setNum(totalNum); |
|
|
|
cityOrder.setAddress(commonAddress.getAddress()); |
|
|
|
cityOrder.setName(commonAddress.getName()); |
|
|
|
cityOrder.setPhone(commonAddress.getPhone()); |
|
|
|
cityOrder.setAddressDetails(commonAddress.getAddressDetails()); |
|
|
|
cityOrder.setName("店铺订单"); |
|
|
|
cityOrder.setPrice(totalPrice); |
|
|
|
commonOrderService.save(cityOrder); |
|
|
|
|
|
|
|
cityOrder.setImage(null); |
|
|
|
cityOrder.setState(0); |
|
|
|
cityOrder.setCreateTime(new Date()); |
|
|
|
//删除旧订单 |
|
|
|
commonOrderService.removeById(order); |
|
|
|
|
|
|
|
commonOrderService.save(cityOrder); |
|
|
|
//吊起微信支付 |
|
|
|
String s = oldOrder.getPrice().multiply(new BigDecimal(100)).toString(); |
|
|
|
int i1 = Double.valueOf(s).intValue(); |
|
|
|
Object appOrder = mpWxPayService.createOrder( |
|
|
|
"购买"+ "店铺订单" , |
|
|
|
"127.0.0.1", |
|
|
|
orderId, |
|
|
|
i1, |
|
|
|
orderId, |
|
|
|
hanHaiMember.getAppletOpenid(), |
|
|
|
cityOrder.toString()); |
|
|
|
|
|
|
|
//吊起微信支付 |
|
|
|
String s = totalPrice.multiply(new BigDecimal(100)).toString(); |
|
|
|
int i1 = Double.valueOf(s).intValue(); |
|
|
|
Object appOrder = mpWxPayService.createOrder( |
|
|
|
"购买"+ "店铺订单" , |
|
|
|
"127.0.0.1", |
|
|
|
orderId, |
|
|
|
i1, |
|
|
|
orderId, |
|
|
|
hanHaiMember.getAppletOpenid(), |
|
|
|
cityOrder.toString()); |
|
|
|
return Result.OK("支付成功",appOrder); |
|
|
|
|
|
|
|
return Result.OK("支付成功",appOrder); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -497,8 +653,24 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
CommonOrder commonOrder = commonOrderService.getById(outTradeNo); |
|
|
|
//如果订单存在则修改订单状态 |
|
|
|
if (commonOrder!=null){ |
|
|
|
commonOrder.setState(1); |
|
|
|
commonOrderService.updateById(commonOrder); |
|
|
|
if(commonOrder.getState()==0){ |
|
|
|
commonOrder.setState(1); |
|
|
|
commonOrderService.updateById(commonOrder); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//如果这个订单是普通订单 |
|
|
|
if (commonOrder.getShopState()==2){ |
|
|
|
//获得这个订单的总价 |
|
|
|
BigDecimal price = commonOrder.getPrice(); |
|
|
|
//如果总价超过1000元则修改用户为会员 |
|
|
|
if (price.compareTo(new BigDecimal(0.01))==1){ |
|
|
|
//查询购买订单的用户信息 |
|
|
|
HanHaiMember hanHaiMember = hanHaiMemberService.getById(commonOrder.getUserId()); |
|
|
|
hanHaiMember.setIsPay(1); |
|
|
|
hanHaiMemberService.updateById(hanHaiMember); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
@ -656,12 +828,225 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
return Result.OK(page); |
|
|
|
} |
|
|
|
|
|
|
|
//获取个人邀请码 |
|
|
|
|
|
|
|
|
|
|
|
private String appid = "wx0839bc52e7849c13"; |
|
|
|
|
|
|
|
private String secret = "c614fd865951c5246e849501204e6f7f"; |
|
|
|
|
|
|
|
private String endpoint = "oss-cn-shenzhen.aliyuncs.com"; |
|
|
|
|
|
|
|
private String accessKey = "LTAI5tQSs47izVy8DLVdwUU9"; |
|
|
|
|
|
|
|
private String secretKey = "qHI7C3PaXYZySr84HTToviC71AYlFq"; |
|
|
|
|
|
|
|
private String bucketName = "hanhaiimage"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String APP_ID = "wx0839bc52e7849c13"; |
|
|
|
private static final String APP_SECRET = "c614fd865951c5246e849501204e6f7f"; |
|
|
|
private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APP_ID + "&secret=" + APP_SECRET; |
|
|
|
private static final String TEMPLATE_MESSAGE_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取推广二维码 |
|
|
|
@Override |
|
|
|
public Result<?> getInviteCode(String token){ |
|
|
|
HanHaiMember member = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
CommonConfig vsion = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName, "v_sion") |
|
|
|
.one(); |
|
|
|
Integer vsionStr = Integer.parseInt(vsion.getKeyContent()); |
|
|
|
String trial = "release"; |
|
|
|
if(vsionStr == 0){ |
|
|
|
trial= "release"; |
|
|
|
}else if(vsionStr == 1){ |
|
|
|
trial= "trial"; |
|
|
|
}else{ |
|
|
|
trial= "develop"; |
|
|
|
} |
|
|
|
|
|
|
|
// WxQrCodeVo o = (WxQrCodeVo)redisUtil.get("CodeImage::" + trial+ member.getId()); |
|
|
|
// if(o!=null){ |
|
|
|
// |
|
|
|
// |
|
|
|
// o.setName("瑶都万能墙欢迎您的加入"); |
|
|
|
// return Result.OK(o); |
|
|
|
// } |
|
|
|
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
|
|
|
|
CommonConfig xcxSharePage = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName, "xcxSharePage") |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String key = "shareId=" + member.getId(); |
|
|
|
|
|
|
|
param.put("path", xcxSharePage.getKeyContent() + "?" + key); //跳转页面 |
|
|
|
String accessToken = this.getAccessToken(); |
|
|
|
RestTemplate rest = new RestTemplate(); |
|
|
|
InputStream inputStream = null; |
|
|
|
OutputStream outputStream = null; |
|
|
|
File file = null; |
|
|
|
|
|
|
|
// LambdaQueryWrapper<DbConf> configImg = new LambdaQueryWrapper<>(); |
|
|
|
// configImg.eq(DbConf::getIsDel,0).eq(DbConf::getKeyValue,"codeImg"); |
|
|
|
// DbConf oneImg = confService.getOne(configImg); |
|
|
|
|
|
|
|
CommonConfig oneImage = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName, "codeImg") |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String codeImg = oneImage.getKeyContent(); |
|
|
|
try{ |
|
|
|
String url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + accessToken; |
|
|
|
param.put("scene", member.getId()); |
|
|
|
param.put("width", 150); |
|
|
|
param.put("auto_color", false); |
|
|
|
param.put("env_version", trial); |
|
|
|
Map<String, Object> line_color = new HashMap<>(); |
|
|
|
line_color.put("r", 0); |
|
|
|
line_color.put("g", 0); |
|
|
|
line_color.put("b", 0); |
|
|
|
param.put("line_color", line_color); |
|
|
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
|
|
|
org.springframework.http.HttpEntity requestEntity = new org.springframework.http.HttpEntity(JSON.toJSONString(param), headers); |
|
|
|
ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); |
|
|
|
byte[] result = entity.getBody(); |
|
|
|
|
|
|
|
inputStream = new ByteArrayInputStream(result); |
|
|
|
String tempSave = codeImg; |
|
|
|
String filePath = tempSave; |
|
|
|
|
|
|
|
file = new File(filePath); |
|
|
|
if (!file.exists()) { |
|
|
|
file.createNewFile(); |
|
|
|
} |
|
|
|
outputStream = new FileOutputStream(file); |
|
|
|
int len = 0; |
|
|
|
byte[] buf = new byte[1024]; |
|
|
|
while ((len = inputStream.read(buf, 0, 1024)) != -1) { |
|
|
|
outputStream.write(buf, 0, len); |
|
|
|
} |
|
|
|
outputStream.flush(); |
|
|
|
/** |
|
|
|
* 将文件上传至阿里云 |
|
|
|
*/ |
|
|
|
DiskFileItemFactory factory = new DiskFileItemFactory(16, null); |
|
|
|
FileItem item = factory.createItem("File", "text/plain", true, file.getName()); |
|
|
|
int bytesRead = 0; |
|
|
|
byte[] buffer = new byte[8192]; |
|
|
|
try { |
|
|
|
FileInputStream fis = new FileInputStream(file); |
|
|
|
OutputStream os = item.getOutputStream(); |
|
|
|
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) { |
|
|
|
os.write(buffer, 0, bytesRead); |
|
|
|
} |
|
|
|
os.close(); |
|
|
|
fis.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
MultipartFile mf = new CommonsMultipartFile(item); |
|
|
|
//返回图片下载地址 |
|
|
|
WxQrCodeVo wxCodeVo = new WxQrCodeVo(); |
|
|
|
wxCodeVo.setUrl(this.uploadAliYunOss(mf)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxCodeVo.setName("三只青蛙欢迎您"); |
|
|
|
|
|
|
|
// redisUtil.set("CodeImage::"+trial+member.getId(),wxCodeVo); |
|
|
|
return Result.OK(wxCodeVo); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} finally { |
|
|
|
|
|
|
|
if (inputStream != null) { |
|
|
|
try { |
|
|
|
inputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (outputStream != null) { |
|
|
|
try { |
|
|
|
outputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
//删除文件 |
|
|
|
if (file.exists()) { |
|
|
|
file.delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取令牌 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String getAccessToken() { |
|
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret; |
|
|
|
String doGet2 = HttpClientUtil.doGet2(requestUrl); |
|
|
|
Map<String, String> map = JSON.parseObject(doGet2, new TypeReference<Map<String, String>>() { |
|
|
|
}); |
|
|
|
return map.get("access_token"); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 上传文件至阿里云oss |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String uploadAliYunOss(MultipartFile mf) throws Exception { |
|
|
|
String uploadFile = "WxCodeFile"; |
|
|
|
String fileName = new StringBuffer(mf.getOriginalFilename()).append(".jpg").toString();// 获取文件名 |
|
|
|
String dbpath = uploadFile + File.separator + fileName; |
|
|
|
if (dbpath.contains("\\")) { |
|
|
|
dbpath = dbpath.replace("\\", "/"); |
|
|
|
} |
|
|
|
String endpoint = this.endpoint; |
|
|
|
String accessKey = this.accessKey; |
|
|
|
String secretKey = this.secretKey; |
|
|
|
// 创建OSSClient实例。 |
|
|
|
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKey, secretKey); |
|
|
|
// 上传Byte数组。 |
|
|
|
byte[] content = mf.getBytes(); |
|
|
|
String bucketName = this.bucketName; |
|
|
|
ossClient.putObject(bucketName, dbpath, new ByteArrayInputStream(content)); |
|
|
|
// 关闭OSSClient。 |
|
|
|
ossClient.shutdown(); |
|
|
|
return dbpath; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取相关介绍 |
|
|
|
@Override |
|
|
|
public Result<?> getInfoIntroduce(String type){ |
|
|
|
@ -685,6 +1070,7 @@ public class ApiRiceServiceImpl implements ApiRiceService { |
|
|
|
@Override |
|
|
|
public Result<?> addOrUpdateAddress(String token,CommonAddress commonAddress){ |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
commonAddress.setUserId(hanHaiMember.getId()); |
|
|
|
commonAddressService.saveOrUpdate(commonAddress); |
|
|
|
return Result.OK("增加成功"); |
|
|
|
} |
|
|
|
|