package com.stylefeng.guns.modular.api; import com.stylefeng.guns.modular.system.service.IMerchantActivityService; import com.stylefeng.guns.modular.system.service.IMerchantService; import com.stylefeng.guns.modular.system.service.IUserInfoService; import com.stylefeng.guns.modular.system.service.IUserMerchantCouponService; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.warpper.*; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; /** * 商家 * @author pzb * @Date 2022/2/8 10:49 */ @RestController @RequestMapping("/api/merchant") public class MerchantController { @Autowired private IMerchantService merchantService; @Autowired private IUserInfoService userInfoService; @Autowired private IMerchantActivityService merchantActivityService; @Autowired private IUserMerchantCouponService userMerchantCouponService; @ResponseBody @PostMapping("/registeredMerchant") @ApiOperation(value = "1.0-提交商家申请", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "商家名称", name = "name", required = true, dataType = "string"), @ApiImplicitParam(value = "商家头像", name = "headImg", required = true, dataType = "string"), @ApiImplicitParam(value = "联系人姓名", name = "contactName", required = true, dataType = "string"), @ApiImplicitParam(value = "联系人电话", name = "contactPhone", required = true, dataType = "string"), @ApiImplicitParam(value = "营业地址", name = "address", required = true, dataType = "string"), @ApiImplicitParam(value = "营业执照", name = "businessLicense", required = true, dataType = "string"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil registeredMerchant(String name, String headImg, String contactName, String contactPhone, String address, String businessLicense, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return merchantService.registeredMerchant(uid, name, headImg, contactName, contactPhone, address, businessLicense); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/getMerchant") @ApiOperation(value = "1.0-获取商家信息", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil getMerchant(HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } MerchantWapper merchant = merchantService.getMerchant(uid); return ResultUtil.success(merchant); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/getMerchantCoupon") @ApiOperation(value = "1.0-商家获取商家券列表", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "数据类型(1=进行中,2=已结束)", name = "type", required = true, dataType = "int"), @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"), @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> getMerchantCoupon(Integer type, Integer pageNum, Integer size, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List merchantCoupon = merchantActivityService.getMerchantCoupon(uid, type, pageNum, size); return ResultUtil.success(merchantCoupon); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/getUserMerchantCoupon") @ApiOperation(value = "1.0-根据核销码获取优惠券详情", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "核销码", name = "code", required = true, dataType = "string"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil getUserMerchantCoupon(String code, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return userMerchantCouponService.getUserMerchantCoupon(uid, code); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/writeOffMerchantCoupon") @ApiOperation(value = "1.0-核销优惠券操作", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "核销码", name = "code", required = true, dataType = "string"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil writeOffMerchantCoupon(String code, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return userMerchantCouponService.writeOffMerchantCoupon(uid, code); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/getWriteOffHistory") @ApiOperation(value = "1.0-商家获取优惠券核销记录", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "活动id", name = "activityId", required = true, dataType = "int"), @ApiImplicitParam(value = "优惠券id", name = "id", required = true, dataType = "int"), @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"), @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil>> getWriteOffHistory(Integer activityId, Integer id, Integer pageNum, Integer size){ try { List> writeOffHistory = userMerchantCouponService.getWriteOffHistory(activityId, id, pageNum, size); return ResultUtil.success(writeOffHistory); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/getMyMerchantCoupon") @ApiOperation(value = "1.0-获取我的商家优惠券", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "数据类型(1=正常,2=失效)", name = "type", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> getMyMerchantCoupon(Integer type, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List myMerchantCoupon = userMerchantCouponService.getMyMerchantCoupon(uid, type); return ResultUtil.success(myMerchantCoupon); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/giveAwayMerchantCoupon") @ApiOperation(value = "1.0-订单完成后获取商家优惠券", tags = {"用户端-出租车", "用户端-专车", "用户端-跨城","用户端-小件物流"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"), @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=跨城,4=同城小件物流,5=跨城小件物流)", name = "orderType", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> giveAwayMerchantCoupon(Integer orderId, Integer orderType, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List listWarppers = userMerchantCouponService.giveAwayMerchantCoupon(uid, orderId, orderType); return ResultUtil.success(listWarppers); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/gainMerchantCoupon") @ApiOperation(value = "1.0-首页获取商家券数据(仅跨城和小件物流)", tags = {"用户端-跨城","用户端-小件物流"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> gainMerchantCoupon(HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List merchantCoupon = userMerchantCouponService.getMerchantCoupon(uid); return ResultUtil.success(merchantCoupon); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } }