某毕业设计里面的特殊需求记录,给卖家评分后,给卖家加分,给邀请自己的人加一半的分,给自己加分

    @RequestMapping(value = "/updateUserScore", method = RequestMethod.POST)
    @ResponseBody
    public DataResponse updateUserScore(@RequestBody Product item, HttpServletRequest request ) {
        User user=userService.getOne(item.getUser_id());

        //1.给卖家加分+Long.valueOf(item.getScore())
        Long score=Long.valueOf(item.getScore());
        item.setScore(Long.toString(score));
        long addScore=Long.valueOf(user.getScore())+score;
        user.setScore(Long.toString(addScore));
        userService.update(user);

        //2.给自己加分
        Long user_id=(Long)request.getSession().getAttribute("user_id");
        User currentUser=userService.getOne(user_id);
        User fromInviteUser=userService.findUserByInviteCode(currentUser.getFrom_invite_code());

        UserProduct userProduct= new UserProduct();
        userProduct.setUser_id(user_id);
        userProduct.setSale_user_id(Long.valueOf(item.getUser_id()));
        userProduct.setProduct_id(item.getId());

        List<UserProduct> userProducts = userProductService.getAll(userProduct);
        userProduct=userProducts.get(0);
        userProduct.setComment_status("1");
        userProductService.update(userProduct);

        if(currentUser!=null){
            long scoreAdd=Long.valueOf(currentUser.getScore())+score;
            currentUser.setScore(Long.toString(scoreAdd));
            userService.update(currentUser);
        }

        if(fromInviteUser!=null){
            double from_score=Long.valueOf(fromInviteUser.getScore())+Long.valueOf(item.getScore())*0.5;
            fromInviteUser.setScore(Double.toString(from_score));
            userService.update(fromInviteUser);
        }
        request.getSession().setAttribute("currentUser",currentUser);
        DataResponse dataResponse = new DataResponse("/");
        dataResponse.setCode("1");
        dataResponse.setInfo("操作成功");
        return dataResponse;
    }

  

posted @ 2023-04-21 16:09  热心市民~菜先生  阅读(12)  评论(0编辑  收藏  举报