| @@ -13,6 +13,7 @@ import com.iformall.domain.vo.WxMerchantTradeVo; | |||||
| import com.iformall.domain.vo.WxMerchantVo; | import com.iformall.domain.vo.WxMerchantVo; | ||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| import org.springframework.scheduling.annotation.Async; | |||||
| import org.springframework.web.bind.annotation.ModelAttribute; | import org.springframework.web.bind.annotation.ModelAttribute; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| @@ -160,4 +161,6 @@ public interface WxMerchantService { | |||||
| List<Long> getMerchantShopIds(Long merchantId); | List<Long> getMerchantShopIds(Long merchantId); | ||||
| @Async | |||||
| void collectCoupon(TenantEntity tenantInfo, Long memberId, Long id); | |||||
| } | } | ||||
| @@ -12,13 +12,13 @@ import com.iformall.domain.dto.WxMerchantDto; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.po.base.BaseEntity; | import com.iformall.domain.po.base.BaseEntity; | ||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.domain.po.tt.TtUserFollow; | |||||
| import com.iformall.domain.vo.*; | import com.iformall.domain.vo.*; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import com.iformall.utils.EventUtil; | |||||
| import org.apache.commons.collections.CollectionUtils; | import org.apache.commons.collections.CollectionUtils; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -102,6 +102,9 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| @Autowired | @Autowired | ||||
| WxPropertyContractService wxPropertyContractService; | WxPropertyContractService wxPropertyContractService; | ||||
| @Autowired | |||||
| TtUserFollowMapper ttUserFollowMapper; | |||||
| @Override | @Override | ||||
| public PageInfo<WxMerchant> listAsPage(WxMerchant record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxMerchant> listAsPage(WxMerchant record, Integer pageIndex, Integer pageSize) { | ||||
| PageHelper.startPage(pageIndex, pageSize); | PageHelper.startPage(pageIndex, pageSize); | ||||
| @@ -940,4 +943,21 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| public List<Long> getMerchantShopIds(Long merchantId) { | public List<Long> getMerchantShopIds(Long merchantId) { | ||||
| return wxMerchantShopMapper.findShopIds(merchantId); | return wxMerchantShopMapper.findShopIds(merchantId); | ||||
| } | } | ||||
| @Override | |||||
| public void collectCoupon(TenantEntity tenantEntity, Long memberId, Long id) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| TtUserFollow userFollow = new TtUserFollow(); | |||||
| userFollow.setId(idWorker.nextId()); | |||||
| userFollow.updateTenantInfo(tenantEntity); | |||||
| userFollow.setUserId(memberId); | |||||
| userFollow.setMerchernId(id); | |||||
| userFollow.setCreateDate(new Date()); | |||||
| userFollow.setUpdateDate(new Date()); | |||||
| try { | |||||
| ttUserFollowMapper.insert(userFollow); | |||||
| } catch (Exception e) { | |||||
| // e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -173,6 +173,7 @@ public class TtCouponServiceImpl implements TtCouponService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| // @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public void collectCoupon(TenantEntity tenantEntity,Long memberId, Long id) { | public void collectCoupon(TenantEntity tenantEntity,Long memberId, Long id) { | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| TtUserCollect userCollect = new TtUserCollect(); | TtUserCollect userCollect = new TtUserCollect(); | ||||
| @@ -187,6 +188,7 @@ public class TtCouponServiceImpl implements TtCouponService { | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| // e.printStackTrace(); | // e.printStackTrace(); | ||||
| } | } | ||||
| ttCouponMapper.addCollectCount(id); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -16,7 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| @RestController | @RestController | ||||
| @RequestMapping("ttCoupon") | |||||
| @RequestMapping("api/ttCoupon") | |||||
| @Api(description = "") | @Api(description = "") | ||||
| public class TtCouponController extends BaseController { | public class TtCouponController extends BaseController { | ||||
| @@ -52,7 +52,7 @@ public class TtCouponController extends BaseController { | |||||
| @GetMapping("/collectCoupon") | @GetMapping("/collectCoupon") | ||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | ||||
| public ResultData collectCoupon(@RequestParam Long id) { | public ResultData collectCoupon(@RequestParam Long id) { | ||||
| logger.debug("[" + getIpAddr() + "] TtCouponController::findById"); | |||||
| logger.debug("[" + getIpAddr() + "] TtCouponController::collectCoupon"); | |||||
| if (id == null) { | if (id == null) { | ||||
| return new ResultData(ResultData.ERROR, "缺少id"); | return new ResultData(ResultData.ERROR, "缺少id"); | ||||
| } | } | ||||
| @@ -0,0 +1,99 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.dto.WxMerchantDto; | |||||
| import com.iformall.domain.po.WxMerchant; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import com.iformall.domain.vo.WxMerchantVo; | |||||
| import com.iformall.enums.EnumMerchantPublic; | |||||
| import com.iformall.enums.EnumMerchantStatus; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.WxMerchantService; | |||||
| import com.iformall.utils.HashUtil; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.HashMap; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("/api/merchant") | |||||
| public class WxMerchantController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxMerchantService wxMerchantService; | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData list(@ModelAttribute WxMerchantDto wxMerchantDto, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::list"); | |||||
| if (null == wxMerchantDto) wxMerchantDto = new WxMerchantDto(); | |||||
| wxMerchantDto.updateTenantInfo(getTenantInfo()); | |||||
| wxMerchantDto.setMerchantStatus(EnumMerchantStatus.VALID.getCode()); | |||||
| wxMerchantDto.setIsPublic(EnumMerchantPublic.PUBLIC.getCode()); | |||||
| return new ResultData(wxMerchantService.listAsPageCVo(wxMerchantDto, pageNum, pageSize)); | |||||
| } | |||||
| @ApiOperation("根据code查询接口") | |||||
| @GetMapping("/findByCode") | |||||
| @ApiImplicitParam(name = "merchantCode", value = "merchantCode", dataType = "String", paramType = "query", required = true) | |||||
| public ResultData findByCode(String merchantCode) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::findByCode"); | |||||
| if(merchantCode == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| String codeMD5 = HashUtil.DecodeByMD5(merchantCode); | |||||
| if(StringUtils.isBlank(codeMD5)) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| HashMap<String, String> params = new HashMap<String, String>(); | |||||
| TenantEntity tenantEntity = getTenantInfo(); | |||||
| params.put("tenantId", tenantEntity.getTenantId()); | |||||
| if (StringUtils.isNotBlank(tenantEntity.getParentTenantId())) { | |||||
| params.put("parentTenantId", tenantEntity.getParentTenantId()); | |||||
| } | |||||
| params.put("merchantCode", codeMD5); | |||||
| WxMerchantVo wxMerchant = wxMerchantService.getMerchantInfo(params); | |||||
| return new ResultData(wxMerchant); | |||||
| } | |||||
| @ApiOperation("关注") | |||||
| @GetMapping("/collectCoupon") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData collectCoupon(@RequestParam Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::collectCoupon"); | |||||
| if (id == null) { | |||||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||||
| } | |||||
| WxMerchant byId = wxMerchantService.getById(id); | |||||
| if(byId == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"找不到数据"); | |||||
| } | |||||
| Long memberId; | |||||
| try { | |||||
| memberId = getMemberId(); | |||||
| } catch (MallinkException e) { | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } | |||||
| wxMerchantService.collectCoupon(getTenantInfo(),memberId,byId.getId()); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | |||||