| | |
| | | import cn.exrick.xboot.your.util.HttpUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @Api(tags = "订单接口") |
| | | @Api(tags = "小程序接口") |
| | | @RequestMapping("/xboot/wx") |
| | | @Transactional |
| | | public class IndexController { |
| | |
| | | @Autowired |
| | | private ICustomerReceiveService iCustomerReceiveService; |
| | | |
| | | @Autowired |
| | | private IOrderLogService iOrderLogService; |
| | | |
| | | |
| | | //2.微信登陆 |
| | | @RequestMapping("/login") |
| | | @RequestMapping(value = "/login", method = RequestMethod.POST) |
| | | @ApiOperation(value = "微信登陆") |
| | | public Object doLogin(String code){ |
| | | |
| | | JSONObject SessionKeyOpenId = getSessionKeyOrOpenId( code ); |
| | |
| | | String openid = SessionKeyOpenId.getStr("openid"); |
| | | |
| | | if(StrUtil.isEmpty(openid)){ |
| | | return ResultUtil.error(SessionKeyOpenId.toString()); |
| | | return ResultUtil.error("error微信:"+SessionKeyOpenId.toString()); |
| | | } |
| | | |
| | | QueryWrapper<Customer> wrapper = new QueryWrapper<>(); |
| | |
| | | if(one==null){ |
| | | return ResultUtil.error(openid);//首次登陆需绑定零售许可证 |
| | | }else { |
| | | one.setLoginNum(one.getLoginNum()+1); |
| | | iCustomerService.saveOrUpdate(one); |
| | | 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; |
| | | String requestUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=wx77c0d2c54010b7e4&secret=2282710e890670e916c189347d70a7c5&grant_type=authorization_code&js_code="+code; |
| | | JSONObject jsonObject = JSONUtil.parseObj( HttpUtil.get(requestUrl)); |
| | | return jsonObject; |
| | | } |
| | |
| | | //3.微信绑定零售许可证 |
| | | //licence:零售许可证号 |
| | | //openId:微信id |
| | | @RequestMapping("/bindWx") |
| | | public Object bindWx(String licence,String openId){ |
| | | @RequestMapping(value = "/bindWx", method = RequestMethod.POST) |
| | | @ApiOperation(value = "微信绑定零售许可证") |
| | | public Object bindWx(String licence,String openId,String linker,String phone){ |
| | | QueryWrapper<Customer> wrapper2 = new QueryWrapper<>(); |
| | | wrapper2.eq("open_id",openId); |
| | | Customer c = iCustomerService.getOne(wrapper2); |
| | | if(c==null){ |
| | | |
| | | }else { |
| | | System.out.println(c.getOpenId()); |
| | | c.setOpenId(""); |
| | | iCustomerService.saveOrUpdate(c); |
| | | } |
| | | |
| | | QueryWrapper<Customer> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("licence",licence); |
| | | if(StrUtil.isNotEmpty(linker)){ |
| | | wrapper.eq("linker",linker); |
| | | } |
| | | if(StrUtil.isNotEmpty(phone)){ |
| | | wrapper.eq("phone",phone); |
| | | } |
| | | Customer one = iCustomerService.getOne(wrapper); |
| | | if(one==null){ |
| | | return ResultUtil.error("零售许可证无效");//首次登陆需绑定零售许可证 |
| | | return ResultUtil.error("请检查输入信息是否正确");//首次登陆需绑定零售许可证 |
| | | }else { |
| | | one.setOpenId(openId); |
| | | iCustomerService.saveOrUpdate(one); |
| | |
| | | } |
| | | |
| | | //4.获取今日配送订单 |
| | | @RequestMapping("/getTodayOrder") |
| | | @RequestMapping(value = "/getTodayOrder", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取今日配送订单") |
| | | public Object getTodayOrder(String customerId){ |
| | | OrderTask orderTask = getOrder(customerId); |
| | | if(orderTask==null){ |
| | |
| | | } |
| | | |
| | | //5.获取车辆位置 |
| | | @RequestMapping("/getCarInfo") |
| | | @RequestMapping(value = "/getCarInfo",method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取车辆位置") |
| | | public Object getCarInfo(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.error("今日无订单"); |
| | | } |
| | | String carId = orderTask.getCarId(); |
| | | Car car = iCarService.getById(carId); |
| | | String[] carids = new String[1]; |
| | | carids[0]= car.getCode(); |
| | | String latestGps = haiKangPost.findLatestGps(carids); |
| | | JSONObject jsonObject = JSONUtil.parseObj(latestGps); |
| | | String data = jsonObject.getStr("data"); |
| | | JSONObject jsonObject2 = JSONUtil.parseObj(data); |
| | | Integer lng = jsonObject2.getInt("longitude"); |
| | | Integer lat = jsonObject2.getInt("latitude"); |
| | | |
| | | DecimalFormat df = new DecimalFormat("#.000000"); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("lng",df.format(lng/360000.0)); |
| | | map.put("lat",df.format(lat/360000.0)); |
| | | map.put("content","还有3单,预计10:22送达"); |
| | | map.put("lng",118.167491); |
| | | map.put("lat",39.651253); |
| | | map.put("content","暂无车辆数据"); |
| | | if(StrUtil.isEmpty(car.getCode())){ |
| | | return ResultUtil.data(map); |
| | | } |
| | | try { |
| | | String[] carids = new String[1]; |
| | | carids[0]= car.getCode(); |
| | | String latestGps = haiKangPost.findLatestGps(carids); |
| | | JSONObject jsonObject = JSONUtil.parseObj(latestGps); |
| | | String data = jsonObject.getStr("data"); |
| | | JSONArray objects = JSONUtil.parseArray(data); |
| | | JSONObject jsonObject2 = objects.getJSONObject(0); |
| | | Integer lng = jsonObject2.getInt("longitude"); |
| | | Integer lat = jsonObject2.getInt("latitude"); |
| | | |
| | | DecimalFormat df = new DecimalFormat("#.000000"); |
| | | map.put("lng",df.format(lng/360000.0)); |
| | | map.put("lat",df.format(lat/360000.0)); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | QueryWrapper<OrderTask> wrapper = new QueryWrapper<OrderTask>(); |
| | | wrapper.eq("area_id",orderTask.getAreaId()); |
| | | wrapper.eq("send_date",format); |
| | | wrapper.eq("status",0); |
| | | wrapper.orderByAsc("seq"); |
| | | List<OrderTask> list = iOrderTaskService.list(wrapper); |
| | | |
| | | if(list.size()>0){ |
| | | if(list.get(0).getSeq()<orderTask.getSeq()){ |
| | | int i = orderTask.getSeq() - list.get(0).getSeq(); |
| | | map.put("content","还有"+i+"单,预计"+(i*5)+"分钟后送达"); |
| | | } |
| | | if(list.get(0).getSeq()==orderTask.getSeq()){ |
| | | int i = orderTask.getSeq() - list.get(0).getSeq(); |
| | | map.put("content","预计5分钟内送达"); |
| | | } |
| | | } |
| | | return ResultUtil.data(map); |
| | | } |
| | | |
| | | //6.加油助力 |
| | | @RequestMapping("/likes") |
| | | @RequestMapping(value = "/likes", method = RequestMethod.POST) |
| | | @ApiOperation(value = "加油助力") |
| | | public Object likes(String customerId){ |
| | | OrderTask order = getOrder(customerId); |
| | | if(order==null){ |
| | | return ResultUtil.error("今日无订单"); |
| | | } |
| | | order.setLikes(1); |
| | | iOrderTaskService.saveOrUpdate(order); |
| | | |
| | | saveLog(); |
| | | return ResultUtil.success("助力成功"); |
| | | } |
| | | |
| | | private void saveLog(){ |
| | | QueryWrapper<OrderLog> wp = new QueryWrapper<>(); |
| | | wp.eq("type",1); |
| | | OrderLog one = iOrderLogService.getOne(wp); |
| | | if(one!=null){ |
| | | one.setNum(one.getNum()+1); |
| | | }else{ |
| | | one = new OrderLog(); |
| | | one.setNum(1); |
| | | one.setType(1); |
| | | } |
| | | iOrderLogService.saveOrUpdate(one); |
| | | } |
| | | |
| | | //7.获取订单列表 |
| | | @RequestMapping("/getOrderList") |
| | | @RequestMapping(value = "/getOrderList", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取订单列表") |
| | | public Object getOrderList(String customerId, String startTime, String endTime, PageVo page){ |
| | | page.setSort("sendDate"); |
| | | page.setOrder("desc"); |
| | |
| | | } |
| | | |
| | | //8.获取订单详情列表 |
| | | @RequestMapping("/getOrderDetail") |
| | | @RequestMapping(value = "/getOrderDetail", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取订单详情列表") |
| | | public Object getOrderDetail(String orderId){ |
| | | QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("order_id",orderId); |
| | |
| | | } |
| | | |
| | | //9.评价 |
| | | @RequestMapping("/remark") |
| | | @RequestMapping(value = "/remark", method = RequestMethod.POST) |
| | | @ApiOperation(value = "评价") |
| | | public Object remark(int level,String orderId){ |
| | | OrderTask byId = iOrderTaskService.getById(orderId); |
| | | byId.setLevel(level); |
| | |
| | | |
| | | //10.获取意见建议列表 |
| | | @RequestMapping(value = "/getSuggestByPage", method = RequestMethod.GET) |
| | | @ApiOperation(value = "获取意见建议列表") |
| | | public Result<IPage<Suggest>> getByPage(String customerId,PageVo page) { |
| | | QueryWrapper<Suggest> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("customer_id",customerId); |
| | |
| | | |
| | | //12.新增意见建议 |
| | | @RequestMapping(value = "/insertSuggest", method = RequestMethod.POST) |
| | | @ApiOperation(value = "新增意见建议") |
| | | public Result<Suggest> insertSuggest(String customerId,String content) { |
| | | Suggest suggest = new Suggest(); |
| | | suggest.setContent(content); |
| | |
| | | |
| | | //13.新增签收人 |
| | | @RequestMapping(value = "/insertReceive", method = RequestMethod.POST) |
| | | @ApiOperation(value = "新增签收人") |
| | | public Result<CustomerReceive> insertReceive(String customerId,String name,String phone) { |
| | | CustomerReceive customerReceive = new CustomerReceive(); |
| | | customerReceive.setCustomerId(customerId); |
| | |
| | | } |
| | | return new ResultUtil<CustomerReceive>().setErrorMsg("操作失败"); |
| | | } |
| | | |
| | | //14.获取签收人列表 |
| | | @RequestMapping(value = "/getCustomerReceive", method = RequestMethod.GET) |
| | | @ApiOperation(value = "获取签收人") |
| | | public Result<List<CustomerReceive>> getCustomerReceive(String customerId) { |
| | | PageVo page = new PageVo(); |
| | | page.setPageSize(30); |
| | | page.setPageNumber(1); |
| | | page.setOrder("desc"); |
| | | page.setSort("createTime"); |
| | | QueryWrapper<CustomerReceive> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("customer_id",customerId); |
| | | IPage<CustomerReceive> data = iCustomerReceiveService.page2(PageUtil.initMpPage(page),wrapper); |
| | | return new ResultUtil<List<CustomerReceive>>().setData(data.getRecords()); |
| | | } |
| | | |
| | | //15.获取签收人 |
| | | @RequestMapping(value = "/getCustomerReceiveById", method = RequestMethod.GET) |
| | | @ApiOperation(value = "获取签收人") |
| | | public Result<CustomerReceive> getCustomerReceiveById(String customerReceiveId) { |
| | | CustomerReceive byId = iCustomerReceiveService.getById(customerReceiveId); |
| | | return new ResultUtil<CustomerReceive>().setData(byId); |
| | | } |
| | | |
| | | //16.删除接货人 |
| | | @RequestMapping(value = "/deleteReceive", method = RequestMethod.POST) |
| | | @ApiOperation(value = "删除接货人") |
| | | public Object deleteReceive(String id) { |
| | | iCustomerReceiveService.removeById(id); |
| | | return ResultUtil.success("删除成功"); |
| | | } |
| | | } |