plf hace 4 años
padre
commit
fadf40f81f

+ 2 - 2
src/main/java/com/caimei/config/SwaggerConfig.java

@@ -39,9 +39,9 @@ public class SwaggerConfig {
     private ApiInfo apiInfo() {
         return new ApiInfoBuilder().
                 // 标题
-                        title("weisha")
+                        title("维沙小程序spi")
                 // 描述
-                .description("weisha")
+                .description("维沙小程序spi")
                 // 服务地址
                 .termsOfServiceUrl("https://www.caimei365.com")
                 // 版本号

+ 10 - 2
src/main/java/com/caimei/controller/LoginApi.java

@@ -4,9 +4,13 @@ import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.BuyerUserDto;
 import com.caimei.model.vo.BuyerUserVo;
 import com.caimei.service.LoginService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -16,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @author : plf
  * @date : 2021/3/22
  */
+@Api(tags = "登录")
 @RestController
 @RequestMapping("/buyer")
 public class LoginApi {
@@ -32,8 +37,10 @@ public class LoginApi {
      *
      * @param code 小程序登录唯一凭证
      */
+    @ApiOperation("授权登录")
     @PostMapping("/authorization")
-    public ResponseJson<BuyerUserVo> authorizationLogin(String code) {
+    @ApiImplicitParam(name = "code", value = "登录凭证", required = true)
+    public ResponseJson<BuyerUserVo> authorizationLogin(@RequestBody String code) {
         if (StringUtils.isEmpty(code)) {
             return ResponseJson.error("参数异常", null);
         }
@@ -43,8 +50,9 @@ public class LoginApi {
     /**
      * 邀请码登录
      */
+    @ApiOperation("邀请码登录")
     @PostMapping("/invitation/code")
-    public ResponseJson<BuyerUserVo> invitationCode(BuyerUserDto buyerUserDto) {
+    public ResponseJson<BuyerUserVo> invitationCode(@RequestBody BuyerUserDto buyerUserDto) {
         return loginService.invitationCode(buyerUserDto);
     }
 }

+ 36 - 0
src/main/java/com/caimei/mapper/LoginMapper.java

@@ -1,7 +1,11 @@
 package com.caimei.mapper;
 
+import com.caimei.model.dto.BuyerUserDto;
+import com.caimei.model.po.CmMallOrganizePo;
+import com.caimei.model.po.CmOrganizeBuyerPo;
 import com.caimei.model.vo.BuyerUserVo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * Description
@@ -13,8 +17,40 @@ import org.apache.ibatis.annotations.Mapper;
 public interface LoginMapper {
     /**
      * 查询采购员
+     *
      * @param openid
      * @return
      */
     BuyerUserVo findBuyer(String openid);
+
+    /**
+     * 邀请码查询采购员
+     *
+     * @param invitationCode 邀请码
+     * @return
+     */
+    CmOrganizeBuyerPo findByInvitationCode(String invitationCode);
+
+    /**
+     * 查询组织信息
+     *
+     * @param organizeId
+     * @return
+     */
+    CmMallOrganizePo findOrganize(Integer organizeId);
+
+    /**
+     * 修改采购员
+     *
+     * @param buyerUserDto
+     */
+    void updateBuyer(BuyerUserDto buyerUserDto);
+
+    /**
+     * 查询订单数量
+     *
+     * @param status
+     * @return
+     */
+    Integer findOrderCount(@Param("organizeId") Integer organizeId,@Param("status") int status);
 }

+ 11 - 1
src/main/java/com/caimei/model/dto/BuyerUserDto.java

@@ -1,21 +1,31 @@
 package com.caimei.model.dto;
 
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
 /**
  * Description
  *
  * @author : plf
  * @date : 2021/3/22
  */
+@Data
 public class BuyerUserDto {
     /**
      * 邀请码
      */
+    @ApiModelProperty("邀请码")
     private String invitationCode;
 
     /**
      * 小程序openid
      */
+    @ApiModelProperty("小程序openid")
     private String openid;
 
-
+    /**
+     * 微信昵称
+     */
+    @ApiModelProperty("微信昵称")
+    private String nickName;
 }

+ 30 - 0
src/main/java/com/caimei/model/vo/BuyerUserVo.java

@@ -24,4 +24,34 @@ public class BuyerUserVo {
      * 小程序openid
      */
     private String openid;
+
+    /**
+     * 组织名称
+     */
+    private String organizeName;
+
+    /**
+     * 待确认数量
+     */
+    private Integer confirmedCount;
+
+    /**
+     * 待付款数量
+     */
+    private Integer paymentCount;
+
+    /**
+     * 待发货数量
+     */
+    private Integer waitShipmentsCount;
+
+    /**
+     * 已发货数量
+     */
+    private Integer shipmentsCount;
+
+    /**
+     * 退货款数量
+     */
+    private Integer salesReturnCount;
 }

+ 51 - 1
src/main/java/com/caimei/service/impl/LoginServiceImpl.java

@@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.caimei.mapper.LoginMapper;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.BuyerUserDto;
+import com.caimei.model.po.CmMallOrganizePo;
+import com.caimei.model.po.CmOrganizeBuyerPo;
 import com.caimei.model.vo.BuyerUserVo;
 import com.caimei.service.LoginService;
 import com.caimei.util.HttpRequest;
@@ -14,6 +16,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -71,11 +74,58 @@ public class LoginServiceImpl implements LoginService {
             buyerUser.setOpenid(openid);
             return ResponseJson.error("未绑定微信", buyerUser);
         }
+        getOrderCount(buyerUser);
         return ResponseJson.success(buyerUser);
     }
 
     @Override
     public ResponseJson<BuyerUserVo> invitationCode(BuyerUserDto buyerUserDto) {
-        return null;
+        CmOrganizeBuyerPo organizeBuyer = loginMapper.findByInvitationCode(buyerUserDto.getInvitationCode());
+        if (organizeBuyer == null) {
+            return ResponseJson.error("邀请码错误,请联系采美客服获取最新邀请码", null);
+        }
+        if ("2".equals(organizeBuyer.getStatus())) {
+            return ResponseJson.error("邀请码已被使用,请联系采美客服获取最新邀请码", null);
+        }
+        if (organizeBuyer.getInvitationCodeTime().compareTo(new Date()) < 0) {
+            return ResponseJson.error("邀请码已失效,请联系采美客服获取最新邀请码", null);
+        }
+        CmMallOrganizePo organize = loginMapper.findOrganize(organizeBuyer.getOrganizeId());
+        if (organize == null) {
+            return ResponseJson.error("您所属公司已下线,暂不能登录。请联系采美客服了解详情", null);
+        }
+        loginMapper.updateBuyer(buyerUserDto);
+        BuyerUserVo buyerUser = new BuyerUserVo();
+        getOrderCount(buyerUser);
+        buyerUser.setOrganizeId(organize.getId());
+        buyerUser.setOrganizeName(organize.getOrganizeName());
+        buyerUser.setOpenid(buyerUser.getOpenid());
+        return ResponseJson.success(buyerUser);
+    }
+
+    /**
+     * 统计订单数量
+     */
+    private void getOrderCount(BuyerUserVo buyerUser) {
+        //待确认数量
+        Integer organizeId = buyerUser.getOrganizeId();
+        Integer confirmedCount = loginMapper.findOrderCount(organizeId, 0);
+        buyerUser.setConfirmedCount(confirmedCount);
+        //待付款数量
+        Integer paymentCount = loginMapper.findOrderCount(organizeId, 1);
+        paymentCount = paymentCount == null ? 0 : paymentCount;
+        buyerUser.setPaymentCount(paymentCount);
+        //待发货数量
+        Integer waitShipmentsCount = loginMapper.findOrderCount(organizeId, 2);
+        waitShipmentsCount = waitShipmentsCount == null ? 0 : waitShipmentsCount;
+        buyerUser.setWaitShipmentsCount(waitShipmentsCount);
+        //已发货数量
+        Integer shipmentsCount = loginMapper.findOrderCount(organizeId, 3);
+        shipmentsCount = shipmentsCount == null ? 0 : shipmentsCount;
+        buyerUser.setShipmentsCount(shipmentsCount);
+        //退货款数量
+        Integer salesReturnCount = loginMapper.findOrderCount(organizeId, 4);
+        salesReturnCount = salesReturnCount == null ? 0 : salesReturnCount;
+        buyerUser.setSalesReturnCount(salesReturnCount);
     }
 }

+ 78 - 2
src/main/resources/mapper/LoginMapper.xml

@@ -4,14 +4,90 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.LoginMapper">
     <select id="findBuyer" resultType="com.caimei.model.vo.BuyerUserVo">
+        SELECT
+          cob.organizeId,
+          cob.name,
+          cob.openid,
+          cmo.organizeName
+        FROM
+          cm_organize_buyer cob
+          LEFT JOIN cm_mall_organize cmo ON cmo.id = cob.organizeId
+        WHERE
+          cob.delFlag = 0
+          AND cob.openid = #{openid}
+    </select>
+
+    <select id="findByInvitationCode" resultType="com.caimei.model.po.CmOrganizeBuyerPo">
         SELECT
           organizeId,
           name,
-          openid
+          openid,
+          invitationCodeTime,
+          status
         FROM
           cm_organize_buyer
         WHERE
           delFlag = 0
-          AND openid = #{openid}
+          AND invitationCode = #{invitationCode}
+    </select>
+
+    <select id="findOrganize" resultType="com.caimei.model.po.CmMallOrganizePo">
+        SELECT
+          id,
+          organizeName,
+          organizeLinkName,
+          mobile,
+          status,
+          contactNumber,
+          systemName,
+          systemImage,
+          introduction,
+          afterSale,
+          shoppingNotes
+        FROM
+          cm_mall_organize
+        WHERE
+          id =
+          AND delFlag = 0
+          AND status = 1
+    </select>
+
+    <update id="updateBuyer">
+        UPDATE
+          cm_organize_buyer
+        SET
+          STATUS = 2,
+          nickName = #{nickName},
+          openid = #{openid},
+          bindTime = NOW(),
+          updateTime = NOW()
+        WHERE
+          invitationCode = #{invitationCode}
+          AND delFlag = 0
+    </update>
+
+    <select id="findOrderCount" resultType="integer">
+        SELECT
+        COUNT(*)
+        FROM
+        cm_order
+        WHERE
+        organizeID = #{organizeId}
+        AND delFlag = '0'
+        <if test="orderState == 0">
+            AND status = '0'
+        </if>
+        <if test="orderState == 1">
+            AND status IN(11,12,13,21,22,23)
+        </if>
+        <if test="orderState == 2">
+            AND status IN(11,12,21,22,31,32)
+        </if>
+        <if test="orderState == 3">
+            AND status IN(12,13,22,23,32,33)
+        </if>
+        <if test="orderState == 4">
+            AND refundType IN(1,2)
+        </if>
     </select>
 </mapper>