/// <summary> /// 添加注册用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <int> InsertWxUserAsync(twxuser user) { const string sql = "INSERT INTO public.twxuser(pkid,fwxid,fk_card_id,fname,frelationship,fphone,fstate,fremark,fcreatetime) VALUES(@pkid, @fwxid,@fk_card_id, @fname, @frelationship, @fphone, @fstate, @fremark, @fcreatetime)"; return(await ExecuteEntityAsync(sql, user)); }
/// <summary> /// 更新微信用户信息 /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <int> UpdateWxUserAsync(twxuser user) { const string sql = "UPDATE public.twxuser SET fk_card_id=@fk_card_id,frelationship=@frelationship,fphone=@fphone WHERE pkid=@pkid"; return(await ExecuteEntityAsync(sql, user)); }
/// <summary> /// TODO 用户注册 /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <RegisVD> DoRegisterAsync(RegisterModel user) { #region 卡号校验 var cardRecord = await _schoolBusRepository.GetCardByCodeAsync(user.cardNum); if (cardRecord == null) { return(new RegisVD { msg = "卡号错误,请重新输入" }); } switch (cardRecord.fstatus) { case 2: return(new RegisVD { msg = "该卡已挂失,请重新输入" }); case 3: return(new RegisVD { msg = "该卡已注销,请重新输入" }); } #endregion #region 验证码校验 var isCode = await CheckCode(user.phoneNum, user.verificationCode, 0); if (isCode.status != 1) { return(new RegisVD { msg = isCode.msg }); } #endregion #region 微信号校验和注册操作 var userRecord = await _schoolBusRepository.GetTwxuserByOpenidAsync(user.wxid); if (userRecord == null) // 用户没有注册过 { twxuser wxuser = new twxuser { fwxid = user.wxid, fname = user.userName, fk_card_id = cardRecord.pkid, frelationship = user.relationship, fphone = user.phoneNum, fstate = 0 }; var res = await _schoolBusRepository.InsertWxUserAsync(wxuser); if (res == 0) { return(new RegisVD { msg = "注册失败,请稍后尝试" }); } } else { // 根据当前用户微信获取之前绑卡卡号信息 var userCardRecord = await _schoolBusRepository.GetCardBypkidAsync(userRecord.fk_card_id);// 这一步一定有卡信息 if (userCardRecord == null) { return(new RegisVD { msg = "你注册的卡已经不存在,请联系管理员" }); } if (userCardRecord.fstatus == 1) { return(new RegisVD { msg = "该微信已注册" }); } // 老卡数据要导入新卡中 if (!string.IsNullOrEmpty(cardRecord.fname) && !string.IsNullOrEmpty(userCardRecord.fname)) { cardRecord.fname = userCardRecord.fname; cardRecord.fsex = userCardRecord.fsex; cardRecord.fk_school_id = userCardRecord.fk_school_id; cardRecord.fk_device_id = userCardRecord.fk_device_id; cardRecord.fboardingaddress = userCardRecord.fboardingaddress; cardRecord.fbirthdate = userCardRecord.fbirthdate; } // userCardRecord.pkid 之前卡片信息 // cardRecord.pkid 新卡信息 // 更新所有绑定老卡用户卡片信息 var s1 = await _schoolBusRepository.UpdateUserCardAsync(userCardRecord.pkid, cardRecord.pkid); if (s1 == 0) { return(new RegisVD { msg = "更新所有绑定老卡用户卡片信息" }); } #region 更新已有用户信息 userRecord.pkid = userRecord.pkid; userRecord.fk_card_id = cardRecord.pkid; userRecord.frelationship = user.relationship; userRecord.fphone = user.phoneNum; var s2 = await _schoolBusRepository.UpdateWxUserAsync(userRecord); if (s2 == 0) { return(new RegisVD { msg = "更新已有用户信息失败" }); } #endregion } #endregion #region 卡片信息维护 if (cardRecord.ftrialdate == null) { DateTime triald = Convert.ToDateTime(cardRecord.ftrialdate); var trialdateRecord = await _schoolBusRepository.GetSchoolConfigAsync("001"); // 首次注册试用期(天) int.TryParse(trialdateRecord.fvalue, out int tt); cardRecord.ftrialdate = triald.AddDays(tt); // 卡片试用期赋值 } cardRecord.fstatus = 1; // 维护卡片信息状态 var s3 = await _schoolBusRepository.UpdateTCardAsync(cardRecord); #endregion return(s3 == 0 ? new RegisVD { msg = "维护卡片信息失败" } : new RegisVD { status = 1, msg = "注册成功" }); }