package com.xhpc.user.controller;

import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.user.service.IXhpcCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 公共的内
 * @author yuyang
 * @date 2021/12/29 10:34
 */
@RestController
@RequestMapping("/common")
public class XhpcCommonController extends BaseController {

    @Autowired
    private IXhpcCommonService xhpcCommonService;

    /**
     * 根据手机号（账号），用户id和类型 获取用户信息
     * @param phone
     * @param userId
     * @param userType
     * @param serialNumber       桩号
     * @return
     */
    @GetMapping(value = "/getUser")
    public AjaxResult getMechanism(String phone,Long userId,Integer userType,String serialNumber,String tenantId) {

        if(phone !=null || "".equals(phone)){
            if(!UserTypeUtil.COMMUNIT.equals(phone.substring(0,2)) && !UserTypeUtil.CUSTOMERS.equals(phone.substring(0,2))){
                //C端用户
                return AjaxResult.success(xhpcCommonService.getLandUser(phone,null,UserTypeUtil.USER_TYPE,serialNumber,tenantId));
            }else if (UserTypeUtil.COMMUNIT.equals(phone.substring(0,2))){
                //社区用户
                return AjaxResult.success(xhpcCommonService.getLandUser(phone,null,UserTypeUtil.COMMUNIT_TYPE,serialNumber,tenantId));
            }else if (UserTypeUtil.CUSTOMERS.equals(phone.substring(0,2))){
                //大客户用户
                return AjaxResult.success(xhpcCommonService.getLandUser(phone,null,UserTypeUtil.CUSTOMERS_TYPE,serialNumber,tenantId));
            }
        }else{
            return AjaxResult.success(xhpcCommonService.getLandUser(null,userId,userType,serialNumber,tenantId));
        }
        return AjaxResult.error();
    }

    /**
     * 根据用户类型，用户id，充值记录，增加流水
     * @param money          充值金额
     * @param userId          充值用户
     * @param userType        用户类型
     * @param tenantId        租户id
     * @param type            充值渠道（1微信 2支付宝  3平台)
     * @param status           1 充值 2退款
     * @param remark          备注
     * @return
     */
    @GetMapping(value = "/insertUserBalance")
    public AjaxResult insertUserBalance(BigDecimal money, Long userId, Integer userType, String tenantId, Integer type, Integer status,String remark,Long moneyOrderId) {

        return xhpcCommonService.insertUserBalance(money,userId,userType,tenantId,type,status,remark,moneyOrderId);
    }

}
