From e0919683625f6a48699ed2c223f22366cc5bc949 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期四, 23 六月 2022 15:09:33 +0800
Subject: [PATCH] 积分

---
 zhengcaioa/zhengcaioa/Controllers/BusinessOrder/OrderBanciOrderController.cs |  202 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 201 insertions(+), 1 deletions(-)

diff --git a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/OrderBanciOrderController.cs b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/OrderBanciOrderController.cs
index 693edfd..ff4bfa7 100644
--- a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/OrderBanciOrderController.cs
+++ b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/OrderBanciOrderController.cs
@@ -18,6 +18,10 @@
 using CommonToolsCore;
 using Services;
 using System.Transactions;
+using Microsoft.Extensions.Configuration;
+using Newtonsoft.Json.Linq;
+using System.Net.Http.Headers;
+using System.IdentityModel.Tokens.Jwt;
 
 namespace zhengcaioa.Controllers.BusinessOrder
 {
@@ -30,11 +34,15 @@
         private readonly IOrderBanciOrderService _orderBanciOrderService;
         private readonly IFiOrderrecievemoneyService _fiOrderrecievemoneyService;
         private readonly ICooperOrderService _cooperOrderService;
+        private readonly IConfiguration _configuration;
+        private readonly IHttpClientFactory _clientFactory;
 
         public OrderBanciOrderController(ILogger<OrderBanciOrderController> logger, ILiaotianService liaotianService, IOrderBanciService orderBanciService, IOrderBanciDtlService orderBanciDtlService
             ,IOrderBanciOrderService orderBanciOrderService
             , IFiOrderrecievemoneyService fiOrderrecievemoneyService
-            , ICooperOrderService cooperOrderService)
+            , ICooperOrderService cooperOrderService
+            , IConfiguration configuration
+              , IHttpClientFactory clientFactory)
         {
             _logger = logger;
             _liaotianService = liaotianService;
@@ -43,6 +51,8 @@
             _fiOrderrecievemoneyService = fiOrderrecievemoneyService;
             _orderBanciOrderService = orderBanciOrderService;
             _cooperOrderService = cooperOrderService;
+            _configuration = configuration;
+            _clientFactory = clientFactory;
         }
 
         [CheckLogin]
@@ -332,6 +342,196 @@
         }
 
 
