From f0226fac55f50b362d145ce969e66d41606a8b06 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期五, 30 七月 2021 14:13:16 +0800
Subject: [PATCH] 今日开发  订单优惠   下订单的时候计算优惠                访问申请

---
 zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs |  136 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 124 insertions(+), 12 deletions(-)

diff --git a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
index 3c67038..ba62186 100644
--- a/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
+++ b/zhengcaioa/zhengcaioa/Controllers/BusinessOrder/CooperOrderController.cs
@@ -19,6 +19,9 @@
 using Services;
 using System.Transactions;
 using System.IdentityModel.Tokens.Jwt;
+using Microsoft.Extensions.Configuration;
+using Newtonsoft.Json.Linq;
+using System.Net.Http.Headers;
 
 namespace zhengcaioa.Controllers.BusinessOrder
 {
@@ -35,11 +38,17 @@
         private readonly IFiBookService _fiBookService;
         private readonly IFiServiceService _fiServiceService;
         private readonly IFiMemberService _fiMemberService;
+        private readonly IConfiguration _configuration;
+        private readonly IHttpClientFactory _clientFactory;
+        private readonly IAskService _askService; 
 
 
         public CooperOrderController(ILogger<CooperOrderController> logger, ILiaotianService liaotianService, IUserService userService, ICooperOrderService cooperOrderService
             , ICooperatecustomCustomerService cooperatecustomCustomerService, IProjectService projectService, IPltPageService pltPageService, IFiBookService fiBookService
-            , IFiServiceService fiServiceService, IFiMemberService fiMemberService)
+            , IFiServiceService fiServiceService, IFiMemberService fiMemberService
+            , IConfiguration configuration
+            , IHttpClientFactory clientFactory
+            , IAskService askService)
         {
             _logger = logger;
             _liaotianService = liaotianService;
@@ -51,6 +60,9 @@
             _fiBookService = fiBookService;
             _fiServiceService = fiServiceService;
             _fiMemberService = fiMemberService;
+            _configuration = configuration;
+            _clientFactory = clientFactory;
+            _askService = askService;
         }
 
         [CheckLogin]
@@ -396,12 +408,14 @@
             {
                 dto = _cooperOrderService.Get(id);
                 ViewBag.ShouliStatus = ShouliStatus;
+                //ViewBag.YouHuiList = _askService.GetAskYouHuiList(dto.Khdw, dto.OrderType);
             }
             else
             {
                 dto.XdTime = DateTime.Now;
                 dto.OrderNum = 1;
                 ViewBag.ShouliStatus = "1";
+                //ViewBag.YouHuiList = new List<AdmAskYouHuiDTO>();
             }
 
 
@@ -447,11 +461,11 @@
         /// 
         [CheckLogin]
         [HttpPost]
-        public IActionResult Save(CooperOrderDTO data)
+        public async Task<IActionResult> SaveAsync(CooperOrderDTO data)
         {
             ResultEntity resultEntity = new ResultEntity();
-            using (TransactionScope scope = new TransactionScope())
-            {
+            //using (TransactionScope scope = new TransactionScope())
+            //{
                 var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
                 ViewData["curentuser"] = curentuser;
                 data.RecStatus = "A";
@@ -460,16 +474,114 @@
                     data.Creater = curentuser.Id;
                     data.Createtime = DateTime.Now;
                     data.XdTime = data.Createtime;
+                    if (data.OrderType == "03" || data.OrderType == "07" || (data.OrderType == "02" && (data.OrderType1 == "浠f嫙鎶曡瘔涔�" || data.OrderType1 == "浠f嫙璐ㄧ枒鍑�")))
+                    {
+                        var cooperatecustomCustomerDTO = _cooperatecustomCustomerService.Get(data.Khdw);
+                        if (cooperatecustomCustomerDTO != null && !string.IsNullOrEmpty(cooperatecustomCustomerDTO.HuiyuanId))
+                        {
+                            string huiyuanurl = _configuration.GetSection("huiyuanurl").Value;
+                            string SetCaseOrder = _configuration.GetSection("SetCaseOrder").Value;
+
+                            Uri postUrl2 = new Uri(huiyuanurl + SetCaseOrder);
+
+                            JObject questions2 = new JObject();
+                            questions2.Add("UserID", cooperatecustomCustomerDTO.HuiyuanId);
+                            if (data.OrderType == "03")
+                            {
+                                questions2.Add("CaseType", 0);
+                            }
+                            else if (data.OrderType == "07")
+                            {
+                                questions2.Add("CaseType", 1);
+                            }
+                            else if (data.OrderType == "07")
+                            {
+                                questions2.Add("CaseType", 1);
+                            }
+                            else if (data.OrderType == "02" && (data.OrderType1 == "浠f嫙鎶曡瘔涔�" || data.OrderType1 == "浠f嫙璐ㄧ枒鍑�"))
+                            {
+                                questions2.Add("CaseType", 2);
+                            }
+
+                            questions2.Add("count", Decimal.ToInt32(data.OrderNum.Value)  );
+
+                            string requestJson2 = questions2.ToString();
+                            string result2 = string.Empty;
+
+                            using (HttpContent httpContent = new StringContent(requestJson2))
+                            {
+                                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
+
+                                var httpClient2 = _clientFactory.CreateClient();
+                                httpClient2.Timeout = new TimeSpan(0, 0, 10);
+                                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")
+                            {
+                                resultEntity.Result = true;
+                            }
+                            else
+                            {
+                                resultEntity.Result = false;
+                                resultEntity.Message = "鍐欏叆浼氬憳璁㈠崟澶辫触";
+                                return new JsonResult(resultEntity);
+                            }
+                        }
+                    }
+
+
+                
+
+                    
+                }
+
+            var youHuiDTOs = _askService.GetAskYouHuiList(data.Khdw, data.OrderType).FirstOrDefault();
+            if (youHuiDTOs != null)
+            {
+                data.Youhuier = youHuiDTOs.Id;
+                if(youHuiDTOs.Youhuistandard == "01")
+                {
+                    data.Youhui = youHuiDTOs.YouHui.Value;
+                    if(data.Money.Value < data.Youhui.Value)
+                    {
+                        data.Money = 0;
+                    }
+                    else
+                    {
+                        data.Money = data.Money.Value - data.Youhui.Value;
+                    }
                    
                 }
-                data.ShouliStatus = "1";
-                data.Modifier = curentuser.Id;
-                data.Modifytime = DateTime.Now;
-
-                resultEntity = _cooperOrderService.save(data);
-                scope.Complete();
+                else if (youHuiDTOs.Youhuistandard == "02")
+                {
+                    if (youHuiDTOs.YouHui.Value >= 100)
+                    {
+                        data.Youhui = data.Money.Value;
+                        data.Money = 0;
+                    }
+                    else
+                    {
+                        data.Youhui =Math.Round(data.Money.Value * youHuiDTOs.YouHui.Value * new decimal(0.01),2);
+                        data.Money = data.Money.Value - data.Youhui.Value;
+                    }
+                }
+                  
+                  
             }
-           
+            
+            data.ShouliStatus = "1";
+            data.Modifier = curentuser.Id;
+            data.Modifytime = DateTime.Now;
+
+            resultEntity = _cooperOrderService.save(data);
+            //    scope.Complete();
+            //}
+
 
             return new JsonResult(resultEntity);
         }
@@ -775,7 +887,7 @@
                 result = JsonConvert.SerializeObject(shi);
             }
 
-            if (OrderType == "08" || OrderType == "10")
+            if (OrderType == "08" || OrderType == "10" || OrderType == "11")
             {
                
                 result = "[]";

--
Gitblit v1.9.1