コード例 #1
0
        public void SettingCrytocurrencies(Guid accountId, List <int> cryptoIds)
        {
            var mwDac      = new MerchantWalletDAC();
            var mwList     = mwDac.GetByAccountId(accountId).ToList();
            var cryptoList = new CryptocurrencyDAC().GetByIds(cryptoIds.ToArray());

            // FIII 不参与排序
            var fiiiCrypto = cryptoList.FirstOrDefault(e => e.Code == FIIICOIN_CODE);

            if (fiiiCrypto != null)
            {
                cryptoIds.Remove(fiiiCrypto.Id);
                var fiiiWallet = mwList.FirstOrDefault(e => e.CryptoId == fiiiCrypto.Id);
                if (fiiiWallet != null)
                {
                    mwList.Remove(fiiiWallet);
                }
            }

            // 白标POS机的白标币不参与排序
            var account = new MerchantAccountDAC().GetById(accountId);
            var pos     = new POSDAC().GetById(account.POSId.Value);

            if (pos.IsWhiteLabel)
            {
                var whiteCrypto = cryptoList.FirstOrDefault(e => e.Code == pos.FirstCrypto);
                if (whiteCrypto != null)
                {
                    cryptoIds.Remove(whiteCrypto.Id);
                    var whiteWallet = mwList.FirstOrDefault(e => e.CryptoId == whiteCrypto.Id);
                    if (whiteWallet != null)
                    {
                        mwList.Remove(whiteWallet);
                    }
                }
            }


            for (int i = 0; i < cryptoIds.Count; i++)
            {
                int seq    = i + 1;
                var crypto = cryptoList.FirstOrDefault(e => e.Id == cryptoIds[i]);
                if (crypto == null)
                {
                    continue;
                }

                var wallet = mwList.FirstOrDefault(e => e.CryptoId == cryptoIds[i]);
                // 新增
                if (wallet == null)
                {
                    GenerateWallet(accountId, crypto.Id, crypto.Code, seq, true);
                    continue;
                }
                // 启用
                if (!wallet.SupportReceipt || wallet.Sequence != seq)
                {
                    mwDac.Support(accountId, crypto.Id, seq);
                }
                mwList.Remove(wallet);
            }

            mwList.RemoveAll(e => !e.SupportReceipt);
            // 禁用
            foreach (var wallet in mwList)
            {
                mwDac.Reject(accountId, wallet.CryptoId);
            }
        }