足力健后端,使用.netcore版本,合并1个项目使用

OrderController.cs 170KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553
  1. /* =============================================
  2. -- Author: <Author,,zhangkun>
  3. -- Create date: <Create Date,,20200618>
  4. -- Description: <Description,,订单相关操作)>
  5. -- ============================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Common;
  9. using System.Common.Helpers;
  10. using System.Data;
  11. using System.IRepositories;
  12. using System.IRepositories.Bus;
  13. using System.IRepositories.Cus;
  14. using System.Linq;
  15. using System.Linq.Expressions;
  16. using System.Model;
  17. using System.Model.Bus;
  18. using System.Model.Cus;
  19. using System.Repositories;
  20. using System.Security.Claims;
  21. using System.Text.RegularExpressions;
  22. using System.Threading.Tasks;
  23. using System.Utility.Http;
  24. using Microsoft.AspNetCore.Mvc;
  25. using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
  26. using Microsoft.Extensions.Configuration;
  27. using SqlSugar;
  28. using TVShoppingCallCenter_ZLJ.Models.Inputs;
  29. namespace TVShoppingCallCenter_ZLJ.Controllers.Order
  30. {
  31. [Produces("application/json")]
  32. [Route("api/[controller]")]
  33. public class OrderController : BaseController
  34. {
  35. private readonly IBus_OrderDetailRepository bus_OrderDetailRepository;
  36. private readonly IBus_OrderRepository bus_OrderRepository;
  37. private readonly ISys_MarketingRepository bus_MarketingRepository;
  38. private readonly IBus_ProductRepository bus_productRepository;
  39. private readonly ICus_VipInfoRepository cus_vip_infoRepository;
  40. private readonly IBus_StockLogRepository bus_StockLogRepository;
  41. private readonly ICus_ScoreSetRepository cus_score_setRepository;
  42. private readonly IBus_OrderMoneyRepository busOrderMoneyRepository;
  43. private readonly IConfiguration config;
  44. private readonly IBus_AfterSaleRepository busAfterSaleRepository;
  45. private readonly IBus_OrderlogsRepository busOrderlogsRepository;
  46. private readonly IBus_ChatLogRepository bus_ChatLogRepository;
  47. private readonly ICus_MembershipRepository _cus_membershiprepository;
  48. private readonly ISys_UserAccountRepository _sys_useraccountRepository;
  49. private readonly OrderFunctionController busOrderFunctionController;
  50. public OrderController(IBus_OrderMoneyRepository _busOrderMoneyRepository,OrderFunctionController _OrderFunctionController,ICus_ScoreSetRepository _cus_score_setRepository, IBus_StockLogRepository _bus_StockLogRepository, IBus_OrderRepository _bus_OrderRepository, IBus_OrderDetailRepository _bus_OrderDetailRepository, ISys_MarketingRepository _bus_MarketingRepository, IBus_ProductRepository _productRepository, ICus_VipInfoRepository _cus_vip_infoRepository, IConfiguration _configuration, IBus_AfterSaleRepository _busAfterSaleRepository, IBus_OrderlogsRepository _busOrderlogsRepository, IBus_ChatLogRepository _bus_ChatLogRepository, ICus_MembershipRepository cus_membershiprepository
  51. , ISys_UserAccountRepository sys_useraccountRepository)
  52. {
  53. bus_OrderDetailRepository = _bus_OrderDetailRepository;
  54. bus_OrderRepository = _bus_OrderRepository;
  55. bus_MarketingRepository = _bus_MarketingRepository;
  56. bus_productRepository = _productRepository;
  57. cus_vip_infoRepository = _cus_vip_infoRepository;
  58. bus_StockLogRepository = _bus_StockLogRepository;
  59. cus_score_setRepository = _cus_score_setRepository;
  60. config = _configuration;
  61. busOrderFunctionController = _OrderFunctionController;
  62. busOrderMoneyRepository = _busOrderMoneyRepository;
  63. busAfterSaleRepository = _busAfterSaleRepository;
  64. busOrderlogsRepository = _busOrderlogsRepository;
  65. bus_ChatLogRepository = _bus_ChatLogRepository;
  66. _cus_membershiprepository = cus_membershiprepository;
  67. _sys_useraccountRepository = sys_useraccountRepository;
  68. }
  69. #region
  70. /// <summary>
  71. /// 创建订单
  72. /// </summary>
  73. /// <param name="input"></param>
  74. /// <returns></returns>
  75. // [HttpPost("addorder")]
  76. /**public async Task<IActionResult> AddOrder([FromBody]OrderInput input)
  77. {
  78. try {
  79. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  80. #region 验证参数 必填项
  81. if (string.IsNullOrEmpty(input.F_ADFrom))
  82. return Error("请输入选择广告来源");
  83. if (string.IsNullOrEmpty(input.F_Type))
  84. return Error("请输入选择订单类型");
  85. if (string.IsNullOrEmpty(input.F_Id))
  86. return Error("请输入订单编号");
  87. if (string.IsNullOrEmpty(input.F_Customer))
  88. return Error("请输入客户姓名");
  89. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  90. return Error("请输入客户电话");
  91. if (input.F_Type=="售后订单")
  92. return Error("售后订单只能根据售后单自动创建");
  93. #endregion
  94. int exist = await bus_OrderRepository.GetCount(q => q.F_Id == input.F_Id);
  95. if (exist > 0)
  96. {
  97. return Error("此订单号已存在");
  98. }
  99. T_Bus_Order modelOrder = new T_Bus_Order();
  100. #region 订单属性
  101. //必填
  102. modelOrder.F_ADFrom = input.F_ADFrom;
  103. modelOrder.F_Type = input.F_Type;
  104. modelOrder.F_Id = input.F_Id;
  105. modelOrder.F_Customer = input.F_Customer;
  106. modelOrder.F_CustomerPhone = input.F_CustomerPhone;
  107. if (input.F_RecommendId>0)
  108. {
  109. modelOrder.F_RecommendId = input.F_RecommendId;
  110. modelOrder.F_RecommendName = input.F_RecommendName;
  111. }
  112. if (input.F_CustomerType > 0)
  113. { modelOrder.F_CustomerType = input.F_CustomerType; }
  114. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  115. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  116. //选填 快递属性
  117. modelOrder.F_TrackingNo = "";
  118. if (!string.IsNullOrEmpty(input.F_Addressee))
  119. { modelOrder.F_Addressee = input.F_Addressee; }
  120. if (!string.IsNullOrEmpty(input.F_AddPhone))
  121. { modelOrder.F_AddPhone = input.F_AddPhone; }
  122. if (!string.IsNullOrEmpty(input.F_AddProvince))
  123. { modelOrder.F_AddProvince = input.F_AddProvince; }
  124. if (!string.IsNullOrEmpty(input.F_AddCity))
  125. { modelOrder.F_AddCity = input.F_AddCity; }
  126. if (!string.IsNullOrEmpty(input.F_AddArea))
  127. { modelOrder.F_AddArea = input.F_AddArea; }
  128. if (!string.IsNullOrEmpty(input.F_AddTown))
  129. { modelOrder.F_AddTown = input.F_AddTown; }
  130. if (!string.IsNullOrEmpty(input.F_AddDes))
  131. { modelOrder.F_AddDes = input.F_AddDes; }
  132. if (!string.IsNullOrEmpty(input.F_Address))
  133. { modelOrder.F_Address = input.F_Address; }
  134. if (!string.IsNullOrEmpty(input.F_PostalCode))
  135. { modelOrder.F_PostalCode = input.F_PostalCode; }
  136. if (!string.IsNullOrEmpty(input.F_Express))
  137. { modelOrder.F_Express = input.F_Express; }
  138. if (!string.IsNullOrEmpty(input.F_Remark))
  139. { modelOrder.F_Remark = input.F_Remark; }
  140. if (!string.IsNullOrEmpty(input.F_PayType))
  141. { modelOrder.F_PayType = input.F_PayType; }
  142. if
  143. (input.F_VipId > 0)
  144. { modelOrder.F_VipId = input.F_VipId; }
  145. else
  146. {
  147. var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
  148. && x.F_State == 1);
  149. if (vip != null && vip.Count > 0)
  150. modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
  151. else
  152. modelOrder.F_VipId = 0;
  153. }
  154. if (input.F_Belong > 0)
  155. {
  156. modelOrder.F_Belong = input.F_Belong;
  157. modelOrder.F_BelongName = input.F_BelongName;
  158. }
  159. else
  160. {
  161. modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
  162. modelOrder.F_BelongName = UserLogin.UserName;
  163. }
  164. modelOrder.F_ExpressFee = input.F_ExpressFee;
  165. modelOrder.F_Stock = input.F_Stock;
  166. modelOrder.F_RealPrice = input.F_RealPrice;
  167. modelOrder.F_UseScore = input.F_UseScore;
  168. //选填 关联属性
  169. modelOrder.F_State = input.F_State;
  170. modelOrder.F_Status = 0;
  171. //必须属性 系统生成
  172. modelOrder.F_AddTime = DateTime.Now;
  173. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  174. modelOrder.F_AddUserName = UserLogin.UserName;
  175. #endregion
  176. if (input.F_State == 1)
  177. {
  178. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  179. { }
  180. else
  181. { return Error("请选择订购商品"); }
  182. if (string.IsNullOrEmpty(input.F_Stock))
  183. {
  184. return Error("请选择出库货仓");
  185. }
  186. if (string.IsNullOrEmpty(modelOrder.F_Express))
  187. {
  188. return Error("快递不能为空");
  189. }
  190. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  191. {
  192. return Error("收件人电话不能为空");
  193. }
  194. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  195. {
  196. return Error("收件人地址不能为空");
  197. }
  198. if (string.IsNullOrEmpty(modelOrder.F_Address))
  199. {
  200. return Error("收件人详细地址不能为空");
  201. }
  202. }
  203. decimal totle = 0.00M;
  204. decimal ActivityMoney = 0.00M;
  205. string UseActivity = "";
  206. string UseActivity4 = ",";
  207. string UseActivity2 = ",";
  208. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  209. #region 订单详情列表核算
  210. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  211. {
  212. int n = 1;
  213. int n2 = input.OrderDetailList.Count + 1;
  214. #region 活动核算
  215. if (input.UseActList != null && input.UseActList.Count > 0)
  216. {
  217. //遍历所有选中的活动
  218. foreach (UseActInput act in input.UseActList)
  219. {
  220. UseActivity += act.id + ",";
  221. //满赠
  222. if (act.type == 1)
  223. {
  224. string[] productidlist = act.gift.Split(',');
  225. foreach (string giftid in productidlist)
  226. {
  227. T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
  228. if (m != null)
  229. {
  230. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  231. modelDetail.F_ProductName = m.F_ProductName;
  232. modelDetail.F_ProductId = m.F_ProductId;
  233. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  234. modelDetail.F_OrderId = input.F_Id;
  235. modelDetail.F_Count = 1;
  236. modelDetail.F_Price = 0.00M;
  237. modelDetail.F_DealPrice = 0.00M;
  238. modelDetail.F_Sort = n2;
  239. modelDetail.F_Remark = "赠品-活动:" + act.id;
  240. modelDetail.F_AddUser = modelOrder.F_AddUser;
  241. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  242. modelDetail.F_TotlePrice = 0.00M;
  243. modelDetail.F_Activity = act.id;
  244. modelDetail.F_AddTime = DateTime.Now;
  245. modelDetailList.Add(modelDetail);
  246. n2++;
  247. }
  248. }
  249. }
  250. //生日赠
  251. else if (act.type == 2)
  252. {
  253. UseActivity2 += act.gift + ",";
  254. }
  255. //满减
  256. else if (act.type == 3)
  257. {
  258. ActivityMoney += act.money;
  259. }
  260. else if (act.type == 4)
  261. {
  262. UseActivity4 += act.gift + ",";
  263. }
  264. }
  265. UseActivity = UseActivity.Trim(',');
  266. }
  267. #endregion
  268. #region 商品核算
  269. foreach (OrderDetailInput m in input.OrderDetailList)
  270. {
  271. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  272. if (modelProduct == null)
  273. return Error("商品不存在:" + m.F_ProductId);
  274. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  275. modelDetail.F_ProductName = modelProduct.F_ProductName;
  276. modelDetail.F_ProductId = modelProduct.F_ProductId;
  277. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  278. modelDetail.F_OrderId = input.F_Id;
  279. modelDetail.F_Count = m.F_Count;
  280. modelDetail.F_Price = modelProduct.F_MemberPrice;
  281. //参加活动特价
  282. if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
  283. modelDetail.F_DealPrice = modelProduct.F_SpecialPrice;
  284. else
  285. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  286. //参加生日
  287. if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
  288. {
  289. modelDetail.F_DealPrice = 0.00M;
  290. modelDetail.F_Remark = "生日赠品-活动:";
  291. }
  292. modelDetail.F_Sort = n;
  293. modelDetail.F_AddTime = DateTime.Now;
  294. modelDetail.F_AddUser = modelOrder.F_AddUser;
  295. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  296. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  297. modelDetail.F_Activity = 0;
  298. if (modelProduct.F_Tag.IndexOf(".") > -1&& !string.IsNullOrEmpty(UseActivity))
  299. {
  300. string[] tagarry = modelProduct.F_Tag.Split(',');
  301. string[] actlist = UseActivity.Split(',');
  302. string tag = tagarry.First(a => a.StartsWith(".")).ToString();
  303. T_Sys_Marketing modelactive = await bus_MarketingRepository.GetFirst(b => actlist.Contains(b.F_ID.ToString())&& b.F_EndTime >= DateTime.Now && b.F_StartTime <= DateTime.Now && b.F_IsDelete == 0 && ("," + b.F_Commodity + ",").Contains(("," + tag + ",")));
  304. //此商品参加活动
  305. if (modelactive != null)
  306. {
  307. modelDetail.F_Activity = modelactive.F_ID;
  308. }
  309. }
  310. else { modelDetail.F_Activity = 0; }
  311. totle += modelDetail.F_TotlePrice;
  312. modelDetailList.Add(modelDetail);
  313. n++;
  314. }
  315. #endregion
  316. modelOrder.F_TotlePrice = totle;
  317. modelOrder.F_ActivityMoney = ActivityMoney;
  318. modelOrder.F_UseActivity = UseActivity;
  319. }
  320. else
  321. {
  322. //不改变订单
  323. }
  324. #endregion
  325. //订单完成后也不计算积分
  326. modelOrder.F_Score = 0.00M;
  327. T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
  328. if (modelscore == null)
  329. {
  330. modelscore = new T_Cus_ScoreSet();
  331. modelscore.F_Start = 0;
  332. modelscore.F_StartDebit = 1;
  333. modelscore.F_DebitPercent = 1000;
  334. }
  335. #region 直接提交 锁库存log 锁积分log
  336. if (input.F_State == 1)
  337. {
  338. if (modelscore.F_StartDebit == 0 || modelOrder.F_VipId == 0)
  339. {
  340. modelOrder.F_UseScore = 0;
  341. }
  342. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss")+"U" + UserLogin.UserId +"R"+ new Random().Next(9);
  343. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
  344. if (strStock != "1")
  345. { return Error(strStock); }
  346. if (modelscore.F_Start == 1)
  347. {
  348. //订单完成后计算积分
  349. modelOrder.F_Score = -0.01M;
  350. }
  351. modelOrder.F_SubmitTime = DateTime.Now;
  352. }
  353. #endregion
  354. //计算结果 积分有规则
  355. modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - ActivityMoney + modelOrder.F_ExpressFee- modelOrder.F_UseScore / modelscore.F_DebitPercent;
  356. modelOrder.F_PayState = 0;
  357. if (await bus_OrderRepository.AddReturnCount(modelOrder))
  358. {
  359. if (modelDetailList != null && modelDetailList.Count > 0)
  360. {
  361. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  362. return Success("订单添加成功2");
  363. else
  364. return Error("订单添加失败,请重试!1");
  365. }
  366. return Success("订单添加成功1");
  367. }
  368. else
  369. {
  370. return Error("订单添加失败,请重试!2");
  371. }
  372. }
  373. catch (Exception ex)
  374. { return Error(ex.Message); }
  375. }**/
  376. #endregion
  377. /// <summary>
  378. /// 创建订单
  379. /// </summary>
  380. /// <param name="input"></param>
  381. /// <returns></returns>
  382. [HttpPost("addorder")]
  383. public async Task<IActionResult> AddOrder([FromBody]OrderInput input)
  384. {
  385. try
  386. {
  387. #region 验证参数 必填项
  388. if (string.IsNullOrEmpty(input.F_ADFrom))
  389. return Error("请输入选择广告来源");
  390. if (string.IsNullOrEmpty(input.F_Type))
  391. return Error("请输入选择订单类型");
  392. if (string.IsNullOrEmpty(input.F_Id))
  393. return Error("请输入订单编号");
  394. if (string.IsNullOrEmpty(input.F_Customer))
  395. return Error("请输入客户姓名");
  396. if (string.IsNullOrEmpty(input.F_AddPhone))
  397. {
  398. return Error("收件人电话不能为空");
  399. }
  400. if (string.IsNullOrEmpty(input.F_AddProvince ))
  401. {
  402. return Error("收件人省份不能为空");
  403. }
  404. if (string.IsNullOrEmpty(input.F_AddCity ))
  405. {
  406. return Error("收件人城市不能为空");
  407. }
  408. if (string.IsNullOrEmpty(input.F_AddArea ))
  409. {
  410. return Error("收件人区/县不能为空");
  411. }
  412. if (string.IsNullOrEmpty(input.F_Address ))
  413. {
  414. return Error("收件人详细地址不能为空");
  415. }
  416. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  417. return Error("请输入客户电话");
  418. if (input.F_Type == "售后订单")
  419. return Error("售后订单只能根据售后单自动创建");
  420. #endregion
  421. int exist = await bus_OrderRepository.GetCount(q => q.F_Id == input.F_Id);
  422. if (exist > 0)
  423. {
  424. return Error("此订单号已存在");
  425. }
  426. T_Bus_Order modelOrder = new T_Bus_Order();
  427. #region 订单属性
  428. //必填
  429. modelOrder.F_ADFrom = input.F_ADFrom;
  430. modelOrder.F_Type = input.F_Type;
  431. modelOrder.F_Id = input.F_Id;
  432. modelOrder.F_Customer = input.F_Customer;
  433. modelOrder.F_CustomerPhone = input.F_CustomerPhone;
  434. if (input.F_RecommendId > 0)
  435. {
  436. modelOrder.F_RecommendId = input.F_RecommendId;
  437. modelOrder.F_RecommendName = input.F_RecommendName;
  438. }
  439. if (input.F_CustomerType > 0)
  440. { modelOrder.F_CustomerType = input.F_CustomerType; }
  441. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  442. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  443. //选填 快递属性
  444. modelOrder.F_TrackingNo = "";
  445. if (!string.IsNullOrEmpty(input.F_Addressee))
  446. { modelOrder.F_Addressee = input.F_Addressee; }
  447. if (!string.IsNullOrEmpty(input.F_AddPhone))
  448. { modelOrder.F_AddPhone = input.F_AddPhone; }
  449. if (!string.IsNullOrEmpty(input.F_AddProvince))
  450. { modelOrder.F_AddProvince = input.F_AddProvince; }
  451. if (!string.IsNullOrEmpty(input.F_AddCity))
  452. { modelOrder.F_AddCity = input.F_AddCity; }
  453. if (!string.IsNullOrEmpty(input.F_AddArea))
  454. { modelOrder.F_AddArea = input.F_AddArea; }
  455. if (!string.IsNullOrEmpty(input.F_AddTown))
  456. { modelOrder.F_AddTown = input.F_AddTown; }
  457. if (!string.IsNullOrEmpty(input.F_AddDes))
  458. { modelOrder.F_AddDes = input.F_AddDes; }
  459. if (!string.IsNullOrEmpty(input.F_Address))
  460. { modelOrder.F_Address = input.F_Address; }
  461. if (!string.IsNullOrEmpty(input.F_PostalCode))
  462. { modelOrder.F_PostalCode = input.F_PostalCode; }
  463. // if (!string.IsNullOrEmpty(input.F_Express))
  464. // { modelOrder.F_Express = input.F_Express; }
  465. if (!string.IsNullOrEmpty(input.F_Remark))
  466. { modelOrder.F_Remark = input.F_Remark; }
  467. if (!string.IsNullOrEmpty(input.F_PayType))
  468. { modelOrder.F_PayType = input.F_PayType; }
  469. if
  470. (input.F_VipId > 0)
  471. { modelOrder.F_VipId = input.F_VipId; }
  472. else
  473. {
  474. var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
  475. && x.F_State == 1);
  476. if (vip != null && vip.Count > 0)
  477. modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
  478. else
  479. modelOrder.F_VipId = 0;
  480. }
  481. var modelvip= await cus_vip_infoRepository.GetSingle (x => x.F_ID == modelOrder.F_VipId);
  482. if (modelvip!=null )
  483. {
  484. modelOrder.F_Belong = modelvip.F_Saleperson.ObjToInt();
  485. var user = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelOrder.F_Belong);
  486. modelOrder.F_BelongName = user.F_UserName ;
  487. if (modelOrder.F_AddTime!=null )
  488. {
  489. TimeSpan time = modelOrder.F_AddTime - DateTime.Now;
  490. if (time.Days >3)
  491. {
  492. modelOrder.F_Type = "回访";
  493. }
  494. else
  495. {
  496. modelOrder.F_Type = "热线";
  497. }
  498. }
  499. }
  500. else if (input.F_Belong > 0)
  501. {
  502. modelOrder.F_Belong = UserLogin.UserId .ObjToInt();
  503. modelOrder.F_BelongName = UserLogin.UserName;
  504. }
  505. if (input .F_Media>0)
  506. {
  507. modelOrder.F_Media = input.F_Media;
  508. modelOrder.F_MediaName = input.F_MediaName;
  509. }
  510. var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelvip.F_Saleperson.ObjToInt());
  511. if (useraccount != null )
  512. {
  513. modelOrder.F_Department = useraccount.F_DeptId;
  514. modelOrder.F_Core = useraccount.F_DeptTeamId ;
  515. modelOrder.F_Group = useraccount.F_GroupId;
  516. }
  517. modelOrder.F_ExpressFee = input.F_ExpressFee;
  518. // modelOrder.F_Stock = input.F_Stock;
  519. modelOrder.F_IsExpress = 0;
  520. modelOrder.F_RealPrice = input.F_RealPrice;
  521. modelOrder.F_MemberNotes = input.F_MemberNotes;//会员备注
  522. modelOrder.F_UseScore = input.F_UseScore;
  523. modelOrder.F_State = 0;
  524. //选填 关联属性
  525. modelOrder.F_Status = 0;
  526. modelOrder.F_IsPayment = input.F_IsPayment;
  527. //必须属性 系统生成
  528. modelOrder.F_AddTime = DateTime.Now;
  529. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  530. modelOrder.F_AddUserName = UserLogin.UserName;
  531. #endregion
  532. decimal totle = 0.00M;
  533. decimal ActivityMoney = 0.00M;
  534. string UseActivity = "";
  535. string UseActivity4 = ",";
  536. string UseActivity2 = ",";
  537. string Eventprice = "";
  538. Dictionary<string, decimal> innerCompute = new Dictionary<string, decimal>();
  539. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  540. Dictionary<string, int> innerEventprice = new Dictionary<string, int >();
  541. #region 订单详情列表核算
  542. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  543. {
  544. int n = 1;
  545. int n2 = input.OrderDetailList.Count + 1;
  546. #region 活动核算
  547. if (input.UseActList != null && input.UseActList.Count > 0)
  548. {
  549. //遍历所有选中的活动
  550. foreach (UseActInput act in input.UseActList)
  551. {
  552. UseActivity += act.id + ",";
  553. //满赠
  554. //if (act.type == 1)
  555. //{
  556. // string[] productidlist = act.gift.Split(',');
  557. // foreach (string giftid in productidlist)
  558. // {
  559. // T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
  560. // if (m != null)
  561. // {
  562. // T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  563. // modelDetail.F_ProductName = m.F_ProductName;
  564. // modelDetail.F_ProductId = m.F_ProductId;
  565. // modelDetail.F_Specifications = m.F_Specifications;
  566. // modelDetail.F_ProductShortName = m.F_ProductShortName;
  567. // modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  568. // modelDetail.F_OrderId = input.F_Id;
  569. // modelDetail.F_Count = 1;
  570. // modelDetail.F_Price = 0.00M;
  571. // modelDetail.F_DealPrice = 0.00M;
  572. // modelDetail.F_Sort = n2;
  573. // modelDetail.F_Remark = "赠品-活动:" + act.id;
  574. // modelDetail.F_AddUser = modelOrder.F_AddUser;
  575. // modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  576. // modelDetail.F_TotlePrice = 0.00M;
  577. // modelDetail.F_Activity = act.id;
  578. // modelDetail.F_AddTime = DateTime.Now;
  579. // modelDetailList.Add(modelDetail);
  580. // n2++;
  581. // }
  582. // }
  583. //}
  584. ////生日赠
  585. //else
  586. if (act.type == 2)
  587. {
  588. UseActivity2 += act.gift + ",";
  589. }
  590. //满减
  591. else if (act.type == 3)
  592. {
  593. ActivityMoney += act.money;
  594. if (string.IsNullOrEmpty(Eventprice))
  595. Eventprice = "" + act.id + "," + act.money;
  596. else
  597. Eventprice += "|" + act.id + "," + act.money;
  598. }
  599. else if (act.type == 4)
  600. {
  601. UseActivity4 += act.gift + ",";
  602. innerCompute.Add(act.gift, act.money);
  603. innerEventprice.Add(act.gift, act.id );
  604. }
  605. }
  606. UseActivity = UseActivity.Trim(',');
  607. }
  608. #endregion
  609. modelOrder.F_IsZeroCommodity = 0;
  610. #region 商品核算
  611. foreach (OrderDetailInput m in input.OrderDetailList)
  612. {
  613. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  614. if (modelProduct == null)
  615. return Error("商品不存在:" + m.F_ProductName );
  616. if (modelProduct.F_OnSaleEnd<DateTime .Now &&UserLogin.RoleCode != "SH")
  617. {
  618. return Error ("商品已下架:" + m.F_ProductName);
  619. }
  620. if (!modelOrder.F_Type.Contains("售后"))
  621. {
  622. // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(modelProduct.F_ProductId, "新乡仓");
  623. if (modelProduct.F_MinimumStock+ m.F_Count > modelProduct.F_Stock1 )
  624. {
  625. return Error(m.F_ProductName + "数量库存低于" + modelProduct.F_MinimumStock + "不能添加");
  626. }
  627. }
  628. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  629. modelDetail.F_ProductName = modelProduct.F_ProductName;
  630. modelDetail.F_ProductId = modelProduct.F_ProductId;
  631. modelDetail.F_Specifications = modelProduct.F_Specifications;
  632. modelDetail.F_ProductShortName = modelProduct.F_ProductShortName;
  633. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  634. modelDetail.F_OrderId = input.F_Id;
  635. modelDetail.F_Count = m.F_Count;
  636. modelDetail.F_Price = modelProduct.F_MemberPrice;
  637. //参加活动特价
  638. if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
  639. {
  640. if (innerCompute.ContainsKey (modelProduct.F_ProductId))
  641. {
  642. ActivityMoney += innerCompute[modelProduct.F_ProductId] * m.F_Count;
  643. if (!string .IsNullOrEmpty (Eventprice))
  644. Eventprice += "|" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
  645. else
  646. Eventprice += "" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
  647. }
  648. }
  649. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  650. //参加生日
  651. if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
  652. {
  653. modelDetail.F_DealPrice = 0.00M;
  654. modelDetail.F_Remark = "生日赠品-活动:";
  655. }
  656. if (modelProduct.F_ClassName =="袜子" && modelDetail.F_DealPrice == 0)
  657. {
  658. modelOrder.F_IsZeroCommodity = 1;
  659. }
  660. modelDetail.F_Sort = n;
  661. modelDetail.F_AddTime = DateTime.Now;
  662. modelDetail.F_AddUser = modelOrder.F_AddUser;
  663. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  664. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  665. modelDetail.F_Activity = 0;
  666. if (modelProduct.F_Tag.IndexOf(".") > -1 && !string.IsNullOrEmpty(UseActivity))
  667. {
  668. string[] tagarry = modelProduct.F_Tag.Split(',');
  669. string[] actlist = UseActivity.Split(',');
  670. string tag = tagarry.First(a => a.StartsWith(".")).ToString();
  671. T_Sys_Marketing modelactive = await bus_MarketingRepository.GetFirst(b => actlist.Contains(b.F_ID.ToString()) && b.F_EndTime >= DateTime.Now && b.F_StartTime <= DateTime.Now && b.F_IsDelete == 0 && ("," + b.F_Commodity + ",").Contains(("," + tag + ",")));
  672. //此商品参加活动
  673. if (modelactive != null)
  674. {
  675. modelDetail.F_Activity = modelactive.F_ID;
  676. }
  677. }
  678. else { modelDetail.F_Activity = 0; }
  679. totle += modelDetail.F_TotlePrice;
  680. modelDetailList.Add(modelDetail);
  681. n++;
  682. }
  683. #endregion
  684. modelOrder.F_TotlePrice = totle;
  685. modelOrder.F_ActivityMoney = ActivityMoney;
  686. modelOrder.F_Eventprice = Eventprice;
  687. modelOrder.F_UseActivity = UseActivity;
  688. }
  689. else
  690. {
  691. //不改变订单
  692. }
  693. #endregion
  694. // modelOrder.F_TotlePrice += input.F_ExpressFee;//订单总额(包括快递费)
  695. modelOrder.F_RecommenderTel = input.F_RecommenderTel;
  696. modelOrder.F_PayState = 0;
  697. if (input .F_State ==1)
  698. {
  699. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  700. { }
  701. else
  702. { return Error("请选择订购商品"); }
  703. //List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
  704. // if (modelDetailList != null && modelDetailList.Count > 0)
  705. // {
  706. // foreach (var it in modelDetailList)
  707. // {
  708. // T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == it.F_ProductId);
  709. // if (t_Bus_Product != null)
  710. // {
  711. // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(it.F_ProductId, "新乡仓");
  712. // t_Bus_Product.F_UseNumber += it.F_Count;
  713. // if (listStock1!=null && listStock1.Count > 0)
  714. // {
  715. // if (t_Bus_Product.F_UseNumber > listStock1[0].qty)
  716. // {
  717. // return Error("提交失败,可配量不足.");
  718. // }
  719. // else
  720. // {
  721. // Productlist.Add(t_Bus_Product);
  722. // }
  723. // }
  724. // else
  725. // return Error("提交失败,可配量不足.");
  726. // }
  727. // else
  728. // {
  729. // return Error("提交失败,商品不存在");
  730. // }
  731. // }
  732. // await bus_productRepository.UpdateList(Productlist);
  733. // }
  734. modelOrder.F_SubmitTime = DateTime.Now;
  735. if (modelOrder.F_IsPayment > 0|| modelOrder.F_PayType != "货到付款")
  736. modelOrder.F_State = 7;
  737. else
  738. modelOrder.F_State = 0;
  739. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
  740. }
  741. T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
  742. if (modelscore == null)
  743. {
  744. modelscore = new T_Cus_ScoreSet();
  745. modelscore.F_Start = 0;
  746. modelscore.F_StartDebit = 1;
  747. modelscore.F_DebitPercent = 1000;
  748. }
  749. string count = UserLogin.UserName + "创建订单";
  750. if (!modelOrder.F_Type.Contains("售后"))
  751. {
  752. string a = string.Format("{0:f0}", Math.Floor(modelOrder.F_UseScore / modelscore.F_DebitPercent));
  753. modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney - int.Parse(a) + input.F_ExpressFee; if (input.OrderUserGift != null && input.OrderUserGift.Count > 0)
  754. {
  755. decimal moneys = 0.00M;
  756. if (modelvip.F_Money != null)
  757. {
  758. moneys= (decimal)modelvip.F_Money + modelOrder.F_ShouldPrice;
  759. }
  760. else
  761. moneys = modelOrder.F_ShouldPrice;
  762. int b = 0;
  763. if (moneys > 3000)
  764. {
  765. decimal fund = moneys - 3000;
  766. string c = string.Format("{0:f0}", Math.Floor(fund / 2000));
  767. b = int.Parse(c) + 1 - modelvip.F_UseGift;
  768. }
  769. int n2 = 0;
  770. foreach (var m in input.OrderUserGift)
  771. {
  772. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  773. modelDetail.F_ProductName = m.F_ProductName;
  774. modelDetail.F_ProductId = m.F_ProductId;
  775. modelDetail.F_Specifications = m.F_Specifications;
  776. modelDetail.F_ProductShortName = m.F_ProductShortName;
  777. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  778. modelDetail.F_OrderId = input.F_Id;
  779. modelDetail.F_Count = 1;
  780. modelDetail.F_Price = 0.00M;
  781. modelDetail.F_DealPrice = 0.00M;
  782. modelDetail.F_Sort = n2;
  783. modelDetail.F_Remark = "满赠营销" ;
  784. modelDetail.F_AddUser = modelOrder.F_AddUser;
  785. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  786. modelDetail.F_TotlePrice = 0.00M;
  787. modelDetail.F_Activity =0;
  788. modelDetail.F_AddTime = DateTime.Now;
  789. modelDetailList.Add(modelDetail);
  790. n2++;
  791. }
  792. if (n2> b)
  793. {
  794. return Error("该会员最多可赠送"+ b+"件赠品");
  795. }
  796. else
  797. {
  798. modelvip.F_UseGift += n2;
  799. modelOrder.F_UseGift = n2;
  800. }
  801. }
  802. if (modelvip != null)
  803. {
  804. modelvip.F_Score -= modelOrder.F_UseScore;
  805. // modelvip.F_TotalScore -= modelOrder.F_UseScore;
  806. await cus_vip_infoRepository.Update(modelvip);
  807. }
  808. //订单完成后也不计算积分
  809. if (input.F_State == 1)
  810. {
  811. if (modelOrder.F_State == 1)
  812. count += "进入客服待分仓";
  813. else if (modelOrder.F_State == 7)
  814. count += "进入客服待付款待审核";
  815. }
  816. else
  817. count += "进入销售待提交";
  818. }
  819. if (input.F_IsPayment > 0 || input.F_PayType != "货到付款")
  820. {
  821. try
  822. {
  823. #region 验证参数 必填项
  824. if (string.IsNullOrEmpty(input.F_Id))
  825. return Error("请输入订单号");
  826. if (string.IsNullOrEmpty(input.F_PayType))
  827. return Error("请选择付款方式");
  828. // if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkKF))
  829. // input.OrderMoney.F_RemarkKF = "";
  830. if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkXS))
  831. input.OrderMoney.F_RemarkXS = "";
  832. // if (input.OrderMoney.F_PayTime == null)
  833. // return Error("请选择打款时间");
  834. if (input.OrderMoney.F_Money <= 0)
  835. return Error("请输入付款金额");
  836. #endregion
  837. modelOrder.F_RealPrice = input.OrderMoney.F_Money;
  838. T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
  839. ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input.OrderMoney);
  840. modelOrderMoeny.F_AddUserId = UserLogin.UserId.ObjToInt();
  841. modelOrderMoeny.F_UserName = UserLogin.UserName;
  842. modelOrderMoeny.F_MoneyBak = modelOrderMoeny.F_Money;
  843. modelOrderMoeny.F_State = 0;
  844. modelOrderMoeny.F_Type = 1;
  845. modelOrderMoeny.F_OrderId = input.F_Id;
  846. modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  847. if (!await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
  848. return Error("付款失败");
  849. }
  850. catch (Exception ex)
  851. { return Error(ex.Message); }
  852. }
  853. int t = await AddLog(modelOrder.F_Id, count, UserLogin.UserCode , modelOrder.F_State);
  854. if (t >0)
  855. {
  856. if (await bus_OrderRepository.AddReturnCount(modelOrder))
  857. {
  858. if (modelDetailList != null && modelDetailList.Count > 0)
  859. {
  860. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  861. {
  862. return Success("订单添加成功2");
  863. }
  864. else
  865. return Error("订单添加失败,请重试!1");
  866. }
  867. return Success("订单添加成功1");
  868. }
  869. }
  870. return Error("订单添加失败,请重试!2");
  871. }
  872. catch (Exception ex)
  873. { return Error(ex.Message); }
  874. }
  875. /// <summary>
  876. /// 获取总金额
  877. /// </summary>
  878. /// <param name="OrderDetailList"></param>
  879. /// <param name="UseActList"></param>
  880. /// <returns></returns>
  881. [HttpPost("getPrice")]
  882. public async Task<IActionResult> GetPrice(List<OrderDetailInput> OrderDetailList
  883. , List<UseActInput> UseActList, decimal F_ExpressFee =0, decimal UseScore =0)
  884. {
  885. decimal totle = 0.00M;
  886. decimal ActivityMoney = 0.00M;
  887. string UseActivity = "";
  888. string UseActivity4 = ",";
  889. string UseActivity2 = ",";
  890. decimal TotlePrice = 0.00M;
  891. Dictionary<string, decimal> innerCompute = new Dictionary<string, decimal>();
  892. List<T_Bus_OrderDetail> orderDetails = new List<T_Bus_OrderDetail>();
  893. if (OrderDetailList != null && OrderDetailList.Count > 0)
  894. {
  895. int n = 1;
  896. int n2 = OrderDetailList.Count + 1;
  897. #region 活动核算
  898. if (UseActList != null && UseActList.Count > 0)
  899. {
  900. //遍历所有选中的活动
  901. foreach (UseActInput act in UseActList)
  902. {
  903. UseActivity += act.id + ",";
  904. if (act.type == 2)
  905. {
  906. UseActivity2 += act.gift + ",";
  907. }
  908. //满减
  909. else if (act.type == 3)
  910. {
  911. ActivityMoney += act.money;
  912. }
  913. else if (act.type == 4)
  914. {
  915. UseActivity4 += act.gift + ",";
  916. innerCompute.Add(act.gift, act.money);
  917. }
  918. }
  919. UseActivity = UseActivity.Trim(',');
  920. }
  921. #endregion
  922. #region 商品核算
  923. foreach (OrderDetailInput m in OrderDetailList)
  924. {
  925. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  926. if (modelProduct == null)
  927. return Error("商品不存在:" + m.F_ProductName );
  928. if (modelProduct.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
  929. {
  930. return Error("商品已下架:" + m.F_ProductName);
  931. }
  932. // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(modelProduct.F_ProductId, "新乡仓");
  933. if (modelProduct.F_MinimumStock + m.F_Count > modelProduct.F_Stock1 )
  934. {
  935. return Error(m.F_ProductName + "数量库存低于" + modelProduct.F_MinimumStock + "不能添加");
  936. }
  937. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  938. //参加活动特价
  939. if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
  940. {if (innerCompute.ContainsKey (modelProduct.F_ProductId))
  941. {
  942. ActivityMoney += innerCompute[modelProduct.F_ProductId] * m.F_Count;
  943. }
  944. }
  945. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  946. //参加生日
  947. if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
  948. {
  949. modelDetail.F_DealPrice = 0.00M;
  950. modelDetail.F_Remark = "生日赠品-活动:";
  951. }
  952. modelDetail.F_ProductId = modelProduct.F_ProductId;
  953. modelDetail.F_ProductName = modelProduct.F_ProductName;
  954. modelDetail.F_Count = m.F_Count;
  955. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  956. orderDetails.Add(modelDetail);
  957. totle += modelDetail.F_TotlePrice;
  958. TotlePrice += modelDetail.F_TotlePrice; ;
  959. n++;
  960. }
  961. #endregion
  962. }
  963. else
  964. {
  965. //不改变订单
  966. }
  967. T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
  968. string a = string.Format("{0:f0}", Math.Floor(UseScore / modelscore.F_DebitPercent));
  969. totle += F_ExpressFee - ActivityMoney-int .Parse ( a);
  970. var obj = new
  971. {
  972. orderDetails,
  973. TotlePrice,
  974. totle
  975. };
  976. return Content(obj.ToJson()); ;
  977. }
  978. /// <returns></returns>
  979. [HttpGet("UseGift")]
  980. public async Task<IActionResult> UseGift(int vip = 0, decimal money = 0)
  981. {
  982. if (vip <= 0)
  983. return Error("请选择会员");
  984. var model = await cus_vip_infoRepository.GetSingleV(x => x.F_ID == vip && x.F_State == (int)EnumDelState.Enabled);
  985. if (model == null)
  986. return Error("该会员不存在");
  987. decimal moneys = 0.00M;
  988. if (model.F_Money != null)
  989. {
  990. moneys = (decimal)model.F_Money + money;
  991. }
  992. else
  993. moneys = money;
  994. if (moneys > 3000)
  995. {
  996. decimal fund = moneys - 3000;
  997. string a = string.Format("{0:f0}", Math.Floor(fund / 2000));
  998. int b = int.Parse(a) + 1- model.F_UseGift ;
  999. return Success("获取成功", b);
  1000. }
  1001. else
  1002. return Success("获取成功", 0);
  1003. }
  1004. /// <summary>
  1005. /// 获取最大可使用积分
  1006. /// </summary>
  1007. /// <param name="OrderDetailList"></param>
  1008. /// <param name="UseActList"></param>
  1009. /// <returns></returns>
  1010. [HttpGet("deductible")]
  1011. public async Task<IActionResult> Deductible(int vip=0,decimal money=0)
  1012. {
  1013. if (vip <= 0)
  1014. return Error("请选择会员");
  1015. var model = await cus_vip_infoRepository .GetSingleV(x => x.F_ID == vip && x.F_State == (int)EnumDelState.Enabled);
  1016. if (model==null )
  1017. return Error("该会员不存在");
  1018. var score = await cus_score_setRepository .GetSingle(x => x.F_State == 1);
  1019. if (model.F_Score>0)
  1020. {
  1021. string a = string.Format("{0:f0}", Math.Floor((decimal)model.F_Score / score.F_DebitPercent));
  1022. string Score = ""; int moneys = 0;
  1023. if (money <= int.Parse(a))
  1024. {
  1025. moneys = (int)money;
  1026. Score = string.Format("{0:f0}", (int)money * score.F_DebitPercent);
  1027. }
  1028. else
  1029. {
  1030. moneys = int.Parse(a);
  1031. Score = string.Format("{0:f0}", int.Parse(a) * score.F_DebitPercent);
  1032. }
  1033. var obj = new
  1034. {
  1035. Score,
  1036. moneys
  1037. };
  1038. return Content(obj.ToJson());
  1039. }
  1040. else
  1041. return Success("获取成功", 0);
  1042. }
  1043. /// <summary>
  1044. /// 提交订单 Audit payment
  1045. /// </summary>
  1046. /// <param name="input"></param>
  1047. /// <returns></returns>
  1048. [HttpPost("submit")]
  1049. public async Task<IActionResult> Submit(string orderids)
  1050. {
  1051. string msg = "";
  1052. if (string.IsNullOrEmpty(orderids))
  1053. return Error("请选择订单号");
  1054. string[] ids = orderids.Split(',');
  1055. // List<EBossStock> listStock = await busOrderFunctionController.GetStock("", "山西仓",1,10000);
  1056. // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock("", "新乡仓",1,10000);
  1057. List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
  1058. List<T_Bus_Order> orderLIst = new List<T_Bus_Order>();
  1059. // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
  1060. foreach (var item in ids)
  1061. {
  1062. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == item);
  1063. T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
  1064. List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id, o => o.F_Sort, OrderByType.Asc);
  1065. if (detaillist != null && detaillist.Count > 0)
  1066. { }
  1067. else
  1068. { msg += "订单" + modelOrder.F_Id + "请选择订购商品"; continue; }
  1069. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  1070. {
  1071. msg += "订单" + modelOrder.F_Id + "收件人电话不能为空";
  1072. continue;
  1073. }
  1074. if (string.IsNullOrEmpty(modelOrder.F_Address))
  1075. {
  1076. msg += "订单" + modelOrder.F_Id + "收件人详细地址不能为空";
  1077. continue;
  1078. }
  1079. if (modelOrder.F_IsZeroCommodity ==1&& !modelOrder.F_Type.Contains ("回访")&& !modelOrder.F_Type.Contains("售后") )
  1080. {
  1081. msg += "订单" + modelOrder.F_Id + "非回访单不能添加0金额袜子";
  1082. continue;
  1083. }
  1084. if (detaillist!=null && detaillist.Count >0)
  1085. {
  1086. foreach (var it in detaillist)
  1087. {
  1088. T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == it.F_ProductId);
  1089. if (t_Bus_Product==null )
  1090. {
  1091. msg += "订单" + modelOrder.F_Id + "商品不存在";
  1092. continue;
  1093. }
  1094. if (t_Bus_Product.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
  1095. {
  1096. msg += "订单" + modelOrder.F_Id + "商品已下架:" + t_Bus_Product.F_ProductName;
  1097. continue;
  1098. }
  1099. //if (t_Bus_Product!=null )
  1100. // {
  1101. // // var listStock2 = listStock.Where(x => x.sku == t_Bus_Product.F_ProductId).ToList(); ;
  1102. // var listStock3 = listStock1.Where(x => x.sku == t_Bus_Product.F_ProductId).ToList(); ;
  1103. // // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(it.F_ProductId, "新乡仓");
  1104. // if (listStock3!=null&& listStock3.Count > 0)
  1105. // {
  1106. // if (t_Bus_Product.F_UseNumber > listStock3[0].qty)
  1107. // {
  1108. // msg += "订单" + modelOrder.F_Id + "提交失败,可配量不足.";
  1109. // continue;
  1110. // }
  1111. // else
  1112. // {
  1113. // t_Bus_Product.F_UseNumber += it.F_Count;
  1114. // Productlist.Add(t_Bus_Product);
  1115. // }
  1116. // }
  1117. // else
  1118. // {
  1119. // msg += "订单" + modelOrder.F_Id + "提交失败,可配量不足.";
  1120. // continue;
  1121. // }
  1122. // }
  1123. // else
  1124. // {
  1125. // msg += "订单" + modelOrder.F_Id + "提交失败,商品不存在.";
  1126. // continue;
  1127. // }
  1128. }
  1129. }
  1130. if (modelOrder.F_IsPayment > 0|| modelOrder.F_PayType != "货到付款")
  1131. {
  1132. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "提交订单"+","+ modelOrder.F_PayType+"流转客服付款待审核";
  1133. modelOrder.F_State = 7;
  1134. }
  1135. else
  1136. {
  1137. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "提交订单"+",流转客服待分仓";
  1138. modelOrder.F_State = 1;
  1139. }
  1140. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
  1141. modelOrder.F_SubmitTime = DateTime.Now;
  1142. modelOrder.F_SubmitUser = UserLogin .UserName ;
  1143. modelOrder.F_SubmitUserId = UserLogin.UserId.ObjToInt () ;
  1144. orderLIst.Add(modelOrder);
  1145. t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
  1146. t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
  1147. t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
  1148. t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
  1149. logs.Add(t_Bus_Orderlogs);
  1150. }
  1151. if (msg == "")
  1152. {
  1153. // if (await bus_productRepository.UpdateList(Productlist))
  1154. // {
  1155. if (bus_OrderRepository.UpdateList(orderLIst).Result)
  1156. {
  1157. await busOrderlogsRepository.AddAndUpdateList(logs);
  1158. return Success("提交成功");
  1159. }
  1160. // }
  1161. }
  1162. else
  1163. {
  1164. return Error(msg);
  1165. }
  1166. return Error("提交失败");
  1167. }
  1168. /// <summary>
  1169. /// 上传文件并导入数据库批量
  1170. /// </summary>审核订单金额
  1171. /// <returns></returns>
  1172. [HttpPost("importcheckordermoney")]
  1173. public async Task<IActionResult> importcheckordermoney(int headrow = 0)
  1174. {
  1175. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  1176. if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
  1177. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  1178. NPOIHelper npoi = new NPOIHelper();
  1179. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  1180. int num = dtExcel.Rows.Count;
  1181. var cols = dtExcel.Columns;
  1182. int colnum = cols.Count;
  1183. string errmsg = string.Empty;
  1184. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  1185. List<T_Bus_Order> _Orders = new List<T_Bus_Order>();
  1186. List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
  1187. if (num > 0)
  1188. {
  1189. int index = 1;
  1190. foreach (DataRow dr in dtExcel.Rows)
  1191. {
  1192. index++;
  1193. T_Bus_Order modelOrder = new T_Bus_Order();
  1194. T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
  1195. if (dr.Table.Columns.Contains("订单号"))
  1196. {
  1197. if (!string.IsNullOrEmpty(dr["订单号"].ToString()))
  1198. {
  1199. modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == dr["订单号"].ToString());
  1200. if (modelOrder == null)
  1201. {
  1202. errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
  1203. continue;
  1204. }
  1205. }
  1206. else
  1207. {
  1208. errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
  1209. continue;
  1210. }
  1211. }
  1212. else
  1213. {
  1214. return Error("模板错误,请选择正确的模板");
  1215. }
  1216. if (dr.Table.Columns.Contains("打款金额"))
  1217. {
  1218. if (!string.IsNullOrEmpty(dr["打款金额"].ToString()))
  1219. {
  1220. try
  1221. {
  1222. if (modelOrder.F_RealPrice==decimal .Parse (dr["打款金额"].ToString()))
  1223. {
  1224. if (modelOrder.F_PayState == 0)
  1225. {
  1226. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  1227. {
  1228. //0待回款1已支付 2待退款3已退款
  1229. modelOrder.F_PayState = 1;
  1230. }
  1231. }
  1232. else if (modelOrder.F_PayState == 2)
  1233. {
  1234. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  1235. {
  1236. //0待回款1已支付 2待退款3已退款
  1237. modelOrder.F_PayState = 3;
  1238. }
  1239. }
  1240. var membership = await _cus_membershiprepository.GetListALL(x => x.F_State != 2);
  1241. if (membership != null && membership.Count > 0)
  1242. {
  1243. T_Cus_VipInfo vip = await cus_vip_infoRepository.GetSingle(x => x.F_ID == modelOrder.F_VipId);
  1244. if (vip != null)
  1245. {
  1246. vip.F_Money += modelOrder.F_RealPrice;
  1247. T_Cus_Membership t_Cus_Membership = membership.Where(x => x.F_MinMoney <= vip.F_Money
  1248. ).OrderByDescending(a => a.F_MaxMoney).FirstOrDefault();
  1249. if (t_Cus_Membership != null)
  1250. {
  1251. vip.F_MembershipId = t_Cus_Membership.F_ID;
  1252. vip.F_Membership = t_Cus_Membership.F_Name;
  1253. }
  1254. await cus_vip_infoRepository.Update(vip);
  1255. }
  1256. }
  1257. modelOrder.F_State = 1;
  1258. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "审核付款金额,审核通过流转客服待分仓";
  1259. }
  1260. else
  1261. {
  1262. errmsg = errmsg + "\r\n第" + index + "行导入失败!打款金额不匹配";
  1263. continue;
  1264. }
  1265. }
  1266. catch
  1267. {
  1268. errmsg = errmsg + "\r\n第" + index + "行导入失败!打款金额格式错误";
  1269. continue;
  1270. }
  1271. }
  1272. else
  1273. {
  1274. errmsg = errmsg + "\r\n第" + index + "行导入失败!请选择打款金额";
  1275. continue;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. return Error("模板错误,请选择正确的模板");
  1281. }
  1282. t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
  1283. t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
  1284. t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
  1285. t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
  1286. logs.Add(t_Bus_Orderlogs);
  1287. _Orders.Add(modelOrder);
  1288. }
  1289. if (_Orders.Count >0)
  1290. {
  1291. await busOrderlogsRepository.AddAndUpdateList(logs);
  1292. if (!await bus_OrderRepository.UpdateList(_Orders))
  1293. {
  1294. if (!string.IsNullOrEmpty(errmsg))
  1295. {
  1296. errmsg = errmsg + "导入失败!";
  1297. }
  1298. else
  1299. {
  1300. errmsg = "导入失败!";
  1301. }
  1302. }
  1303. }
  1304. }
  1305. else
  1306. {
  1307. return Error("文件中无数据");
  1308. }
  1309. if (!string.IsNullOrEmpty(errmsg))
  1310. {
  1311. return Error(errmsg);
  1312. }
  1313. return Success("导入成功");
  1314. }
  1315. /// <summary>
  1316. /// 销售选择未发原因
  1317. /// </summary>
  1318. /// <param name="input"></param>
  1319. /// <returns></returns>
  1320. [HttpPost("notissued")]
  1321. public async Task<IActionResult> Notissued(string orderids,string remarks)
  1322. {
  1323. string msg = "";
  1324. if (string.IsNullOrEmpty(orderids))
  1325. return Error("请选择订单号");
  1326. if (string.IsNullOrEmpty(remarks))
  1327. return Error("请选择未发原因");
  1328. string[] ids = orderids.Split(',');
  1329. List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
  1330. List<T_Bus_Order> orderLIst = new List<T_Bus_Order>();
  1331. foreach (var item in ids)
  1332. {
  1333. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == item);
  1334. T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
  1335. modelOrder.F_Notissued = remarks;
  1336. modelOrder.F_NotissuedID = 1;
  1337. orderLIst.Add(modelOrder);
  1338. t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
  1339. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "填写未发原因:" + remarks;
  1340. t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
  1341. t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
  1342. t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
  1343. logs.Add(t_Bus_Orderlogs);
  1344. }
  1345. if (msg == "")
  1346. {
  1347. if (bus_OrderRepository.UpdateList(orderLIst).Result)
  1348. {
  1349. await busOrderlogsRepository.AddMany (logs);
  1350. return Success("提交成功");
  1351. }
  1352. }
  1353. else
  1354. {
  1355. return Error(msg);
  1356. }
  1357. return Error("提交失败");
  1358. }
  1359. /// <summary>
  1360. /// 审核订单金额
  1361. /// </summary>
  1362. /// <param name="input"></param>
  1363. /// <returns></returns>
  1364. [HttpPost("checkordermoney")]
  1365. public async Task<IActionResult> CheckOrderMoney(string orderids,int state)
  1366. {
  1367. try
  1368. {
  1369. #region 验证参数 必填项
  1370. if (string.IsNullOrEmpty(orderids))
  1371. return Error("请选择订单号");
  1372. string[] ids = orderids.Split(',');
  1373. List<T_Bus_Order> _Orders = new List<T_Bus_Order>();
  1374. List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
  1375. string msg = "";
  1376. foreach (var it in ids)
  1377. {
  1378. #endregion
  1379. T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
  1380. Expression<Func<T_Bus_OrderMoney, bool>> eq = a => a.F_OrderId == it;
  1381. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == it);
  1382. if (state == 1)
  1383. {
  1384. if (modelOrder.F_PayState == 0)
  1385. {
  1386. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  1387. {
  1388. //0待回款1已支付 2待退款3已退款
  1389. modelOrder.F_PayState = 1;
  1390. }
  1391. }
  1392. else if (modelOrder.F_PayState == 2)
  1393. {
  1394. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  1395. {
  1396. //0待回款1已支付 2待退款3已退款
  1397. modelOrder.F_PayState = 3;
  1398. }
  1399. }
  1400. var membership = await _cus_membershiprepository.GetListALL(x => x.F_State != 2);
  1401. if (membership != null && membership.Count > 0)
  1402. {
  1403. T_Cus_VipInfo vip = await cus_vip_infoRepository.GetSingle(x => x.F_ID == modelOrder.F_VipId);
  1404. if (vip != null)
  1405. {
  1406. vip.F_Money += modelOrder.F_RealPrice;
  1407. T_Cus_Membership t_Cus_Membership = membership.Where(x => x.F_MinMoney <= vip.F_Money
  1408. ).OrderByDescending(a => a.F_MaxMoney).FirstOrDefault();
  1409. if (t_Cus_Membership != null)
  1410. {
  1411. vip.F_MembershipId = t_Cus_Membership.F_ID ;
  1412. vip.F_Membership = t_Cus_Membership.F_Name;
  1413. }
  1414. await cus_vip_infoRepository.Update(vip);
  1415. }
  1416. }
  1417. modelOrder.F_State = 1;
  1418. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "审核付款金额,审核通过流转客服待分仓";
  1419. _Orders.Add(modelOrder);
  1420. }
  1421. else
  1422. {
  1423. List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id, o => o.F_Sort, OrderByType.Asc);
  1424. // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
  1425. if (detaillist != null && detaillist.Count > 0)
  1426. {
  1427. foreach (var iv in detaillist)
  1428. {
  1429. T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == iv.F_ProductId);
  1430. if (t_Bus_Product != null)
  1431. {
  1432. if (t_Bus_Product.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
  1433. {
  1434. return Error("商品已下架:" + t_Bus_Product.F_ProductId);
  1435. }
  1436. // t_Bus_Product.F_UseNumber -= iv.F_Count;
  1437. // Productlist.Add(t_Bus_Product);
  1438. }
  1439. else
  1440. {
  1441. msg += "订单" + modelOrder.F_Id + "提交失败,商品不存在.";
  1442. continue;
  1443. }
  1444. }
  1445. }
  1446. //if (msg == "")
  1447. //{
  1448. // if (Productlist != null && Productlist.Count > 0)
  1449. // {
  1450. // if (!await bus_productRepository.UpdateList(Productlist))
  1451. // {
  1452. // msg += "订单" + modelOrder.F_Id + "提交失败";
  1453. // continue;
  1454. // }
  1455. // }
  1456. // else
  1457. // {
  1458. // msg += "订单" + modelOrder.F_Id + "提交失败,请选择商品";
  1459. // continue;
  1460. // }
  1461. //}
  1462. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "审核付款金额,审核不通过,退回销售待提交";
  1463. modelOrder.F_State = 0;
  1464. _Orders.Add(modelOrder);
  1465. }
  1466. t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
  1467. t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
  1468. t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
  1469. t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
  1470. logs.Add(t_Bus_Orderlogs);
  1471. }
  1472. if (msg == "")
  1473. {
  1474. await busOrderlogsRepository.AddAndUpdateList(logs);
  1475. if (await bus_OrderRepository.UpdateList(_Orders))
  1476. return Success("成功");
  1477. }
  1478. else
  1479. return Error(msg);
  1480. return Error("失败!");
  1481. }
  1482. catch (Exception ex)
  1483. { return Error(ex.Message); }
  1484. }
  1485. /// <summary>
  1486. /// 上传文件并导入数据库批量导入快递信息
  1487. /// </summary>
  1488. /// <returns></returns>
  1489. [HttpPost("importorderexpressexcel")]
  1490. public async Task<IActionResult> importorderexpressexcel(int headrow = 0)
  1491. {
  1492. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  1493. if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
  1494. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  1495. NPOIHelper npoi = new NPOIHelper();
  1496. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  1497. int num = dtExcel.Rows.Count;
  1498. var cols = dtExcel.Columns;
  1499. int colnum = cols.Count;
  1500. string errmsg = string.Empty;
  1501. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  1502. List<T_Bus_Order> orderLIst = new List<T_Bus_Order>();
  1503. List<T_Bus_AfterSale> afterList = new List<T_Bus_AfterSale>();
  1504. List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
  1505. if (num > 0)
  1506. {
  1507. int index = 1;
  1508. foreach (DataRow dr in dtExcel.Rows)
  1509. {
  1510. index++;
  1511. T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
  1512. T_Bus_Order modelOrder = new T_Bus_Order();
  1513. List<T_Bus_AfterSale > after = new List<T_Bus_AfterSale>();
  1514. if (dr.Table.Columns.Contains("订单号"))
  1515. {
  1516. if (!string.IsNullOrEmpty(dr["订单号"].ToString()))
  1517. {
  1518. modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == dr["订单号"].ToString());
  1519. after =await busAfterSaleRepository.GetListALL(x => x.F_OrderId == dr["订单号"].ToString()&&x .F_Type ==9 && x.F_WoState == 0);
  1520. if (after==null|| after.Count <=0)
  1521. {
  1522. errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在售后改代收";
  1523. continue;
  1524. }
  1525. if (modelOrder == null)
  1526. {
  1527. errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
  1528. continue;
  1529. }
  1530. }
  1531. else
  1532. {
  1533. errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
  1534. continue;
  1535. }
  1536. }
  1537. else
  1538. {
  1539. return Error("模板错误,请选择正确的模板");
  1540. }
  1541. if (dr.Table.Columns.Contains("运单号"))
  1542. {
  1543. if (!string.IsNullOrEmpty(dr["运单号"].ToString()))
  1544. {
  1545. if (IsRegex(dr["运单号"].ToString()))
  1546. {
  1547. modelOrder.F_NewTrackingNo = dr["运单号"].ToString();
  1548. after[0].F_TrackingNo = dr["运单号"].ToString();
  1549. }
  1550. else
  1551. {
  1552. errmsg = errmsg + "\r\n第" + index + "行导入失败!运单号格式错误";
  1553. continue;
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. return Error("模板错误,请选择正确的模板");
  1560. }
  1561. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName +"改代收导入运单号"+ modelOrder.F_NewTrackingNo;
  1562. t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
  1563. t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
  1564. t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
  1565. t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
  1566. logs.Add(t_Bus_Orderlogs);
  1567. orderLIst.Add(modelOrder);
  1568. afterList.Add(after[0]);
  1569. }
  1570. if (errmsg == "")
  1571. {
  1572. if (await bus_OrderRepository.UpdateList(orderLIst))
  1573. {
  1574. await busOrderlogsRepository.AddAndUpdateList(logs);
  1575. if (!await busAfterSaleRepository .UpdateList(afterList))
  1576. {
  1577. errmsg = errmsg + "导入失败!";
  1578. }
  1579. }
  1580. else
  1581. errmsg = errmsg + "导入失败!";
  1582. }
  1583. }
  1584. else
  1585. {
  1586. return Error("文件中无数据");
  1587. }
  1588. if (!string.IsNullOrEmpty(errmsg))
  1589. {
  1590. return Error(errmsg);
  1591. }
  1592. return Success("导入成功");
  1593. }
  1594. private bool IsRegex(string accountStr)
  1595. {
  1596. Regex reg = new Regex(@"^[A-Za-z0-9]+$");
  1597. return reg.IsMatch(accountStr);
  1598. }
  1599. /// <summary>
  1600. /// 更新改代收运单号
  1601. /// </summary>
  1602. /// <param name="orderids"></param>
  1603. /// <param name="status">
  1604. /// <returns></returns>
  1605. [HttpPost("updateexpres")]
  1606. public async Task<IActionResult> UpdateTrackingNo(string orderids, string trackingNo="")
  1607. {
  1608. #region 验证参数 必填项
  1609. if (string.IsNullOrEmpty(orderids))
  1610. return Error("请选择订单号");
  1611. if (string.IsNullOrEmpty(trackingNo))
  1612. return Error("请输入运单号");
  1613. #endregion
  1614. // string[] ids = orderids.Split(',');
  1615. var after = await busAfterSaleRepository.GetSingle (x => x.F_Id == orderids );
  1616. if (after == null )
  1617. {
  1618. return Error("售后不存在");
  1619. }
  1620. int t = await AddLog(orderids, UserLogin.UserName + "改代收更新运单号", UserLogin.UserCode,-1);
  1621. if (await bus_OrderRepository.Update(s => new T_Bus_Order() { F_NewTrackingNo = trackingNo }, q => q .F_Id ==after .F_OrderId ))
  1622. {
  1623. after.F_TrackingNo = trackingNo;
  1624. if (await busAfterSaleRepository .Update(after))
  1625. {
  1626. return Success("成功");
  1627. }
  1628. }
  1629. return Error("失败,请重试!");
  1630. }
  1631. #region
  1632. /// <summary>
  1633. /// 修改订单
  1634. /// </summary>
  1635. /// <param name="input"></param>
  1636. /// <returns></returns>
  1637. /**
  1638. [HttpPost("editorder")]
  1639. public async Task<IActionResult> EditOrder([FromBody]OrderInput input)
  1640. {
  1641. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  1642. #region 验证参数 必填项
  1643. if (string.IsNullOrEmpty(input.F_ADFrom))
  1644. return Error("请输入选择广告来源");
  1645. if (string.IsNullOrEmpty(input.F_Type))
  1646. return Error("请输入选择订单类型");
  1647. if (string.IsNullOrEmpty(input.F_Id))
  1648. return Error("请输入订单编号");
  1649. if (string.IsNullOrEmpty(input.F_Customer))
  1650. return Error("请输入客户姓名");
  1651. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  1652. return Error("请输入客户电话");
  1653. if (input.F_Type == "售后订单")
  1654. return Error("售后订单销售不能修改");
  1655. #endregion
  1656. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
  1657. if (modelOrder == null)
  1658. {
  1659. return Error("此订单号不存在");
  1660. }
  1661. //保存 审退回 仓退回
  1662. if (!(new int[] { 0, 2 }.Contains(modelOrder.F_State)))
  1663. {
  1664. return Error("已提交订单不允许修改,先撤回订单");
  1665. }
  1666. #region 数据绑定
  1667. //必填
  1668. modelOrder.F_ADFrom = input.F_ADFrom;
  1669. modelOrder.F_Type = input.F_Type;
  1670. modelOrder.F_Customer = input.F_Customer;
  1671. modelOrder.F_CustomerPhone = input.F_CustomerPhone;
  1672. if (input.F_RecommendId > 0)
  1673. {
  1674. modelOrder.F_RecommendId = input.F_RecommendId;
  1675. modelOrder.F_RecommendName = input.F_RecommendName;
  1676. }
  1677. if (input.F_CustomerType > 0)
  1678. { modelOrder.F_CustomerType = input.F_CustomerType; }
  1679. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  1680. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  1681. //选填 快递属性
  1682. modelOrder.F_TrackingNo = "";
  1683. if (!string.IsNullOrEmpty(input.F_Addressee))
  1684. { modelOrder.F_Addressee = input.F_Addressee; }
  1685. if (!string.IsNullOrEmpty(input.F_AddPhone))
  1686. { modelOrder.F_AddPhone = input.F_AddPhone; }
  1687. if (!string.IsNullOrEmpty(input.F_AddProvince))
  1688. { modelOrder.F_AddProvince = input.F_AddProvince; }
  1689. if (!string.IsNullOrEmpty(input.F_AddCity))
  1690. { modelOrder.F_AddCity = input.F_AddCity; }
  1691. if (!string.IsNullOrEmpty(input.F_AddArea))
  1692. { modelOrder.F_AddArea = input.F_AddArea; }
  1693. if (!string.IsNullOrEmpty(input.F_AddTown))
  1694. { modelOrder.F_AddTown = input.F_AddTown; }
  1695. if (!string.IsNullOrEmpty(input.F_AddDes))
  1696. { modelOrder.F_AddDes = input.F_AddDes; }
  1697. if (!string.IsNullOrEmpty(input.F_Address))
  1698. { modelOrder.F_Address = input.F_Address; }
  1699. if (!string.IsNullOrEmpty(input.F_PostalCode))
  1700. { modelOrder.F_PostalCode = input.F_PostalCode; }
  1701. if (!string.IsNullOrEmpty(input.F_Express))
  1702. { modelOrder.F_Express = input.F_Express; }
  1703. if (!string.IsNullOrEmpty(input.F_Remark))
  1704. { modelOrder.F_Remark = input.F_Remark; }
  1705. if (!string.IsNullOrEmpty(input.F_PayType))
  1706. { modelOrder.F_PayType = input.F_PayType; }
  1707. if (input.F_Belong > 0)
  1708. {
  1709. modelOrder.F_Belong = input.F_Belong;
  1710. modelOrder.F_BelongName = input.F_BelongName;
  1711. }
  1712. else
  1713. {
  1714. modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
  1715. modelOrder.F_BelongName = UserLogin.UserName;
  1716. }
  1717. modelOrder.F_ExpressFee = input.F_ExpressFee;
  1718. modelOrder.F_Stock = input.F_Stock;
  1719. modelOrder.F_RealPrice = input.F_RealPrice;
  1720. modelOrder.F_UseScore = input.F_UseScore;
  1721. //选填 关联属性
  1722. if (input.F_VipId>0)
  1723. modelOrder.F_VipId = input.F_VipId;
  1724. else
  1725. {
  1726. var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
  1727. && x.F_State == 1);
  1728. if (vip != null && vip.Count > 0)
  1729. modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
  1730. else
  1731. modelOrder.F_VipId = 0;
  1732. }
  1733. modelOrder.F_State = input.F_State;
  1734. modelOrder.F_Status = 0;
  1735. modelOrder.F_IsPayment = input.F_IsPayment;
  1736. if (input.F_IsPayment > 0 && input.F_PaymentMoney <= 0)
  1737. return Error("付款金额不能小于0");
  1738. //必须属性 系统生成
  1739. modelOrder.F_AddTime = DateTime.Now;
  1740. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  1741. modelOrder.F_AddUserName = UserLogin.UserName;
  1742. #endregion
  1743. //计算属性 商品计算
  1744. decimal totle = 0.00M;
  1745. decimal ActivityMoney = 0.00M;
  1746. string UseActivity = "";
  1747. string UseActivity4 = ",";
  1748. string UseActivity2 = ",";
  1749. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  1750. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  1751. {
  1752. #region 核算活动
  1753. int n2 = input.OrderDetailList.Count + 1;
  1754. if (input.UseActList != null && input.UseActList.Count > 0)
  1755. {
  1756. //遍历所有选中的活动
  1757. foreach (UseActInput act in input.UseActList)
  1758. {
  1759. UseActivity += act.id + ",";
  1760. //满赠
  1761. if (act.type == 1)
  1762. {
  1763. string[] productidlist = act.gift.Split(',');
  1764. foreach (string giftid in productidlist)
  1765. {
  1766. T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
  1767. if (m != null)
  1768. {
  1769. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  1770. modelDetail.F_ProductName = m.F_ProductName;
  1771. modelDetail.F_ProductId = m.F_ProductId;
  1772. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  1773. modelDetail.F_OrderId = input.F_Id;
  1774. modelDetail.F_Count = 1;
  1775. modelDetail.F_Price = 0.00M;
  1776. modelDetail.F_DealPrice = 0.00M;
  1777. modelDetail.F_Sort = n2;
  1778. modelDetail.F_Remark = "赠品-活动:" + act.id;
  1779. modelDetail.F_AddUser = modelOrder.F_AddUser;
  1780. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  1781. modelDetail.F_TotlePrice = 0.00M;
  1782. modelDetail.F_Activity = act.id;
  1783. modelDetail.F_AddTime = DateTime.Now.AddSeconds(30);
  1784. modelDetailList.Add(modelDetail);
  1785. n2++;
  1786. }
  1787. }
  1788. }
  1789. //生日赠
  1790. else if (act.type == 2)
  1791. {
  1792. UseActivity2 += act.gift + ",";
  1793. }
  1794. //满减
  1795. else if (act.type == 3)
  1796. {
  1797. ActivityMoney += act.money;
  1798. }
  1799. else if (act.type == 4)
  1800. {
  1801. UseActivity4 += act.gift + ",";
  1802. }
  1803. }
  1804. UseActivity = UseActivity.Trim(',');
  1805. }
  1806. #endregion
  1807. #region 核算商品
  1808. int n = 1;
  1809. foreach (OrderDetailInput m in input.OrderDetailList)
  1810. {
  1811. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  1812. if (modelProduct == null) return Error("在售商品不存在");
  1813. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  1814. modelDetail.F_ProductName = modelProduct.F_ProductName;
  1815. modelDetail.F_ProductId = modelProduct.F_ProductId;
  1816. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  1817. modelDetail.F_OrderId = input.F_Id;
  1818. modelDetail.F_Count = m.F_Count;
  1819. modelDetail.F_Price = modelProduct.F_MemberPrice;
  1820. //参加活动特价
  1821. if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
  1822. modelDetail.F_DealPrice = modelProduct.F_SpecialPrice;
  1823. else
  1824. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  1825. //参加生日
  1826. if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
  1827. {
  1828. modelDetail.F_DealPrice = 0.00M;
  1829. modelDetail.F_Remark = "生日赠品-活动:";
  1830. }
  1831. modelDetail.F_Sort = n;
  1832. modelDetail.F_AddTime = DateTime.Now;
  1833. modelDetail.F_AddUser = modelOrder.F_AddUser;
  1834. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  1835. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  1836. modelDetail.F_Activity = 0;
  1837. if (modelProduct.F_Tag.IndexOf(".") > -1 && !string.IsNullOrEmpty(UseActivity))
  1838. {
  1839. string[] tagarry = modelProduct.F_Tag.Split(',');
  1840. string[] actlist = UseActivity.Split(',');
  1841. string tag = tagarry.First(a => a.StartsWith(".")).ToString();
  1842. T_Sys_Marketing modelactive = await bus_MarketingRepository.GetFirst(b => actlist.Contains(b.F_ID.ToString()) && b.F_EndTime >= DateTime.Now && b.F_StartTime<=DateTime.Now && b.F_IsDelete==0&&("," + b.F_Commodity + ",").Contains(("," + tag + ",")));
  1843. //此商品参加活动
  1844. if (modelactive != null)
  1845. {
  1846. modelDetail.F_Activity = modelactive.F_ID;
  1847. }
  1848. }
  1849. totle += modelDetail.F_TotlePrice;
  1850. modelDetailList.Add(modelDetail);
  1851. n++;
  1852. }
  1853. #endregion
  1854. modelOrder.F_TotlePrice = totle;
  1855. modelOrder.F_ActivityMoney = ActivityMoney;
  1856. modelOrder.F_UseActivity = UseActivity;
  1857. }
  1858. else
  1859. {
  1860. //不传商品 表明不修改商品信息 不重新计算商品
  1861. }
  1862. //直接提交 锁库存
  1863. T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
  1864. if (modelscore == null)
  1865. {
  1866. modelscore = new T_Cus_ScoreSet();
  1867. modelscore.F_Start = 0;
  1868. modelscore.F_StartDebit = 1;
  1869. modelscore.F_DebitPercent = 1000;
  1870. }
  1871. #region 提交 更改状态 库存 积分
  1872. if (input.F_State == 1)
  1873. {
  1874. if (string.IsNullOrEmpty(input.F_Stock))
  1875. {
  1876. return Error("请选择出库货仓");
  1877. }
  1878. if (string.IsNullOrEmpty(modelOrder.F_Express))
  1879. {
  1880. return Error("快递不能为空");
  1881. }
  1882. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  1883. {
  1884. return Error("收件人电话不能为空");
  1885. }
  1886. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  1887. {
  1888. return Error("收件人地址不能为空");
  1889. }
  1890. if (string.IsNullOrEmpty(modelOrder.F_Address))
  1891. {
  1892. return Error("收件人详细地址不能为空");
  1893. }
  1894. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
  1895. if (modelscore.F_Start == 1)
  1896. {
  1897. //订单完成后计算积分
  1898. modelOrder.F_Score = -0.01M;
  1899. }
  1900. else
  1901. { //订单完成后也不计算积分
  1902. modelOrder.F_Score = 0.00M;
  1903. }
  1904. if (modelscore.F_StartDebit == 0 || modelOrder.F_VipId == 0)
  1905. {
  1906. modelOrder.F_UseScore = 0;
  1907. }
  1908. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
  1909. if (strStock != "1")
  1910. { return Error(strStock); }
  1911. modelOrder.F_SubmitTime = DateTime.Now;
  1912. }
  1913. #endregion
  1914. if (!modelOrder.F_Type.Contains("售后"))
  1915. { modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney + modelOrder.F_ExpressFee - modelOrder.F_UseScore / modelscore.F_DebitPercent;
  1916. }
  1917. DataTable dt=await busOrderMoneyRepository.GetTableSugar(string.Format("SELECT IFNULL(SUM(F_Money),0) FROM T_Bus_OrderMoney WHERE F_OrderId='{0}' AND F_State=1", modelOrder.F_Id));
  1918. modelOrder.F_RealPrice = dt.Rows[0][0].ObjToDecimal() ;
  1919. if (modelOrder.F_ShouldPrice > 0)
  1920. {
  1921. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  1922. modelOrder.F_PayState = 1;
  1923. else
  1924. modelOrder.F_PayState = 0;
  1925. }
  1926. else
  1927. {
  1928. if (modelOrder.F_ShouldPrice >= modelOrder.F_RealPrice)
  1929. modelOrder.F_PayState = 3;
  1930. else
  1931. modelOrder.F_PayState = 2;
  1932. }
  1933. //待付款 客服审核付款情况后改为已付款
  1934. if (await bus_OrderRepository.Update(modelOrder))
  1935. {
  1936. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  1937. {
  1938. //删除之前订单商品,重新添加
  1939. if (await bus_OrderDetailRepository.Delete(q => q.F_OrderId == modelOrder.F_Id))
  1940. {
  1941. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  1942. return Success("订单生成成功");
  1943. else
  1944. return Error("订单操作失败,请重试1!");
  1945. }
  1946. else {
  1947. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  1948. return Success("订单生成成功2");
  1949. else
  1950. return Error("订单操作失败,请重试2!");
  1951. }
  1952. }
  1953. else { return Success("成功"); }
  1954. }
  1955. return Error("订单添加失败,请重试!");
  1956. }
  1957. **/
  1958. #endregion
  1959. #region
  1960. /// <summary>
  1961. /// 修改订单
  1962. /// </summary>
  1963. /// <param name="input"></param>
  1964. /// <returns></returns>
  1965. [HttpPost("editorder")]
  1966. public async Task<IActionResult> EditOrder([FromBody]OrderInput input)
  1967. {
  1968. // T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  1969. #region 验证参数 必填项
  1970. if (string.IsNullOrEmpty(input.F_ADFrom))
  1971. return Error("请输入选择广告来源");
  1972. if (string.IsNullOrEmpty(input.F_Type))
  1973. return Error("请输入选择订单类型");
  1974. if (string.IsNullOrEmpty(input.F_Id))
  1975. return Error("请输入订单编号");
  1976. if (string.IsNullOrEmpty(input.F_Customer))
  1977. return Error("请输入客户姓名");
  1978. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  1979. return Error("请输入客户电话");
  1980. if (string.IsNullOrEmpty(input.F_AddProvince))
  1981. {
  1982. return Error("收件人省份不能为空");
  1983. }
  1984. if (string.IsNullOrEmpty(input.F_AddCity))
  1985. {
  1986. return Error("收件人城市不能为空");
  1987. }
  1988. if (string.IsNullOrEmpty(input.F_AddArea))
  1989. {
  1990. return Error("收件人区/县不能为空");
  1991. }
  1992. if (string.IsNullOrEmpty(input.F_Address))
  1993. {
  1994. return Error("收件人详细地址不能为空");
  1995. }
  1996. if (input.F_Type == "售后订单")
  1997. {
  1998. if (UserLogin .RoleCode !="SH")
  1999. return Error("售后订单只能售后修改");
  2000. }
  2001. #endregion
  2002. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
  2003. if (modelOrder == null)
  2004. {
  2005. return Error("此订单号不存在");
  2006. }
  2007. //保存 审退回 仓退回
  2008. if (!(new int[] { 0, 2 }.Contains(modelOrder.F_State)))
  2009. {
  2010. return Error("已提交订单不允许修改,先撤回订单");
  2011. }
  2012. #region 数据绑定
  2013. //必填
  2014. modelOrder.F_ADFrom = input.F_ADFrom;
  2015. modelOrder.F_Type = input.F_Type;
  2016. modelOrder.F_Customer = input.F_Customer;
  2017. modelOrder.F_CustomerPhone = input.F_CustomerPhone;
  2018. if (input.F_RecommendId > 0)
  2019. {
  2020. modelOrder.F_RecommendId = input.F_RecommendId;
  2021. modelOrder.F_RecommendName = input.F_RecommendName;
  2022. }
  2023. if (input.F_CustomerType > 0)
  2024. { modelOrder.F_CustomerType = input.F_CustomerType; }
  2025. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  2026. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  2027. //选填 快递属性
  2028. modelOrder.F_TrackingNo = "";
  2029. if (!string.IsNullOrEmpty(input.F_Addressee))
  2030. { modelOrder.F_Addressee = input.F_Addressee; }
  2031. if (!string.IsNullOrEmpty(input.F_AddPhone))
  2032. { modelOrder.F_AddPhone = input.F_AddPhone; }
  2033. if (!string.IsNullOrEmpty(input.F_AddProvince))
  2034. { modelOrder.F_AddProvince = input.F_AddProvince; }
  2035. if (!string.IsNullOrEmpty(input.F_AddCity))
  2036. { modelOrder.F_AddCity = input.F_AddCity; }
  2037. if (!string.IsNullOrEmpty(input.F_AddArea))
  2038. { modelOrder.F_AddArea = input.F_AddArea; }
  2039. if (!string.IsNullOrEmpty(input.F_AddTown))
  2040. { modelOrder.F_AddTown = input.F_AddTown; }
  2041. if (!string.IsNullOrEmpty(input.F_AddDes))
  2042. { modelOrder.F_AddDes = input.F_AddDes; }
  2043. if (!string.IsNullOrEmpty(input.F_Address))
  2044. { modelOrder.F_Address = input.F_Address; }
  2045. // if (!string.IsNullOrEmpty(input.F_PostalCode))//快递
  2046. // { modelOrder.F_PostalCode = input.F_PostalCode; }
  2047. if (!string.IsNullOrEmpty(input.F_Express))
  2048. { modelOrder.F_Express = input.F_Express; }
  2049. if (!string.IsNullOrEmpty(input.F_Remark))
  2050. { modelOrder.F_Remark = input.F_Remark; }
  2051. if (!string.IsNullOrEmpty(input.F_PayType))
  2052. { modelOrder.F_PayType = input.F_PayType; }
  2053. var modelvip = await cus_vip_infoRepository.GetSingle(x => x.F_ID == modelOrder.F_VipId);
  2054. if (modelvip != null)
  2055. {
  2056. modelOrder.F_Belong = modelvip.F_Saleperson.ObjToInt();
  2057. var user = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelOrder.F_Belong);
  2058. modelOrder.F_BelongName = user.F_UserName ;
  2059. }
  2060. else if (input.F_Belong > 0)
  2061. {
  2062. modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
  2063. modelOrder.F_BelongName = UserLogin.UserName;
  2064. }
  2065. var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelvip.F_Saleperson.ObjToInt());
  2066. if (useraccount != null)
  2067. {
  2068. modelOrder.F_Department = useraccount.F_DeptId;
  2069. modelOrder.F_Core = useraccount.F_DeptTeamId;
  2070. modelOrder.F_Group = useraccount.F_GroupId;
  2071. }
  2072. if (input.F_Media > 0)
  2073. {
  2074. modelOrder.F_Media = input.F_Media;
  2075. modelOrder.F_MediaName = input.F_MediaName;
  2076. }
  2077. // modelOrder.F_Stock = input.F_Stock;//仓库
  2078. modelOrder.F_IsExpress = 0;
  2079. modelOrder.F_MemberNotes = input.F_MemberNotes;//会员备注
  2080. if (modelvip != null)
  2081. {
  2082. modelvip.F_Score += modelOrder.F_UseScore;
  2083. }
  2084. modelOrder.F_RealPrice = input.F_RealPrice;
  2085. modelOrder.F_UseScore = input.F_UseScore;
  2086. //选填 关联属性
  2087. if (input.F_VipId>0)
  2088. modelOrder.F_VipId = input.F_VipId;
  2089. else
  2090. {
  2091. var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
  2092. && x.F_State == 1);
  2093. if (vip != null && vip.Count > 0)
  2094. modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
  2095. else
  2096. modelOrder.F_VipId = 0;
  2097. }
  2098. modelOrder.F_State = input.F_State;
  2099. modelOrder.F_Status = 0;
  2100. modelOrder.F_IsPayment = input.F_IsPayment;
  2101. //必须属性 系统生成
  2102. modelOrder.F_AddTime = DateTime.Now;
  2103. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  2104. modelOrder.F_AddUserName = UserLogin.UserName;
  2105. #endregion
  2106. //计算属性 商品计算
  2107. decimal totle = 0.00M;
  2108. decimal ActivityMoney = 0.00M;
  2109. string UseActivity = "";
  2110. string UseActivity4 = ",";
  2111. string UseActivity2 = ",";
  2112. string Eventprice = "";
  2113. Dictionary<string , decimal> innerCompute = new Dictionary<string, decimal>();
  2114. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  2115. Dictionary<string, int> innerEventprice = new Dictionary<string, int>();
  2116. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  2117. {
  2118. #region 核算活动
  2119. int n2 = input.OrderDetailList.Count + 1;
  2120. if (input.UseActList != null && input.UseActList.Count > 0)
  2121. {
  2122. //遍历所有选中的活动
  2123. foreach (UseActInput act in input.UseActList)
  2124. {
  2125. UseActivity += act.id + ",";
  2126. //满赠
  2127. //if (act.type == 1)
  2128. //{
  2129. // string[] productidlist = act.gift.Split(',');
  2130. // foreach (string giftid in productidlist)
  2131. // {
  2132. // T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
  2133. // if (m != null)
  2134. // {
  2135. // T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  2136. // modelDetail.F_ProductName = m.F_ProductName;
  2137. // modelDetail.F_ProductId = m.F_ProductId;
  2138. // modelDetail.F_Specifications = m.F_Specifications;
  2139. // modelDetail.F_ProductShortName = m.F_ProductShortName;
  2140. // modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  2141. // modelDetail.F_OrderId = input.F_Id;
  2142. // modelDetail.F_Count = 1;
  2143. // modelDetail.F_Price = 0.00M;
  2144. // modelDetail.F_DealPrice = 0.00M;
  2145. // modelDetail.F_Sort = n2;
  2146. // modelDetail.F_Remark = "赠品-活动:" + act.id;
  2147. // modelDetail.F_AddUser = modelOrder.F_AddUser;
  2148. // modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  2149. // modelDetail.F_TotlePrice = 0.00M;
  2150. // modelDetail.F_Activity = act.id;
  2151. // modelDetail.F_AddTime = DateTime.Now.AddSeconds(30);
  2152. // modelDetailList.Add(modelDetail);
  2153. // n2++;
  2154. // }
  2155. // }
  2156. //}
  2157. ////生日赠
  2158. //else
  2159. if (act.type == 2)
  2160. {
  2161. UseActivity2 += act.gift + ",";
  2162. }
  2163. //满减
  2164. else if (act.type == 3)
  2165. {
  2166. ActivityMoney += act.money;
  2167. if (string .IsNullOrEmpty (Eventprice))
  2168. Eventprice= "" + act.id + "," + act.money;
  2169. else
  2170. Eventprice+= "|" + act.id + "," + act.money;
  2171. }
  2172. else if (act.type == 4)
  2173. {
  2174. UseActivity4 += act.gift + ",";
  2175. innerCompute.Add(act.gift, act.money);
  2176. innerEventprice.Add(act.gift, act.id);
  2177. }
  2178. }
  2179. UseActivity = UseActivity.Trim(',');
  2180. }
  2181. #endregion
  2182. #region 核算商品
  2183. modelOrder.F_IsZeroCommodity = 0;
  2184. int n = 1;
  2185. foreach (OrderDetailInput m in input.OrderDetailList)
  2186. {
  2187. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  2188. if (modelProduct == null) return Error("在售商品不存在");
  2189. if (modelProduct.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
  2190. {
  2191. return Error("商品已下架:" + m.F_ProductName);
  2192. }
  2193. if (!modelOrder.F_Type.Contains("售后"))
  2194. {
  2195. // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(modelProduct.F_ProductId, "新乡仓");
  2196. if (modelProduct.F_MinimumStock + m.F_Count > modelProduct.F_Stock1 )
  2197. {
  2198. return Error(m.F_ProductName + "数量库存低于" + modelProduct.F_MinimumStock + "不能添加");
  2199. }
  2200. }
  2201. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  2202. modelDetail.F_ProductName = modelProduct.F_ProductName;
  2203. modelDetail.F_ProductId = modelProduct.F_ProductId;
  2204. modelDetail.F_Specifications = modelProduct.F_Specifications;
  2205. modelDetail.F_ProductShortName = modelProduct.F_ProductShortName;
  2206. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  2207. modelDetail.F_OrderId = input.F_Id;
  2208. modelDetail.F_Count = m.F_Count;
  2209. modelDetail.F_Price = modelProduct.F_MemberPrice;
  2210. //参加活动特价
  2211. if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
  2212. {
  2213. if (innerCompute.ContainsKey(modelProduct.F_ProductId))
  2214. {
  2215. ActivityMoney += innerCompute[modelProduct.F_ProductId] * m.F_Count;
  2216. if (!string .IsNullOrEmpty (Eventprice))
  2217. Eventprice += "|" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
  2218. else
  2219. Eventprice += "" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
  2220. }
  2221. }
  2222. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  2223. //参加生日
  2224. if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
  2225. {
  2226. modelDetail.F_DealPrice = 0.00M;
  2227. modelDetail.F_Remark = "生日赠品-活动:";
  2228. }
  2229. if (modelProduct.F_ClassName == "袜子" && modelDetail.F_DealPrice == 0)
  2230. {
  2231. modelOrder.F_IsZeroCommodity = 1;
  2232. }
  2233. modelDetail.F_Sort = n;
  2234. modelDetail.F_AddTime = DateTime.Now;
  2235. modelDetail.F_AddUser = modelOrder.F_AddUser;
  2236. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  2237. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  2238. modelDetail.F_Activity = 0;
  2239. if (modelProduct.F_Tag.IndexOf(".") > -1 && !string.IsNullOrEmpty(UseActivity))
  2240. {
  2241. string[] tagarry = modelProduct.F_Tag.Split(',');
  2242. string[] actlist = UseActivity.Split(',');
  2243. string tag = tagarry.First(a => a.StartsWith(".")).ToString();
  2244. T_Sys_Marketing modelactive = await bus_MarketingRepository.GetFirst(b => actlist.Contains(b.F_ID.ToString()) && b.F_EndTime >= DateTime.Now && b.F_StartTime<=DateTime.Now && b.F_IsDelete==0&&("," + b.F_Commodity + ",").Contains(("," + tag + ",")));
  2245. //此商品参加活动
  2246. if (modelactive != null)
  2247. {
  2248. modelDetail.F_Activity = modelactive.F_ID;
  2249. }
  2250. }
  2251. totle += modelDetail.F_TotlePrice;
  2252. modelDetailList.Add(modelDetail);
  2253. n++;
  2254. }
  2255. #endregion
  2256. modelOrder.F_TotlePrice = totle;
  2257. modelOrder.F_ActivityMoney = ActivityMoney;
  2258. modelOrder.F_Eventprice = Eventprice;
  2259. modelOrder.F_UseActivity = UseActivity;
  2260. }
  2261. else
  2262. {
  2263. //不传商品 表明不修改商品信息 不重新计算商品
  2264. }
  2265. modelOrder.F_ExpressFee = input.F_ExpressFee;
  2266. //直接提交 锁库存
  2267. T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
  2268. if (modelscore == null)
  2269. {
  2270. modelscore = new T_Cus_ScoreSet();
  2271. modelscore.F_Start = 0;
  2272. modelscore.F_StartDebit = 1;
  2273. modelscore.F_DebitPercent = 1000;
  2274. }
  2275. #region 提交 更改状态 库存 积分
  2276. if (input.F_State == 1)
  2277. {
  2278. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  2279. { }
  2280. else
  2281. { return Error("请选择订购商品"); }
  2282. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  2283. {
  2284. return Error("收件人电话不能为空");
  2285. }
  2286. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  2287. {
  2288. return Error("收件人地址不能为空");
  2289. }
  2290. if (string.IsNullOrEmpty(modelOrder.F_Address))
  2291. {
  2292. return Error("收件人详细地址不能为空");
  2293. }
  2294. // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
  2295. if (modelDetailList != null && modelDetailList.Count > 0)
  2296. {
  2297. foreach (var it in modelDetailList)
  2298. {
  2299. T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == it.F_ProductId);
  2300. if (t_Bus_Product != null)
  2301. {
  2302. // List<EBossStock> listStock = await busOrderFunctionController.GetStock(it.F_ProductId, "山西仓");
  2303. //List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(it.F_ProductId, "新乡仓");
  2304. //t_Bus_Product.F_UseNumber += it.F_Count;
  2305. //if (listStock1!=null && listStock1.Count >0)
  2306. //{
  2307. // if (t_Bus_Product.F_UseNumber > listStock1[0].qty)
  2308. // {
  2309. // return Error("提交失败,可配量不足.");
  2310. // }
  2311. // else
  2312. // {
  2313. // Productlist.Add(t_Bus_Product);
  2314. // }
  2315. //}
  2316. //else
  2317. // return Error("提交失败,可配量不足.");
  2318. }
  2319. else
  2320. {
  2321. return Error("提交失败,商品不存在");
  2322. }
  2323. }
  2324. // await bus_productRepository.UpdateList(Productlist);
  2325. }
  2326. modelOrder.F_SubmitTime = DateTime.Now;
  2327. if (modelOrder.F_IsPayment > 0 || modelOrder.F_PayType != "货到付款")
  2328. modelOrder.F_State = 7;
  2329. else
  2330. modelOrder.F_State = 1;
  2331. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
  2332. }
  2333. // if (modelscore.F_Start == 1)
  2334. // {
  2335. //订单完成后计算积分
  2336. // modelOrder.F_Score = -0.01M;
  2337. // }
  2338. // else
  2339. // { //订单完成后也不计算积分
  2340. // modelOrder.F_Score = 0.00M;
  2341. // }
  2342. // if (modelscore.F_StartDebit == 0 || modelOrder.F_VipId == 0)
  2343. // {
  2344. // modelOrder.F_UseScore = 0;
  2345. // }
  2346. // string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
  2347. // if (strStock != "1")
  2348. // { return Error(strStock); }
  2349. // modelOrder.F_SubmitTime = DateTime.Now;
  2350. // }
  2351. #endregion
  2352. string count = UserLogin.UserName + "修改订单";
  2353. if (!modelOrder.F_Type.Contains("售后"))
  2354. {
  2355. string a = string.Format("{0:f0}", Math.Floor(modelOrder.F_UseScore / modelscore.F_DebitPercent));
  2356. modelOrder.F_Discount = int.Parse(a);
  2357. modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney -int .Parse (a) + input.F_ExpressFee;
  2358. modelvip.F_UseGift -= modelOrder.F_UseGift;
  2359. if (input.OrderUserGift != null && input.OrderUserGift.Count > 0)
  2360. {
  2361. decimal moneys = 0.00M;
  2362. if (modelvip.F_Money != null)
  2363. {
  2364. moneys = (decimal)modelvip.F_Money + modelOrder.F_ShouldPrice;
  2365. }
  2366. else
  2367. moneys = modelOrder.F_ShouldPrice;
  2368. int b = 0;
  2369. if (moneys > 3000)
  2370. {
  2371. decimal fund = moneys - 3000;
  2372. string c = string.Format("{0:f0}", Math.Floor(fund / 2000));
  2373. b = int.Parse(c) + 1 - modelvip.F_UseGift;
  2374. }
  2375. int n2 = 0;
  2376. foreach (var m in input.OrderUserGift)
  2377. {
  2378. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  2379. modelDetail.F_ProductName = m.F_ProductName;
  2380. modelDetail.F_ProductId = m.F_ProductId;
  2381. modelDetail.F_Specifications = m.F_Specifications;
  2382. modelDetail.F_ProductShortName = m.F_ProductShortName;
  2383. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  2384. modelDetail.F_OrderId = input.F_Id;
  2385. modelDetail.F_Count = 1;
  2386. modelDetail.F_Price = 0.00M;
  2387. modelDetail.F_DealPrice = 0.00M;
  2388. modelDetail.F_Sort = n2;
  2389. modelDetail.F_Remark = "满赠营销";
  2390. modelDetail.F_AddUser = modelOrder.F_AddUser;
  2391. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  2392. modelDetail.F_TotlePrice = 0.00M;
  2393. modelDetail.F_Activity = 0;
  2394. modelDetail.F_AddTime = DateTime.Now;
  2395. modelDetailList.Add(modelDetail);
  2396. n2++;
  2397. }
  2398. if (n2 > b)
  2399. {
  2400. return Error("该会员最多可赠送" + b + "件赠品");
  2401. }
  2402. else
  2403. {
  2404. modelvip.F_UseGift += n2;
  2405. modelOrder.F_UseGift = n2;
  2406. }
  2407. }
  2408. if (modelvip != null)
  2409. {
  2410. modelvip.F_Score -= modelOrder.F_UseScore;
  2411. await cus_vip_infoRepository.Update(modelvip);
  2412. }
  2413. if (input.F_State == 1)
  2414. {
  2415. if (modelOrder.F_State == 1)
  2416. count += "进入客服待分仓";
  2417. else if (modelOrder.F_State == 7)
  2418. count += "进入客服待付款待审核";
  2419. }
  2420. else
  2421. count += "进入销售待提交";
  2422. }
  2423. if (input.F_IsPayment > 0 || input.F_PayType != "货到付款")
  2424. {
  2425. try
  2426. {
  2427. if (string.IsNullOrEmpty(input.F_PayType))
  2428. return Error("请输入打款方式");
  2429. if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkKF))
  2430. input.OrderMoney.F_RemarkKF = "";
  2431. if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkXS))
  2432. input.OrderMoney.F_RemarkXS = "";
  2433. if (input.OrderMoney.F_PayTime == null)
  2434. return Error("请输入打款时间");
  2435. if (input.OrderMoney.F_Money <= 0)
  2436. return Error("请输入付款金额");
  2437. #region 验证参数 必填项
  2438. Expression<Func<T_Bus_OrderMoney, bool>> eq = a => a.F_OrderId == input.F_Id;
  2439. //var modelOrderMoen = await busOrderMoneyRepository.GetListALL(eq, o => o.F_AddTime, OrderByType.Asc);
  2440. var modelOrderMoen = await busOrderMoneyRepository.GetListALL(x => x.F_OrderId == modelOrder.F_Id && x.F_Type == 1);
  2441. T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
  2442. if (modelOrderMoen != null && modelOrderMoen.Count > 0)
  2443. {
  2444. modelOrderMoeny = modelOrderMoen.FirstOrDefault();
  2445. }
  2446. modelOrder.F_RealPrice = input.OrderMoney.F_Money;
  2447. #endregion
  2448. ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input.OrderMoney);
  2449. modelOrderMoeny.F_AddUserId = UserLogin.UserId.ObjToInt();
  2450. modelOrderMoeny.F_UserName = UserLogin.UserName;
  2451. modelOrderMoeny.F_OrderId = input.F_Id;
  2452. modelOrderMoeny.F_MoneyBak = modelOrderMoeny.F_Money;
  2453. modelOrderMoeny.F_State = 0;
  2454. modelOrderMoeny.F_Type = 1;
  2455. if (modelOrderMoen != null && modelOrderMoen.Count > 0)
  2456. {
  2457. if (!await busOrderMoneyRepository.Update(modelOrderMoeny))
  2458. return Error("付款失败");
  2459. }
  2460. else
  2461. {
  2462. modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  2463. if (!await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
  2464. return Error("付款失败");
  2465. }
  2466. }
  2467. catch (Exception ex)
  2468. { return Error(ex.Message); }
  2469. }
  2470. //DataTable dt=await busOrderMoneyRepository.GetTableSugar(string.Format("SELECT IFNULL(SUM(F_Money),0) FROM T_Bus_OrderMoney WHERE F_OrderId='{0}' AND F_State=1", modelOrder.F_Id));
  2471. //modelOrder.F_RealPrice = dt.Rows[0][0].ObjToDecimal() ;
  2472. //if (modelOrder.F_ShouldPrice > 0)
  2473. //{
  2474. // if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  2475. // modelOrder.F_PayState = 1;
  2476. // else
  2477. // modelOrder.F_PayState = 0;
  2478. //}
  2479. //else
  2480. //{
  2481. // if (modelOrder.F_ShouldPrice >= modelOrder.F_RealPrice)
  2482. // modelOrder.F_PayState = 3;
  2483. // else
  2484. // modelOrder.F_PayState = 2;
  2485. //}
  2486. //待付款 客服审核付款情况后改为已付款
  2487. int t = await AddLog(modelOrder.F_Id, count, UserLogin.UserCode , modelOrder.F_State);
  2488. if (t >0)
  2489. {
  2490. if (await bus_OrderRepository.Update(modelOrder))
  2491. {
  2492. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  2493. {
  2494. //删除之前订单商品,重新添加
  2495. if (await bus_OrderDetailRepository.Delete(q => q.F_OrderId == modelOrder.F_Id))
  2496. {
  2497. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  2498. return Success("订单生成成功");
  2499. else
  2500. return Error("订单操作失败,请重试1!");
  2501. }
  2502. else
  2503. {
  2504. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  2505. return Success("订单生成成功2");
  2506. else
  2507. return Error("订单操作失败,请重试2!");
  2508. }
  2509. }
  2510. else if (input.OrderUserGift != null && input.OrderUserGift.Count > 0)
  2511. {
  2512. //删除之前订单商品,重新添加
  2513. if (await bus_OrderDetailRepository.Delete(q => q.F_OrderId == modelOrder.F_Id
  2514. &&q .F_Remark == "满赠营销"))
  2515. {
  2516. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  2517. return Success("订单生成成功");
  2518. else
  2519. return Error("订单操作失败,请重试1!");
  2520. }
  2521. else
  2522. {
  2523. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  2524. return Success("订单生成成功2");
  2525. else
  2526. return Error("订单操作失败,请重试2!");
  2527. }
  2528. }
  2529. else { return Success("成功"); }
  2530. }
  2531. }
  2532. return Error("订单添加失败,请重试!");
  2533. }
  2534. #endregion
  2535. /// <summary>
  2536. /// 根据商品组合 获取符合的所有活动
  2537. /// </summary>
  2538. /// <param name="input"></param>
  2539. /// <returns></returns>
  2540. [HttpPost("getact")]
  2541. public async Task<IActionResult> GetAct([FromBody]List<OrderDetailInput> input)
  2542. {
  2543. decimal def = 0.00M;
  2544. if (input==null&& input.Count<=0)
  2545. return Error("请选择商品/数量");
  2546. //统计活动金额是否符合条件 满减
  2547. Dictionary<int, decimal> acttype3 = new Dictionary<int, decimal>();
  2548. //内部计算
  2549. Dictionary<int, decimal> innerCompute = new Dictionary<int, decimal>();
  2550. //选择活动
  2551. Dictionary<int, string> chooseact = new Dictionary<int, string>();
  2552. List<UseActInput> actlist = new List<UseActInput>();
  2553. Dictionary<string , string> MarketingDic = new Dictionary<string, string>();
  2554. List<T_Sys_Marketing> t_Sys_Marketings = new List<T_Sys_Marketing>();
  2555. foreach (var m in input)
  2556. {
  2557. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  2558. if (modelProduct != null)
  2559. {
  2560. if (modelProduct.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
  2561. {
  2562. return Error("商品已下架:" + modelProduct.F_ProductName);
  2563. }
  2564. if (modelProduct.F_Tag.IndexOf(".") > -1)
  2565. {
  2566. string[] tagarry = modelProduct.F_Tag.Split(',');
  2567. foreach (var it in tagarry)
  2568. {
  2569. var Marketing = await bus_MarketingRepository.GetListALL(q => q.F_IsDelete == 0 && q.F_Commodity==
  2570. it && q.F_StartTime <= DateTime.Now && q.F_EndTime >= DateTime.Now && q.F_IsDelete == 0);
  2571. if (Marketing!=null&& Marketing.Count >0)
  2572. {
  2573. T_Sys_Marketing modelactive = Marketing.FirstOrDefault();
  2574. //if (modelactive.F_Type == 1)
  2575. //{
  2576. // //满赠
  2577. // //判断此人是否有参与活动的资格 默认暂不筛选
  2578. // if (chooseact.ContainsKey(modelactive.F_ID))
  2579. // continue;
  2580. // if (innerCompute.ContainsKey(modelactive.F_ID))
  2581. // {
  2582. // innerCompute[modelactive.F_ID] = (decimal)modelProduct.F_MemberPrice * m.F_Count + innerCompute[modelactive.F_ID].ObjToDecimal();
  2583. // }
  2584. // else
  2585. // {
  2586. // innerCompute.Add(modelactive.F_ID, (decimal)modelProduct.F_MemberPrice * m.F_Count);
  2587. // }
  2588. // if (modelactive.F_Money.ObjToDecimal() <= (decimal)innerCompute[modelactive.F_ID])
  2589. // {
  2590. // chooseact.Add(modelactive.F_ID, "1_" + modelactive.F_Gift);
  2591. // actlist.Add(new UseActInput { id = modelactive.F_ID, type = 1, gift = modelactive.F_Gift, money = def, actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  2592. // }
  2593. //}
  2594. //else
  2595. if (modelactive.F_Type == 2)
  2596. {
  2597. // 生日
  2598. //TODO 判断此人是否有参与活动的资格 默认暂不筛选
  2599. if (chooseact.ContainsKey(modelactive.F_ID))
  2600. continue;
  2601. chooseact.Add(modelactive.F_ID, "2_" + modelactive.F_Commodity);
  2602. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 2, gift = modelactive.F_Gift, money = def, actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  2603. }
  2604. else if (modelactive.F_Type == 3)
  2605. {
  2606. //满减
  2607. //判断此人是否有参与活动的资格 默认暂不筛选
  2608. string[] AmountRange = modelactive.F_AmountRange.Split(',');
  2609. if (modelactive.F_Describe == "按总件数")
  2610. {
  2611. if (innerCompute.ContainsKey(modelactive.F_ID))
  2612. {
  2613. innerCompute[modelactive.F_ID] = m.F_Count + innerCompute[modelactive.F_ID];
  2614. }
  2615. else
  2616. {
  2617. innerCompute.Add(modelactive.F_ID, m.F_Count);
  2618. }
  2619. for (int i = 0; i < AmountRange.Length; i++)
  2620. {
  2621. //符合满减某个条件
  2622. if (innerCompute[modelactive.F_ID] >= AmountRange[i].ObjToDecimal())
  2623. {
  2624. if (acttype3.ContainsKey(modelactive.F_ID))
  2625. {
  2626. string a = string.Format("{0:f0}", Math.Floor(innerCompute[modelactive.F_ID] / AmountRange[i].ObjToDecimal()));
  2627. acttype3[modelactive.F_ID] = modelactive.F_Money.Split(',')[i].ObjToDecimal() * int.Parse(a);
  2628. actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.money = modelactive.F_Money.Split(',')[i].ObjToDecimal() * int.Parse(a); } });
  2629. }
  2630. else
  2631. {
  2632. string a = string.Format("{0:f0}", Math.Floor(innerCompute[modelactive.F_ID] / AmountRange[i].ObjToDecimal()));
  2633. acttype3.Add(modelactive.F_ID, modelactive.F_Money.Split(',')[i].ObjToDecimal() * int.Parse(a));
  2634. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 3, gift = "", money = modelactive.F_Money.Split(',')[i].ObjToDecimal() * int.Parse(a), actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  2635. }
  2636. }
  2637. }
  2638. }
  2639. else
  2640. {
  2641. if (innerCompute.ContainsKey(modelactive.F_ID))
  2642. {
  2643. innerCompute[modelactive.F_ID] = (decimal)modelProduct.F_MemberPrice * m.F_Count + innerCompute[modelactive.F_ID];
  2644. }
  2645. else
  2646. {
  2647. innerCompute.Add(modelactive.F_ID, (decimal)modelProduct.F_MemberPrice * m.F_Count);
  2648. }
  2649. for (int i = 0; i < AmountRange.Length; i++)
  2650. {
  2651. //符合满减某个条件
  2652. if (innerCompute[modelactive.F_ID] >= AmountRange[i].ObjToDecimal())
  2653. {
  2654. if (acttype3.ContainsKey(modelactive.F_ID))
  2655. {
  2656. //当前减免金额大于之前发赋值,替换掉
  2657. if (modelactive.F_Money.Split(',')[i].ObjToDecimal() > acttype3[modelactive.F_ID])
  2658. {
  2659. acttype3[modelactive.F_ID] = modelactive.F_Money.Split(',')[i].ObjToDecimal();
  2660. actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.money = modelactive.F_Money.Split(',')[i].ObjToDecimal(); } });
  2661. }
  2662. }
  2663. else
  2664. {
  2665. //满足条件,赋值满减金额 减的金额
  2666. acttype3.Add(modelactive.F_ID, modelactive.F_Money.Split(',')[i].ObjToDecimal());
  2667. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 3, gift = "", money = modelactive.F_Money.Split(',')[i].ObjToDecimal(), actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  2668. }
  2669. }
  2670. }
  2671. }
  2672. }
  2673. else if (modelactive.F_Type == 4)
  2674. {
  2675. //限时特惠
  2676. //判断此人是否有参与活动的资格 默认暂不筛选
  2677. if (chooseact.ContainsKey(modelactive.F_ID))
  2678. {
  2679. chooseact[modelactive.F_ID] = chooseact[modelactive.F_ID] + "," + m.F_ProductId.ToString();
  2680. actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.gift = q.gift + m.F_ProductId.ToString(); } });
  2681. }
  2682. else
  2683. {
  2684. chooseact.Add(modelactive.F_ID, "4_" + m.F_ProductId.ToString());
  2685. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 4, gift = m.F_ProductId.ToString(), money = modelactive.F_Money.ObjToDecimal(), actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. else
  2693. {
  2694. return Error("商品不存在" + modelProduct.F_ProductName);
  2695. }
  2696. }
  2697. return Success("参与活动", actlist);
  2698. }
  2699. /// <summary>
  2700. /// 获取订单详情
  2701. /// </summary>
  2702. /// <param name="input"></param>
  2703. /// <returns></returns>
  2704. [HttpPost("getorderdetail")]
  2705. public async Task<IActionResult> GetOrderDetail(string orderid)
  2706. {
  2707. if (string.IsNullOrEmpty(orderid))
  2708. return Error("请输入订单号");
  2709. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == orderid);
  2710. OrderInput modelreturn = new OrderInput();
  2711. if (modelOrder != null)
  2712. {
  2713. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(modelreturn, modelOrder);
  2714. List<OrderDetailInput> modeldetailreturn = new List<OrderDetailInput>();
  2715. List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id
  2716. &&q .F_Remark!="满赠营销", o => o.F_Sort, OrderByType.Asc);
  2717. if (detaillist != null)
  2718. {
  2719. foreach (T_Bus_OrderDetail m in detaillist)
  2720. {
  2721. OrderDetailInput model = new OrderDetailInput();
  2722. model.F_ProductName = m.F_ProductName;
  2723. model.F_ProductId = m.F_ProductId;
  2724. model.F_Specifications = m.F_Specifications;
  2725. model.F_ProductShortName = m.F_ProductShortName;
  2726. model.F_Id = m.F_Id;
  2727. model.F_OrderId = m.F_OrderId;
  2728. model.F_Count = m.F_Count;
  2729. model.F_Price = m.F_Price;
  2730. model.F_DealPrice = m.F_DealPrice;
  2731. model.F_Sort = m.F_Sort;
  2732. model.F_AddTime = m.F_AddTime;
  2733. model.F_Remark = m.F_Remark;
  2734. model.F_AddUser = m.F_AddUser;
  2735. model.F_AddUserName = m.F_ProductName;
  2736. model.F_TotlePrice = m.F_TotlePrice;
  2737. model.F_Activity = m.F_Activity;
  2738. modeldetailreturn.Add(model);
  2739. }
  2740. }
  2741. modelreturn.OrderDetailList = modeldetailreturn;
  2742. List<OrderDetailInput> modelUserGift = new List<OrderDetailInput>();
  2743. List<T_Bus_OrderDetail> detaillistgife = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id
  2744. && q.F_Remark == "满赠营销", o => o.F_Sort, OrderByType.Asc);
  2745. if (detaillist != null)
  2746. {
  2747. foreach (T_Bus_OrderDetail m in detaillistgife)
  2748. {
  2749. OrderDetailInput model = new OrderDetailInput();
  2750. model.F_ProductName = m.F_ProductName;
  2751. model.F_ProductId = m.F_ProductId;
  2752. model.F_Specifications = m.F_Specifications;
  2753. model.F_ProductShortName = m.F_ProductShortName;
  2754. model.F_Id = m.F_Id;
  2755. model.F_OrderId = m.F_OrderId;
  2756. model.F_Count = m.F_Count;
  2757. model.F_Price = m.F_Price;
  2758. model.F_DealPrice = m.F_DealPrice;
  2759. model.F_Sort = m.F_Sort;
  2760. model.F_AddTime = m.F_AddTime;
  2761. model.F_Remark = m.F_Remark;
  2762. model.F_AddUser = m.F_AddUser;
  2763. model.F_AddUserName = m.F_ProductName;
  2764. model.F_TotlePrice = m.F_TotlePrice;
  2765. model.F_Activity = m.F_Activity;
  2766. modelUserGift.Add(model);
  2767. }
  2768. }
  2769. modelreturn.OrderUserGift = modelUserGift;
  2770. var useraccount =await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelOrder.F_Belong);
  2771. if (useraccount!=null )
  2772. {
  2773. modelreturn.F_BelongName = useraccount.F_UserName;
  2774. modelreturn.F_GroupName = useraccount.F_Group ;
  2775. modelreturn.F_CoreName = useraccount.F_Team ;
  2776. }
  2777. modelreturn.UseActList = new List<UseActInput>();
  2778. List<IConditionalModel> conModels = new List<IConditionalModel>();
  2779. conModels.Add(new ConditionalModel() { FieldName = "F_ID", ConditionalType = ConditionalType.In , FieldValue = modelOrder.F_UseActivity });
  2780. List<T_Sys_Marketing> modelactiveList = await bus_MarketingRepository.GetListALL(conModels, "F_ID DESC");
  2781. Dictionary<string, string> innerEventprice = new Dictionary<string, string >();
  2782. if (modelactiveList != null && modelactiveList.Count > 0)
  2783. {
  2784. if (!string.IsNullOrEmpty(modelOrder.F_Eventprice))
  2785. {
  2786. string[] Eventprice = modelOrder.F_Eventprice.Split('|');
  2787. foreach (var it in Eventprice)
  2788. {
  2789. try
  2790. {
  2791. string[] sprit = it.Split(',');
  2792. innerEventprice.Add(sprit[0], sprit[1]);
  2793. }
  2794. catch
  2795. {
  2796. }
  2797. }
  2798. }
  2799. if (!string.IsNullOrEmpty(modelOrder.F_Eventprice))
  2800. {
  2801. foreach (T_Sys_Marketing modelactive in modelactiveList)
  2802. {
  2803. modelreturn.UseActList.Add(new UseActInput
  2804. {
  2805. id = modelactive.F_ID,
  2806. type = modelactive.F_Type,
  2807. gift = modelactive.F_Gift,
  2808. money = decimal.Parse(innerEventprice[modelactive.F_ID.ToString()]),
  2809. actname = modelactive.F_Name,
  2810. actdes = modelactive.F_PromotionRules
  2811. });
  2812. }
  2813. }
  2814. else
  2815. {
  2816. foreach (T_Sys_Marketing modelactive in modelactiveList)
  2817. {
  2818. modelreturn.UseActList.Add(new UseActInput
  2819. {
  2820. id = modelactive.F_ID,
  2821. type = modelactive.F_Type,
  2822. gift = modelactive.F_Gift,
  2823. money = modelOrder.F_ActivityMoney,
  2824. actname = modelactive.F_Name,
  2825. actdes = modelactive.F_PromotionRules
  2826. });
  2827. }
  2828. }
  2829. }
  2830. // modelreturn.UseActList = actlist;
  2831. }
  2832. else
  2833. return Error("订单不存在");
  2834. Expression<Func<T_Bus_Orderlogs , bool>> eq = a => a.F_WoID == orderid;
  2835. var ItemList = await busOrderlogsRepository.GetListALL(eq, o => o.F_CreateTime , OrderByType.Desc );
  2836. Expression<Func<T_Bus_ChatLog, bool>> aq = a => a.F_WoID == orderid;
  2837. aq = aq.And(a => a.F_IsDelete == 0);
  2838. var modelOrderMoen = await busOrderMoneyRepository.GetListALL(x => x.F_OrderId == modelOrder.F_Id && x.F_Type == 1);
  2839. modelreturn.OrderMoney = new OrderMoneyInput();
  2840. if (modelOrderMoen!=null && modelOrderMoen.Count >0)
  2841. {
  2842. ModelConvertHelper<OrderMoneyInput, T_Bus_OrderMoney>.ModeToModel(modelreturn.OrderMoney, modelOrderMoen.FirstOrDefault());
  2843. }
  2844. V_Cus_VipInfo vip = new V_Cus_VipInfo();
  2845. if (modelOrder.F_VipId >0)
  2846. {
  2847. vip = await cus_vip_infoRepository .GetSingleV(x => x.F_ID == modelOrder.F_VipId && x.F_State == (int)EnumDelState.Enabled);
  2848. }
  2849. if (UserLogin.RoleCode == "XS")
  2850. {
  2851. aq = aq.And(a => a.F_IsSo ==1);
  2852. }
  2853. aq = aq.And(a => a.F_State == 0);
  2854. var ChatList = await bus_ChatLogRepository.GetListALL(aq, o => o.F_AddTime , OrderByType.Asc);
  2855. var obj = new
  2856. {
  2857. modelreturn,
  2858. ItemList,
  2859. ChatList,
  2860. vip
  2861. };
  2862. return Content(obj.ToJson());
  2863. }
  2864. /// <summary>
  2865. /// 获取订单分页列表
  2866. /// </summary>
  2867. /// <param name="input"></param>
  2868. /// <returns></returns>
  2869. [HttpPost("getorderlistbypage")]
  2870. public async Task<IActionResult> GetXSOrderListByPage(OrderInput input,string keywords,int State = -1)
  2871. {
  2872. List<IConditionalModel> conModels = new List<IConditionalModel>();
  2873. #region 条件筛选
  2874. if (State > 0)
  2875. {
  2876. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.NotIn, FieldValue = "0,2" });
  2877. }
  2878. if (input.F_State > -2)
  2879. {
  2880. if (input.F_State == 14)
  2881. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.In, FieldValue = "1,4,7" });
  2882. else
  2883. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = input.F_State.ToString() });
  2884. }
  2885. if (!string.IsNullOrEmpty(input .F_SubmitUser ))
  2886. {
  2887. conModels.Add(new ConditionalModel() { FieldName = "F_SubmitUser", ConditionalType = ConditionalType.Like , FieldValue = input.F_SubmitUser });
  2888. }
  2889. //根据角色展示列表
  2890. if (UserLogin.RoleCode == "XS")
  2891. {
  2892. conModels.Add(new ConditionalCollections()
  2893. {
  2894. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  2895. {
  2896. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_AddUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  2897. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Belong", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId })
  2898. }
  2899. } );
  2900. }
  2901. else if (UserLogin.RoleCode == "KF" && input.F_State != 1)
  2902. {
  2903. conModels.Add(new ConditionalModel() { FieldName = "F_CheckUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  2904. }
  2905. else if (UserLogin.RoleCode == "KG" && input.F_State != 3)
  2906. {
  2907. conModels.Add(new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  2908. //OR conModels.Add(new ConditionalModel() { FieldName = "F_SendUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  2909. }
  2910. else if (UserLogin .RoleCode == "ZXFZR")
  2911. {
  2912. var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == UserLogin.UserId .ObjToInt());
  2913. conModels.Add(new ConditionalModel() { FieldName = "F_Core", ConditionalType = ConditionalType.Equal, FieldValue = useraccount.F_DeptTeamId.ToString() });
  2914. }
  2915. else if (UserLogin.RoleCode == "XZFZR")
  2916. {
  2917. var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == UserLogin.UserId.ObjToInt());
  2918. conModels.Add(new ConditionalModel() { FieldName = "F_Group", ConditionalType = ConditionalType.Equal, FieldValue = useraccount.F_GroupId .ToString() });
  2919. }
  2920. if (input.F_Core > 0)
  2921. {
  2922. conModels.Add(new ConditionalModel() { FieldName = "F_Core", ConditionalType = ConditionalType.Like, FieldValue = input.F_Core.ToString() });
  2923. }
  2924. if (input.F_Group > 0)
  2925. {
  2926. conModels.Add(new ConditionalModel() { FieldName = "F_Group", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Group.ToString () });
  2927. }
  2928. if (!string .IsNullOrEmpty (input.F_BelongName))
  2929. {
  2930. conModels.Add(new ConditionalModel() { FieldName = "F_BelongName", ConditionalType = ConditionalType.Equal, FieldValue = input.F_BelongName });
  2931. }
  2932. if (!string.IsNullOrEmpty(input.F_ADFrom))
  2933. {
  2934. conModels.Add(new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Like, FieldValue = input.F_ADFrom });
  2935. }
  2936. if (!string.IsNullOrEmpty(input.F_Type))
  2937. {
  2938. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Type });
  2939. }
  2940. if (!string.IsNullOrEmpty(input.F_Id))
  2941. {
  2942. conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Like, FieldValue = input.F_Id });
  2943. }
  2944. if (input .F_IsZeroCommodity>-1)
  2945. {
  2946. conModels.Add(new ConditionalModel() { FieldName = "F_IsZeroCommodity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_IsZeroCommodity.ToString () });
  2947. }
  2948. if (!string.IsNullOrEmpty(input.F_Customer))
  2949. {
  2950. conModels.Add(new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Like, FieldValue = input.F_Customer });
  2951. }
  2952. if (input.F_Media > 0)
  2953. {
  2954. conModels.Add(new ConditionalModel() { FieldName = "F_Media", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Media.ToString () });
  2955. }
  2956. if (input.F_Status > -1)
  2957. {
  2958. conModels.Add(new ConditionalModel() { FieldName = "F_Status", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Status.ToString() });
  2959. }
  2960. if (!string.IsNullOrEmpty(keywords))
  2961. {
  2962. conModels.Add(new ConditionalCollections()
  2963. {
  2964. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  2965. {
  2966. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
  2967. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
  2968. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Addressee", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
  2969. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_AddPhone", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
  2970. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_CustomerTel", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
  2971. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
  2972. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
  2973. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Like, FieldValue = keywords })
  2974. }
  2975. });
  2976. }
  2977. if (input.F_VipId>0)
  2978. {
  2979. var model = await cus_vip_infoRepository.GetSingleV(x => x.F_ID == input.F_VipId && x.F_State == (int)EnumDelState.Enabled);
  2980. if (model == null)
  2981. return Error("会员不存在");
  2982. var modellist = await cus_vip_infoRepository.GetListALL(x => x.F_ParentID == input.F_VipId && x.F_State == (int)EnumDelState.Delete);
  2983. if (modellist != null || modellist.Count> 0)
  2984. {
  2985. string msgvip = input.F_VipId.ToString();
  2986. foreach (var it in modellist)
  2987. {
  2988. msgvip+=","+ it.F_ID ;
  2989. }
  2990. conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.In, FieldValue = msgvip });
  2991. }
  2992. else
  2993. conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.Equal, FieldValue = input.F_VipId.ToString() });
  2994. }
  2995. if (!string.IsNullOrEmpty(input.F_CustomerPhone))
  2996. {
  2997. conModels.Add(new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Like , FieldValue = input.F_CustomerPhone });
  2998. }
  2999. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  3000. {
  3001. conModels.Add(new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Like, FieldValue = input.F_TrackingNo });
  3002. }
  3003. if (!string.IsNullOrEmpty(input.F_AddProvince))
  3004. {
  3005. conModels.Add(new ConditionalModel() { FieldName = "F_AddProvince", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddProvince });
  3006. }
  3007. if (!string.IsNullOrEmpty(input.F_AddCity))
  3008. {
  3009. conModels.Add(new ConditionalModel() { FieldName = "F_AddCity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddCity });
  3010. }
  3011. if (!string.IsNullOrEmpty(input.F_AddArea))
  3012. {
  3013. conModels.Add(new ConditionalModel() { FieldName = "F_AddArea", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddArea });
  3014. }
  3015. if (!string.IsNullOrEmpty(input.F_AddTown))
  3016. {
  3017. conModels.Add(new ConditionalModel() { FieldName = "F_AddTown", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddTown });
  3018. }
  3019. if (!string.IsNullOrEmpty(input.F_Express))
  3020. {
  3021. conModels.Add(new ConditionalModel() { FieldName = "F_Express", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Express });
  3022. }
  3023. if (!string.IsNullOrEmpty(input.F_PayType))
  3024. {
  3025. conModels.Add(new ConditionalModel() { FieldName = "F_PayType", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayType });
  3026. }
  3027. if (!string.IsNullOrEmpty(input.F_Stock))
  3028. {
  3029. conModels.Add(new ConditionalModel() { FieldName = "F_Stock", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Stock });
  3030. }
  3031. if (input.F_PayState > -1)
  3032. {
  3033. conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
  3034. }
  3035. if (input.SearchEndTime != null)
  3036. {
  3037. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
  3038. }
  3039. if (input.SearchStartTime != null)
  3040. {
  3041. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
  3042. }
  3043. #endregion
  3044. RefAsync<int> recordCount = 0;
  3045. PageData<T_Bus_Order> list = await bus_OrderRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = recordCount }, " F_AddTime DESC");
  3046. PageData<OrderInput> returnobj = new PageData<OrderInput>() { Totals = list.Totals };
  3047. List<OrderInput> returnlist = new List<OrderInput>();
  3048. foreach (T_Bus_Order t in list.Rows)
  3049. {
  3050. OrderInput m = new OrderInput();
  3051. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(m, t);
  3052. List<OrderDetailInput> orderDetailInputs = new List<OrderDetailInput>();
  3053. #region 遍历订单商品
  3054. List<T_Bus_OrderDetail> orderDetails = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == t.F_Id);
  3055. if (orderDetails != null)
  3056. {
  3057. foreach (T_Bus_OrderDetail t1 in orderDetails)
  3058. {
  3059. OrderDetailInput m1 = new OrderDetailInput();
  3060. ModelConvertHelper<OrderDetailInput, T_Bus_OrderDetail>.ModeToModel(m1, t1);
  3061. orderDetailInputs.Add(m1);
  3062. }
  3063. }
  3064. #endregion
  3065. m.OrderDetailList = orderDetailInputs;
  3066. m.IsSale = busAfterSaleRepository.GetListALL(x => x.F_OrderId == t.F_Id).Result!=null
  3067. ? busAfterSaleRepository.GetListALL(x => x.F_OrderId == t.F_Id).Result.Count :0;
  3068. returnlist.Add(m);
  3069. }
  3070. returnobj.Rows = returnlist;
  3071. return Success("成功", returnobj);
  3072. }
  3073. /// <summary>
  3074. /// 撤回未审核订单
  3075. /// </summary>
  3076. /// <param name="orderid">订单号</param>
  3077. /// <param name="state">订单状态 -1无效 0暂存 1提交 2KF退回 3通过 4KG退回 5已分拣 6已发货</param>
  3078. /// <param name="remark">客服备注</param>
  3079. /// <returns></returns>
  3080. [HttpPost("cancelorder")]
  3081. public async Task<IActionResult> CancelOrder(string orderids, int state = 0)
  3082. {
  3083. try
  3084. {
  3085. //状态变化 积分变化 处理时间人变化 库存变化 备注
  3086. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  3087. #region 验证参数 必填项
  3088. if (string.IsNullOrEmpty(orderids))
  3089. return Error("请选择订单号");
  3090. if (state != 0)
  3091. return Error("请选择操作类型");
  3092. string[] orderid = orderids.Split(',');
  3093. string msg = "";
  3094. #endregion
  3095. List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
  3096. List<T_Bus_Order> orders = new List<T_Bus_Order>();
  3097. foreach (var it in orderid)
  3098. {
  3099. T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
  3100. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == it && new int[] {1, 3, 7 }.Contains(q.F_State));
  3101. if (modelOrder == null)
  3102. {
  3103. msg +="订单"+ it + "已审核";
  3104. continue;
  3105. }
  3106. else
  3107. {
  3108. if (modelOrder.F_State ==1)
  3109. {
  3110. List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id, o => o.F_Sort, OrderByType.Asc);
  3111. // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
  3112. if (detaillist != null && detaillist.Count > 0)
  3113. {
  3114. foreach (var iv in detaillist)
  3115. {
  3116. T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == iv.F_ProductId);
  3117. if (t_Bus_Product != null)
  3118. {
  3119. // t_Bus_Product.F_UseNumber -= iv.F_Count;
  3120. // Productlist.Add(t_Bus_Product);
  3121. }
  3122. else
  3123. {
  3124. msg += "订单" + modelOrder.F_Id + "退回失败,商品不存在.";
  3125. continue;
  3126. }
  3127. }
  3128. //if (Productlist != null && Productlist.Count > 0)
  3129. //{
  3130. // if (!await bus_productRepository.UpdateList(Productlist))
  3131. // {
  3132. // msg += "订单" + modelOrder.F_Id + "退回失败";
  3133. // continue;
  3134. // }
  3135. // }
  3136. //else
  3137. //{
  3138. // msg += "订单" + modelOrder.F_Id + "退回失败,请选择商品";
  3139. // continue;
  3140. //}
  3141. }
  3142. }
  3143. modelOrder.F_TrackingNo = "";
  3144. modelOrder.F_Express = "";
  3145. modelOrder.F_IsExpress = 0;
  3146. modelOrder.F_Stock = "";
  3147. modelOrder.F_State = state;
  3148. t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
  3149. t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
  3150. t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
  3151. t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "撤回订单,流转销售待提交";
  3152. t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
  3153. logs.Add(t_Bus_Orderlogs);
  3154. orders.Add(modelOrder);
  3155. }
  3156. }
  3157. // string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 0, null);
  3158. // if (strStock != "1")
  3159. // return Error(strStock);
  3160. // modelOrder.F_State = 0;
  3161. // modelOrder.F_Score = 0.00M;
  3162. if (msg =="")
  3163. {
  3164. if (await bus_OrderRepository.UpdateList(orders))
  3165. {
  3166. await busOrderlogsRepository.AddMany (logs);
  3167. return Success("订单成功审核!");
  3168. }
  3169. }
  3170. else
  3171. return Error(msg);
  3172. return Error("订单审核失败,请汇报技术支持!");
  3173. }
  3174. catch (Exception ex)
  3175. { return Error(ex.Message); }
  3176. }
  3177. [HttpPost("ordermoney")]
  3178. public async Task<IActionResult> OrderMoney(OrderMoneyInput input)
  3179. {
  3180. try
  3181. {
  3182. #region 验证参数 必填项
  3183. if (string.IsNullOrEmpty(input.F_OrderId))
  3184. return Error("请输入订单号");
  3185. if (string.IsNullOrEmpty(input.F_PayUser))
  3186. return Error("请输入打款人");
  3187. if (string.IsNullOrEmpty(input.F_PayType))
  3188. return Error("请输入打款方式");
  3189. if (string.IsNullOrEmpty(input.F_RemarkKF))
  3190. input.F_RemarkKF = "";
  3191. if (string.IsNullOrEmpty(input.F_RemarkXS))
  3192. input.F_RemarkXS = "";
  3193. if (input.F_PayTime==null)
  3194. return Error("请输入打款时间");
  3195. if (input.F_Money <= 0)
  3196. return Error("请输入金额");
  3197. #endregion
  3198. T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
  3199. ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input);
  3200. modelOrderMoeny.F_AddUserId =UserLogin.UserId.ObjToInt();
  3201. modelOrderMoeny.F_UserName = UserLogin.UserName;
  3202. modelOrderMoeny.F_MoneyBak= modelOrderMoeny.F_Money;
  3203. modelOrderMoeny.F_State= 0;
  3204. modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-","");
  3205. if (await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
  3206. return Success("成功!");
  3207. return Error("失败!");
  3208. }
  3209. catch (Exception ex)
  3210. { return Error(ex.Message); }
  3211. }
  3212. private async Task<int> AddLog(string WoID,string count,string user,int state)
  3213. {
  3214. T_Bus_Orderlogs logs = new T_Bus_Orderlogs();
  3215. logs.F_WoID = WoID;
  3216. logs.F_WoState = state;
  3217. logs.F_OptContent = count;
  3218. logs.F_CreateUser = user;
  3219. logs.F_CreateTime = DateTime .Now ;
  3220. var res =await busOrderlogsRepository.Add(logs);
  3221. return res;
  3222. }
  3223. }
  3224. }