+        /// <summary>
+        /// 淇濆瓨
+        /// </summary>
+        /// <param name="data">宀椾綅瀹炰綋绫诲璞�</param>
+        /// <returns></returns>
+        /// 
+        [HttpPost]
+        public  IActionResult JifenSave([FromBody] OrderBanciOrderDTO data)
+        {
+            //var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
+            //ViewData["curentuser"] = curentuser;
+            ReturnMsg<OrderBanciOrderDTO> returnMsg = new ReturnMsg<OrderBanciOrderDTO>();
+            returnMsg.code = 2;
+            try
+            {
+                string userid = "";
+                var headers = Request.Headers;
+                if (headers != null)
+                {
+                    //string SecurityKey = _configuration.GetSection("SecurityKey").Value;
+                    var keyId = headers["Authorization"].FirstOrDefault();
+                    if (string.IsNullOrEmpty("keyId"))
+                    {
+                        returnMsg.code = 2;
+                        returnMsg.error = "娌℃湁鑾峰彇鍒皌oken";
+                        returnMsg.count = 0;
+
+                        return new JsonResult(returnMsg);
+                    }
+
+
+                    JwtSecurityToken jwt = null;
+                    var handler = new JwtSecurityTokenHandler();
+                    var key1 = keyId.Replace("Bearer", "").Trim();
+                    jwt = handler.ReadJwtToken(key1);
+                    System.Security.Claims.Claim sss = jwt.Claims.Where(x => x.Type == "id").FirstOrDefault();
+                    userid = sss.Value;
+
+                }
+                else
+                {
+                    returnMsg.code = 2;
+                    returnMsg.error = "娌℃湁鑾峰彇鍒皌oken";
+                    returnMsg.count = 0;
+                    return new JsonResult(returnMsg);
+                }
+
+                using (TransactionScope scope = new TransactionScope())
+                {
+                    data.RecStatus = "A";
+                    if (String.IsNullOrEmpty(data.Id))
+                    {
+                        data.Creater = "1";
+                        data.Createtime = DateTime.Now;
+                    }
+                    data.Modifier = "1";
+                    data.Modifytime = DateTime.Now;
+                    data.PersonId = userid;
+                    //OrderBanciOrderDTOSearch search = new OrderBanciOrderDTOSearch();
+                    //search.page = 1;
+                    //search.rows = 1000;
+                    //search.BanciId = data.BanciId;
+                    //ResultDataEntity<OrderBanciOrderDTO> resultDataEntity = _orderBanciOrderService.SearchByPaging(search);
+
+                    if (data.Baomingrenshu.HasValue)
+                    {
+                        //if (resultDataEntity.DataList.Count > 0)
+                        //{
+                        //  var orderBanciOrderDTO =   resultDataEntity.DataList.OrderByDescending(x => x.Baomingrenshu).FirstOrDefault();
+
+                        //    data.Baomingrenshu += orderBanciOrderDTO.Baomingrenshu;
+                        //}
+                    }
+                    else
+                    {
+                        //if (resultDataEntity.DataList.Count > 0)
+                        //{
+                        //    var orderBanciOrderDTO = resultDataEntity.DataList.OrderByDescending(x => x.Baomingrenshu).FirstOrDefault();
+
+                        //    data.Baomingrenshu = orderBanciOrderDTO.Baomingrenshu+1;
+                        //}
+                        //else
+                        //{
+                        data.Baomingrenshu = 1;
+                        //}   
+                    }
+                    //data.Jine = resultDataEntity.DataList.Sum(x => x.Xuefei);
+                    //data.Jine += data.Xuefei;
+                    ResultEntity resultEntity = _orderBanciOrderService.save(data);
+                    if (resultEntity.Result)
+                    {
+                        returnMsg.code = 1;
+                        returnMsg.count = 1;
+                        returnMsg.returnObj = data;
+                    }
+                    else
+                    {
+                        returnMsg.error = resultEntity.Message;
+                    }
+                    int OnePorints = 0;
+                   var orderBanciDTO = _orderBanciService.Get(data.BanciId);
+                   var  orderBanciDtlDTO = _orderBanciDtlService.GetList(data.BanciId).Where(x=>x.Shangxiawu == data.KechengleixingId).FirstOrDefault();
+                    if(orderBanciDtlDTO!=null&& orderBanciDtlDTO.Jifen.HasValue)
+                    {
+                        OnePorints = decimal.ToInt32(orderBanciDtlDTO.Jifen.Value); ;
+                    }
+                    else
+                    {
+                        returnMsg.code = 2;
+                        returnMsg.error = "璇ョ彮娆′笉鑳界Н鍒嗗厬鎹�";
+                        returnMsg.count = 0;
+                        return new JsonResult(returnMsg);
+                    }
+                    string huiyuanurl = _configuration.GetSection("huiyuanurl").Value;
+                    string GetYGYaoQingYonghu = _configuration.GetSection("PassPoints").Value;
+                    Uri postUrl2 = new Uri(huiyuanurl + GetYGYaoQingYonghu);
+                    JObject questions2 = new JObject();
+                    questions2.Add("UserID", data.PersonId);
+                    questions2.Add("GoodsName", data.Peixunbanci);
+                    questions2.Add("Content", data.Peixunbanci);
+                    questions2.Add("ToatlPorints", data.Baomingrenshu.Value* OnePorints);//璁$畻
+                    questions2.Add("OnePorints", OnePorints);//璁$畻
+                    questions2.Add("Count", data.Baomingrenshu);
+                    questions2.Add("OderID", data.Id);
+                    questions2.Add("describe", data.Peixunbanci +"绉垎鎶ュ悕");
+
+                    string requestJson2 = questions2.ToString();
+                    string result2 = string.Empty;
+
+                    result2 = HttpClientRequest.HttpClientPost(postUrl2.ToString(), "POST", requestJson2);
+
+                    //using (HttpContent httpContent = new StringContent(requestJson2))
+                    //{
+                    //    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
+
+                    //    var httpClient2 = _clientFactory.CreateClient();
+                    //    httpClient2.Timeout = new TimeSpan(0, 0, 60);
+                    //    var Result2 = await httpClient2.PostAsync(postUrl2, httpContent);
+                    //    result2 = Result2.Content.ReadAsStringAsync().Result;
+                    //}
+
+                    _logger.LogInformation("result2:" + result2);
+                    JObject jobjectresult = (JObject)JsonConvert.DeserializeObject(result2);
+
+                    if (jobjectresult["code"] != null && jobjectresult["code"].ToString() == "1")
+                    {
+                        string OaWriteTrainClassOder = _configuration.GetSection("OaWriteTrainClassOder").Value;
+                        Uri postUrl = new Uri(huiyuanurl + OaWriteTrainClassOder);
+                        JObject questions = new JObject();
+                        questions.Add("UserID", data.PersonId);
+                        questions.Add("TrainClass", data.Peixunbanci);
+                        questions.Add("TrainClassType", int.Parse(data.KechengleixingId));
+                        questions.Add("Name", data.Xingming);//璁$畻
+                        questions.Add("IdentificationNumber", data.Shenfenzheng);//璁$畻
+                        questions.Add("PhoneNo", data.Lianxidianhua);
+                        questions.Add("StartTime", orderBanciDTO.Shijian.Value.ToString("yyyy-MM-dd HH:mm:ss"));
+                        questions.Add("BanciId", data.BanciId);
+                        questions.Add("BanciAddr", orderBanciDTO.Didian);
+                        questions.Add("PersonCount", data.Baomingrenshu);
+                        questions.Add("Ptions", data.Baomingrenshu.Value * OnePorints);
+                        string requestJson = questions.ToString();
+                        string result = string.Empty;
+
+                        result = HttpClientRequest.HttpClientPost(postUrl.ToString(), "POST", requestJson);
+                        _logger.LogInformation("result:" + result);
+                        scope.Complete();
+                    }
+                    else
+                    {
+                        returnMsg.code = 2;
+                        returnMsg.error = jobjectresult["msg"].ToString();
+                        returnMsg.count = 0;
+                        return new JsonResult(returnMsg);
+                    }
+
+                  
+                }
+            }
+            catch (Exception ex)
+            {
+                returnMsg.code = 2;
+                returnMsg.error = "娌℃湁鑾峰彇鍒皌oken";
+                returnMsg.count = 0;
+
+            }
+
+            return new JsonResult(returnMsg);
+        }
+
+
 
         //鑾峰彇褰撳墠鐨勬姤鍚嶇殑浜烘暟
         public IActionResult GetBaoMingRenShu([FromBody] OrderBanciOrderDTOSearch search)

--
Gitblit v1.9.1