package com.bjtdba.userCenter.controller;

import com.alibaba.fastjson.JSONObject;
import com.bjtdba.entity.order.User;
import com.bjtdba.entity.userCenter.UserAddress;
import com.bjtdba.entity.userCenter.UserBill;
import com.bjtdba.entity.userCenter.UserCertification;
import com.bjtdba.userCenter.dto.request.*;
import com.bjtdba.userCenter.dto.response.UserContributeModifyResponse;
import com.bjtdba.userCenter.dto.request.GetUserListRequest;
import com.bjtdba.userCenter.dto.request.ModifyPVRequest;
import com.bjtdba.userCenter.dto.request.UserScoreModifyRequest;
import com.bjtdba.userCenter.dto.response.ModifyPVResponse;
import com.bjtdba.userCenter.dto.response.UserScoreModifyResponse;
import com.bjtdba.userCenter.dto.response.common.ApiResponse;
import com.bjtdba.userCenter.dto.response.common.PageResult;
import com.bjtdba.userCenter.dto.response.UserDTO;
import com.bjtdba.userCenter.service.UserAddressService;
import com.bjtdba.userCenter.service.UserCertificationService;
import com.bjtdba.userCenter.service.UserService;
import com.bjtdba.userCenter.util.OcrUtil;
import com.bjtdba.userCenter.vo.UserAddressVo;
import com.bjtdba.userCenter.vo.UserInfoVo;
import com.bjtdba.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

@RestController
@RequestMapping("userCenter_service/user")
public class UserController {

    public static  OcrUtil ocrUtil;
    @Autowired
    public UserCertificationService userCertificationService;
    @Autowired
    public UserAddressService userAddressService;
    @Autowired
    public UserService userService;

    /**
     * 实名认证
     * @param Hmap
     * @param map
     * @return
     * @throws Exception
     */
    @GetMapping("/add_certification")
    public Object add_certification(@RequestHeader Map<String,String> Hmap, @RequestParam Map<String,String> map) throws Exception {
        if(!Hmap.containsKey("uid")){
            ResponseUtil.fail("uid 参数错误");
        }
        if(!map.containsKey("user_name")||!map.containsKey("mobile")||!map.containsKey("user_card")||!map.containsKey("card_positive")||
                !map.containsKey("card_reverse")){
            ResponseUtil.fail("参数错误");
        }
        UserCertification userCertification=new UserCertification();
        userCertification.setUserName(map.get("user_name"));
        userCertification.setMobile(map.get("mobile"));
        userCertification.setUserCard(map.get("user_card"));
        userCertification.setCardPositive(map.get("card_positive"));
        userCertification.setCardReverse(map.get("card_reverse"));
        userCertification.setUid(Integer.parseInt(Hmap.get("uid")));

        InputStream image=OcrUtil.getFileInputStreamFromUrlHttps(map.get("card_positive"));
//        File targetFile = new File("src/main/resources/20020.jpeg");
//        FileUtils.copyInputStreamToFile(stream, targetFile);
//        targetFile.
//        File image=stream.;//身份证正面图片
        //百度ai认证
        JSONObject res= ocrUtil.getIdCardInfo(image,1);
        if(!res.containsKey("error_code")&&(res.get("image_status").equals("normal")||res.get("idcard_number_type").equals("1"))){

            int nums=0;
            Long tiem=new Date().getTime()/1000;
            nums=Integer.parseInt(tiem+"");
            userCertification.setStatus(1);
            userCertification.setReason("");
            userCertification.setAuditTime(nums);
            userCertification.setCreateTime(tiem);
            userCertification.setUpdateTime(tiem);
            JSONObject  renzheng=res.getJSONObject("words_result");
            String shenfenzheng=renzheng.getJSONObject("公民身份号码").getString("words");
//           System.out.println("========="+shenfenzheng);
            //百度认证出问题的bug调整 2023-2-17
            if(shenfenzheng.equals(userCertification.getUserCard())){
                JSONObject resObj=userCertificationService.add_cer(userCertification,userCertification.getUid());
                if(resObj!=null) {
                    return ResponseUtil.ok("认证成功");

                }else{
                    return ResponseUtil.fail("认证失败");
                }
            }else{
                return  ResponseUtil.fail("认证失败，身份证号不匹配");
            }

//            JSONObject resObj=userCertificationService.add_cer(userCertification,userCertification.getUid());
//            if(resObj!=null) {
//                if(shenfenzheng.equals(userCertification.getUserCard())){
//                    return ResponseUtil.ok("认证成功");
//                }else{
//                    return  ResponseUtil.fail("认证失败，身份证号不匹配");
//                }
//
//            }else{
//                return ResponseUtil.fail("认证失败");
//            }

        }else{
            return  ResponseUtil.fail("认证失败，请重新认证");
        }
    }

