package com.sifang.modules.site.registerInfo.service;

import com.jfinal.plugin.activerecord.Db;
import com.sifang.modules.site.siteInfo.dao.SiteCompanyInfoDao;
import com.sifang.modules.sys.common.service.BaseService;
import com.sifang.modules.sys.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RegisterService extends BaseService {

    @Autowired
    private UserDao userDao;
    @Autowired
    private SiteCompanyInfoDao siteCompanyInfoDao;

    /**
     * 校验输入的验证码和手机获取的是否一致
     *
     * @param codeMsg
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String checkConfirmCode(String code, String codeMsg, String mobile) {
        String result = "ok";
        Long count = Db.queryLong("select count(*) from sys_user a where a.status='0' and a.mobile='" + mobile + "'");
        if (count > 1) {
            return "existName";
        }
        if (!codeMsg.equals(code)) {
            return "wrongMsg";
        }
        return result;
    }

    /**
     * 用户表中校验输入的手机号码
     *
     * @param mobile
     * @param code
     * @return
     */
    public String checkMobile(String mobile, String code) {
        try {
            Long count = Db.queryLong("select count(*) from sys_user a where a.status='0' and a.mobile='" + mobile + "'");
            if (count > 0) {
                return "existName";
            }
            return "ok";
        } catch (Exception e) {
            return "no";
        }

    }


}
