package cn.exrick.xboot.your.controller.wx;
|
|
import cn.exrick.xboot.core.common.utils.ResultUtil;
|
import cn.exrick.xboot.your.entity.*;
|
import cn.exrick.xboot.your.service.*;
|
import cn.exrick.xboot.your.util.HttpUtil;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import io.swagger.annotations.Api;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
/**
|
* @author whj
|
*/
|
@Slf4j
|
@RestController
|
@Api(tags = "订单接口")
|
@RequestMapping("/xboot/wx")
|
@Transactional
|
public class IndexController {
|
|
@Autowired
|
private IOrderTaskService iOrderTaskService;
|
|
@Autowired
|
private ICustomerService iCustomerService;
|
|
@Autowired
|
private IOrderDetailService iOrderDetailService;
|
|
|
//获取今日配送订单
|
@RequestMapping("/getTodayOrder")
|
public Object getTodayOrder(String customerId){
|
QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<OrderTask>();
|
String format = DateUtil.format(new Date(), "yyyy-MM-dd");
|
wrapper2.eq("customer_id",customerId);
|
wrapper2.eq("send_date",format);
|
OrderTask orderTask = iOrderTaskService.getOne(wrapper2);
|
if(orderTask==null){
|
return ResultUtil.data(new ArrayList<>());
|
}else{
|
QueryWrapper<OrderDetail> wrapper = new QueryWrapper<OrderDetail>();
|
wrapper.eq("order_id",orderTask.getId());
|
List<OrderDetail> list = iOrderDetailService.list(wrapper);
|
return ResultUtil.data(list);
|
}
|
}
|
|
//微信绑定零售许可证
|
@RequestMapping("/bindWx")
|
public Object bindWx(String licence,String openId){
|
QueryWrapper<Customer> wrapper = new QueryWrapper<>();
|
wrapper.eq("licence",licence);
|
Customer one = iCustomerService.getOne(wrapper);
|
if(one==null){
|
return ResultUtil.error("零售许可证无效");//首次登陆需绑定零售许可证
|
}else {
|
one.setOpenId(openId);
|
iCustomerService.saveOrUpdate(one);
|
return ResultUtil.data(one,"登录成功");
|
}
|
}
|
|
//微信登陆
|
@RequestMapping("/login")
|
public Object doLogin(String code){
|
|
JSONObject SessionKeyOpenId = getSessionKeyOrOpenId( code );
|
|
String openid = SessionKeyOpenId.getStr("openid");
|
|
if(StrUtil.isEmpty(openid)){
|
return ResultUtil.error(SessionKeyOpenId.toString());
|
}
|
|
QueryWrapper<Customer> wrapper = new QueryWrapper<>();
|
wrapper.eq("open_id",openid);
|
Customer one = iCustomerService.getOne(wrapper);
|
if(one==null){
|
return ResultUtil.error(openid);//首次登陆需绑定零售许可证
|
}else {
|
return ResultUtil.data(one,"登录成功");
|
}
|
}
|
|
public static JSONObject getSessionKeyOrOpenId(String code){
|
//微信端登录code
|
String wxCode = code;
|
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=wx0f10f6d253f3ee6b&secret=4d4cbc8da31a96559114ad693de70631&grant_type=authorization_code&js_code="+code;
|
JSONObject jsonObject = JSONUtil.parseObj( HttpUtil.get(requestUrl));
|
return jsonObject;
|
}
|
}
|