package com.gic.haoban.manage.web.qo.licence;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * <p>
 *
 * </p>
 *
 * @author jx
 * @since 2023-03-09
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class LicenceOrderQO implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 订单类型，1：购买帐号，2：续期帐号
     */
    private Integer orderType;

    /**
     * 互通帐号个数
     */
    private Integer externalContactCount;

//    /**
//     * 基础帐号个数
//     */
//    private Integer baseCount;

    /**
     * 订单金额，单位分
     */
    private Integer price;

    /**
     * 购买时间类型 1：按月购买，2：按天购买
     */
    private Integer timeType;

    /**
     * 购买的时间数值
     */
    private Integer timeValue;

    /**
     * 支付类型 1在线支付 2对公转账
     */
    private Integer payType;

    /**
     * 校验金额
     */
    public Integer checkPrice(){
        if (this.externalContactCount ==null || this.externalContactCount<0){
            return -1;
        }
        Integer myPrice=0;
        //根据企业微信的计费规则计算
        if (this.externalContactCount<=5){
            myPrice = 50*this.externalContactCount;
        } else if (this.externalContactCount<=200) {
            myPrice = 250+40*(this.externalContactCount-5);
        } else if (this.externalContactCount<=500) {
            myPrice = 8050+30*(this.externalContactCount-200);
        } else if (this.externalContactCount<=1000) {
            myPrice = 17050+20*(this.externalContactCount-500);
        } else if (this.externalContactCount<=10000) {
            myPrice = 27050+10*(this.externalContactCount-1000);
        }else {
            return -1;
        }
        //转化为分
        myPrice = myPrice*this.timeValue*100;
        if (this.timeType == 1){
            //企业微信的规则： 12.312，最终保留的是12.32
            if (myPrice%12==0){
                myPrice = myPrice/12;
            }else {
                myPrice = myPrice/12+1;
            }
        }else {
            if (myPrice%372==0){
                myPrice = myPrice/372;
            }else {
                myPrice = myPrice/372+1;
            }
        }
        if (!this.price .equals(myPrice)){
            return 0;
        }
        return 1;
    }
}
