基于javaweb+mysql的springboot前台后台玩具商城系统(java+ssm+springboot+html+maven+mysql+redis)

基于javaweb+mysql的springboot前台后台玩具商城系统(java+ssm+springboot+html+maven+mysql+redis)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SpringBoot前台后台玩具商城系统(java+ssm+springboot+html+maven+mysql+redis)

一、项目简述本系统主要实现的功能有: 网上商城系统,前台+后台管理,用户注册,登录,商品展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,用户管理,信息修改等等。

二、项目运行 环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

Springboot+ SpringMVC + MyBatis + Html+ JavaScript + JQuery + Ajax + maven等等

}
package com.wsy.controller.admin;

/**
 * 普通用户管理
 */
@Controller
@RequestMapping("childType")
public class ChildTypeController {

    @Autowired
    private ChildTypeService childTypeService  ;

    /**
     * 根据1级分类查询2级分类
     * @param type
     * @return
     */
    @PostMapping("childList.htm")
    @ResponseBody
    public Result childList(Integer type){
        EntityWrapper entityWrapper = new EntityWrapper();
        List<ChildTypeEntity> list =  childTypeService.selectList(entityWrapper);
        return Result.success(list);
    }

    /**
     * 根据1级分类查询2级分类
     * @param type
            EntityWrapper wrapper = new EntityWrapper();
            wrapper.like("label",s);
            List<ShopEntity> shops = shopService.selectList(wrapper);
            if(shops!=null){
                for (ShopEntity shop : shops) {
                    ids.add(shop.getId());
                }
            }
        }
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.in("id",ids).orderBy("rand()");
        List<ShopEntity> shops = shopService.selectList(wrapper);
        if(shops!=null){
            if(shops.size()>3){
                shops = shops.subList(0,3);
            }
        }
        return Result.success(shops);
    }

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @GetMapping("info.html")
    public String info(String id, Model model)throws Exception{
        ArticleEntity articleEntity = articleService.selectById(id);
        model.addAttribute("article",articleEntity);
        model.addAttribute("id",id);
        String[]  lebel = articleEntity.getLabel().split(",");
        model.addAttribute("lebels",lebel);
        CustomerEntity customerEntity = customerService.selectById(articleEntity.getCustomerId());
        model.addAttribute("customerEntity",customerEntity);
        if(!StringUtils.isEmpty(articleEntity.getShopIds())){
            String articles[] = articleEntity.getShopIds().split(",");
            List<String> str = new ArrayList<>();
            for (String article : articles) {
                str.add(article);
            }
            List<ShopEntity> shopEntities = shopService.selectBatchIds(str);
            model.addAttribute("shopEntities",shopEntities);
        }
        return "article/info";
    }

    /**
    /**
     * 我的Data
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("infoData.do")
    @ResponseBody
    public Result infoData(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        return Result.success(customerEntity);
    }

    /**
     * 我的界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("info.do")
    public String info(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        model.addAttribute("customer",customerEntity);
        return "mobile/my";
    }

    /**
     * 我的界面 -- 修改
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("myUpdate.do")
    public String my_update(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        model.addAttribute("entity",customerEntity);
        return "mobile/my_update";
    }

    /**
     * 我的界面 -- 修改
     * @return
     * @throws Exception
     */
    @RequestMapping("myUpdateData.do")
            InputStream inputStream = new FileInputStream(file1.getPath());
            byte[] b = new byte[inputStream.available()];
            inputStream.read(b);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return Result.error("上传文件失败");
        }
        return Result.success("/file/pic?pictureName="+fileName,"文件上传成功");
    }

    /**
     * 获取本地图片
     * @param pictureName //文件名
     * @return
     */
    @RequestMapping("/pic")
    public void ShowImg(String pictureName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        //这里是存放图片的文件夹地址
        FileInputStream fileIs=null;
        OutputStream outStream = null;
        try {
            fileIs = new FileInputStream(FILE_PATH+"/"+pictureName);
            //得到文件大小
            int i=fileIs.available();
            //准备一个字节数组存放二进制图片
            byte data[]=new byte[i];
            //读字节数组的数据
            fileIs.read(data);
            //设置返回的文件类型
            response.setContentType("application/octet-stream;charset=UTF-8");
            //得到向客户端输出二进制数据的对象
            outStream=response.getOutputStream();
            //输出数据
            outStream.write(data);
            outStream.flush();
        } catch (Exception e) {
            return;
        }finally {
            if(outStream!=null){
                //关闭输出流
                outStream.close();
                //关闭输入流
                fileIs.close();
            }
        }
    }
    @Autowired
    private ArticleShopService articleShopService;

    @Autowired
    private ShopService shopService;

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @GetMapping("list.htm")
    public String list(Model model)throws Exception{
        return "article/list";
    }

    /**
     * 分页
     * @return
     * @throws Exception
     */
    @GetMapping("page.htm")
    @ResponseBody
    public PageVo page(String title, String  summary,int page , int limit)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        if(!StringUtils.isEmpty(title)){
            entityWrapper.like(ArticleTable.TITLE,title);
        }
        if(!StringUtils.isEmpty(summary)){
            entityWrapper.like(ArticleTable.SUMMARY,summary);
        }
        entityWrapper.orderBy("top",false).orderBy("time",false);
        Page<ArticleEntity> paged = new Page();
        paged.setSize(limit);
        paged.setCurrent(page);
        Page<ArticleEntity> userTablePage = articleService.selectPage(paged, entityWrapper);

        List<ArticleEntity> list = userTablePage.getRecords();
        if(list!=null && !list.isEmpty()){
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("del.htm")
    @ResponseBody
    @ImLog(type = "用户",mark = "删除用户 {id}")
    public Result del(Model model, String id )throws Exception{
        userService.deleteById(id);
        return Result.success("保存成功");
    }

}
package com.wsy.controller.mobile;