    /**
     * 获取实名认证状态
     * @param Hmap
     * @return
     * @throws Exception
     */
    @GetMapping("/get_certification")
    public Object get_certification(@RequestHeader Map<String,String> Hmap) throws Exception {
        if (!Hmap.containsKey("uid")) {
            ResponseUtil.fail("uid 参数错误");
        }
        UserCertification ucr=userCertificationService.queryByUId(Integer.parseInt(Hmap.get("uid")));
        if(ucr!=null&&ucr.getId()>0){
            Map<String,Object> data=new HashMap<String,Object>();
            data.put("userName",ucr.getUserName());
            data.put("mobile",ucr.getMobile());
            data.put("userCard",ucr.getUserCard());
            return ResponseUtil.ok(data);
        }else{
            return ResponseUtil.fail("未认证");
        }
    }

    /**
     * 地址添加和修改
     * @param Hmap
     * @param map
     * @return
     */
    //地址
    @PostMapping("/address/new_create")
    public  Object addressCreate(@RequestHeader Map<String,String> Hmap,@RequestBody Map<String,String> map){
        if(!Hmap.containsKey("uid")){
            return ResponseUtil.fail("uid 参数错误");
        }
        //'address_id','real_name','phone','province','city','city_id','district','detail','post_code','is_default','code_list'
        //验证参数是否为空
        if(!map.containsKey("address_id")||!map.containsKey("real_name")
                ||!map.containsKey("phone")||!map.containsKey("province")
                ||!map.containsKey("city")||!map.containsKey("city_id")
                ||!map.containsKey("district")||!map.containsKey("detail")
                ||!map.containsKey("post_code")||!map.containsKey("is_default")
                ||!map.containsKey("code_list")
        ){
            return ResponseUtil.fail("参数错误");
        }
        //装载参数
        UserAddress userAddress=new UserAddress();
        userAddress.setAddressId(Integer.parseInt(map.get("address_id")));
        userAddress.setRealName(map.get("real_name"));
        userAddress.setCreateTime(new Date());
        userAddress.setDetail(map.get("detail"));
        userAddress.setDistrict(map.get("district"));
        userAddress.setCityId(Integer.parseInt(map.get("city_id")));
        userAddress.setPhone(map.get("phone"));
        userAddress.setProvince(map.get("province"));
        userAddress.setCity(map.get("city"));
        userAddress.setPostCode(Long.parseLong(map.get("post_code")) );
        userAddress.setIsDefault(Integer.parseInt(map.get("is_default")));
        userAddress.setCodeList(map.get("code_list"));
        userAddress.setUid(Long.parseLong(Hmap.get("uid")));
        if(userAddress.getIsDefault()==1){
            //把该用户的地址 默认值都改成0
            UserAddress uas=new UserAddress();
            uas.setUid(userAddress.getUid());
            uas.setIsDefault(0);
            userAddressService.update(uas);
        }else{
            UserAddress queryObj=new UserAddress();
            queryObj.setUid(userAddress.getUid());
            List<UserAddress> userAddressList=userAddressService.queryListByObj(queryObj);
            if(userAddressList!=null&&userAddressList.size()>0){
                userAddress.setIsDefault(1);
            }

        }

        //判断是否更新还是添加（address_id>0 更新）
        if(userAddress.getIsDefault()>0){
            //更新
            UserAddress queryIsObj=new UserAddress();
            queryIsObj.setUid(userAddress.getUid());
            queryIsObj.setAddressId(userAddress.getAddressId());
            List<UserAddress> is_UserAddressList=userAddressService.queryListByObj(queryIsObj);
            if(is_UserAddressList==null&&is_UserAddressList.size()==0){
                return ResponseUtil.fail("信息不存在");
            }else{
              UserAddress resObj= userAddressService.update(userAddress);
               if(resObj!=null&&resObj.getAddressId()>0){
                   JSONObject object=new JSONObject();
                   object.put("address_id",resObj.getAddressId());
                   return ResponseUtil.ok("编辑成功",object);
               }
            }
        }
        //添加
        userAddress.setLatitude("0");
        userAddress.setIsDel(0);
        userAddress.setLongitude("0");
        //插入信息
        UserAddress resObj= userAddressService.insert(userAddress);
        //装载返回参数
        UserAddressVo resVo=new UserAddressVo();
        resVo.setAddress_id(resObj.getAddressId());
        resVo.setCreate_time(resObj.getCreateTime());
        resVo.setCity_id(resObj.getCityId());
        resVo.setCode_list(resObj.getCodeList());
        resVo.setDetail(resObj.getDetail());
        resVo.setPhone(resObj.getPhone());
        resVo.setUid(resObj.getUid());
        resVo.setCity(resObj.getCity());
        resVo.setPost_code(resObj.getPostCode());
        resVo.setProvince(resObj.getProvince());
        resVo.setReal_name(resObj.getRealName());
        resVo.setIs_default(resObj.getIsDefault());
        resVo.setDistrict(resObj.getDistrict());
        return  ResponseUtil.ok("添加成功",resVo);

    }



