void OnAddOrderRecordRequest(IMessage msg, SessionEventArgs e)
        {
            var state = OrderRecordOptState.Failed;

            OrderRecord orderRecord = msg.Obj as OrderRecord;

            if (e.Session.SessionId != null)
            {
                try
                {
                    orderRecord.UserId = (e.Session.SessionId as UserSessionIdMetaData).Id;

                    if (orderRecord.OrderStateId == 999999)
                    {
                        state = OrderRecordOptState.ReturnGold;
                    }
                    else
                    {
                        if (!_orderRecordBll.HasNotCompletedOrder(orderRecord.UserId,
                                                                  orderRecord.ClientUserId, orderRecord.ClientUserSubAccountId))
                        {
                            if (_userBll.UpdateGold(orderRecord.UserId, -100))
                            {
                                state = OrderRecordOptState.DeductionGold;
                            }
                        }

                        if (orderRecord.OrderStateId >= 10 && orderRecord.OrderStateId <= 40)
                        {
                            _subAccountOrderTypeInfoBll.UpdateOrderTypeCount(
                                orderRecord.ClientUserSubAccountId, orderRecord.OrderTypeId.Value);

                            if (orderRecord.OrderStateId >= 20)
                            {
                                _subAccountUsageInfoBll.UpdateOrderCount(orderRecord.ClientUserSubAccountId);
                            }
                        }
                    }

                    if (!_orderRecordBll.Add(orderRecord))
                    {
                        state = OrderRecordOptState.Failed;
                    }
                }
                catch (Exception ex)
                {
                    state = OrderRecordOptState.Failed;
                    ErrorLog(msg.Header.Type, ex);
                }
            }
            else
            {
                state = OrderRecordOptState.InvalidOpt;
            }

            e.Session.Send(state, MessageType.AddOrderRecordResponse);
        }
Ejemplo n.º 2
0
        void AddOrderRecord()
        {
            var orderState = scbOrderState.SelectedItem as OrderState;

            if (orderState.Id == -1)
            {
                errorProvider.SetError(scbOrderState, "必须选择刷单状态!");
                return;
            }

            Shop      shop      = null;
            OrderType orderType = null;

            if (orderState.Id != 999999)
            {
                shop = scbShopAccount.SelectedItem as Shop;
                if (shop.Id == -1)
                {
                    errorProvider.SetError(scbShopAccount, "必须选择店铺掌柜!");
                    return;
                }

                orderType = scbOrderType.SelectedItem as OrderType;
                if (orderType.Id == -1)
                {
                    errorProvider.SetError(scbOrderType, "必须选择刷单类别!");
                    return;
                }
            }

            if (orderState.Id >= 20 && orderState.Id <= 40)
            {
                if (string.IsNullOrEmpty(stbOrderNum.SkinTxt.Text))
                {
                    errorProvider.SetError(stbOrderNum, "必须输入订单号!");
                    return;
                }
            }

            Action <OrderRecordOptState> addResponse = state =>
            {
                string info = string.Empty;

                switch (state)
                {
                case OrderRecordOptState.CannotConnectServer:
                    info = "服务器连接失败,未能保存刷单信息!";
                    break;

                case OrderRecordOptState.Failed:
                    info = "服务器异常,保存刷单信息失败!";
                    break;

                case OrderRecordOptState.InvalidOpt:
                    info = "非法操作!与服务器连接断开,请稍后重试!";
                    break;

                case OrderRecordOptState.DeductionGold:
                    info = "首次远程刷单操作成功,扣除 100 金币。\r\n\r\n请在30天内完成刷单!";
                    break;

                case OrderRecordOptState.ReturnGold:
                    info = "刷单失败,本次刷单未扣除金币。";
                    break;
                }

                Invoke(() =>
                {
                    if (state != OrderRecordOptState.Successed)
                    {
                        MessageBoxEx.Show(this, info, "保存刷单信息",
                                          MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    if (state != OrderRecordOptState.DeductionGold &&
                        state != OrderRecordOptState.ReturnGold &&
                        state != OrderRecordOptState.Successed)
                    {
                        return;
                    }

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                });
            };

            _orderRecordBll.Add(new OrderRecord
            {
                ClientUserId           = UserSubAccountPageListVM.UserId,
                ClientUserSubAccountId = UserSubAccountPageListVM.Id,
                OrderStateId           = orderState.Id,
                OrderTypeId            = orderType == null ? null : (int?)orderType.Id,
                UserShopId             = shop == null ? null : (int?)shop.Id,
                OrderNum           = stbOrderNum.SkinTxt.Text.Trim(),
                StartDateTime      = DateTime.Parse(lbStartDateTime.Text),
                LastUpdateDateTime = DateTime.Now,
                OrderIp            = UserSubAccountPageListVM.IpAddress
            }, addResponse);
        }