@Controller
@RequestMapping("customerAddress")
public class CustomerAddressController {

    @Autowired
    private CustomerAddressService service;

    /**
                ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType());
                if(childTypeEntity!=null){
                    articleEntity.setChildName(childTypeEntity.getName());
                }
            }
        }
        model.addAttribute("articleEntities",articleEntities);

        return "mobile/articleHome";
    }

}
package com.wsy.controller.admin;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserDao userDao;

    @Autowired
    private RoleService roleService;

    @Autowired
    private UserService userService;

    /**
     * 用户界面
        response.addCookie(cookie);
        return Result.success("退出成功");
    }

    /**
     * 登陆
     * @return
     * @throws Exception
     */
    @RequestMapping("loginData.html")
    @ResponseBody
    public Result loginData(String phone,String password, HttpServletResponse response)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("phone",phone);
        CustomerEntity customerEntity = customerService.selectOne(entityWrapper);
        if(customerEntity==null){
            return Result.error("用户不存在");
        }
        if(!customerEntity.getPassword().equals(password)){
            return Result.error("密码错误");
        }
        Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        response.addCookie(cookie);
        return Result.success(customerEntity.getId(),"登陆成功");
    }

    /**
     * 登陆界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("reg.html")
    public String reg(Model model) throws Exception{
        return "mobile/reg";
    }

    /**
     * 登陆
    public void unUseIntegral() {
        System.out.println("false");
        jedis.set("WSY-INTEGRALFLAG", "false");
    }

    @RequestMapping("/pay")
    @ResponseBody
    public String payController(@RequestParam("ids") String ids[], @RequestParam("amount") String amount) throws Exception {
        String name = jedis.get("WSY-SHOPID");
        jedis.del("WSY-IDS");
        for (String id : ids) {
            jedis.lpush("WSY-IDS", id);
        }
        double s = Double.parseDouble(amount);
        Integer pay = (int) s;
        Integer flag = (int) s;
        CustomerEntity customer = Contants.getCustomer();
        CustomerEntity customerEntity = customerService.selectById(customer.getId());
        Integer integral = customerEntity.getIntegral();
        String INTEGRALFLA = jedis.get("WSY-INTEGRALFLAG");
        if (integral != null && integral > 0 && "true".equals(INTEGRALFLA)) {
            pay = pay - integral;
            if (pay < 0) {
                pay = 0;
                integral = integral - flag;
            } else {
                integral = 0;
            }
            jedis.set("WSY-FLAG", "true");
            jedis.set("WSY-INTEGRAL", String.valueOf(integral));
            jedis.set("WSY-USERID", customerEntity.getId());
        } else {
            jedis.set("WSY-FLAG", "false");
        }
        name = name.substring(0, name.length() - 1);
        String id = IdUtil.simpleUUID();
//        String pays = alipayService.webPagePay(id, pay, name);
        return "下单成功";
    }

    @RequestMapping("/payresult")
    private String payResult() {
        List<String> ids = jedis.lrange("WSY-IDS", 0, -1);
        jedis.del("WSY-IDS");
        for (String id : ids) {
            shoppingGatService.deleteById(id);
        }
    /**
     * 购物车界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    public String list(Model model)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
        List<ShoppingGatEntity> gats = shoppingGatService.selectList(entityWrapper);
        if(gats!=null ){
            for (ShoppingGatEntity gat : gats) {
                ShopEntity shopEntity = shopService.selectById(gat.getShopId());
                gat.setShopEntity(shopEntity);
            }
        }
        model.addAttribute("gats",gats);
        CustomerEntity customerEntity = customerService.selectById(userEntity.getId());
        model.addAttribute("integral",customerEntity.getIntegral());
       List<CustomerAddressEntity> customerAddressEntities =   customerAddressService.selectList(entityWrapper);
        model.addAttribute("customerAddressEntities",customerAddressEntities);
        return "mobile/gat";
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("delete.do")
    @ResponseBody
    public Result delete(String id)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        if(StringUtils.isEmpty(id)){
            EntityWrapper entityWrapper = new EntityWrapper();
            entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
            shoppingGatService.delete(entityWrapper);
        }else{
            shoppingGatService.deleteById(id);
        }
        return Result.success("成功");
    }
                royaltyEntity.setMark("订单下单抽取提成");
                royaltyEntity.setTime(new Date());
                royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
                royaltyService.insert(royaltyEntity);
            }
        }
        jedis.set("WSY-SHOPID", name);
        return Result.success("订单结算成功");
    }

}
package com.wsy.controller.common;

/**
 * Created by Wsy
 */
