示例#1
0
 public static CarChargeViewModel.CarChargeItem ConvertToViewModel(this UpdateChargeResponse response)
 {
     CarChargeViewModel.CarChargeItem view = new CarChargeViewModel.CarChargeItem();
     if (response != null)
     {
         view.CarVin   = response.CarVin;
         view.EngineNo = response.EngineNo;
         //view.LicenseOwner = response.LicenseOwner;
         view.MoldName = response.MoldName;
         //view.OwnerIdNo = response.OwnerIdNo;
         view.LicenseNo    = response.LicenseNo;
         view.RegisterDate = response.RegisterDate;
         view.TotalCount   = response.TotalCount;
         view.UsedCount    = response.UsedCount;
     }
     return(view);
 }
        public async Task <UpdateChargeResponse> Update(UpdateChargeRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var response = new UpdateChargeResponse();

            //根据经纪人获取手机号
            IBxAgent agentModel = GetAgentModelFactory(request.Agent);

            //logInfo.Info("获取到的经纪人信息:"+agentModel.ToJson());
            //参数校验
            if (!agentModel.AgentCanUse())
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }

            if (!ValidateReqest(pairs, agentModel.SecretKey, request.SecCode))
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }

            bx_charge charge = _chargeRepository.Find(request.Agent, request.BusyKey);

            if (charge == null)
            {
                response.Status = HttpStatusCode.BadRequest;
                return(response);
            }
            try
            {
                //发送请求 checkneed
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(_url);
                    var requestmodel = new
                    {
                        LicenseNo = request.LicenseNo,
                        Agent     = request.Agent
                    };

                    HttpResponseMessage res = await client.PostAsJsonAsync("api/userinfo/FindCarInfoBy", requestmodel);

                    if (res.IsSuccessStatusCode)
                    {
                        WaFindCarInfoResponse result = await res.Content.ReadAsAsync <WaFindCarInfoResponse>();

                        if (result.ErrCode == 0)
                        {
                            //更新bx_charge

                            if (charge.total_count == charge.used_count)
                            {
                                //余额不足
                                response.Status  = HttpStatusCode.OK;
                                response.ErrCode = -2;
                                return(response);
                            }

                            charge.used_count += 1;
                            charge.update_time = DateTime.Now;
                            var chargeCount = _chargeRepository.Update(charge);
                            if (chargeCount == 1)
                            {
                                //插入bx_charge_history
                                var history = new bx_charge_history
                                {
                                    charge_id     = charge.id,
                                    license_no    = request.LicenseNo,
                                    result_status = 1 //成功
                                };
                                _chargeHistoryRepository.Add(history);
                            }

                            response.TotalCount   = charge.total_count.HasValue ? charge.total_count.Value : 0;
                            response.UsedCount    = charge.used_count.HasValue ? charge.used_count.Value : 0;
                            response.MoldName     = result.CarInfo.MoldName;
                            response.CarVin       = result.CarInfo.CarVin;
                            response.RegisterDate = result.CarInfo.RegisteDate;
                            response.LicenseNo    = result.CarInfo.PlateNo;
                            response.EngineNo     = result.CarInfo.EngineNo;
                            response.LicenseOwner = result.CarInfo.LicenseOwner;
                            response.OwnerIdNo    = result.CarInfo.OwnerIdNo;
                            response.Status       = HttpStatusCode.OK;
                            response.ErrCode      = 0;
                            return(response);
                        }
                        else
                        {
                            //插入bx_charge_history
                            var history = new bx_charge_history
                            {
                                charge_id     = charge.id,
                                license_no    = request.LicenseNo,
                                result_status = 0 //失败
                            };
                            _chargeHistoryRepository.Add(history);
                            response.Status  = HttpStatusCode.OK;
                            response.ErrCode = -1;
                            return(response);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.Status = HttpStatusCode.ExpectationFailed;
                logError.Info("收费服务-获取车辆信息发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }

            return(response);
        }