    /**
     * 删除地址
     * @param Hmap
     * @param id
     * @return
     */
    @PostMapping("/address/delete/{id}")
    public Object addresDel(@RequestHeader Map<String,String> Hmap, @PathVariable Integer id) {
        if(!Hmap.containsKey("uid")){
            return ResponseUtil.fail("uid 参数错误");
        }
        UserAddress queryUA=new UserAddress();
        queryUA.setUid(Long.parseLong(Hmap.get("uid")+""));
        queryUA.setAddressId(id);
        List<UserAddress> userAddressList=userAddressService.queryListByObj(queryUA);
        //验证信息是否存在
        if(userAddressList==null||userAddressList.size()==0){
            return ResponseUtil.fail("信息不存在");
        }

        UserAddress isUA=userAddressList.get(0);

        //当前地址是默认地址不能删除
        if(isUA.getIsDefault()==1){
            return ResponseUtil.fail("默认地址不能删除");
        }
        //通过地址id进行删除
        userAddressService.deleteById(id);

        return ResponseUtil.ok();
    }


    /**
     * 地址列表
     * @param Hmap
     * @return
     */
    @GetMapping("address/lst")
    public Object addresslist(@RequestHeader Map<String,String> Hmap){
        if(!Hmap.containsKey("uid")){
            return ResponseUtil.fail("uid 参数错误");
        }
        List<UserAddress> lst=new ArrayList<UserAddress>();
        UserAddress queryUA=new UserAddress();
        queryUA.setUid(Long.parseLong(Hmap.get("uid")+""));
        lst=userAddressService.queryListByObj(queryUA);

        List<UserAddressVo> lstvo=new ArrayList<UserAddressVo>();
        for (int i = 0; i <lst.size() ; i++) {
            UserAddress resObj=lst.get(i);
            UserAddressVo resVo=new UserAddressVo();
            resVo.setAddress_id(resObj.getAddressId());
            resVo.setCreate_time(resObj.getCreateTime());
            resVo.setCity_id(resObj.getCityId());
            resVo.setCode_list(resObj.getCodeList());
            resVo.setDetail(resObj.getDetail());
            resVo.setPhone(resObj.getPhone());
            resVo.setUid(resObj.getUid());
            resVo.setCity(resObj.getCity());
            resVo.setPost_code(resObj.getPostCode());
            resVo.setProvince(resObj.getProvince());
            resVo.setReal_name(resObj.getRealName());
            resVo.setIs_default(resObj.getIsDefault());
            resVo.setDistrict(resObj.getDistrict());
            lstvo.add(resVo);
        }

        Map<String,Object> data=new HashMap<String,Object>();
        data.put("list",lstvo);
        return ResponseUtil.ok(data);

    }