@Controller
@RequestMapping("fileNoCos")
public class ImgController {
//    //secretId
//    public static final String secretId = "";
//            // 指定文件将要存放的存储桶
//            String bucketName = BUCKETNAME;
//            // 指定文件上传到 COS 上的路径,即对象键。例如对象键为folder/picture.jpg,则表示将文件 picture.jpg 上传到 folder 路径下
//            String key = KEY + fileName;
//            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file1);
//            PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Result.error("上传文件失败");
//        }
//        return Result.success(BASEURL + fileName, "文件上传成功");
//    }

	 public static final String FILE_PATH = "D:\\immersive_shopping\\";
	    static {
	        File file = new File(FILE_PATH);
	        file.mkdirs();
	    }

	    /**
	     * 文件上传返回code为200
	     * @param file
	     * @return
	     * @throws Exception
	     */
	    @PostMapping("/upload")
	    @ResponseBody
	    public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
	        //用来检测程序运行时间
	        String fileName =  IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
	        try {
	            File file1 = new File(FILE_PATH+"\\"+fileName);
	            file1.createNewFile();
	            //获取输出流
	            OutputStream os=new FileOutputStream(file1.getPath());
	            //获取输入流 CommonsMultipartFile 中可以直接得到文件的流
	            InputStream is=file.getInputStream();
	            int temp;
	            //一个一个字节的读取并写入
	            while((temp=is.read())!=(-1))
            }
            List<ShopEntity> shopEntities = shopService.selectBatchIds(str);
            model.addAttribute("shopEntities",shopEntities);
        }
        return "article/info";
    }

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @GetMapping("edit.htm")
    public String edit(String id, Model model )throws Exception{
        ArticleEntity articleEntity = articleService.selectById(id);
        model.addAttribute("articleEntity",articleEntity);
        List<ShopEntity> shopEntities =  shopService.selectList(new EntityWrapper<>());
        model.addAttribute("shopEntities",shopEntities);
        return "article/edit";
    }

    /**
     * 保存数据
     * @return
     * @throws Exception
     */
    @RequestMapping("editData.htm")
    @ResponseBody
    public Result editData(ArticleEntity articleEntity)throws Exception{
        articleService.updateById(articleEntity);
        return Result.success("保存成功");
    }

}
package com.wsy.controller.admin;


