631 lines
28 KiB
Java
631 lines
28 KiB
Java
package com.wisdo.mmining.api;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.wisdo.mmining.api.dto.IntegralDto;
|
|
import com.wisdo.mmining.entity.*;
|
|
import com.wisdo.mmining.redis.RedisService;
|
|
import com.wisdo.mmining.result.Result;
|
|
import com.wisdo.mmining.result.ResultUtil;
|
|
import com.wisdo.mmining.service.*;
|
|
import com.wisdo.mmining.util.UploadUtil;
|
|
import com.wisdo.mmining.utils.DistanceUtil;
|
|
import com.wisdo.mmining.utils.PhoneUtils;
|
|
import com.wisdo.mmining.utils.smsUtils.SmsSend;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.gavaghan.geodesy.Ellipsoid;
|
|
import org.gavaghan.geodesy.GlobalCoordinates;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @Auther: cg
|
|
* @Date: 2020/9/27 16:04
|
|
* @Description:
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/user")
|
|
public class UserApi {
|
|
|
|
@Autowired
|
|
private WxuserService wxuserService;
|
|
@Autowired
|
|
private WisdUserService wisdUserService;
|
|
@Autowired
|
|
private UserPackageService userPackageService;
|
|
@Autowired
|
|
private UserAddressService userAddressService;
|
|
@Autowired
|
|
private StoresService storesService;
|
|
@Autowired
|
|
private CompanyService companyService;
|
|
@Autowired
|
|
private RedisService redisService;
|
|
@Autowired
|
|
private PackageService packageService;
|
|
@Autowired
|
|
private GoodsService goodsService;
|
|
@Autowired
|
|
private FeedBackService feedBackService;
|
|
@Autowired
|
|
private AboutService aboutService;
|
|
@Autowired
|
|
private BillService billService;
|
|
@Autowired
|
|
private IntegralRolesService integralRolesService;
|
|
@Autowired
|
|
private OrderService orderService;
|
|
@Autowired
|
|
private OrderDetailService orderDetailService;
|
|
@Autowired
|
|
private GoodsSpecService goodsSpecService;
|
|
@Autowired
|
|
private BlukService blukService;
|
|
@Autowired
|
|
private WelfareService welfareService;
|
|
@Autowired
|
|
private WithdrawalService withdrawalService;
|
|
@Autowired
|
|
private BackService backService;
|
|
@Autowired
|
|
private VipService vipService;
|
|
|
|
@ApiOperation(value = "获取个人信息")
|
|
@GetMapping("getTwoGoodsType")
|
|
public Result getTwoGoodsType(Long userId) {
|
|
WisdWxuser wisdWxuser = wxuserService.getById(userId);
|
|
Integer count = 0;
|
|
if (wisdWxuser.getUserIscompany() == 1) {
|
|
WisdUser wisdUser = wisdUserService.getByUserId(wisdWxuser.getCompanyUserId());
|
|
QueryWrapper<WisdUserPackage> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("user_id", wisdUser.getId());
|
|
queryWrapper.eq("is_used", 0);
|
|
count = userPackageService.count(queryWrapper);
|
|
WisdCompany wisdCompany = companyService.getById(wisdUser.getCompanyId());
|
|
wisdWxuser.setCompanyName(wisdCompany.getCompanyName());
|
|
wisdWxuser.setCompanyId(wisdCompany.getId());
|
|
}
|
|
wisdWxuser.setOrderNum1(getOrderNum(userId, 1));
|
|
wisdWxuser.setOrderNum2(getOrderNum(userId, 2));
|
|
wisdWxuser.setOrderNum3(getOrderNum(userId, 3));
|
|
wisdWxuser.setOrderNum4(getOrderNum(userId, 6));
|
|
wisdWxuser.setOrderNum5(getOrderNum(userId, 4));
|
|
wisdWxuser.setPavkageNum(count);
|
|
WisdStores wisdStores = storesService.getById(wisdWxuser.getUserStoresId());
|
|
if (wisdStores != null) {
|
|
wisdWxuser.setWisdStores(wisdStores);
|
|
}
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdWxuser);
|
|
}
|
|
|
|
public Integer getOrderNum(Long userId, Integer status) {
|
|
QueryWrapper<WisdOeder> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("user_id", userId);
|
|
if (status == 6) {
|
|
queryWrapper.and(wrapper -> wrapper.eq("after_sales_status", status).or().eq("after_sales_status", 61).or().eq("after_sales_status", 62).or().eq("after_sales_status", 63).or().eq("after_sales_status", 64).or().eq("after_sales_status", 65).or().eq("after_sales_status", 66).or().eq("after_sales_status", 67));
|
|
} else {
|
|
queryWrapper.eq("status", status).and(wrapper -> wrapper
|
|
.isNull("after_sales_status").or().eq("after_sales_status", 66).or().eq("after_sales_status", 67)
|
|
);
|
|
}
|
|
queryWrapper.eq("is_deleted", 0);
|
|
return orderService.count(queryWrapper);
|
|
}
|
|
|
|
@ApiOperation(value = "获取收货地址")
|
|
@GetMapping("getUserAddress")
|
|
public Result getUserAddress(Long userId) {
|
|
QueryWrapper<WisdUserAddress> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("wxuser_id", userId);
|
|
queryWrapper.orderByDesc("address_default");
|
|
List<WisdUserAddress> wisdUserAddressList = userAddressService.list(queryWrapper);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdUserAddressList);
|
|
}
|
|
|
|
@ApiOperation(value = "添加/修改收货地址")
|
|
@PostMapping("addUserAddress")
|
|
public Result addUserAddress(@RequestBody WisdUserAddress wisdUserAddress) {
|
|
if (wisdUserAddress.getAddressDefault() == 1) {
|
|
QueryWrapper<WisdUserAddress> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("address_default", 1);
|
|
queryWrapper.eq("wxuser_id", wisdUserAddress.getWxuserId());
|
|
WisdUserAddress wisdUserAddress1 = userAddressService.getOne(queryWrapper);
|
|
if (wisdUserAddress1 != null) {
|
|
wisdUserAddress1.setAddressDefault(0);
|
|
userAddressService.saveOrUpdate(wisdUserAddress1);
|
|
}
|
|
}
|
|
Boolean flag = userAddressService.saveOrUpdate(wisdUserAddress);
|
|
if (flag) {
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
} else {
|
|
return new Result(ResultUtil.ERROR, ResultUtil.ERROR_MSG);
|
|
}
|
|
}
|
|
|
|
@ApiOperation(value = "根据id获取收货地址")
|
|
@GetMapping("getUserAddressDetail")
|
|
public Result getUserAddressDetail(Long id) {
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, userAddressService.getById(id));
|
|
}
|
|
|
|
@ApiOperation(value = "删除收货地址")
|
|
@DeleteMapping("delUserAddress")
|
|
public Result delUserAddress(Long id) {
|
|
// List<Long> idList = new ArrayList<>();
|
|
// idList.add(id);
|
|
Boolean flag = userAddressService.removeById(id);
|
|
if (flag) {
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
} else {
|
|
return new Result(ResultUtil.ERROR, ResultUtil.ERROR_MSG);
|
|
}
|
|
}
|
|
|
|
@ApiOperation(value = "获取门店列表")
|
|
@GetMapping("getStores")
|
|
public Result getStores(Double latitude, Double longitude) {
|
|
List<WisdStores> wisdStoresList = storesService.list();
|
|
for (WisdStores wisdStores : wisdStoresList) {
|
|
//用户当前坐标
|
|
GlobalCoordinates userSource = new GlobalCoordinates(latitude, longitude);
|
|
//店铺位置坐标
|
|
GlobalCoordinates businessTarget = new GlobalCoordinates(wisdStores.getStoresLatitude(), wisdStores.getStoresLongitude());
|
|
Double meterDouble = DistanceUtil.getDistanceMeter(userSource, businessTarget, Ellipsoid.Sphere);
|
|
wisdStores.setDistance(meterDouble.intValue());
|
|
}
|
|
wisdStoresList.sort(new Comparator<WisdStores>() {
|
|
@Override
|
|
public int compare(WisdStores o1, WisdStores o2) {
|
|
Integer distance = o1.getDistance() - o2.getDistance();
|
|
return distance;
|
|
}
|
|
});
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdStoresList);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "获取公司列表")
|
|
@GetMapping("getCompany")
|
|
public Result getCompany(String conpanyName) {
|
|
QueryWrapper<WisdCompany> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("is_deleted", 0);
|
|
if (!"".equals(conpanyName) && conpanyName != null) {
|
|
queryWrapper.like("company_name", conpanyName);
|
|
}
|
|
List<WisdCompany> wisdCompany = companyService.list(queryWrapper);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdCompany);
|
|
}
|
|
|
|
@GetMapping(value = "sendSms")
|
|
@ApiOperation(value = "发送短信")
|
|
public Result sendSms(String phone) throws InterruptedException {
|
|
String regex = "^[1][3,4,5,6,7,8,9][0-9]{9}$";
|
|
|
|
Pattern p = Pattern.compile(regex);
|
|
Matcher m = p.matcher(phone);
|
|
boolean isMatch = m.matches();
|
|
if (!isMatch) {
|
|
return ResultUtil.error("请填入正确的手机号");
|
|
}
|
|
if (!PhoneUtils.isPhoneLegal(phone)) {
|
|
return new Result(ResultUtil.ERROR, "请输入正确手机号");
|
|
}
|
|
String random = SmsSend.sendMsg(phone);
|
|
//存入redis缓存
|
|
redisService.set(phone, random, 3 * 60 * 1000);
|
|
System.out.println(redisService.get(phone));
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_DATA);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "信息修改")
|
|
@PutMapping("updateInfo")
|
|
public Result updateInfo(String userName, Long userId, String phone, Long companyId) {
|
|
if (userName == null) {
|
|
return new Result(ResultUtil.ERROR, "请输入姓名");
|
|
}
|
|
if (phone == null) {
|
|
return new Result(ResultUtil.ERROR, "请输入手机号");
|
|
}
|
|
if (!PhoneUtils.isPhoneLegal(phone)) {
|
|
return new Result(ResultUtil.ERROR, "请输入正确手机号");
|
|
}
|
|
WisdWxuser wisdWxuser = wxuserService.getById(userId);
|
|
if (wisdWxuser == null) {
|
|
return new Result(ResultUtil.ERROR, "该用户不存在");
|
|
}
|
|
WisdCompany wisdCompany = companyService.getById(companyId);
|
|
if (wisdCompany == null) {
|
|
return new Result(ResultUtil.ERROR, "该公司不存在");
|
|
}
|
|
WisdUser wisdUser = wisdUserService.getByPhone(phone, companyId);
|
|
if (wisdUser == null) {
|
|
return new Result(ResultUtil.ERROR, "此公司下不存在该员工");
|
|
}
|
|
if (wisdUser.getUserName() != userName) {
|
|
return new Result(ResultUtil.ERROR, "姓名输入错误");
|
|
}
|
|
wisdWxuser.setCompanyUserId(wisdUser.getId());
|
|
wisdWxuser.setUserId(wisdUser.getId());
|
|
wisdWxuser.setUserName(userName);
|
|
wisdWxuser.setUserPhone(phone);
|
|
wisdWxuser.setUserSex(wisdUser.getUserSex());
|
|
wisdWxuser.setUserVolumeBalance(wisdUser.getUserVolumeBalance());
|
|
wisdWxuser.setUserDiscountBalance(wisdUser.getUserDiscountBalance());
|
|
wisdWxuser.setUserDiscount(wisdUser.getUserDiscount());
|
|
wisdWxuser.setUserIscompany(1);
|
|
wisdWxuser.setPavkageNum(wisdUser.getPavkageNum());
|
|
Boolean flag = wxuserService.saveOrUpdate(wisdWxuser);
|
|
if (flag) {
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
} else {
|
|
return new Result(ResultUtil.ERROR, ResultUtil.ERROR_MSG);
|
|
}
|
|
}
|
|
|
|
@ApiOperation(value = "信息完善")
|
|
@PutMapping("perfectInfo")
|
|
public Result perfectInfo(String userName, Long userId, String phone, String code, Long companyId) {
|
|
String codes = (String) redisService.get(phone);
|
|
if (codes == null && !code.equals(codes)) {
|
|
return new Result(ResultUtil.ERROR, "请输入正确验证码");
|
|
}
|
|
if (userName == null) {
|
|
return new Result(ResultUtil.ERROR, "请输入姓名");
|
|
}
|
|
if (phone == null) {
|
|
return new Result(ResultUtil.ERROR, "请输入手机号");
|
|
}
|
|
if (!PhoneUtils.isPhoneLegal(phone)) {
|
|
return new Result(ResultUtil.ERROR, "请输入正确手机号");
|
|
}
|
|
WisdWxuser wisdWxuser = wxuserService.getById(userId);
|
|
if (wisdWxuser == null) {
|
|
return new Result(ResultUtil.ERROR, "该用户不存在");
|
|
}
|
|
WisdCompany wisdCompany = companyService.getById(companyId);
|
|
if (wisdCompany == null) {
|
|
return new Result(ResultUtil.ERROR, "该公司不存在");
|
|
}
|
|
WisdUser wisdUser = wisdUserService.getByPhone(phone, companyId);
|
|
if (wisdUser == null) {
|
|
return new Result(ResultUtil.ERROR, "此公司下不存在该员工");
|
|
}
|
|
if (!wisdUser.getUserName().equals(userName)) {
|
|
return new Result(ResultUtil.ERROR, "姓名输入错误");
|
|
}
|
|
wisdWxuser.setCompanyUserId(wisdUser.getId());
|
|
wisdWxuser.setUserId(wisdUser.getId());
|
|
wisdWxuser.setUserName(userName);
|
|
wisdWxuser.setUserPhone(phone);
|
|
wisdWxuser.setUserSex(wisdUser.getUserSex());
|
|
wisdWxuser.setUserVolumeBalance(wisdUser.getUserVolumeBalance());
|
|
wisdWxuser.setUserDiscountBalance(wisdUser.getUserDiscountBalance());
|
|
wisdWxuser.setUserDiscount(wisdUser.getUserDiscount());
|
|
wisdWxuser.setUserIscompany(1);
|
|
wisdWxuser.setPavkageNum(wisdUser.getPavkageNum());
|
|
Boolean flag = wxuserService.saveOrUpdate(wisdWxuser);
|
|
if (flag) {
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
} else {
|
|
return new Result(ResultUtil.ERROR, ResultUtil.ERROR_MSG);
|
|
}
|
|
}
|
|
|
|
@ApiOperation(value = "获取套餐券")
|
|
@GetMapping("getUserPackage")
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Result getUserPackage(Long userId, Integer type) {
|
|
WisdWxuser wxuser = wxuserService.getById(userId);
|
|
QueryWrapper<WisdUserPackage> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("user_id", wxuser.getCompanyUserId());
|
|
queryWrapper.eq("is_used", type);
|
|
queryWrapper.orderByDesc("create_time");
|
|
List<WisdUserPackage> wisdUserPackageList = userPackageService.list(queryWrapper);
|
|
List<WisdPackage> wisdPackageList = new ArrayList<>();
|
|
for (WisdUserPackage wisdUserPackage : wisdUserPackageList) {
|
|
WisdPackage wisdPackage = packageService.getById(wisdUserPackage.getPackageId());
|
|
// 套餐券已过期并且未使用,则将其设改为已过期
|
|
if (wisdPackage.getPackageEndTime().getTime() < System.currentTimeMillis() && wisdUserPackage.getIsUsed().equals(0)) {
|
|
wisdUserPackage.setIsUsed(2);
|
|
userPackageService.updateById(wisdUserPackage);
|
|
} else {
|
|
wisdPackageList.add(wisdPackage);
|
|
}
|
|
}
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_DATA, wisdPackageList);
|
|
}
|
|
|
|
@ApiOperation(value = "根据套餐卷获取套餐商品")
|
|
@GetMapping("getGoodsByPackage")
|
|
public Result getGoodsByPackage(Long packageId) {
|
|
WisdPackage wisdPackage = packageService.getById(packageId);
|
|
String[] goodsIds = wisdPackage.getGoodsId().split(",");
|
|
List<WisdGoods> wisdGoodsList = new ArrayList<>();
|
|
for (int i = 0; i < goodsIds.length; i++) {
|
|
WisdGoods wisdGoods = goodsService.getInfoById(Long.parseLong(goodsIds[i]));
|
|
if (wisdGoods != null) {
|
|
wisdGoodsList.add(wisdGoods);
|
|
}
|
|
}
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_DATA, wisdGoodsList);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "获取套餐商品详情")
|
|
@GetMapping("getPackageGoods")
|
|
public Result getPackageGoods(Long goodsId) {
|
|
WisdGoods wisdGoods = goodsService.getById(goodsId);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_DATA, wisdGoods);
|
|
}
|
|
|
|
@ApiOperation(value = "问题反馈列表")
|
|
@GetMapping("addFeedBack")
|
|
public Result feedBackList(Long userId) {
|
|
QueryWrapper<WisdFeedback> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("user_id", userId);
|
|
List<WisdFeedback> feedbackList = feedBackService.list(queryWrapper);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, feedbackList);
|
|
}
|
|
|
|
@ApiOperation(value = "问题反馈提交")
|
|
@PostMapping("addFeedBack")
|
|
public Result addFeedBack(@RequestBody WisdFeedback wisdFeedback) {
|
|
Boolean flag = feedBackService.save(wisdFeedback);
|
|
if (flag) {
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
} else {
|
|
return new Result(ResultUtil.ERROR, ResultUtil.ERROR_MSG);
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping(value = "img")
|
|
@ApiOperation(value = "单图上传")
|
|
public Map<String, Object> uploadImg(HttpServletRequest request) throws Exception {
|
|
return UploadUtil.webImg(request);
|
|
}
|
|
|
|
@ApiOperation(value = "获取关于我们")
|
|
@GetMapping("getAbout")
|
|
public Result getAbout() {
|
|
QueryWrapper<WisdWelfare> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("id", 3);
|
|
WisdWelfare wisdWelfare = welfareService.getOne(queryWrapper);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdWelfare);
|
|
}
|
|
|
|
@ApiOperation(value = "获取会员介绍")
|
|
@GetMapping("getVipAbout")
|
|
public Result getVipAbout() {
|
|
QueryWrapper<WisdWelfare> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("id", 4);
|
|
WisdWelfare wisdWelfare = welfareService.getOne(queryWrapper);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdWelfare);
|
|
}
|
|
|
|
@ApiOperation(value = "我得团队")
|
|
@GetMapping("getTeam")
|
|
public Result getTeam(Long userId) {
|
|
WisdWxuser wisdWxuser = wxuserService.getById(userId);
|
|
WisdWxuser pwisdWxuser = wxuserService.getById(wisdWxuser.getUserPid());
|
|
QueryWrapper<WisdWxuser> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("user_pid", userId);
|
|
List<WisdWxuser> wisdWxuserList = wxuserService.list(queryWrapper);
|
|
Integer count = 0;
|
|
for (WisdWxuser wisdWxuser1 : wisdWxuserList) {
|
|
QueryWrapper<WisdWxuser> queryWrapper1 = new QueryWrapper<>();
|
|
queryWrapper1.eq("user_pid", wisdWxuser1.getId());
|
|
Integer count1 = wxuserService.count(queryWrapper1);
|
|
count += count1;
|
|
}
|
|
wisdWxuser.setOneLevelNum(wisdWxuserList.size());
|
|
wisdWxuser.setTwoLevelNum(count);
|
|
wisdWxuser.setSuperiorUser(pwisdWxuser);
|
|
wisdWxuser.setUnderUserList(wisdWxuserList);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdWxuser);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "我的账单")
|
|
@GetMapping("getBill")
|
|
public Result getBill(Long userId, Integer category) {
|
|
QueryWrapper<WisdBill> queryWrapper = new QueryWrapper<>();
|
|
if (category != 0) {
|
|
queryWrapper.eq("bill_category", category);
|
|
}
|
|
if (category == 4) {
|
|
queryWrapper.and(wrapper -> wrapper.eq("bill_category", category).or().eq("bill_category", 44));
|
|
}
|
|
queryWrapper.eq("user_id", userId);
|
|
queryWrapper.orderByDesc("create_time");
|
|
List<WisdBill> wisdBillList = billService.list(queryWrapper);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdBillList);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "积分收益")
|
|
@GetMapping("getIntetralEarnings")
|
|
public Result getIntetralEarnings(Long userId) {
|
|
IntegralDto integralDto = new IntegralDto();
|
|
WisdIntegrlRoles wisdIntegrlRoles = integralRolesService.getById(1);
|
|
QueryWrapper<WisdBill> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("bill_category", 44);
|
|
queryWrapper.eq("bill_type", 1);
|
|
queryWrapper.eq("user_id", userId);
|
|
List<WisdBill> wisdBillList = billService.list(queryWrapper);
|
|
Integer integral = wisdBillList.stream().collect(Collectors.summingInt(WisdBill::getBillIntegral));
|
|
Date now = new Date();
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
|
String createTime = dateFormat.format(now);//格式化然后放入字符串中
|
|
queryWrapper.like("create_time", createTime);
|
|
List<WisdBill> wisdBillList1 = billService.list(queryWrapper);
|
|
Integer nowintegral = wisdBillList1.stream().collect(Collectors.summingInt(WisdBill::getBillIntegral));
|
|
WisdWxuser wisdWxuser = wxuserService.getById(userId);
|
|
WisdWxuser pwisdWxuser = wxuserService.getById(wisdWxuser.getUserPid());
|
|
QueryWrapper<WisdWxuser> queryWrapper3 = new QueryWrapper<>();
|
|
queryWrapper3.eq("user_pid", userId);
|
|
List<WisdWxuser> wisdWxuserList = wxuserService.list(queryWrapper3);
|
|
Integer count = 0;
|
|
for (WisdWxuser wisdWxuser1 : wisdWxuserList) {
|
|
QueryWrapper<WisdWxuser> queryWrapper1 = new QueryWrapper<>();
|
|
queryWrapper1.eq("user_pid", wisdWxuser1.getId());
|
|
Integer count1 = wxuserService.count(queryWrapper1);
|
|
count += count1;
|
|
}
|
|
QueryWrapper<WisdWxuser> queryWrapper2 = new QueryWrapper<>();
|
|
queryWrapper2.like("create_time", createTime);
|
|
queryWrapper2.like("user_pid", userId);
|
|
Integer nowteamNum = wxuserService.count(queryWrapper2);
|
|
integralDto.setWisdIntegrlRoles(wisdIntegrlRoles);
|
|
integralDto.setNowdayIntegral(nowintegral);
|
|
integralDto.setShareIntegral(integral);
|
|
integralDto.setTeamNum(wisdWxuserList.size() + count);
|
|
integralDto.setNowteamNum(nowteamNum);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, integralDto);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "店铺订单")
|
|
@GetMapping("getMerchantsStores")
|
|
public Result getMerchantsStores(Long userId, Long storesId, Integer type, Integer page, Integer num) {
|
|
QueryWrapper<WisdOeder> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("order_pick", 1);
|
|
queryWrapper.eq("address_id", storesId);
|
|
if (type == 1) {
|
|
queryWrapper.eq("status", 2);
|
|
}
|
|
if (type == 2) {
|
|
queryWrapper.eq("status", 4);
|
|
}
|
|
queryWrapper.eq("is_deleted", 0);
|
|
queryWrapper.orderByDesc("create_time");
|
|
Page<WisdOeder> p = new Page<>(page, num);
|
|
IPage<WisdOeder> wisdOederList = orderService.page(p, queryWrapper);
|
|
for (WisdOeder wisdOeder : wisdOederList.getRecords()) {
|
|
QueryWrapper<WisdOrderDetail> queryWrapper2 = new QueryWrapper<>();
|
|
queryWrapper2.eq("order_id", wisdOeder.getId());
|
|
List<WisdOrderDetail> wisdOrderDetailList = orderDetailService.list(queryWrapper2);
|
|
List<WisdGoods> wisdGoodsList = new ArrayList<>();
|
|
for (WisdOrderDetail wisdOrderDetail : wisdOrderDetailList) {
|
|
WisdGoods wisdGoods = goodsService.getInfoById(wisdOrderDetail.getGoodsId());
|
|
WisdGoodsSpec wisdGoodsSpec = goodsSpecService.getInfoById(wisdOrderDetail.getSpecId());
|
|
WisdWxuser wisdWxuser = wxuserService.getById(userId);
|
|
if (wisdWxuser.getUserIscompany() == 1 && wisdOeder.getOrderPayWay() != 3 && wisdOeder.getOrderPayWay() != 4 && wisdOeder.getOrderPayWay() != 5) {
|
|
WisdUser wisdUser = wisdUserService.getByUserId(wisdWxuser.getUserId());
|
|
QueryWrapper<WisdBulk> queryWrapper3 = new QueryWrapper<>();
|
|
queryWrapper3.eq("goods_id", wisdGoods.getId());
|
|
queryWrapper3.eq("company_id", wisdUser.getCompanyId());
|
|
queryWrapper3.eq("spec_id", wisdGoodsSpec.getId());
|
|
queryWrapper3.eq("is_enable", 1);
|
|
WisdBulk wisdBulk = blukService.getOne(queryWrapper3);
|
|
if (wisdBulk != null) {
|
|
wisdGoodsSpec.setSpecBulyPrice(wisdBulk.getGoodsBulkPrice());
|
|
}
|
|
}
|
|
wisdGoods.setWisdGoodsSpec(wisdGoodsSpec);
|
|
wisdGoods.setGoodsNum(wisdOrderDetail.getGoodsNum());
|
|
wisdGoodsList.add(wisdGoods);
|
|
}
|
|
wisdOeder.setGoodsList(wisdGoodsList);
|
|
}
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdOederList);
|
|
}
|
|
|
|
@ApiOperation(value = "提现记录")
|
|
@GetMapping("getWisdWithdrawal")
|
|
public Result getWisdWithdrawal(Long userId, Integer status, Integer page, Integer num) {
|
|
QueryWrapper<WisdWithdrawal> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("user_id", userId);
|
|
if (status != 0) {
|
|
queryWrapper.eq("status", status);
|
|
}
|
|
Page<WisdWithdrawal> p = new Page<>(page, num);
|
|
IPage<WisdWithdrawal> wisdWithdrawalIPage = withdrawalService.page(p, queryWrapper);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdWithdrawalIPage);
|
|
}
|
|
|
|
@ApiOperation(value = "申请提现")
|
|
@PostMapping("addWisdWithdrawal")
|
|
public Result addWisdWithdrawal(@RequestBody WisdWithdrawal wisdWithdrawal) {
|
|
QueryWrapper<WisdBack> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.like("back_name", wisdWithdrawal.getWithdrawalCard());
|
|
WisdBack wisdBack = backService.getOne(queryWrapper);
|
|
if (wisdBack == null) {
|
|
return new Result(ResultUtil.ERROR, "请输入开户行完整名称");
|
|
}
|
|
wisdWithdrawal.setWithdrawalCardNo(wisdBack.getBackNumber());
|
|
String wisdWithdrawalNumber = "WN" + (new Date()).getTime();
|
|
WisdWxuser wisdWxuser = wxuserService.getById(wisdWithdrawal.getUserId());
|
|
wisdWithdrawal.setWithdrawalNumber(wisdWithdrawalNumber);
|
|
Boolean flag = withdrawalService.save(wisdWithdrawal);
|
|
if (flag) {
|
|
wisdWxuser.setUserBalance(wisdWxuser.getUserBalance().subtract(wisdWithdrawal.getWithdrawalMoney()));
|
|
wxuserService.saveOrUpdate(wisdWxuser);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
} else {
|
|
return new Result(ResultUtil.ERROR, ResultUtil.ERROR_MSG);
|
|
}
|
|
}
|
|
|
|
@ApiOperation(value = "获取提现规则")
|
|
@GetMapping("getWithdrawalRole")
|
|
public Result getWithdrawalRole() {
|
|
WisdIntegrlRoles wisdIntegrlRoles = integralRolesService.getById(1);
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG, wisdIntegrlRoles);
|
|
}
|
|
|
|
@ApiOperation(value = "分享获得积分")
|
|
@PutMapping("putIntetralEarnings")
|
|
public Result putIntetralEarnings(Long userId) {
|
|
if (userId == 0) {
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
}
|
|
WisdWxuser wisdWxuser = wxuserService.getById(userId);
|
|
// WisdUser wisdUser=wisdUserService.getByUserId(wisdWxuser.getCompanyUserId());
|
|
QueryWrapper<WisdBill> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("bill_category", 44);
|
|
queryWrapper.eq("bill_type", 1);
|
|
queryWrapper.eq("user_id", userId);
|
|
Date now = new Date();
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
|
String createTime = dateFormat.format(now);//格式化然后放入字符串中
|
|
queryWrapper.like("create_time", createTime);
|
|
List<WisdBill> wisdBillList = billService.list(queryWrapper);
|
|
WisdIntegrlRoles wisdIntegrlRoles = integralRolesService.getById(1);
|
|
if (wisdIntegrlRoles.getIntegralDayNum() < wisdBillList.size() || wisdIntegrlRoles.getIntegralDayNum() == wisdBillList.size()) {
|
|
return new Result(ResultUtil.ERROR, "今日分享收益次数已达上限");
|
|
} else {
|
|
wisdWxuser.setUserIntegral(wisdWxuser.getUserIntegral() + wisdIntegrlRoles.getIntegralDay());
|
|
wisdWxuser.setUserAllIntegral(wisdWxuser.getUserAllIntegral() + wisdIntegrlRoles.getIntegralDay());
|
|
//wisdUser.setUserIntegral(wisdWxuser.getUserIntegral()+wisdIntegrlRoles.getIntegralDay());
|
|
Boolean flag1 = wxuserService.saveOrUpdate(wisdWxuser);
|
|
// Boolean flag2=wisdUserService.saveOrUpdate(wisdUser);
|
|
if (flag1) {
|
|
WisdBill wisdBill = new WisdBill();
|
|
wisdBill.setBillIntegral(wisdIntegrlRoles.getIntegralDay());
|
|
wisdBill.setBillType(1);
|
|
wisdBill.setBillCategory(44);
|
|
wisdBill.setUserId(userId);
|
|
wisdBill.setBillIntroduction("分享得积分");
|
|
billService.save(wisdBill);
|
|
vipService.addVip(wisdWxuser.getId());
|
|
return new Result(ResultUtil.SUCCESS, ResultUtil.SUCCESS_MSG);
|
|
} else {
|
|
return new Result(ResultUtil.ERROR, ResultUtil.ERROR_MSG);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|