    /**
     * 获取用户信息
     * @param Hmap
     * @return
     */
    @GetMapping("")
    public Object userInfo(@RequestHeader Map<String,String> Hmap){
        if(!Hmap.containsKey("uid")){
            return  ResponseUtil.fail("uid 参数错误");
        }

        User user=userService.queryByid(Integer.parseInt(Hmap.get("uid")));
        UserInfoVo userInfoVo=new UserInfoVo();
        userInfoVo.setAddres(user.getAddres());
        userInfoVo.setAvatar(userInfoVo.getAvatar());
        userInfoVo.setBirthday(user.getBirthday());
        userInfoVo.setPhone(user.getPhone());
        userInfoVo.setUid(user.getUid());
        userInfoVo.setNickname(user.getNickname());
        userInfoVo.setScore(user.getScore());
        userInfoVo.setBrokeragePrice(user.getBrokeragePrice());
        userInfoVo.setSex(user.getSex());

        Integer type=0;
        type=userService.dachangType(Integer.parseInt(Hmap.get("uid")));

        if(type!=null&&type>0){
            userInfoVo.setIs_da_cang_vip(type);
        }else{
            userInfoVo.setIs_da_cang_vip(0);
        }
        return  ResponseUtil.ok(userInfoVo);
    }


    /*
     * 养老金统计
     * */
    @GetMapping("/get_yanglao_statistics")
    public Object get_yanglao_statistics(@RequestHeader Map<String,String> Hmap){
        if(!Hmap.containsKey("uid")){
            return  ResponseUtil.fail("uid 参数错误");
        }

        Integer uid=Integer.parseInt(Hmap.get("uid"));
        //线下数量
//        $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>0];
        UserBill queryUserBill=new UserBill();
        queryUserBill.setUid(uid);
        queryUserBill.setStatus(1);
        queryUserBill.setCommission_type(5);
        queryUserBill.setSource(1);
        queryUserBill.setType_shop(0);

        List<UserBill> userBillList= userService.getUserBillList(queryUserBill);
        BigDecimal offLine_yanglao = userBillList.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add); //对list的对象的某个字段进行相加
        Integer num =userService.getUserBillCount(queryUserBill);

