package com.ruoyi.model.service.impl;

import com.cyl.manager.ums.domain.Member;
import com.cyl.manager.ums.pojo.query.MemberQuery;
import com.cyl.manager.ums.pojo.vo.MemberDataStatisticsVO;
import com.cyl.manager.ums.pojo.vo.MemberExtendVo;
import com.cyl.manager.ums.service.MemberService;
import com.ruoyi.applet.utils.conf.AppletUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.model.domain.AppUsers;
import com.ruoyi.model.domain.AppletConfig;
import com.ruoyi.model.service.IAApiAppletHhrWorkOutService;
import com.ruoyi.model.service.IAppUsersService;
import com.ruoyi.model.service.IAppletConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.*;

@Slf4j
@Service
public class AApiAppletHhrWorkOutServiceImpl implements IAApiAppletHhrWorkOutService {

    @Resource
    private IAppUsersService appUsersService;
    @Resource
    private TokenService tokenService;
    @Resource
    private IAppletConfigService appletConfigService;


    @Resource
    private MemberService memberService;


    //合伙人工作台 - 绑定用户基础信息
    @Override
    public AjaxResult HhrInfo(Long appUserId){
//      AppUsers localAppletUser = AppletUtil.getLocalAppletUser();
        AppUsers localAppletUser = new AppUsers();
        localAppletUser.setUserId(appUserId);
        AppUsers appUsers = appUsersService.selectAppUsersByUserId(localAppletUser.getUserId());

        Map<String,Object> map = new HashMap<>();
        map.put("info",appUsers); //用户信息
//        map.put("partner_level","初级合伙人"); //合伙人等级
        map.put("partner_day","138天"); //合伙人加入天数

        AppletConfig petPaymentHh = appletConfigService.selectAppletConfigByClassAndNum("pet_payment_hh", appUsers.getUserHhRole());
        map.put("partner_new_num",petPaymentHh.getParamValueText()); //合伙人当前合伙人比例


        AppletConfig partner_upgrade_num = appletConfigService.selectAppletConfigByClassAndNum("pet_payment_hh", appUsers.getUserHhRole()+1);
        map.put("partner_upgrade_num",partner_upgrade_num.getParamValueText()); //合伙人晋级之后的合伙人比例
//        map.put("user_code","jsk66623"); //邀请码
        map.put("user_code_bj","https://image.hhlm1688.com/img/work/log/indexInfo/11.png"); //邀请码背景图
        map.put("user_code_fx","https://image.hhlm1688.com/img/work/log/indexInfo/11.png"); //分享海报背景图
        map.put("user_code_url","https://image.hhlm1688.com/img/work/log/indexInfo/11.png"); //分销链接背景图


        map.put("register_users","0"); //当月注册用户
        map.put("order_users","0"); //当月下单用户
        map.put("use_users","0"); //当月有效用户

        map.put("order_users_money","0"); //本月订单金额
        map.put("use_users_money","0"); //本月有效订单金额


        map.put("register_users_sum","0"); //累积注册用户
        map.put("order_users_sum","0"); //累积下单用户
        map.put("use_users_sum","0"); //累积有效用户


        map.put("order_users_sum_money","0"); //累积订单金额
        map.put("use_users_sum_money","0"); //累积有效订单金额



        map.put("money",appUsers.getMoney()); //钱包金额
        map.put("new_money","0"); //本月分成
        map.put("old_money","0"); //累积分成





        map.put("upgrade_register_num","5"); //距离下一个等级需要注册多少人
        map.put("upgrade_order_num","20"); //距离下一个等级需要下单人数
        map.put("upgrade_image","https://image.hhlm1688.com/img/work/log/indexInfo/11.png"); //背景图
        map.put("upgrade_details","合伙人权益说明：富文本"); //合伙人权益说明：富文本



        map.put("user_details","*累计报酬:当该用户订单完成时，才会纳入报酬计算：这是一个富文本"); //我的用户说明
        map.put("level_details","累积数据:即注册至今的累计数据:这是一个富文本"); //我的等级说明
        map.put("withdrawal_details","提现说明:这是一个富文本提现说明:这是一个富文本提现说明:这是一个富文本提现说明:这是一个富文本"); //提现说明



        return  AjaxResult.success(map);
    }



    //合伙人工作台 - 绑定二维码
    @Override
    public AjaxResult HhrCode(Long appUserId){
        AppUsers localAppletUser = new AppUsers();
        localAppletUser.setUserId(appUserId);
        AppUsers appUsers = appUsersService.selectAppUsersByUserId(localAppletUser.getUserId());

        Map<String,Object> map = new HashMap<>();
        map.put("code",appUsers.getInvitationCode());//邀请码





        List<AppletConfig> appletConfigs = appletConfigService.selectAppletConfigList(null);
        for (AppletConfig appletConfig : appletConfigs){
            if(appletConfig.getParamCode().equals("background_poster")){
                map.put("bj_url",appletConfig.getParamValueImage());//海报背景图
            }
            if(appletConfig.getParamCode().equals("share_qr_url")){
                map.put("url",appletConfig.getParamValueImage());//二维码地址
            }
        }


        map.put("title","欢迎来到宠物小程序二维码");//说明

        return AjaxResult.success(map);
    }


    //合伙人工作台 - 我的用户列表 0 未下单 1已下单
    @Override
    public AjaxResult HhrMyUserList(Long appUserId,Integer state, Pageable page){
        AppUsers localAppletUser = new AppUsers();
        localAppletUser.setUserId(appUserId);
        List<AppUsers> pageRes = appUsersService.selectAppUsersList(new AppUsers());
//        memberService.selectList()
//        PageImpl<AppUsers> appUsers = new PageImpl<>(pageRes, page, ((Page) pageRes).getTotal());
        return AjaxResult.success("查询分页成功",pageRes);
    }




    //合伙人工作台 - 根据用户标识查询用户下单详细信息
    @Override
    public AjaxResult HhrMyUserGetById(Long appUserId){
        Map<String,Object> map = new HashMap<>();
        map.put("createTime",new Date());//注册时间
        map.put("recently_pay_time",new Date());//最近下单时间
        map.put("accumulate_money","9999.99");//海报背景图
        map.put("reward_money","100");//累积报酬
        return  AjaxResult.success("用户下单详细信息成功",map);
    }


}
