public object Do_MemberReg(BaseApi baseApi) { MemberRegParam memberRegParam = JsonConvert.DeserializeObject <MemberRegParam>(baseApi.param.ToString()); if (memberRegParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } SessionBag sessionBag = SessionContainer.GetSession(baseApi.token); if (sessionBag == null) { throw new ApiException(CodeMessage.InvalidToken, "InvalidToken"); } OpenDao openDao = new OpenDao(); string openID = Utils.GetOpenID(baseApi.token); var member = openDao.GetMember(openID); if (member != null) { throw new ApiException(CodeMessage.MemberExist, "MemberExist"); } if (!openDao.MemberReg(memberRegParam, openID)) { throw new ApiException(CodeMessage.MemberRegError, "MemberRegError"); } member = openDao.GetMember(openID); SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name); sessionUser.openid = sessionBag.OpenId; sessionUser.memberId = member.memberId; sessionUser.userType = "MEMBER"; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S)); return(""); }
public object Do_CommitBy3rdUser(BaseApi baseApi) { CommitBy3rdUserParam commitBy3rdUserParam = JsonConvert.DeserializeObject <CommitBy3rdUserParam>(baseApi.param.ToString()); if (commitBy3rdUserParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } RemoteDao remoteDao = new RemoteDao(); Store store = remoteDao.GetStoreByStoreId(baseApi.code); if (store == null) { throw new ApiException(CodeMessage.InvalidStoreCode, "InvalidStoreCode"); } if (commitBy3rdUserParam.phone == null) { throw new ApiException(CodeMessage.StorePhoneExist, "StorePhoneExist"); } Member member = null; Goods goods = null; goods = remoteDao.GetGoodsByGoodsId(commitBy3rdUserParam.goodsId); if (goods == null) { throw new ApiException(CodeMessage.InvalidGoods, "InvalidGoods"); } if (remoteDao.GetMemberStoreById(baseApi.code, commitBy3rdUserParam.phone)) { MemberRegParam memberRegParam = new MemberRegParam { avatarUrl = commitBy3rdUserParam.avatarUrl, gender = commitBy3rdUserParam.gender, nickName = commitBy3rdUserParam.nickName }; string openID = "3rd-" + Guid.NewGuid().ToString(); remoteDao.MemberReg(memberRegParam, openID); member = remoteDao.GetMember(openID); if (member == null) { throw new ApiException(CodeMessage.MemberRegError, "MemberRegError"); } RemoteStoreMember remoteStoreMember = new RemoteStoreMember { cardCode = commitBy3rdUserParam.phone, phone = commitBy3rdUserParam.phone, storeId = store.storeId }; if (!remoteDao.BindMemberStore(member.memberId, remoteStoreMember, false)) { throw new ApiException(CodeMessage.BindStoreMemberError, "BindStoreMemberError"); } } else { member = remoteDao.GetMember(baseApi.code, commitBy3rdUserParam.phone); } if (commitBy3rdUserParam.goodsId != null) { commitBy3rdUserParam.preOrderId = "APP_" + store.storeCode + "_" + commitBy3rdUserParam.preOrderId; if (remoteDao.GetOrderByOrderCode(commitBy3rdUserParam.preOrderId)) { if (!remoteDao.CreateOrder( commitBy3rdUserParam.preOrderId, commitBy3rdUserParam.state, member.memberId, commitBy3rdUserParam.addr, commitBy3rdUserParam.goodsNum, store, goods )) { throw new ApiException(CodeMessage.CreateOrderError, "CreateOrderError"); } } } if (commitBy3rdUserParam.heartAdd != 0) { if (!remoteDao.GetHeartCommitByFromId(commitBy3rdUserParam.heartFromId)) { throw new ApiException(CodeMessage.UpdateHeartCommitError, "UpdateHeartCommitError"); } if (!remoteDao.AddHeart( "1", commitBy3rdUserParam.heartFromId, member.memberId, commitBy3rdUserParam.heartAdd)) { throw new ApiException(CodeMessage.UpdateHeartCommitError, "UpdateHeartCommitError"); } } return(member.openid.StartsWith("3rd-") ? member.openid : ""); }