        Map<String,Object> data=new HashMap<String,Object>();
        Map<String,Object> dataZi=new HashMap<String,Object>();
        dataZi.put("num",num);
        dataZi.put("yanglao",offLine_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("offLine",dataZi);

        //线上已确认收货
//        $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
        UserBill queryUserBill_onLine=new UserBill();
        queryUserBill_onLine.setUid(uid);
        queryUserBill_onLine.setStatus(1);
        queryUserBill_onLine.setCommission_type(5);
        queryUserBill_onLine.setSource(0);
        queryUserBill_onLine.setType_shop(0);
        List<UserBill> userBillList_onLine= userService.getUserBillList(queryUserBill_onLine);
        BigDecimal onLine_yanglao=userBillList_onLine.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add);
        Map<String,Object> dataZi_online=new HashMap<String,Object>();
        Integer num_onLine =userService.getUserBillCount(queryUserBill_onLine);
        dataZi_online.put("num",num_onLine);
        dataZi_online.put("yanglao",onLine_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("onLine",dataZi_online);

        //线上未确认收货
//        $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
        UserBill queryUserBill_onLine_take_no=new UserBill();
        queryUserBill_onLine_take_no.setUid(uid);
        queryUserBill_onLine_take_no.setStatus(0);
        queryUserBill_onLine_take_no.setCommission_type(5);
        queryUserBill_onLine_take_no.setSource(0);
        queryUserBill_onLine_take_no.setType_shop(0);
        List<UserBill> userBillList_onLine_take_no= userService.getUserBillList(queryUserBill_onLine_take_no);
        BigDecimal onLine_take_no_yanglao=userBillList_onLine_take_no.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add);
        Map<String,Object> dataZi_onLine_take_no=new HashMap<String,Object>();
        Integer num_onLine_take_no =userService.getUserBillCount(queryUserBill_onLine_take_no);
        dataZi_onLine_take_no.put("num",num_onLine_take_no);
        dataZi_onLine_take_no.put("yanglao",onLine_take_no_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("onLine_take_no",dataZi_onLine_take_no);

        //淘宝
//        $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
        UserBill queryUserBill_tb=new UserBill();
        queryUserBill_tb.setUid(uid);
        queryUserBill_tb.setStatus(-1);
        queryUserBill_tb.setCommission_type(5);
        queryUserBill_tb.setSource(0);
        queryUserBill_tb.setType_shop(5);
        List<UserBill> userBillList_tb= userService.getUserBillList(queryUserBill_tb);
        BigDecimal tb_yanglao=userBillList_tb.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add);
        Map<String,Object> dataZi_tb=new HashMap<String,Object>();
        Integer num_tb =userService.getUserBillCount(queryUserBill_tb);
        int tb_a=0;
        BigDecimal yanglao_a=new BigDecimal(0);
        for (int i = 0; i <userBillList_tb.size() ; i++) {
            UserBill userBillObj=userBillList_tb.get(i);
            if(userBillObj.getStatus().equals(1)){
                yanglao_a=yanglao_a.add(userBillObj.getNumber());
                tb_a++;
            }
        }