@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;

    /**
     * 登录
     * @return
     */
    @GetMapping("login.html")
    public String login(){
        return "login";
    }

    /**
     * 登录
     * @return
     */
    @GetMapping("logout.htm")
    public String logout(HttpServletResponse response){
        Cookie cookie = new Cookie("login_key_auth","");
        cookie.setPath("/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
        return "redirect:/login.html";
    }

    /**
     * 登录
     * @param loginName
     * @param password
     * @return
     * @throws Exception
     */
    @PostMapping("loginData.html")
    @ResponseBody
    @ImLog(type = "登录",mark = "用户 {loginName} 登录")
    public Result loginData(String loginName, String password, HttpServletResponse response)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(UserTable.LOGIN_NAME,loginName);
        UserEntity userEntity = userService.selectOne(entityWrapper);
        if(userEntity==null){
            return Result.error("用户名或密码错误");
        }

@Controller
@RequestMapping("royalty")
public class RoyaltyController {

    @Autowired
    private RoyaltyService royaltyService;

    @Autowired
    private CustomerService customerService;
    /**
     * 列表界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    public String list(Model model)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("customer",Contants.getCustomer().getId());
        entityWrapper.orderBy("time",false);
        List<RoyaltyEntity> list = royaltyService.selectList(entityWrapper);
        model.addAttribute("list",list);
        BigDecimal all = new BigDecimal(0);

/**
 * 普通用户管理
 */
@Controller
@RequestMapping("childType")
public class ChildTypeController {

    @Autowired
    private ChildTypeService childTypeService  ;

    /**
     * 根据1级分类查询2级分类
     * @param type
     * @return
     */
    @PostMapping("childList.htm")
    @ResponseBody
    public Result childList(Integer type){
        EntityWrapper entityWrapper = new EntityWrapper();
        List<ChildTypeEntity> list =  childTypeService.selectList(entityWrapper);
        return Result.success(list);
    }

    /**
     * 根据1级分类查询2级分类
     * @param type
     * @return
     */
    @PostMapping("childList.do")
    @ResponseBody
    public Result childListdo(Integer type){
        EntityWrapper entityWrapper = new EntityWrapper();
        List<ChildTypeEntity> list =  childTypeService.selectList(entityWrapper);
        return Result.success(list);
    }

    /**
     * 列表
     * @param model
     * @return
     * @throws Exception
     */
    @GetMapping("indexPage.htm")
        orderService.insert(orderEntity);
        String name = StrUtil.EMPTY;
        for (int i = 0; i < ids.length; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            OrderShopEntity orderShopEntity = new OrderShopEntity();
            orderShopEntity.setId(IdWorkerUtil.getId());
            orderShopEntity.setPrice(new BigDecimal(prices[i]));
            orderShopEntity.setNum(nums[i]);
            orderShopEntity.setOrderId(orderEntity.getId());
            orderShopEntity.setName(shopEntity.getName());
            name = name.concat(shopEntity.getName() + "+");
            orderShopEntity.setCover(shopEntity.getCover());
            orderShopEntity.setShopId(shopEntity.getId());
            orderShopEntity.setCustomerId(userEntity.getId());
            orderShopService.insert(orderShopEntity);
            shopEntity.setStock(shopEntity.getStock() - nums[i]);
            shopService.updateById(shopEntity);
            if (!StringUtils.isEmpty(shoppingGatEntity.getCid())) {
                RoyaltyEntity royaltyEntity = new RoyaltyEntity();
                royaltyEntity.setId(IdWorkerUtil.getId());
                royaltyEntity.setCustomer(shoppingGatEntity.getCid());
                royaltyEntity.setMark("订单下单抽取提成");
                royaltyEntity.setTime(new Date());
                royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
                royaltyService.insert(royaltyEntity);
            }
        }
        jedis.set("WSY-SHOPID", name);
        return Result.success("订单结算成功");
    }

}
package com.wsy.controller.common;

    @Autowired
    private ArticleService articleService;

    @RequestMapping("info.html")
    public String info(String id,String customerId, Model model)throws Exception{
        ShopEntity shopEntity =  shopService.selectById(id);
        model.addAttribute("shop",shopEntity);
        model.addAttribute("id",id);
        List<OrderShopEntity> list = orderShopDao.list(id);
        model.addAttribute("list",list);
        model.addAttribute("customerId",customerId);
        return "mobile/shop_info";
    }

    /**
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("aList.html")
    @ResponseBody
    public Result shopList(String id)throws Exception{
        ShopEntity shopEntity =  shopService.selectById(id);
        if(StringUtils.isEmpty(shopEntity.getLabel())){
            return Result.success("无");
        }
        String[] lebel = shopEntity.getLabel().split(",");
        //查询
        List<String> ids = new ArrayList<>();
        for (String s : lebel) {
            EntityWrapper wrapper = new EntityWrapper();
            wrapper.like("label",s);
            List<ArticleEntity> shops = articleService.selectList(wrapper);
            if(shops!=null){
                for (ArticleEntity shop : shops) {
                    ids.add(shop.getId());
                }
            }
        }
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.in("id",ids).orderBy("rand()");
        List<ArticleEntity> shops = articleService.selectList(wrapper);
        if(shops!=null){
            if(shops.size()>3){
                shops = shops.subList(0,3);
            }
        }

        return Result.success(shops);
    }

@Controller
@RequestMapping("shoppingGat")
public class ShoppingGatController {

    @Autowired
    private ShoppingGatService shoppingGatService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private CustomerAddressService customerAddressService;
    @Autowired
    private CustomerService customerService;
    @Autowired
    private RoyaltyService royaltyService;

    /**
     * 购物车界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    public String list(Model model)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
        List<ShoppingGatEntity> gats = shoppingGatService.selectList(entityWrapper);
        if(gats!=null ){
            for (ShoppingGatEntity gat : gats) {
                ShopEntity shopEntity = shopService.selectById(gat.getShopId());
                gat.setShopEntity(shopEntity);
            }
        }
        model.addAttribute("gats",gats);
        CustomerEntity customerEntity = customerService.selectById(userEntity.getId());
        model.addAttribute("integral",customerEntity.getIntegral());
       List<CustomerAddressEntity> customerAddressEntities =   customerAddressService.selectList(entityWrapper);
        model.addAttribute("customerAddressEntities",customerAddressEntities);
        return "mobile/gat";
    }

    /**
     * @return
     * @throws Exception
     */
    @RequestMapping("infoData.do")
    @ResponseBody
    public Result infoData(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        return Result.success(customerEntity);
    }

    /**
     * 我的界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("info.do")
    public String info(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        model.addAttribute("customer",customerEntity);
        return "mobile/my";
    }

    /**
     * 我的界面 -- 修改
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("myUpdate.do")
    public String my_update(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        model.addAttribute("entity",customerEntity);
        return "mobile/my_update";
    }

    /**
     * 我的界面 -- 修改
     * @return
     * @throws Exception
     */
    @RequestMapping("myUpdateData.do")
    @ResponseBody
    public Result myUpdateData( CustomerEntity customerEntity)throws Exception{
        customerEntity.setId(Contants.getCustomer().getId());
        customerService.updateById(customerEntity);
        return Result.success("成功");

    /**
     * 退出登陆
     * @return
     * @throws Exception
     */
    @RequestMapping("logOut.do")
    @ResponseBody
    public Result logOut( HttpServletResponse response)throws Exception{
        Cookie cookie = new Cookie("login_key_auth_customer","-1");
        cookie.setPath("/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
        return Result.success("退出成功");
    }

    /**
     * 登陆
     * @return
     * @throws Exception
     */
    @RequestMapping("loginData.html")
    @ResponseBody
    public Result loginData(String phone,String password, HttpServletResponse response)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("phone",phone);
        CustomerEntity customerEntity = customerService.selectOne(entityWrapper);
        if(customerEntity==null){
            return Result.error("用户不存在");
        }
        if(!customerEntity.getPassword().equals(password)){
            return Result.error("密码错误");
        }
        Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        response.addCookie(cookie);
        return Result.success(customerEntity.getId(),"登陆成功");
    }

    /**
     * 登陆界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("reg.html")
    public String reg(Model model) throws Exception{
        return "mobile/reg";
    @ResponseBody
    public Result tiqu(String money)throws Exception{
        RoyaltyEntity royaltyEntity = new RoyaltyEntity();
        String id = Contants.getCustomer().getId();
        BigDecimal bigDecimal = new BigDecimal(money);
        royaltyEntity.setId(IdWorkerUtil.getId());
        royaltyEntity.setCustomer(id);
        royaltyEntity.setMark("用户提取佣金");
        royaltyEntity.setTime(new Date());
        royaltyEntity.setMoney(bigDecimal);
        royaltyService.insert(royaltyEntity);
        CustomerEntity customerEntity = customerService.selectById(id);
        money = money.replace("-","");
        Integer integer = Integer.valueOf(money);
        customerEntity.setIntegral(customerEntity.getIntegral()+integer/10);
        customerService.updateById(customerEntity);
        return Result.success("提取成功");
    }
}
package com.wsy.controller.mobile;

@Controller
@RequestMapping("mobileShop")
public class MobileShopController {
    @Autowired
    private ShopService shopService;
            for (RoleMenuEntity roleMenuEntity : entity) {
                menuids.add(roleMenuEntity.getMenuId());
            }
            for (MenuEntity menuEntity : menuEntities) {
                if(menuids.contains(menuEntity.getId())){
                    menuEntity.setAuth(true);
                }
            }
        }
        model.addAttribute("menuEntities",menuEntities);
        model.addAttribute("roleId",id);
        return "role/auth";
    }

    /**
     * 权限分配
     * @param ids
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("authData.htm")
    @ResponseBody
    @ImLog(type = "角色",mark = "角色分配权限 {id} {ids}")
    public Result data(String[] ids,String roleId,Model model)throws Exception{
        List<String> list = new ArrayList<>();
        for (String id : ids) {
            list.add(id);
        }
        List<MenuEntity> menuEntities = menuService.selectBatchIds(list);
        //删除原有权限
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(RoleMenuTable.ROLE_ID,roleId);
        roleMenuService.delete(entityWrapper);
        Set<String> set = new HashSet<>();
        //循环添加新的权限
        for (MenuEntity menuEntity : menuEntities) {
            set.add(menuEntity.getPId());
        }
        for (String s : set) {
            RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
            roleMenuEntity.setId(IdWorkerUtil.getId());
            roleMenuEntity.setMenuId(s);
            roleMenuEntity.setRoleId(roleId);
            roleMenuService.insert(roleMenuEntity);
        }
        for (String s : list) {
            RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
            roleMenuEntity.setId(IdWorkerUtil.getId());
            roleMenuEntity.setMenuId(s);
            roleMenuEntity.setRoleId(roleId);
            roleMenuService.insert(roleMenuEntity);
            orderShopEntity.setName(shopEntity.getName());
            name = name.concat(shopEntity.getName() + "+");
            orderShopEntity.setCover(shopEntity.getCover());
            orderShopEntity.setShopId(shopEntity.getId());
            orderShopEntity.setCustomerId(userEntity.getId());
            orderShopService.insert(orderShopEntity);
            shopEntity.setStock(shopEntity.getStock() - nums[i]);
            shopService.updateById(shopEntity);
            if (!StringUtils.isEmpty(shoppingGatEntity.getCid())) {
                RoyaltyEntity royaltyEntity = new RoyaltyEntity();
                royaltyEntity.setId(IdWorkerUtil.getId());
                royaltyEntity.setCustomer(shoppingGatEntity.getCid());
                royaltyEntity.setMark("订单下单抽取提成");
                royaltyEntity.setTime(new Date());
                royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
                royaltyService.insert(royaltyEntity);
            }
        }
        jedis.set("WSY-SHOPID", name);
        return Result.success("订单结算成功");
    }

}
package com.wsy.controller.common;

/**
 * Created by Wsy
 */
@Controller
@RequestMapping("fileNoCos")
//            String[] filename = originalFilename.split("\\.");
//            file = File.createTempFile(filename[0], filename[1]);
//            multipartFile.transferTo(file);
//            file.deleteOnExit();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return file;
//    }
//
//    /**
//     * 文件上传返回code为200
//     *
//     * @param file
//     * @return
//     * @throws Exception
//     */
//    @PostMapping("/upload")
//    @ResponseBody
//    public Result uplaod(@RequestParam("file") MultipartFile file) throws Exception {
//        //用来检测程序运行时间
//        String fileName = IdWorker.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
//        try {
//            File file1 = transferToFile(file);
//            // 1 初始化用户身份信息(secretId, secretKey)。
//            COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
//            // 2 设置 bucket 的地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
 clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
//            Region region = new Region(REGION);
//            ClientConfig clientConfig = new ClientConfig(region);
 这里建议设置使用 https 协议
//            clientConfig.setHttpProtocol(HttpProtocol.https);
//            // 3 生成 cos 客户端。
//            COSClient cosClient = new COSClient(cred, clientConfig);
//            // 指定要上传的文件
//            // 指定文件将要存放的存储桶
//            String bucketName = BUCKETNAME;
//            // 指定文件上传到 COS 上的路径,即对象键。例如对象键为folder/picture.jpg,则表示将文件 picture.jpg 上传到 folder 路径下
//            String key = KEY + fileName;
//            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file1);
//            PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Result.error("上传文件失败");
//        }
//        return Result.success(BASEURL + fileName, "文件上传成功");
//    }
        entityWrapper.eq(RoleMenuTable.ROLE_ID,id);
        List<RoleMenuEntity> entity = roleMenuService.selectList(entityWrapper);

        List<MenuEntity> menuEntities = menuService.selectList(null);
        if(entity!=null && !entity.isEmpty()){
            Set<String> menuids = new HashSet<>();
            for (RoleMenuEntity roleMenuEntity : entity) {
                menuids.add(roleMenuEntity.getMenuId());
            }
            for (MenuEntity menuEntity : menuEntities) {
                if(menuids.contains(menuEntity.getId())){
                    menuEntity.setAuth(true);
                }
            }
        }
        model.addAttribute("menuEntities",menuEntities);
        model.addAttribute("roleId",id);
        return "role/auth";
    }

    /**
     * 权限分配
     * @param ids
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("authData.htm")
    @ResponseBody
    @ImLog(type = "角色",mark = "角色分配权限 {id} {ids}")
    public Result data(String[] ids,String roleId,Model model)throws Exception{
        List<String> list = new ArrayList<>();
        for (String id : ids) {
            list.add(id);
        }
        List<MenuEntity> menuEntities = menuService.selectBatchIds(list);
        //删除原有权限
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(RoleMenuTable.ROLE_ID,roleId);
        roleMenuService.delete(entityWrapper);
        Set<String> set = new HashSet<>();
        //循环添加新的权限

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值