| | |
| | | package cn.exrick.xboot.your.controller.wx; |
| | | |
| | | import cn.exrick.xboot.core.common.utils.PageUtil; |
| | | import cn.exrick.xboot.core.common.utils.ResultUtil; |
| | | import cn.exrick.xboot.core.common.vo.PageVo; |
| | | import cn.exrick.xboot.core.common.vo.Result; |
| | | import cn.exrick.xboot.your.entity.*; |
| | | import cn.exrick.xboot.your.service.*; |
| | | import cn.exrick.xboot.your.util.HaiKangPost; |
| | | 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; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | 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.text.DecimalFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @Api(tags = "订单接口") |
| | | @Api(tags = "小程序接口") |
| | | @RequestMapping("/xboot/wx") |
| | | @Transactional |
| | | public class IndexController { |
| | |
| | | @Autowired |
| | | private IOrderDetailService iOrderDetailService; |
| | | |
| | | @Autowired |
| | | private ICarService iCarService; |
| | | |
| | | //4.获取今日配送订单 |
| | | @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); |
| | | } |
| | | } |
| | | @Autowired |
| | | private HaiKangPost haiKangPost; |
| | | |
| | | //3.微信绑定零售许可证 |
| | | //licence:零售许可证号 |
| | | //openId:微信id |
| | | @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,"登录成功"); |
| | | } |
| | | } |
| | | @Autowired |
| | | private ISuggestService iSuggestService; |
| | | |
| | | @Autowired |
| | | private ICustomerReceiveService iCustomerReceiveService; |
| | | |
| | | |
| | | //2.微信登陆 |
| | | @RequestMapping("/login") |
| | | @RequestMapping(value = "/login", method = RequestMethod.POST) |
| | | @ApiOperation(value = "微信登陆") |
| | | public Object doLogin(String code){ |
| | | |
| | | JSONObject SessionKeyOpenId = getSessionKeyOrOpenId( code ); |
| | |
| | | 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(value = "/bindWx", method = RequestMethod.POST) |
| | | @ApiOperation(value = "微信绑定零售许可证") |
| | | 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,"登录成功"); |
| | | } |
| | | } |
| | | |
| | | //4.获取今日配送订单 |
| | | @RequestMapping(value = "/getTodayOrder", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取今日配送订单") |
| | | public Object getTodayOrder(String customerId){ |
| | | OrderTask orderTask = getOrder(customerId); |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | public OrderTask getOrder(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); |
| | | return orderTask; |
| | | } |
| | | |
| | | //5.获取车辆位置 |
| | | @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); |
| | | 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"); |
| | | 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<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送达"); |
| | | return ResultUtil.data(map); |
| | | } |
| | | |
| | | //6.加油助力 |
| | | @RequestMapping(value = "/likes", method = RequestMethod.POST) |
| | | @ApiOperation(value = "加油助力") |
| | | public Object likes(String customerId){ |
| | | OrderTask order = getOrder(customerId); |
| | | order.setLikes(1); |
| | | iOrderTaskService.saveOrUpdate(order); |
| | | return ResultUtil.success("助力成功"); |
| | | } |
| | | |
| | | //7.获取订单列表 |
| | | @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"); |
| | | QueryWrapper<OrderTask> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("customer_id",customerId); |
| | | if(StrUtil.isNotEmpty(startTime)){ |
| | | wrapper.ge("send_date",startTime); |
| | | } |
| | | if(StrUtil.isNotEmpty(endTime)){ |
| | | wrapper.le("send_date",endTime); |
| | | } |
| | | IPage<OrderTask> page1 = iOrderTaskService.page(PageUtil.initMpPage(page), wrapper); |
| | | return ResultUtil.data(page1.getRecords()); |
| | | } |
| | | |
| | | //8.获取订单详情列表 |
| | | @RequestMapping(value = "/getOrderDetail", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取订单详情列表") |
| | | public Object getOrderDetail(String orderId){ |
| | | QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("order_id",orderId); |
| | | List<OrderDetail> list1 = iOrderDetailService.list(wrapper); |
| | | return ResultUtil.data(list1); |
| | | } |
| | | |
| | | //9.评价 |
| | | @RequestMapping(value = "/remark", method = RequestMethod.POST) |
| | | @ApiOperation(value = "评价") |
| | | public Object remark(int level,String orderId){ |
| | | OrderTask byId = iOrderTaskService.getById(orderId); |
| | | byId.setLevel(level); |
| | | iOrderTaskService.saveOrUpdate(byId); |
| | | return ResultUtil.success("评价成功"); |
| | | } |
| | | |
| | | |
| | | //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); |
| | | IPage<Suggest> data = iSuggestService.page2(PageUtil.initMpPage(page),wrapper); |
| | | return new ResultUtil<IPage<Suggest>>().setData(data); |
| | | } |
| | | |
| | | //12.新增意见建议 |
| | | @RequestMapping(value = "/insertSuggest", method = RequestMethod.POST) |
| | | @ApiOperation(value = "新增意见建议") |
| | | public Result<Suggest> insertSuggest(String customerId,String content) { |
| | | Suggest suggest = new Suggest(); |
| | | suggest.setContent(content); |
| | | suggest.setCustomerId(customerId); |
| | | if (iSuggestService.saveOrUpdate(suggest)) { |
| | | return new ResultUtil<Suggest>().setSuccessMsg("操作成功"); |
| | | } |
| | | return new ResultUtil<Suggest>().setErrorMsg("操作失败"); |
| | | } |
| | | |
| | | //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); |
| | | customerReceive.setPhone(phone); |
| | | customerReceive.setName(name); |
| | | customerReceive.setFstatus(0); |
| | | if (iCustomerReceiveService.saveOrUpdate(customerReceive)) { |
| | | return new ResultUtil<CustomerReceive>().setSuccessMsg("操作成功"); |
| | | } |
| | | return new ResultUtil<CustomerReceive>().setErrorMsg("操作失败"); |
| | | } |
| | | } |