        dataZi_tb.put("num",num_tb);
        dataZi_tb.put("num_a",tb_a);
        dataZi_tb.put("yanglao",tb_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        dataZi_tb.put("yanglao_a",yanglao_a.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("tb",dataZi_tb);

        //京东
//        $jd_a = 0;
//        $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
        UserBill queryUserBill_jd=new UserBill();
        queryUserBill_jd.setUid(uid);
        queryUserBill_jd.setStatus(-1);
        queryUserBill_jd.setCommission_type(5);
        queryUserBill_jd.setSource(0);
        queryUserBill_jd.setType_shop(6);
        List<UserBill> userBillList_jd= userService.getUserBillList(queryUserBill_jd);
        BigDecimal jd_yanglao=userBillList_jd.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add);
        Map<String,Object> dataZi_jd=new HashMap<String,Object>();
        Integer num_jd =userService.getUserBillCount(queryUserBill_jd);
        int jd_a=0;
        BigDecimal yanglao_jd_a=new BigDecimal(0);
        for (int i = 0; i <userBillList_jd.size() ; i++) {
            UserBill userBillObj=userBillList_jd.get(i);
            if(userBillObj.getStatus().equals(1)){
                yanglao_jd_a=yanglao_jd_a.add(userBillObj.getNumber());
                jd_a++;
            }
        }

        dataZi_jd.put("num",num_jd);
        dataZi_jd.put("num_a",jd_a);
        dataZi_jd.put("yanglao",jd_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        dataZi_jd.put("yanglao_a",yanglao_jd_a.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("jd",dataZi_jd);


        //苏宁
//        $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
        UserBill queryUserBill_su=new UserBill();
        queryUserBill_su.setUid(uid);
        queryUserBill_su.setStatus(-1);
        queryUserBill_su.setCommission_type(5);
        queryUserBill_su.setSource(0);
        queryUserBill_su.setType_shop(3);
        List<UserBill> userBillList_su= userService.getUserBillList(queryUserBill_su);
        BigDecimal su_yanglao=userBillList_su.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add);
        Map<String,Object> dataZi_su=new HashMap<String,Object>();
        Integer num_su =userService.getUserBillCount(queryUserBill_su);
        int su_a=0;
        BigDecimal yanglao_su_a=new BigDecimal(0);
        for (int i = 0; i <userBillList_su.size() ; i++) {
            UserBill userBillObj=userBillList_su.get(i);
            if(userBillObj.getStatus().equals(1)){
                yanglao_su_a=yanglao_su_a.add(userBillObj.getNumber());
                su_a++;
            }
        }

        dataZi_su.put("num",num_su);
        dataZi_su.put("num_a",su_a);
        dataZi_su.put("yanglao",su_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        dataZi_su.put("yanglao_a",yanglao_su_a.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("su",dataZi_su);

        //拼多多
//        $pdd_a = 0;
//        $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
        UserBill queryUserBill_pdd=new UserBill();
        queryUserBill_pdd.setUid(uid);
        queryUserBill_pdd.setStatus(-1);
        queryUserBill_pdd.setCommission_type(5);
        queryUserBill_pdd.setSource(0);
        queryUserBill_pdd.setType_shop(3);
        List<UserBill> userBillList_pdd= userService.getUserBillList(queryUserBill_pdd);
        BigDecimal pdd_yanglao=userBillList_pdd.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add);
        Map<String,Object> dataZi_pdd=new HashMap<String,Object>();
        Integer num_pdd =userService.getUserBillCount(queryUserBill_pdd);
        int pdd_a=0;
        BigDecimal yanglao_pdd_a=new BigDecimal(0);
        for (int i = 0; i <userBillList_pdd.size() ; i++) {
            UserBill userBillObj=userBillList_pdd.get(i);
            if(userBillObj.getStatus().equals(1)){
                yanglao_pdd_a=yanglao_pdd_a.add(userBillObj.getNumber());
                pdd_a++;
            }
        }

        dataZi_pdd.put("num",num_pdd);
        dataZi_pdd.put("num_a",pdd_a);
        dataZi_pdd.put("yanglao",pdd_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        dataZi_pdd.put("yanglao_a",yanglao_pdd_a.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("pdd",dataZi_pdd);

        //唯品会
//        $vip_a = 0;
//        $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
        UserBill queryUserBill_vip=new UserBill();
        queryUserBill_vip.setUid(uid);
        queryUserBill_vip.setStatus(-1);
        queryUserBill_vip.setCommission_type(5);
        queryUserBill_vip.setSource(0);
        queryUserBill_vip.setType_shop(2);
        List<UserBill> userBillList_vip= userService.getUserBillList(queryUserBill_vip);
        BigDecimal vip_yanglao=userBillList_vip.stream().map(UserBill::getNumber).reduce(BigDecimal.ZERO, BigDecimal::add);
        Map<String,Object> dataZi_vip=new HashMap<String,Object>();
        Integer num_vip =userService.getUserBillCount(queryUserBill_vip);
        int vip_a=0;
        BigDecimal yanglao_vip_a=new BigDecimal(0);
        for (int i = 0; i <userBillList_vip.size() ; i++) {
            UserBill userBillObj=userBillList_vip.get(i);
            if(userBillObj.getStatus().equals(1)){
                yanglao_vip_a=yanglao_pdd_a.add(userBillObj.getNumber());
                vip_a++;
            }
        }

        dataZi_pdd.put("num",num_vip);
        dataZi_pdd.put("num_a",vip_a);
        dataZi_pdd.put("yanglao",vip_yanglao.setScale(2,BigDecimal.ROUND_HALF_UP));
        dataZi_pdd.put("yanglao_a",yanglao_vip_a.setScale(2,BigDecimal.ROUND_HALF_UP));
        data.put("vip",dataZi_pdd);


//        $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'] + $data['tb']['num'] + $data['jd']['num'] + $data['su']['num'] + $data['pdd']['num'] + $data['vip']['num'];
//        $data['all_yanglao'] = round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] + $data['tb']['yanglao'] + $data['jd']['yanglao'] + $data['su']['yanglao'] + $data['pdd']['yanglao'] + $data['vip']['yanglao'], 2);
//        $data['all_yanglao_a'] = round($data['offLine']['yanglao'] + $data['onLine']['yanglao'] + $data['tb']['yanglao_a'] + $data['jd']['yanglao_a'] + $data['su']['yanglao_a'] + $data['pdd']['yanglao_a'] + $data['vip']['yanglao_a'], 2);
//        $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']];
//        $data['third_party_num_a']=['all_num_a'=>$data['tb']['num_a']+$data['jd']['num_a']+$data['su']['num_a']+ $data['pdd']['num_a'] + $data['vip']['num_a']];
//        $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
        Integer all_num=num+num_onLine_take_no+num_onLine+num_tb+num_jd+num_su+num_pdd+num_vip;
        data.put("all_num",all_num);
        BigDecimal all_yanglao=offLine_yanglao.add(onLine_yanglao).add(tb_yanglao).add(jd_yanglao).add(su_yanglao).add(pdd_yanglao).add(vip_yanglao);
        data.put("all_yanglao",all_yanglao);
        BigDecimal all_yanglao_a=offLine_yanglao.add(onLine_yanglao).add(yanglao_a).add(yanglao_jd_a).add(yanglao_su_a).add(yanglao_pdd_a).add(yanglao_vip_a);
        data.put("all_yanglao_a",all_yanglao_a);

        Integer third_party_num=num_tb+num_jd+num_su+num_pdd+num_vip;
        Map<String ,Object> date_third_party_num=new HashMap<String,Object>();
        date_third_party_num.put("all_num",third_party_num);
        data.put("third_party_num",date_third_party_num);

        Map<String ,Object> data_third_party_num_a=new HashMap<String,Object>();
        Integer all_num_a=tb_a+jd_a+su_a+pdd_a+vip_a;
        data_third_party_num_a.put("all_num_a",all_num_a);
        data.put("third_party_num_a",data_third_party_num_a);

        Map<String ,Object> data_third_party_num_n=new HashMap<String,Object>();
        Integer all_num_n=third_party_num-all_num_a;
        data_third_party_num_n.put("all_num_n",all_num_n);
        data.put("third_party_num_n",data_third_party_num_n);
        return  ResponseUtil.ok(data);

    }


    /**
     * 佣金
     * @param Hmap
     * @return
     */
    @GetMapping("/userCommission")
    public Object getUserCommission(@RequestHeader Map<String,String> Hmap) {
        if (!Hmap.containsKey("uid")) {
            return ResponseUtil.fail("uid 参数错误");
        }
        Integer uid= Integer.parseInt(Hmap.get("uid"));
        BigDecimal totle_number=userService.getUserCommission(uid);

        Map<String,Object> data=new HashMap<String,Object>();
        data.put("totle_number",totle_number.setScale(2,BigDecimal.ROUND_DOWN));

        return ResponseUtil.ok(data);
    }

    @GetMapping("/getUserList")
    public ResponseEntity<PageResult<UserDTO>> getUserList(@Valid GetUserListRequest request) {
        return ResponseEntity.ok(userService.getUserList(request));
    }

    @PostMapping("/createUserInfo")
    public ApiResponse<UserDTO> createUserInfo(@Validated @RequestBody CreateUserInfoRequest request) {
        return ApiResponse.success(userService.createUserInfo(request));
    }

    @PostMapping("/updateUserInfo")
    public ApiResponse<UserDTO> updateUserInfo(@Validated @RequestBody UpdateUserInfoRequest request) {
        return ApiResponse.success(userService.updateUserInfo(request));
    }

    @PostMapping("/modifyUserScore")
    public ApiResponse<UserScoreModifyResponse> modifyUserScore(@Validated @RequestBody UserScoreModifyRequest request) {
        return ApiResponse.success(userService.modifyUserScore(request));
    }

    @PostMapping("/modifyUserContribute")
    public ApiResponse<UserContributeModifyResponse> modifyUserContribute(@Validated @RequestBody UserContributeModifyRequest request) {
        return ApiResponse.success(userService.modifyUserContribute(request));
    }

    @PostMapping("/modifyPV")
    public ApiResponse<ModifyPVResponse> modifyUserPV(
            @Validated @RequestBody ModifyPVRequest request) {
        return ApiResponse.success(userService.modifyUserPV(request));
}


}
