2021-08-12

8.12总结

店铺申请代码

在这里插入图片描述

ShopController

package com.helei.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.helei.pojo.Code;
import com.helei.pojo.Shop;
import com.helei.pojo.User;
import com.helei.service.CodeService;
import com.helei.service.ShopService;
import com.helei.service.UserService;
import com.helei.util.JWTUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/shop")
public class ShopController {

    @Resource(name = "shopService")
    private ShopService shopService;

    @Resource(name = "codeService")
    private CodeService codeService;

    @Resource(name = "userService")
    private UserService userService;

    @RequestMapping("/getShopByUserId")
    public @ResponseBody Map<String,Object> getShopByUserId(HttpServletRequest request){
        DecodedJWT verify = (DecodedJWT)request.getAttribute("verify");
        Map<String, Object> map = userService.checkJWT(verify);
        if ((Integer)map.get("status") == 2){
            return map;
        }
        User user = JWTUtils.parse(verify);

        Shop shop = shopService.getByUserId(user.getUserId());

        if (shop == null){
            map.put("status",0);
        } else {
            map.put("shop",shop);
        }

        return map;
    }

    @RequestMapping("/checkShopName")
    public @ResponseBody Map<String,Object> checkShopName(@RequestBody Map<String,Object> m){
        Map<String,Object> map = new HashMap<>();
        String shopName = (String)m.get("shopName");
        Shop shop = shopService.getByShopName(shopName);
        if (shop != null){
            map.put("status",1);//表示已有店铺
        } else {
            map.put("status",0);//表示没有店铺
        }

        return map;
    }

    @RequestMapping("/startShop")
    public @ResponseBody Map<String,Object> startShop(@RequestBody Map<String,Object> m){
        //验证邮箱是否合法
        User u = new User();
        u.setEmail((String)m.get("email"));
        User user = userService.getUserByUser(u);
        Shop shop0 = shopService.getByUserId(user.getUserId());

        //验证码是否正确
        Code code = new Code();
        code.setNum((Integer)m.get("num"));
        code.setCheckCode((String)m.get("checkCode"));
        code.setEmail((String)m.get("email"));
        Map<String, Object> map = codeService.checkCode(code);
        if ((Integer)map.get("status") != 1){
            return map;
        }
        //该邮箱是否已有店铺
        if (shop0 != null){
            map.put("status",5);
            return map;
        }
        //该店铺名称是否已存在
        String shopName = (String)m.get("shopName");
        Shop shop = shopService.getByShopName(shopName);
        if (shop != null){
            map.put("status",4);//表示已有店铺
            return map;
        }
        shopService.saveShop(shopName,user.getUserId());
        codeService.updateCodeStatus((Integer)map.get("checkId"));

        return map;

    }

}

Service

package com.helei.service.impl;

import com.helei.dao.ShopDao;
import com.helei.pojo.Shop;
import com.helei.service.ShopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("shopService")
public class ShopServiceImpl implements ShopService {

    @Resource(name = "shopDao")
    private ShopDao shopDao;

    /**
     * 通过用户id查找店铺
     * @param userId
     * @return
     */
    @Override
    public Shop getByUserId(Integer userId) {
        return shopDao.getByUserId(userId);
    }


    /**
     * 通过店铺名称查找店铺
     * @param shopName
     * @return
     */
    @Override
    public Shop getByShopName(String shopName) {
        return shopDao.getByShopName(shopName);
    }

    /**
     * 通过店铺名和用户id创建店铺
     * @param shopName
     */
    @Override
    public void saveShop(String shopName,Integer userId) {
        shopDao.saveShop(shopName,userId);
    }
}

dao

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.helei.dao.ShopDao">
<!--    通过userId查询店铺-->
    <select id="getByUserId" parameterType="Integer" resultType="Shop">
        select * from shop_information where userid=#{userId}
    </select>

<!--    通过店铺名称查找店铺-->
    <select id="getByShopName" resultType="Shop" parameterType="String">
        select * from shop_information where shopname=#{shopName}
    </select>

<!--    新建店铺-->
    <insert id="saveShop" >
        insert into shop_information (shopname,userid) values (#{shopName},#{userId})
    </insert>

</mapper>

店铺页面

在这里插入图片描述

在这里插入图片描述

商品分类

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值