public object Do_BindMemberStore(BaseApi baseApi) { BindStoreParam bindStoreParam = JsonConvert.DeserializeObject <BindStoreParam>(baseApi.param.ToString()); if (bindStoreParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } MemberDao memberDao = new MemberDao(); string memberId = Utils.GetMemberID(baseApi.token); SessionBag sessionBag = SessionContainer.GetSession(baseApi.token); SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name); if (sessionUser == null) { throw new ApiException(CodeMessage.InvalidToken, "InvalidToken"); } if (sessionUser.checkCode != bindStoreParam.checkCode || sessionUser.checkPhone != bindStoreParam.phone) { throw new ApiException(CodeMessage.InvalidCheckCode, "InvalidCheckCode"); } sessionUser.checkCode = ""; sessionUser.checkPhone = ""; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S)); List <MemberStore> memberStoreList = memberDao.GetMemberStoreListByMemberId(memberId); MemberStore memberStore = memberStoreList.Find ( item => item.storeId.Equals(bindStoreParam.storeId) ); if (memberStore != null) { throw new ApiException(CodeMessage.StoreMemberExist, "StoreMemberExist"); } if (!memberDao.CheckPhone(bindStoreParam.phone, bindStoreParam.storeId)) { throw new ApiException(CodeMessage.StorePhoneExist, "StorePhoneExist"); } Store store = memberDao.GetStoreByStoreId(bindStoreParam.storeId); RemoteStoreMember remoteStoreMember = memberDao.GetRemoteStoreMember(bindStoreParam.storeId, bindStoreParam.phone); if (remoteStoreMember == null) { if (store != null && store.openReg == 1) { remoteStoreMember = memberDao.GetNewRemoteStoreMember(bindStoreParam.storeId, bindStoreParam.phone); } if (remoteStoreMember == null) { throw new ApiException(CodeMessage.RemoteStoreMemberNotExist, "RemoteStoreMemberNotExist"); } } bool setDefault = memberStoreList.Count == 0; if (!memberDao.BindMemberStore(memberId, remoteStoreMember, setDefault)) { throw new ApiException(CodeMessage.BindStoreMemberError, "BindStoreMemberError"); } return(""); }