| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553 |
- /* =============================================
- -- Author: <Author,,zhangkun>
- -- Create date: <Create Date,,20200618>
- -- Description: <Description,,订单相关操作)>
- -- ============================================*/
- using System;
- using System.Collections.Generic;
- using System.Common;
- using System.Common.Helpers;
- using System.Data;
- using System.IRepositories;
- using System.IRepositories.Bus;
- using System.IRepositories.Cus;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Model;
- using System.Model.Bus;
- using System.Model.Cus;
- using System.Repositories;
- using System.Security.Claims;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Utility.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
- using Microsoft.Extensions.Configuration;
- using SqlSugar;
- using TVShoppingCallCenter_ZLJ.Models.Inputs;
- namespace TVShoppingCallCenter_ZLJ.Controllers.Order
- {
- [Produces("application/json")]
- [Route("api/[controller]")]
- public class OrderController : BaseController
- {
- private readonly IBus_OrderDetailRepository bus_OrderDetailRepository;
- private readonly IBus_OrderRepository bus_OrderRepository;
- private readonly ISys_MarketingRepository bus_MarketingRepository;
- private readonly IBus_ProductRepository bus_productRepository;
- private readonly ICus_VipInfoRepository cus_vip_infoRepository;
- private readonly IBus_StockLogRepository bus_StockLogRepository;
- private readonly ICus_ScoreSetRepository cus_score_setRepository;
- private readonly IBus_OrderMoneyRepository busOrderMoneyRepository;
- private readonly IConfiguration config;
- private readonly IBus_AfterSaleRepository busAfterSaleRepository;
- private readonly IBus_OrderlogsRepository busOrderlogsRepository;
- private readonly IBus_ChatLogRepository bus_ChatLogRepository;
- private readonly ICus_MembershipRepository _cus_membershiprepository;
- private readonly ISys_UserAccountRepository _sys_useraccountRepository;
- private readonly OrderFunctionController busOrderFunctionController;
- 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
- , ISys_UserAccountRepository sys_useraccountRepository)
- {
- bus_OrderDetailRepository = _bus_OrderDetailRepository;
- bus_OrderRepository = _bus_OrderRepository;
- bus_MarketingRepository = _bus_MarketingRepository;
- bus_productRepository = _productRepository;
- cus_vip_infoRepository = _cus_vip_infoRepository;
- bus_StockLogRepository = _bus_StockLogRepository;
- cus_score_setRepository = _cus_score_setRepository;
- config = _configuration;
- busOrderFunctionController = _OrderFunctionController;
- busOrderMoneyRepository = _busOrderMoneyRepository;
- busAfterSaleRepository = _busAfterSaleRepository;
- busOrderlogsRepository = _busOrderlogsRepository;
- bus_ChatLogRepository = _bus_ChatLogRepository;
- _cus_membershiprepository = cus_membershiprepository;
- _sys_useraccountRepository = sys_useraccountRepository;
- }
- #region
- /// <summary>
- /// 创建订单
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- // [HttpPost("addorder")]
- /**public async Task<IActionResult> AddOrder([FromBody]OrderInput input)
- {
- try {
- T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(input.F_ADFrom))
- return Error("请输入选择广告来源");
- if (string.IsNullOrEmpty(input.F_Type))
- return Error("请输入选择订单类型");
- if (string.IsNullOrEmpty(input.F_Id))
- return Error("请输入订单编号");
- if (string.IsNullOrEmpty(input.F_Customer))
- return Error("请输入客户姓名");
- if (string.IsNullOrEmpty(input.F_CustomerPhone))
- return Error("请输入客户电话");
- if (input.F_Type=="售后订单")
- return Error("售后订单只能根据售后单自动创建");
- #endregion
- int exist = await bus_OrderRepository.GetCount(q => q.F_Id == input.F_Id);
- if (exist > 0)
- {
- return Error("此订单号已存在");
- }
- T_Bus_Order modelOrder = new T_Bus_Order();
- #region 订单属性
- //必填
- modelOrder.F_ADFrom = input.F_ADFrom;
- modelOrder.F_Type = input.F_Type;
- modelOrder.F_Id = input.F_Id;
- modelOrder.F_Customer = input.F_Customer;
- modelOrder.F_CustomerPhone = input.F_CustomerPhone;
- if (input.F_RecommendId>0)
- {
- modelOrder.F_RecommendId = input.F_RecommendId;
- modelOrder.F_RecommendName = input.F_RecommendName;
- }
- if (input.F_CustomerType > 0)
- { modelOrder.F_CustomerType = input.F_CustomerType; }
- if (!string.IsNullOrEmpty(input.F_CustomerTel))
- { modelOrder.F_CustomerTel = input.F_CustomerTel; }
- //选填 快递属性
- modelOrder.F_TrackingNo = "";
- if (!string.IsNullOrEmpty(input.F_Addressee))
- { modelOrder.F_Addressee = input.F_Addressee; }
- if (!string.IsNullOrEmpty(input.F_AddPhone))
- { modelOrder.F_AddPhone = input.F_AddPhone; }
- if (!string.IsNullOrEmpty(input.F_AddProvince))
- { modelOrder.F_AddProvince = input.F_AddProvince; }
- if (!string.IsNullOrEmpty(input.F_AddCity))
- { modelOrder.F_AddCity = input.F_AddCity; }
- if (!string.IsNullOrEmpty(input.F_AddArea))
- { modelOrder.F_AddArea = input.F_AddArea; }
- if (!string.IsNullOrEmpty(input.F_AddTown))
- { modelOrder.F_AddTown = input.F_AddTown; }
- if (!string.IsNullOrEmpty(input.F_AddDes))
- { modelOrder.F_AddDes = input.F_AddDes; }
- if (!string.IsNullOrEmpty(input.F_Address))
- { modelOrder.F_Address = input.F_Address; }
- if (!string.IsNullOrEmpty(input.F_PostalCode))
- { modelOrder.F_PostalCode = input.F_PostalCode; }
- if (!string.IsNullOrEmpty(input.F_Express))
- { modelOrder.F_Express = input.F_Express; }
- if (!string.IsNullOrEmpty(input.F_Remark))
- { modelOrder.F_Remark = input.F_Remark; }
- if (!string.IsNullOrEmpty(input.F_PayType))
- { modelOrder.F_PayType = input.F_PayType; }
- if
- (input.F_VipId > 0)
- { modelOrder.F_VipId = input.F_VipId; }
- else
- {
- var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
- && x.F_State == 1);
- if (vip != null && vip.Count > 0)
- modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
- else
- modelOrder.F_VipId = 0;
- }
- if (input.F_Belong > 0)
- {
- modelOrder.F_Belong = input.F_Belong;
- modelOrder.F_BelongName = input.F_BelongName;
- }
- else
- {
- modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
- modelOrder.F_BelongName = UserLogin.UserName;
- }
- modelOrder.F_ExpressFee = input.F_ExpressFee;
- modelOrder.F_Stock = input.F_Stock;
-
- modelOrder.F_RealPrice = input.F_RealPrice;
- modelOrder.F_UseScore = input.F_UseScore;
- //选填 关联属性
- modelOrder.F_State = input.F_State;
- modelOrder.F_Status = 0;
- //必须属性 系统生成
- modelOrder.F_AddTime = DateTime.Now;
- modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
- modelOrder.F_AddUserName = UserLogin.UserName;
- #endregion
- if (input.F_State == 1)
- {
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- { }
- else
- { return Error("请选择订购商品"); }
- if (string.IsNullOrEmpty(input.F_Stock))
- {
- return Error("请选择出库货仓");
- }
- if (string.IsNullOrEmpty(modelOrder.F_Express))
- {
- return Error("快递不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
- {
- return Error("收件人电话不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_AddTown))
- {
- return Error("收件人地址不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_Address))
- {
- return Error("收件人详细地址不能为空");
- }
- }
- decimal totle = 0.00M;
- decimal ActivityMoney = 0.00M;
- string UseActivity = "";
- string UseActivity4 = ",";
- string UseActivity2 = ",";
- List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
- #region 订单详情列表核算
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- {
- int n = 1;
- int n2 = input.OrderDetailList.Count + 1;
- #region 活动核算
- if (input.UseActList != null && input.UseActList.Count > 0)
- {
- //遍历所有选中的活动
- foreach (UseActInput act in input.UseActList)
- {
- UseActivity += act.id + ",";
- //满赠
- if (act.type == 1)
- {
- string[] productidlist = act.gift.Split(',');
- foreach (string giftid in productidlist)
- {
- T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
- if (m != null)
- {
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = m.F_ProductName;
- modelDetail.F_ProductId = m.F_ProductId;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = 1;
- modelDetail.F_Price = 0.00M;
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Sort = n2;
- modelDetail.F_Remark = "赠品-活动:" + act.id;
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = 0.00M;
- modelDetail.F_Activity = act.id;
- modelDetail.F_AddTime = DateTime.Now;
- modelDetailList.Add(modelDetail);
- n2++;
- }
- }
- }
- //生日赠
- else if (act.type == 2)
- {
- UseActivity2 += act.gift + ",";
- }
- //满减
- else if (act.type == 3)
- {
- ActivityMoney += act.money;
- }
- else if (act.type == 4)
- {
- UseActivity4 += act.gift + ",";
- }
- }
- UseActivity = UseActivity.Trim(',');
- }
- #endregion
- #region 商品核算
- foreach (OrderDetailInput m in input.OrderDetailList)
- {
- T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
- if (modelProduct == null)
- return Error("商品不存在:" + m.F_ProductId);
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = modelProduct.F_ProductName;
- modelDetail.F_ProductId = modelProduct.F_ProductId;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = m.F_Count;
- modelDetail.F_Price = modelProduct.F_MemberPrice;
- //参加活动特价
- if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
- modelDetail.F_DealPrice = modelProduct.F_SpecialPrice;
- else
- modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
- //参加生日
- if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
- {
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Remark = "生日赠品-活动:";
- }
- modelDetail.F_Sort = n;
- modelDetail.F_AddTime = DateTime.Now;
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
- modelDetail.F_Activity = 0;
- if (modelProduct.F_Tag.IndexOf(".") > -1&& !string.IsNullOrEmpty(UseActivity))
- {
- string[] tagarry = modelProduct.F_Tag.Split(',');
- string[] actlist = UseActivity.Split(',');
- string tag = tagarry.First(a => a.StartsWith(".")).ToString();
- 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 + ",")));
- //此商品参加活动
- if (modelactive != null)
- {
- modelDetail.F_Activity = modelactive.F_ID;
- }
- }
- else { modelDetail.F_Activity = 0; }
- totle += modelDetail.F_TotlePrice;
- modelDetailList.Add(modelDetail);
- n++;
- }
- #endregion
- modelOrder.F_TotlePrice = totle;
- modelOrder.F_ActivityMoney = ActivityMoney;
- modelOrder.F_UseActivity = UseActivity;
- }
- else
- {
- //不改变订单
- }
- #endregion
- //订单完成后也不计算积分
- modelOrder.F_Score = 0.00M;
- T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
- if (modelscore == null)
- {
- modelscore = new T_Cus_ScoreSet();
- modelscore.F_Start = 0;
- modelscore.F_StartDebit = 1;
- modelscore.F_DebitPercent = 1000;
- }
- #region 直接提交 锁库存log 锁积分log
- if (input.F_State == 1)
- {
- if (modelscore.F_StartDebit == 0 || modelOrder.F_VipId == 0)
- {
- modelOrder.F_UseScore = 0;
- }
- modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss")+"U" + UserLogin.UserId +"R"+ new Random().Next(9);
- string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
- if (strStock != "1")
- { return Error(strStock); }
- if (modelscore.F_Start == 1)
- {
- //订单完成后计算积分
- modelOrder.F_Score = -0.01M;
- }
- modelOrder.F_SubmitTime = DateTime.Now;
- }
- #endregion
- //计算结果 积分有规则
- modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - ActivityMoney + modelOrder.F_ExpressFee- modelOrder.F_UseScore / modelscore.F_DebitPercent;
- modelOrder.F_PayState = 0;
-
- if (await bus_OrderRepository.AddReturnCount(modelOrder))
- {
- if (modelDetailList != null && modelDetailList.Count > 0)
- {
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- return Success("订单添加成功2");
- else
- return Error("订单添加失败,请重试!1");
- }
- return Success("订单添加成功1");
- }
- else
- {
- return Error("订单添加失败,请重试!2");
- }
- }
- catch (Exception ex)
- { return Error(ex.Message); }
- }**/
- #endregion
- /// <summary>
- /// 创建订单
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("addorder")]
- public async Task<IActionResult> AddOrder([FromBody]OrderInput input)
- {
- try
- {
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(input.F_ADFrom))
- return Error("请输入选择广告来源");
- if (string.IsNullOrEmpty(input.F_Type))
- return Error("请输入选择订单类型");
- if (string.IsNullOrEmpty(input.F_Id))
- return Error("请输入订单编号");
- if (string.IsNullOrEmpty(input.F_Customer))
- return Error("请输入客户姓名");
- if (string.IsNullOrEmpty(input.F_AddPhone))
- {
- return Error("收件人电话不能为空");
- }
- if (string.IsNullOrEmpty(input.F_AddProvince ))
- {
- return Error("收件人省份不能为空");
- }
- if (string.IsNullOrEmpty(input.F_AddCity ))
- {
- return Error("收件人城市不能为空");
- }
- if (string.IsNullOrEmpty(input.F_AddArea ))
- {
- return Error("收件人区/县不能为空");
- }
- if (string.IsNullOrEmpty(input.F_Address ))
- {
- return Error("收件人详细地址不能为空");
- }
- if (string.IsNullOrEmpty(input.F_CustomerPhone))
- return Error("请输入客户电话");
- if (input.F_Type == "售后订单")
- return Error("售后订单只能根据售后单自动创建");
- #endregion
- int exist = await bus_OrderRepository.GetCount(q => q.F_Id == input.F_Id);
- if (exist > 0)
- {
- return Error("此订单号已存在");
- }
- T_Bus_Order modelOrder = new T_Bus_Order();
- #region 订单属性
- //必填
- modelOrder.F_ADFrom = input.F_ADFrom;
- modelOrder.F_Type = input.F_Type;
- modelOrder.F_Id = input.F_Id;
- modelOrder.F_Customer = input.F_Customer;
- modelOrder.F_CustomerPhone = input.F_CustomerPhone;
- if (input.F_RecommendId > 0)
- {
- modelOrder.F_RecommendId = input.F_RecommendId;
- modelOrder.F_RecommendName = input.F_RecommendName;
- }
- if (input.F_CustomerType > 0)
- { modelOrder.F_CustomerType = input.F_CustomerType; }
- if (!string.IsNullOrEmpty(input.F_CustomerTel))
- { modelOrder.F_CustomerTel = input.F_CustomerTel; }
- //选填 快递属性
- modelOrder.F_TrackingNo = "";
- if (!string.IsNullOrEmpty(input.F_Addressee))
- { modelOrder.F_Addressee = input.F_Addressee; }
- if (!string.IsNullOrEmpty(input.F_AddPhone))
- { modelOrder.F_AddPhone = input.F_AddPhone; }
- if (!string.IsNullOrEmpty(input.F_AddProvince))
- { modelOrder.F_AddProvince = input.F_AddProvince; }
- if (!string.IsNullOrEmpty(input.F_AddCity))
- { modelOrder.F_AddCity = input.F_AddCity; }
- if (!string.IsNullOrEmpty(input.F_AddArea))
- { modelOrder.F_AddArea = input.F_AddArea; }
- if (!string.IsNullOrEmpty(input.F_AddTown))
- { modelOrder.F_AddTown = input.F_AddTown; }
- if (!string.IsNullOrEmpty(input.F_AddDes))
- { modelOrder.F_AddDes = input.F_AddDes; }
- if (!string.IsNullOrEmpty(input.F_Address))
- { modelOrder.F_Address = input.F_Address; }
- if (!string.IsNullOrEmpty(input.F_PostalCode))
- { modelOrder.F_PostalCode = input.F_PostalCode; }
- // if (!string.IsNullOrEmpty(input.F_Express))
- // { modelOrder.F_Express = input.F_Express; }
-
- if (!string.IsNullOrEmpty(input.F_Remark))
- { modelOrder.F_Remark = input.F_Remark; }
- if (!string.IsNullOrEmpty(input.F_PayType))
- { modelOrder.F_PayType = input.F_PayType; }
- if
- (input.F_VipId > 0)
- { modelOrder.F_VipId = input.F_VipId; }
- else
- {
- var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
- && x.F_State == 1);
- if (vip != null && vip.Count > 0)
- modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
- else
- modelOrder.F_VipId = 0;
- }
- var modelvip= await cus_vip_infoRepository.GetSingle (x => x.F_ID == modelOrder.F_VipId);
- if (modelvip!=null )
- {
- modelOrder.F_Belong = modelvip.F_Saleperson.ObjToInt();
- var user = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelOrder.F_Belong);
- modelOrder.F_BelongName = user.F_UserName ;
- if (modelOrder.F_AddTime!=null )
- {
- TimeSpan time = modelOrder.F_AddTime - DateTime.Now;
- if (time.Days >3)
- {
- modelOrder.F_Type = "回访";
- }
- else
- {
- modelOrder.F_Type = "热线";
- }
- }
-
- }
- else if (input.F_Belong > 0)
- {
- modelOrder.F_Belong = UserLogin.UserId .ObjToInt();
- modelOrder.F_BelongName = UserLogin.UserName;
- }
-
- if (input .F_Media>0)
- {
- modelOrder.F_Media = input.F_Media;
- modelOrder.F_MediaName = input.F_MediaName;
- }
- var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelvip.F_Saleperson.ObjToInt());
- if (useraccount != null )
- {
- modelOrder.F_Department = useraccount.F_DeptId;
- modelOrder.F_Core = useraccount.F_DeptTeamId ;
- modelOrder.F_Group = useraccount.F_GroupId;
- }
-
- modelOrder.F_ExpressFee = input.F_ExpressFee;
- // modelOrder.F_Stock = input.F_Stock;
- modelOrder.F_IsExpress = 0;
- modelOrder.F_RealPrice = input.F_RealPrice;
- modelOrder.F_MemberNotes = input.F_MemberNotes;//会员备注
- modelOrder.F_UseScore = input.F_UseScore;
-
-
-
- modelOrder.F_State = 0;
- //选填 关联属性
-
- modelOrder.F_Status = 0;
-
- modelOrder.F_IsPayment = input.F_IsPayment;
-
- //必须属性 系统生成
- modelOrder.F_AddTime = DateTime.Now;
- modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
- modelOrder.F_AddUserName = UserLogin.UserName;
- #endregion
-
- decimal totle = 0.00M;
- decimal ActivityMoney = 0.00M;
- string UseActivity = "";
- string UseActivity4 = ",";
- string UseActivity2 = ",";
- string Eventprice = "";
- Dictionary<string, decimal> innerCompute = new Dictionary<string, decimal>();
- List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
- Dictionary<string, int> innerEventprice = new Dictionary<string, int >();
- #region 订单详情列表核算
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- {
- int n = 1;
- int n2 = input.OrderDetailList.Count + 1;
- #region 活动核算
- if (input.UseActList != null && input.UseActList.Count > 0)
- {
- //遍历所有选中的活动
- foreach (UseActInput act in input.UseActList)
- {
- UseActivity += act.id + ",";
- //满赠
- //if (act.type == 1)
- //{
- // string[] productidlist = act.gift.Split(',');
- // foreach (string giftid in productidlist)
- // {
- // T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
- // if (m != null)
- // {
- // T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- // modelDetail.F_ProductName = m.F_ProductName;
- // modelDetail.F_ProductId = m.F_ProductId;
- // modelDetail.F_Specifications = m.F_Specifications;
- // modelDetail.F_ProductShortName = m.F_ProductShortName;
- // modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- // modelDetail.F_OrderId = input.F_Id;
- // modelDetail.F_Count = 1;
- // modelDetail.F_Price = 0.00M;
- // modelDetail.F_DealPrice = 0.00M;
- // modelDetail.F_Sort = n2;
- // modelDetail.F_Remark = "赠品-活动:" + act.id;
- // modelDetail.F_AddUser = modelOrder.F_AddUser;
- // modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- // modelDetail.F_TotlePrice = 0.00M;
- // modelDetail.F_Activity = act.id;
- // modelDetail.F_AddTime = DateTime.Now;
-
- // modelDetailList.Add(modelDetail);
- // n2++;
- // }
- // }
- //}
- ////生日赠
- //else
- if (act.type == 2)
- {
- UseActivity2 += act.gift + ",";
- }
- //满减
- else if (act.type == 3)
- {
- ActivityMoney += act.money;
- if (string.IsNullOrEmpty(Eventprice))
- Eventprice = "" + act.id + "," + act.money;
- else
- Eventprice += "|" + act.id + "," + act.money;
- }
- else if (act.type == 4)
- {
- UseActivity4 += act.gift + ",";
- innerCompute.Add(act.gift, act.money);
- innerEventprice.Add(act.gift, act.id );
- }
- }
- UseActivity = UseActivity.Trim(',');
- }
- #endregion
- modelOrder.F_IsZeroCommodity = 0;
- #region 商品核算
- foreach (OrderDetailInput m in input.OrderDetailList)
- {
- T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
- if (modelProduct == null)
- return Error("商品不存在:" + m.F_ProductName );
- if (modelProduct.F_OnSaleEnd<DateTime .Now &&UserLogin.RoleCode != "SH")
- {
- return Error ("商品已下架:" + m.F_ProductName);
- }
-
- if (!modelOrder.F_Type.Contains("售后"))
- {
- // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(modelProduct.F_ProductId, "新乡仓");
- if (modelProduct.F_MinimumStock+ m.F_Count > modelProduct.F_Stock1 )
- {
- return Error(m.F_ProductName + "数量库存低于" + modelProduct.F_MinimumStock + "不能添加");
- }
- }
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = modelProduct.F_ProductName;
- modelDetail.F_ProductId = modelProduct.F_ProductId;
- modelDetail.F_Specifications = modelProduct.F_Specifications;
- modelDetail.F_ProductShortName = modelProduct.F_ProductShortName;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = m.F_Count;
- modelDetail.F_Price = modelProduct.F_MemberPrice;
- //参加活动特价
- if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
- {
-
- if (innerCompute.ContainsKey (modelProduct.F_ProductId))
- {
- ActivityMoney += innerCompute[modelProduct.F_ProductId] * m.F_Count;
- if (!string .IsNullOrEmpty (Eventprice))
- Eventprice += "|" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
- else
- Eventprice += "" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
- }
-
- }
- modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
- //参加生日
- if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
- {
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Remark = "生日赠品-活动:";
- }
- if (modelProduct.F_ClassName =="袜子" && modelDetail.F_DealPrice == 0)
- {
- modelOrder.F_IsZeroCommodity = 1;
- }
- modelDetail.F_Sort = n;
- modelDetail.F_AddTime = DateTime.Now;
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
- modelDetail.F_Activity = 0;
- if (modelProduct.F_Tag.IndexOf(".") > -1 && !string.IsNullOrEmpty(UseActivity))
- {
- string[] tagarry = modelProduct.F_Tag.Split(',');
- string[] actlist = UseActivity.Split(',');
- string tag = tagarry.First(a => a.StartsWith(".")).ToString();
- 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 + ",")));
- //此商品参加活动
- if (modelactive != null)
- {
- modelDetail.F_Activity = modelactive.F_ID;
- }
- }
- else { modelDetail.F_Activity = 0; }
- totle += modelDetail.F_TotlePrice;
- modelDetailList.Add(modelDetail);
- n++;
- }
- #endregion
- modelOrder.F_TotlePrice = totle;
- modelOrder.F_ActivityMoney = ActivityMoney;
- modelOrder.F_Eventprice = Eventprice;
- modelOrder.F_UseActivity = UseActivity;
- }
- else
- {
- //不改变订单
- }
- #endregion
-
-
- // modelOrder.F_TotlePrice += input.F_ExpressFee;//订单总额(包括快递费)
- modelOrder.F_RecommenderTel = input.F_RecommenderTel;
- modelOrder.F_PayState = 0;
- if (input .F_State ==1)
- {
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- { }
- else
- { return Error("请选择订购商品"); }
-
- //List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
- // if (modelDetailList != null && modelDetailList.Count > 0)
- // {
- // foreach (var it in modelDetailList)
- // {
- // T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == it.F_ProductId);
- // if (t_Bus_Product != null)
- // {
-
- // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(it.F_ProductId, "新乡仓");
-
- // t_Bus_Product.F_UseNumber += it.F_Count;
- // if (listStock1!=null && listStock1.Count > 0)
- // {
- // if (t_Bus_Product.F_UseNumber > listStock1[0].qty)
- // {
- // return Error("提交失败,可配量不足.");
- // }
- // else
- // {
- // Productlist.Add(t_Bus_Product);
- // }
- // }
- // else
- // return Error("提交失败,可配量不足.");
- // }
- // else
- // {
- // return Error("提交失败,商品不存在");
- // }
-
- // }
- // await bus_productRepository.UpdateList(Productlist);
- // }
- modelOrder.F_SubmitTime = DateTime.Now;
- if (modelOrder.F_IsPayment > 0|| modelOrder.F_PayType != "货到付款")
- modelOrder.F_State = 7;
- else
- modelOrder.F_State = 0;
- modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
- }
- T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
- if (modelscore == null)
- {
- modelscore = new T_Cus_ScoreSet();
- modelscore.F_Start = 0;
- modelscore.F_StartDebit = 1;
- modelscore.F_DebitPercent = 1000;
- }
- string count = UserLogin.UserName + "创建订单";
- if (!modelOrder.F_Type.Contains("售后"))
- {
-
-
- string a = string.Format("{0:f0}", Math.Floor(modelOrder.F_UseScore / modelscore.F_DebitPercent));
- modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney - int.Parse(a) + input.F_ExpressFee; if (input.OrderUserGift != null && input.OrderUserGift.Count > 0)
- {
- decimal moneys = 0.00M;
- if (modelvip.F_Money != null)
- {
- moneys= (decimal)modelvip.F_Money + modelOrder.F_ShouldPrice;
- }
- else
- moneys = modelOrder.F_ShouldPrice;
- int b = 0;
- if (moneys > 3000)
- {
- decimal fund = moneys - 3000;
- string c = string.Format("{0:f0}", Math.Floor(fund / 2000));
- b = int.Parse(c) + 1 - modelvip.F_UseGift;
- }
- int n2 = 0;
- foreach (var m in input.OrderUserGift)
- {
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = m.F_ProductName;
- modelDetail.F_ProductId = m.F_ProductId;
- modelDetail.F_Specifications = m.F_Specifications;
- modelDetail.F_ProductShortName = m.F_ProductShortName;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = 1;
- modelDetail.F_Price = 0.00M;
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Sort = n2;
- modelDetail.F_Remark = "满赠营销" ;
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = 0.00M;
- modelDetail.F_Activity =0;
- modelDetail.F_AddTime = DateTime.Now;
- modelDetailList.Add(modelDetail);
- n2++;
- }
- if (n2> b)
- {
- return Error("该会员最多可赠送"+ b+"件赠品");
- }
- else
- {
- modelvip.F_UseGift += n2;
- modelOrder.F_UseGift = n2;
- }
- }
- if (modelvip != null)
- {
- modelvip.F_Score -= modelOrder.F_UseScore;
- // modelvip.F_TotalScore -= modelOrder.F_UseScore;
- await cus_vip_infoRepository.Update(modelvip);
- }
- //订单完成后也不计算积分
- if (input.F_State == 1)
- {
- if (modelOrder.F_State == 1)
- count += "进入客服待分仓";
- else if (modelOrder.F_State == 7)
- count += "进入客服待付款待审核";
- }
- else
- count += "进入销售待提交";
- }
- if (input.F_IsPayment > 0 || input.F_PayType != "货到付款")
- {
- try
- {
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(input.F_Id))
- return Error("请输入订单号");
- if (string.IsNullOrEmpty(input.F_PayType))
- return Error("请选择付款方式");
- // if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkKF))
- // input.OrderMoney.F_RemarkKF = "";
- if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkXS))
- input.OrderMoney.F_RemarkXS = "";
- // if (input.OrderMoney.F_PayTime == null)
- // return Error("请选择打款时间");
- if (input.OrderMoney.F_Money <= 0)
- return Error("请输入付款金额");
-
- #endregion
- modelOrder.F_RealPrice = input.OrderMoney.F_Money;
- T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
- ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input.OrderMoney);
- modelOrderMoeny.F_AddUserId = UserLogin.UserId.ObjToInt();
- modelOrderMoeny.F_UserName = UserLogin.UserName;
- modelOrderMoeny.F_MoneyBak = modelOrderMoeny.F_Money;
- modelOrderMoeny.F_State = 0;
- modelOrderMoeny.F_Type = 1;
- modelOrderMoeny.F_OrderId = input.F_Id;
- modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- if (!await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
- return Error("付款失败");
- }
- catch (Exception ex)
- { return Error(ex.Message); }
- }
- int t = await AddLog(modelOrder.F_Id, count, UserLogin.UserCode , modelOrder.F_State);
- if (t >0)
- {
- if (await bus_OrderRepository.AddReturnCount(modelOrder))
- {
- if (modelDetailList != null && modelDetailList.Count > 0)
- {
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- {
- return Success("订单添加成功2");
- }
- else
- return Error("订单添加失败,请重试!1");
- }
- return Success("订单添加成功1");
- }
- }
- return Error("订单添加失败,请重试!2");
-
- }
- catch (Exception ex)
- { return Error(ex.Message); }
- }
- /// <summary>
- /// 获取总金额
- /// </summary>
- /// <param name="OrderDetailList"></param>
- /// <param name="UseActList"></param>
- /// <returns></returns>
- [HttpPost("getPrice")]
- public async Task<IActionResult> GetPrice(List<OrderDetailInput> OrderDetailList
- , List<UseActInput> UseActList, decimal F_ExpressFee =0, decimal UseScore =0)
- {
- decimal totle = 0.00M;
- decimal ActivityMoney = 0.00M;
- string UseActivity = "";
- string UseActivity4 = ",";
- string UseActivity2 = ",";
- decimal TotlePrice = 0.00M;
- Dictionary<string, decimal> innerCompute = new Dictionary<string, decimal>();
- List<T_Bus_OrderDetail> orderDetails = new List<T_Bus_OrderDetail>();
- if (OrderDetailList != null && OrderDetailList.Count > 0)
- {
- int n = 1;
- int n2 = OrderDetailList.Count + 1;
- #region 活动核算
- if (UseActList != null && UseActList.Count > 0)
- {
- //遍历所有选中的活动
- foreach (UseActInput act in UseActList)
- {
- UseActivity += act.id + ",";
-
- if (act.type == 2)
- {
- UseActivity2 += act.gift + ",";
- }
- //满减
- else if (act.type == 3)
- {
-
- ActivityMoney += act.money;
- }
- else if (act.type == 4)
- {
- UseActivity4 += act.gift + ",";
- innerCompute.Add(act.gift, act.money);
-
- }
- }
- UseActivity = UseActivity.Trim(',');
- }
- #endregion
- #region 商品核算
-
- foreach (OrderDetailInput m in OrderDetailList)
- {
- T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
- if (modelProduct == null)
- return Error("商品不存在:" + m.F_ProductName );
- if (modelProduct.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
- {
- return Error("商品已下架:" + m.F_ProductName);
- }
- // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(modelProduct.F_ProductId, "新乡仓");
- if (modelProduct.F_MinimumStock + m.F_Count > modelProduct.F_Stock1 )
- {
- return Error(m.F_ProductName + "数量库存低于" + modelProduct.F_MinimumStock + "不能添加");
- }
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- //参加活动特价
- if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
- {if (innerCompute.ContainsKey (modelProduct.F_ProductId))
- {
- ActivityMoney += innerCompute[modelProduct.F_ProductId] * m.F_Count;
- }
-
- }
-
- modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
- //参加生日
- if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
- {
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Remark = "生日赠品-活动:";
- }
- modelDetail.F_ProductId = modelProduct.F_ProductId;
- modelDetail.F_ProductName = modelProduct.F_ProductName;
- modelDetail.F_Count = m.F_Count;
- modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
- orderDetails.Add(modelDetail);
- totle += modelDetail.F_TotlePrice;
- TotlePrice += modelDetail.F_TotlePrice; ;
- n++;
- }
- #endregion
-
- }
- else
- {
- //不改变订单
- }
- T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
-
- string a = string.Format("{0:f0}", Math.Floor(UseScore / modelscore.F_DebitPercent));
- totle += F_ExpressFee - ActivityMoney-int .Parse ( a);
- var obj = new
- {
- orderDetails,
- TotlePrice,
- totle
- };
- return Content(obj.ToJson()); ;
- }
- /// <returns></returns>
- [HttpGet("UseGift")]
- public async Task<IActionResult> UseGift(int vip = 0, decimal money = 0)
- {
- if (vip <= 0)
- return Error("请选择会员");
- var model = await cus_vip_infoRepository.GetSingleV(x => x.F_ID == vip && x.F_State == (int)EnumDelState.Enabled);
- if (model == null)
- return Error("该会员不存在");
- decimal moneys = 0.00M;
- if (model.F_Money != null)
- {
- moneys = (decimal)model.F_Money + money;
- }
- else
- moneys = money;
- if (moneys > 3000)
- {
- decimal fund = moneys - 3000;
- string a = string.Format("{0:f0}", Math.Floor(fund / 2000));
- int b = int.Parse(a) + 1- model.F_UseGift ;
- return Success("获取成功", b);
- }
- else
- return Success("获取成功", 0);
- }
- /// <summary>
- /// 获取最大可使用积分
- /// </summary>
- /// <param name="OrderDetailList"></param>
- /// <param name="UseActList"></param>
- /// <returns></returns>
- [HttpGet("deductible")]
- public async Task<IActionResult> Deductible(int vip=0,decimal money=0)
- {
- if (vip <= 0)
- return Error("请选择会员");
- var model = await cus_vip_infoRepository .GetSingleV(x => x.F_ID == vip && x.F_State == (int)EnumDelState.Enabled);
- if (model==null )
- return Error("该会员不存在");
- var score = await cus_score_setRepository .GetSingle(x => x.F_State == 1);
- if (model.F_Score>0)
- {
- string a = string.Format("{0:f0}", Math.Floor((decimal)model.F_Score / score.F_DebitPercent));
- string Score = ""; int moneys = 0;
- if (money <= int.Parse(a))
- {
- moneys = (int)money;
- Score = string.Format("{0:f0}", (int)money * score.F_DebitPercent);
- }
- else
- {
- moneys = int.Parse(a);
- Score = string.Format("{0:f0}", int.Parse(a) * score.F_DebitPercent);
- }
-
- var obj = new
- {
- Score,
- moneys
- };
- return Content(obj.ToJson());
- }
- else
- return Success("获取成功", 0);
- }
-
- /// <summary>
- /// 提交订单 Audit payment
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("submit")]
- public async Task<IActionResult> Submit(string orderids)
- {
- string msg = "";
- if (string.IsNullOrEmpty(orderids))
- return Error("请选择订单号");
- string[] ids = orderids.Split(',');
- // List<EBossStock> listStock = await busOrderFunctionController.GetStock("", "山西仓",1,10000);
- // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock("", "新乡仓",1,10000);
- List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
- List<T_Bus_Order> orderLIst = new List<T_Bus_Order>();
- // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
- foreach (var item in ids)
- {
- T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == item);
- T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
- List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id, o => o.F_Sort, OrderByType.Asc);
- if (detaillist != null && detaillist.Count > 0)
- { }
- else
- { msg += "订单" + modelOrder.F_Id + "请选择订购商品"; continue; }
- if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
- {
- msg += "订单" + modelOrder.F_Id + "收件人电话不能为空";
- continue;
- }
-
- if (string.IsNullOrEmpty(modelOrder.F_Address))
- {
- msg += "订单" + modelOrder.F_Id + "收件人详细地址不能为空";
- continue;
- }
- if (modelOrder.F_IsZeroCommodity ==1&& !modelOrder.F_Type.Contains ("回访")&& !modelOrder.F_Type.Contains("售后") )
- {
- msg += "订单" + modelOrder.F_Id + "非回访单不能添加0金额袜子";
- continue;
- }
-
- if (detaillist!=null && detaillist.Count >0)
- {
- foreach (var it in detaillist)
- {
- T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == it.F_ProductId);
- if (t_Bus_Product==null )
- {
- msg += "订单" + modelOrder.F_Id + "商品不存在";
- continue;
- }
-
- if (t_Bus_Product.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
- {
- msg += "订单" + modelOrder.F_Id + "商品已下架:" + t_Bus_Product.F_ProductName;
- continue;
- }
- //if (t_Bus_Product!=null )
- // {
- // // var listStock2 = listStock.Where(x => x.sku == t_Bus_Product.F_ProductId).ToList(); ;
- // var listStock3 = listStock1.Where(x => x.sku == t_Bus_Product.F_ProductId).ToList(); ;
- // // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(it.F_ProductId, "新乡仓");
-
-
- // if (listStock3!=null&& listStock3.Count > 0)
- // {
- // if (t_Bus_Product.F_UseNumber > listStock3[0].qty)
- // {
- // msg += "订单" + modelOrder.F_Id + "提交失败,可配量不足.";
- // continue;
-
- // }
- // else
- // {
- // t_Bus_Product.F_UseNumber += it.F_Count;
- // Productlist.Add(t_Bus_Product);
- // }
- // }
- // else
- // {
- // msg += "订单" + modelOrder.F_Id + "提交失败,可配量不足.";
- // continue;
- // }
- // }
- // else
- // {
- // msg += "订单" + modelOrder.F_Id + "提交失败,商品不存在.";
- // continue;
- // }
-
- }
- }
-
-
-
- if (modelOrder.F_IsPayment > 0|| modelOrder.F_PayType != "货到付款")
- {
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "提交订单"+","+ modelOrder.F_PayType+"流转客服付款待审核";
- modelOrder.F_State = 7;
- }
-
- else
- {
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "提交订单"+",流转客服待分仓";
- modelOrder.F_State = 1;
- }
-
- modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
- modelOrder.F_SubmitTime = DateTime.Now;
- modelOrder.F_SubmitUser = UserLogin .UserName ;
- modelOrder.F_SubmitUserId = UserLogin.UserId.ObjToInt () ;
- orderLIst.Add(modelOrder);
- t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
-
- t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
- t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
- t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
- logs.Add(t_Bus_Orderlogs);
- }
- if (msg == "")
- {
- // if (await bus_productRepository.UpdateList(Productlist))
- // {
- if (bus_OrderRepository.UpdateList(orderLIst).Result)
- {
- await busOrderlogsRepository.AddAndUpdateList(logs);
- return Success("提交成功");
- }
- // }
- }
- else
- {
- return Error(msg);
- }
- return Error("提交失败");
- }
- /// <summary>
- /// 上传文件并导入数据库批量
- /// </summary>审核订单金额
- /// <returns></returns>
- [HttpPost("importcheckordermoney")]
- public async Task<IActionResult> importcheckordermoney(int headrow = 0)
- {
- Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
- 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"))
- return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
- NPOIHelper npoi = new NPOIHelper();
- var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
- int num = dtExcel.Rows.Count;
- var cols = dtExcel.Columns;
- int colnum = cols.Count;
- string errmsg = string.Empty;
- string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- List<T_Bus_Order> _Orders = new List<T_Bus_Order>();
- List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
- if (num > 0)
- {
- int index = 1;
- foreach (DataRow dr in dtExcel.Rows)
- {
- index++;
- T_Bus_Order modelOrder = new T_Bus_Order();
- T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
- if (dr.Table.Columns.Contains("订单号"))
- {
- if (!string.IsNullOrEmpty(dr["订单号"].ToString()))
- {
- modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == dr["订单号"].ToString());
- if (modelOrder == null)
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
- continue;
- }
- }
- else
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
- continue;
- }
- }
- else
- {
- return Error("模板错误,请选择正确的模板");
- }
- if (dr.Table.Columns.Contains("打款金额"))
- {
- if (!string.IsNullOrEmpty(dr["打款金额"].ToString()))
- {
- try
- {
- if (modelOrder.F_RealPrice==decimal .Parse (dr["打款金额"].ToString()))
- {
- if (modelOrder.F_PayState == 0)
- {
- if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
- {
- //0待回款1已支付 2待退款3已退款
- modelOrder.F_PayState = 1;
- }
- }
- else if (modelOrder.F_PayState == 2)
- {
- if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
- {
- //0待回款1已支付 2待退款3已退款
- modelOrder.F_PayState = 3;
- }
- }
- var membership = await _cus_membershiprepository.GetListALL(x => x.F_State != 2);
- if (membership != null && membership.Count > 0)
- {
- T_Cus_VipInfo vip = await cus_vip_infoRepository.GetSingle(x => x.F_ID == modelOrder.F_VipId);
- if (vip != null)
- {
- vip.F_Money += modelOrder.F_RealPrice;
- T_Cus_Membership t_Cus_Membership = membership.Where(x => x.F_MinMoney <= vip.F_Money
- ).OrderByDescending(a => a.F_MaxMoney).FirstOrDefault();
- if (t_Cus_Membership != null)
- {
- vip.F_MembershipId = t_Cus_Membership.F_ID;
- vip.F_Membership = t_Cus_Membership.F_Name;
- }
- await cus_vip_infoRepository.Update(vip);
- }
- }
- modelOrder.F_State = 1;
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "审核付款金额,审核通过流转客服待分仓";
- }
- else
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!打款金额不匹配";
- continue;
- }
-
- }
- catch
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!打款金额格式错误";
- continue;
- }
-
- }
- else
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!请选择打款金额";
- continue;
- }
- }
- else
- {
- return Error("模板错误,请选择正确的模板");
- }
- t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
- t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
- t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
- t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
- logs.Add(t_Bus_Orderlogs);
- _Orders.Add(modelOrder);
-
- }
- if (_Orders.Count >0)
- {
- await busOrderlogsRepository.AddAndUpdateList(logs);
- if (!await bus_OrderRepository.UpdateList(_Orders))
- {
- if (!string.IsNullOrEmpty(errmsg))
- {
- errmsg = errmsg + "导入失败!";
- }
- else
- {
- errmsg = "导入失败!";
- }
- }
- }
-
- }
- else
- {
- return Error("文件中无数据");
- }
- if (!string.IsNullOrEmpty(errmsg))
- {
- return Error(errmsg);
- }
- return Success("导入成功");
- }
- /// <summary>
- /// 销售选择未发原因
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("notissued")]
- public async Task<IActionResult> Notissued(string orderids,string remarks)
- {
- string msg = "";
- if (string.IsNullOrEmpty(orderids))
- return Error("请选择订单号");
- if (string.IsNullOrEmpty(remarks))
- return Error("请选择未发原因");
- string[] ids = orderids.Split(',');
- List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
- List<T_Bus_Order> orderLIst = new List<T_Bus_Order>();
- foreach (var item in ids)
- {
- T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == item);
- T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
- modelOrder.F_Notissued = remarks;
- modelOrder.F_NotissuedID = 1;
- orderLIst.Add(modelOrder);
- t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "填写未发原因:" + remarks;
- t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
- t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
- t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
- logs.Add(t_Bus_Orderlogs);
- }
- if (msg == "")
- {
- if (bus_OrderRepository.UpdateList(orderLIst).Result)
- {
- await busOrderlogsRepository.AddMany (logs);
- return Success("提交成功");
- }
- }
- else
- {
- return Error(msg);
- }
- return Error("提交失败");
- }
- /// <summary>
- /// 审核订单金额
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("checkordermoney")]
- public async Task<IActionResult> CheckOrderMoney(string orderids,int state)
- {
- try
- {
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(orderids))
- return Error("请选择订单号");
- string[] ids = orderids.Split(',');
- List<T_Bus_Order> _Orders = new List<T_Bus_Order>();
- List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
- string msg = "";
- foreach (var it in ids)
- {
- #endregion
- T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
- Expression<Func<T_Bus_OrderMoney, bool>> eq = a => a.F_OrderId == it;
- T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == it);
-
- if (state == 1)
- {
- if (modelOrder.F_PayState == 0)
- {
- if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
- {
- //0待回款1已支付 2待退款3已退款
- modelOrder.F_PayState = 1;
- }
- }
- else if (modelOrder.F_PayState == 2)
- {
- if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
- {
- //0待回款1已支付 2待退款3已退款
- modelOrder.F_PayState = 3;
- }
- }
- var membership = await _cus_membershiprepository.GetListALL(x => x.F_State != 2);
- if (membership != null && membership.Count > 0)
- {
- T_Cus_VipInfo vip = await cus_vip_infoRepository.GetSingle(x => x.F_ID == modelOrder.F_VipId);
- if (vip != null)
- {
- vip.F_Money += modelOrder.F_RealPrice;
- T_Cus_Membership t_Cus_Membership = membership.Where(x => x.F_MinMoney <= vip.F_Money
- ).OrderByDescending(a => a.F_MaxMoney).FirstOrDefault();
- if (t_Cus_Membership != null)
- {
- vip.F_MembershipId = t_Cus_Membership.F_ID ;
- vip.F_Membership = t_Cus_Membership.F_Name;
- }
- await cus_vip_infoRepository.Update(vip);
- }
- }
- modelOrder.F_State = 1;
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "审核付款金额,审核通过流转客服待分仓";
- _Orders.Add(modelOrder);
- }
- else
- {
- List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id, o => o.F_Sort, OrderByType.Asc);
- // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
- if (detaillist != null && detaillist.Count > 0)
- {
- foreach (var iv in detaillist)
- {
- T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == iv.F_ProductId);
- if (t_Bus_Product != null)
- {
- if (t_Bus_Product.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
- {
- return Error("商品已下架:" + t_Bus_Product.F_ProductId);
- }
- // t_Bus_Product.F_UseNumber -= iv.F_Count;
- // Productlist.Add(t_Bus_Product);
- }
- else
- {
- msg += "订单" + modelOrder.F_Id + "提交失败,商品不存在.";
- continue;
- }
- }
- }
- //if (msg == "")
- //{
- // if (Productlist != null && Productlist.Count > 0)
- // {
- // if (!await bus_productRepository.UpdateList(Productlist))
- // {
- // msg += "订单" + modelOrder.F_Id + "提交失败";
- // continue;
- // }
-
- // }
- // else
- // {
- // msg += "订单" + modelOrder.F_Id + "提交失败,请选择商品";
- // continue;
- // }
- //}
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "审核付款金额,审核不通过,退回销售待提交";
- modelOrder.F_State = 0;
- _Orders.Add(modelOrder);
- }
-
-
- t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
-
- t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
- t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
- t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
- logs.Add(t_Bus_Orderlogs);
- }
- if (msg == "")
- {
- await busOrderlogsRepository.AddAndUpdateList(logs);
- if (await bus_OrderRepository.UpdateList(_Orders))
- return Success("成功");
- }
- else
- return Error(msg);
- return Error("失败!");
- }
- catch (Exception ex)
- { return Error(ex.Message); }
- }
- /// <summary>
- /// 上传文件并导入数据库批量导入快递信息
- /// </summary>
- /// <returns></returns>
- [HttpPost("importorderexpressexcel")]
- public async Task<IActionResult> importorderexpressexcel(int headrow = 0)
- {
- Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
- 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"))
- return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
- NPOIHelper npoi = new NPOIHelper();
- var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
- int num = dtExcel.Rows.Count;
- var cols = dtExcel.Columns;
- int colnum = cols.Count;
- string errmsg = string.Empty;
- string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- List<T_Bus_Order> orderLIst = new List<T_Bus_Order>();
- List<T_Bus_AfterSale> afterList = new List<T_Bus_AfterSale>();
- List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
- if (num > 0)
- {
- int index = 1;
- foreach (DataRow dr in dtExcel.Rows)
- {
- index++;
- T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
- T_Bus_Order modelOrder = new T_Bus_Order();
- List<T_Bus_AfterSale > after = new List<T_Bus_AfterSale>();
- if (dr.Table.Columns.Contains("订单号"))
- {
- if (!string.IsNullOrEmpty(dr["订单号"].ToString()))
- {
- modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == dr["订单号"].ToString());
- after =await busAfterSaleRepository.GetListALL(x => x.F_OrderId == dr["订单号"].ToString()&&x .F_Type ==9 && x.F_WoState == 0);
- if (after==null|| after.Count <=0)
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在售后改代收";
- continue;
- }
- if (modelOrder == null)
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
- continue;
- }
- }
- else
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!订单不存在";
- continue;
- }
- }
- else
- {
- return Error("模板错误,请选择正确的模板");
- }
- if (dr.Table.Columns.Contains("运单号"))
- {
- if (!string.IsNullOrEmpty(dr["运单号"].ToString()))
- {
- if (IsRegex(dr["运单号"].ToString()))
- {
- modelOrder.F_NewTrackingNo = dr["运单号"].ToString();
- after[0].F_TrackingNo = dr["运单号"].ToString();
- }
- else
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!运单号格式错误";
- continue;
- }
- }
- }
- else
- {
- return Error("模板错误,请选择正确的模板");
- }
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName +"改代收导入运单号"+ modelOrder.F_NewTrackingNo;
- t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
- t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
- t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
- t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
- logs.Add(t_Bus_Orderlogs);
- orderLIst.Add(modelOrder);
- afterList.Add(after[0]);
-
- }
- if (errmsg == "")
- {
- if (await bus_OrderRepository.UpdateList(orderLIst))
- {
- await busOrderlogsRepository.AddAndUpdateList(logs);
- if (!await busAfterSaleRepository .UpdateList(afterList))
- {
- errmsg = errmsg + "导入失败!";
- }
- }
- else
- errmsg = errmsg + "导入失败!";
- }
- }
- else
- {
- return Error("文件中无数据");
- }
- if (!string.IsNullOrEmpty(errmsg))
- {
- return Error(errmsg);
- }
- return Success("导入成功");
- }
- private bool IsRegex(string accountStr)
- {
- Regex reg = new Regex(@"^[A-Za-z0-9]+$");
- return reg.IsMatch(accountStr);
- }
- /// <summary>
- /// 更新改代收运单号
- /// </summary>
- /// <param name="orderids"></param>
- /// <param name="status">
- /// <returns></returns>
- [HttpPost("updateexpres")]
- public async Task<IActionResult> UpdateTrackingNo(string orderids, string trackingNo="")
- {
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(orderids))
- return Error("请选择订单号");
- if (string.IsNullOrEmpty(trackingNo))
- return Error("请输入运单号");
- #endregion
- // string[] ids = orderids.Split(',');
- var after = await busAfterSaleRepository.GetSingle (x => x.F_Id == orderids );
- if (after == null )
- {
- return Error("售后不存在");
- }
- int t = await AddLog(orderids, UserLogin.UserName + "改代收更新运单号", UserLogin.UserCode,-1);
- if (await bus_OrderRepository.Update(s => new T_Bus_Order() { F_NewTrackingNo = trackingNo }, q => q .F_Id ==after .F_OrderId ))
- {
- after.F_TrackingNo = trackingNo;
- if (await busAfterSaleRepository .Update(after))
- {
- return Success("成功");
- }
- }
- return Error("失败,请重试!");
- }
- #region
- /// <summary>
- /// 修改订单
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- /**
- [HttpPost("editorder")]
- public async Task<IActionResult> EditOrder([FromBody]OrderInput input)
- {
- T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(input.F_ADFrom))
- return Error("请输入选择广告来源");
- if (string.IsNullOrEmpty(input.F_Type))
- return Error("请输入选择订单类型");
- if (string.IsNullOrEmpty(input.F_Id))
- return Error("请输入订单编号");
- if (string.IsNullOrEmpty(input.F_Customer))
- return Error("请输入客户姓名");
- if (string.IsNullOrEmpty(input.F_CustomerPhone))
- return Error("请输入客户电话");
- if (input.F_Type == "售后订单")
- return Error("售后订单销售不能修改");
- #endregion
- T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
- if (modelOrder == null)
- {
- return Error("此订单号不存在");
- }
- //保存 审退回 仓退回
- if (!(new int[] { 0, 2 }.Contains(modelOrder.F_State)))
- {
- return Error("已提交订单不允许修改,先撤回订单");
- }
- #region 数据绑定
- //必填
- modelOrder.F_ADFrom = input.F_ADFrom;
- modelOrder.F_Type = input.F_Type;
- modelOrder.F_Customer = input.F_Customer;
- modelOrder.F_CustomerPhone = input.F_CustomerPhone;
- if (input.F_RecommendId > 0)
- {
- modelOrder.F_RecommendId = input.F_RecommendId;
- modelOrder.F_RecommendName = input.F_RecommendName;
- }
- if (input.F_CustomerType > 0)
- { modelOrder.F_CustomerType = input.F_CustomerType; }
- if (!string.IsNullOrEmpty(input.F_CustomerTel))
- { modelOrder.F_CustomerTel = input.F_CustomerTel; }
- //选填 快递属性
- modelOrder.F_TrackingNo = "";
- if (!string.IsNullOrEmpty(input.F_Addressee))
- { modelOrder.F_Addressee = input.F_Addressee; }
- if (!string.IsNullOrEmpty(input.F_AddPhone))
- { modelOrder.F_AddPhone = input.F_AddPhone; }
- if (!string.IsNullOrEmpty(input.F_AddProvince))
- { modelOrder.F_AddProvince = input.F_AddProvince; }
- if (!string.IsNullOrEmpty(input.F_AddCity))
- { modelOrder.F_AddCity = input.F_AddCity; }
- if (!string.IsNullOrEmpty(input.F_AddArea))
- { modelOrder.F_AddArea = input.F_AddArea; }
- if (!string.IsNullOrEmpty(input.F_AddTown))
- { modelOrder.F_AddTown = input.F_AddTown; }
- if (!string.IsNullOrEmpty(input.F_AddDes))
- { modelOrder.F_AddDes = input.F_AddDes; }
- if (!string.IsNullOrEmpty(input.F_Address))
- { modelOrder.F_Address = input.F_Address; }
- if (!string.IsNullOrEmpty(input.F_PostalCode))
- { modelOrder.F_PostalCode = input.F_PostalCode; }
- if (!string.IsNullOrEmpty(input.F_Express))
- { modelOrder.F_Express = input.F_Express; }
- if (!string.IsNullOrEmpty(input.F_Remark))
- { modelOrder.F_Remark = input.F_Remark; }
- if (!string.IsNullOrEmpty(input.F_PayType))
- { modelOrder.F_PayType = input.F_PayType; }
- if (input.F_Belong > 0)
- {
- modelOrder.F_Belong = input.F_Belong;
- modelOrder.F_BelongName = input.F_BelongName;
- }
- else
- {
- modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
- modelOrder.F_BelongName = UserLogin.UserName;
- }
- modelOrder.F_ExpressFee = input.F_ExpressFee;
- modelOrder.F_Stock = input.F_Stock;
- modelOrder.F_RealPrice = input.F_RealPrice;
- modelOrder.F_UseScore = input.F_UseScore;
- //选填 关联属性
- if (input.F_VipId>0)
- modelOrder.F_VipId = input.F_VipId;
- else
- {
- var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
- && x.F_State == 1);
- if (vip != null && vip.Count > 0)
- modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
- else
- modelOrder.F_VipId = 0;
- }
- modelOrder.F_State = input.F_State;
- modelOrder.F_Status = 0;
- modelOrder.F_IsPayment = input.F_IsPayment;
- if (input.F_IsPayment > 0 && input.F_PaymentMoney <= 0)
- return Error("付款金额不能小于0");
-
- //必须属性 系统生成
- modelOrder.F_AddTime = DateTime.Now;
- modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
- modelOrder.F_AddUserName = UserLogin.UserName;
- #endregion
- //计算属性 商品计算
- decimal totle = 0.00M;
- decimal ActivityMoney = 0.00M;
- string UseActivity = "";
- string UseActivity4 = ",";
- string UseActivity2 = ",";
- List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- {
- #region 核算活动
- int n2 = input.OrderDetailList.Count + 1;
- if (input.UseActList != null && input.UseActList.Count > 0)
- {
- //遍历所有选中的活动
- foreach (UseActInput act in input.UseActList)
- {
- UseActivity += act.id + ",";
- //满赠
- if (act.type == 1)
- {
- string[] productidlist = act.gift.Split(',');
- foreach (string giftid in productidlist)
- {
- T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
- if (m != null)
- {
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = m.F_ProductName;
- modelDetail.F_ProductId = m.F_ProductId;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = 1;
- modelDetail.F_Price = 0.00M;
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Sort = n2;
- modelDetail.F_Remark = "赠品-活动:" + act.id;
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = 0.00M;
- modelDetail.F_Activity = act.id;
- modelDetail.F_AddTime = DateTime.Now.AddSeconds(30);
- modelDetailList.Add(modelDetail);
- n2++;
- }
- }
- }
- //生日赠
- else if (act.type == 2)
- {
- UseActivity2 += act.gift + ",";
- }
- //满减
- else if (act.type == 3)
- {
- ActivityMoney += act.money;
- }
- else if (act.type == 4)
- {
- UseActivity4 += act.gift + ",";
- }
- }
- UseActivity = UseActivity.Trim(',');
- }
- #endregion
- #region 核算商品
- int n = 1;
- foreach (OrderDetailInput m in input.OrderDetailList)
- {
- T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
- if (modelProduct == null) return Error("在售商品不存在");
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = modelProduct.F_ProductName;
- modelDetail.F_ProductId = modelProduct.F_ProductId;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = m.F_Count;
- modelDetail.F_Price = modelProduct.F_MemberPrice;
- //参加活动特价
- if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
- modelDetail.F_DealPrice = modelProduct.F_SpecialPrice;
- else
- modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
- //参加生日
- if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
- {
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Remark = "生日赠品-活动:";
- }
- modelDetail.F_Sort = n;
- modelDetail.F_AddTime = DateTime.Now;
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
- modelDetail.F_Activity = 0;
- if (modelProduct.F_Tag.IndexOf(".") > -1 && !string.IsNullOrEmpty(UseActivity))
- {
- string[] tagarry = modelProduct.F_Tag.Split(',');
- string[] actlist = UseActivity.Split(',');
- string tag = tagarry.First(a => a.StartsWith(".")).ToString();
- 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 + ",")));
- //此商品参加活动
- if (modelactive != null)
- {
- modelDetail.F_Activity = modelactive.F_ID;
- }
- }
- totle += modelDetail.F_TotlePrice;
- modelDetailList.Add(modelDetail);
- n++;
- }
- #endregion
- modelOrder.F_TotlePrice = totle;
- modelOrder.F_ActivityMoney = ActivityMoney;
- modelOrder.F_UseActivity = UseActivity;
- }
- else
- {
- //不传商品 表明不修改商品信息 不重新计算商品
- }
- //直接提交 锁库存
- T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
- if (modelscore == null)
- {
- modelscore = new T_Cus_ScoreSet();
- modelscore.F_Start = 0;
- modelscore.F_StartDebit = 1;
- modelscore.F_DebitPercent = 1000;
- }
- #region 提交 更改状态 库存 积分
-
- if (input.F_State == 1)
- {
- if (string.IsNullOrEmpty(input.F_Stock))
- {
- return Error("请选择出库货仓");
- }
- if (string.IsNullOrEmpty(modelOrder.F_Express))
- {
- return Error("快递不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
- {
- return Error("收件人电话不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_AddTown))
- {
- return Error("收件人地址不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_Address))
- {
- return Error("收件人详细地址不能为空");
- }
- modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
- if (modelscore.F_Start == 1)
- {
- //订单完成后计算积分
- modelOrder.F_Score = -0.01M;
- }
- else
- { //订单完成后也不计算积分
- modelOrder.F_Score = 0.00M;
- }
- if (modelscore.F_StartDebit == 0 || modelOrder.F_VipId == 0)
- {
- modelOrder.F_UseScore = 0;
- }
- string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
- if (strStock != "1")
- { return Error(strStock); }
- modelOrder.F_SubmitTime = DateTime.Now;
- }
- #endregion
- if (!modelOrder.F_Type.Contains("售后"))
- { modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney + modelOrder.F_ExpressFee - modelOrder.F_UseScore / modelscore.F_DebitPercent;
- }
- 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));
- modelOrder.F_RealPrice = dt.Rows[0][0].ObjToDecimal() ;
- if (modelOrder.F_ShouldPrice > 0)
- {
- if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
- modelOrder.F_PayState = 1;
- else
- modelOrder.F_PayState = 0;
- }
- else
- {
- if (modelOrder.F_ShouldPrice >= modelOrder.F_RealPrice)
- modelOrder.F_PayState = 3;
- else
- modelOrder.F_PayState = 2;
- }
- //待付款 客服审核付款情况后改为已付款
- if (await bus_OrderRepository.Update(modelOrder))
- {
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- {
- //删除之前订单商品,重新添加
- if (await bus_OrderDetailRepository.Delete(q => q.F_OrderId == modelOrder.F_Id))
- {
-
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- return Success("订单生成成功");
- else
- return Error("订单操作失败,请重试1!");
- }
- else {
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- return Success("订单生成成功2");
- else
- return Error("订单操作失败,请重试2!");
- }
- }
- else { return Success("成功"); }
- }
- return Error("订单添加失败,请重试!");
- }
- **/
- #endregion
- #region
- /// <summary>
- /// 修改订单
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("editorder")]
- public async Task<IActionResult> EditOrder([FromBody]OrderInput input)
- {
- // T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(input.F_ADFrom))
- return Error("请输入选择广告来源");
- if (string.IsNullOrEmpty(input.F_Type))
- return Error("请输入选择订单类型");
- if (string.IsNullOrEmpty(input.F_Id))
- return Error("请输入订单编号");
- if (string.IsNullOrEmpty(input.F_Customer))
- return Error("请输入客户姓名");
- if (string.IsNullOrEmpty(input.F_CustomerPhone))
- return Error("请输入客户电话");
- if (string.IsNullOrEmpty(input.F_AddProvince))
- {
- return Error("收件人省份不能为空");
- }
- if (string.IsNullOrEmpty(input.F_AddCity))
- {
- return Error("收件人城市不能为空");
- }
- if (string.IsNullOrEmpty(input.F_AddArea))
- {
- return Error("收件人区/县不能为空");
- }
- if (string.IsNullOrEmpty(input.F_Address))
- {
- return Error("收件人详细地址不能为空");
- }
- if (input.F_Type == "售后订单")
- {
- if (UserLogin .RoleCode !="SH")
- return Error("售后订单只能售后修改");
- }
-
- #endregion
- T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
- if (modelOrder == null)
- {
- return Error("此订单号不存在");
- }
- //保存 审退回 仓退回
- if (!(new int[] { 0, 2 }.Contains(modelOrder.F_State)))
- {
- return Error("已提交订单不允许修改,先撤回订单");
- }
- #region 数据绑定
- //必填
- modelOrder.F_ADFrom = input.F_ADFrom;
- modelOrder.F_Type = input.F_Type;
- modelOrder.F_Customer = input.F_Customer;
- modelOrder.F_CustomerPhone = input.F_CustomerPhone;
- if (input.F_RecommendId > 0)
- {
- modelOrder.F_RecommendId = input.F_RecommendId;
- modelOrder.F_RecommendName = input.F_RecommendName;
- }
- if (input.F_CustomerType > 0)
- { modelOrder.F_CustomerType = input.F_CustomerType; }
- if (!string.IsNullOrEmpty(input.F_CustomerTel))
- { modelOrder.F_CustomerTel = input.F_CustomerTel; }
- //选填 快递属性
- modelOrder.F_TrackingNo = "";
- if (!string.IsNullOrEmpty(input.F_Addressee))
- { modelOrder.F_Addressee = input.F_Addressee; }
- if (!string.IsNullOrEmpty(input.F_AddPhone))
- { modelOrder.F_AddPhone = input.F_AddPhone; }
- if (!string.IsNullOrEmpty(input.F_AddProvince))
- { modelOrder.F_AddProvince = input.F_AddProvince; }
- if (!string.IsNullOrEmpty(input.F_AddCity))
- { modelOrder.F_AddCity = input.F_AddCity; }
- if (!string.IsNullOrEmpty(input.F_AddArea))
- { modelOrder.F_AddArea = input.F_AddArea; }
- if (!string.IsNullOrEmpty(input.F_AddTown))
- { modelOrder.F_AddTown = input.F_AddTown; }
- if (!string.IsNullOrEmpty(input.F_AddDes))
- { modelOrder.F_AddDes = input.F_AddDes; }
- if (!string.IsNullOrEmpty(input.F_Address))
- { modelOrder.F_Address = input.F_Address; }
- // if (!string.IsNullOrEmpty(input.F_PostalCode))//快递
- // { modelOrder.F_PostalCode = input.F_PostalCode; }
- if (!string.IsNullOrEmpty(input.F_Express))
- { modelOrder.F_Express = input.F_Express; }
- if (!string.IsNullOrEmpty(input.F_Remark))
- { modelOrder.F_Remark = input.F_Remark; }
- if (!string.IsNullOrEmpty(input.F_PayType))
- { modelOrder.F_PayType = input.F_PayType; }
- var modelvip = await cus_vip_infoRepository.GetSingle(x => x.F_ID == modelOrder.F_VipId);
- if (modelvip != null)
- {
- modelOrder.F_Belong = modelvip.F_Saleperson.ObjToInt();
- var user = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelOrder.F_Belong);
- modelOrder.F_BelongName = user.F_UserName ;
- }
- else if (input.F_Belong > 0)
- {
- modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
- modelOrder.F_BelongName = UserLogin.UserName;
- }
- var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelvip.F_Saleperson.ObjToInt());
- if (useraccount != null)
- {
- modelOrder.F_Department = useraccount.F_DeptId;
- modelOrder.F_Core = useraccount.F_DeptTeamId;
- modelOrder.F_Group = useraccount.F_GroupId;
- }
- if (input.F_Media > 0)
- {
- modelOrder.F_Media = input.F_Media;
- modelOrder.F_MediaName = input.F_MediaName;
- }
-
- // modelOrder.F_Stock = input.F_Stock;//仓库
- modelOrder.F_IsExpress = 0;
- modelOrder.F_MemberNotes = input.F_MemberNotes;//会员备注
- if (modelvip != null)
- {
- modelvip.F_Score += modelOrder.F_UseScore;
- }
- modelOrder.F_RealPrice = input.F_RealPrice;
- modelOrder.F_UseScore = input.F_UseScore;
- //选填 关联属性
- if (input.F_VipId>0)
- modelOrder.F_VipId = input.F_VipId;
- else
- {
- var vip = await cus_vip_infoRepository.GetListALL(x => x.F_Phone == input.F_CustomerPhone
- && x.F_State == 1);
- if (vip != null && vip.Count > 0)
- modelOrder.F_VipId = vip.FirstOrDefault().F_ID;
- else
- modelOrder.F_VipId = 0;
- }
-
-
- modelOrder.F_State = input.F_State;
- modelOrder.F_Status = 0;
- modelOrder.F_IsPayment = input.F_IsPayment;
-
- //必须属性 系统生成
- modelOrder.F_AddTime = DateTime.Now;
- modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
- modelOrder.F_AddUserName = UserLogin.UserName;
- #endregion
- //计算属性 商品计算
- decimal totle = 0.00M;
- decimal ActivityMoney = 0.00M;
- string UseActivity = "";
- string UseActivity4 = ",";
- string UseActivity2 = ",";
- string Eventprice = "";
- Dictionary<string , decimal> innerCompute = new Dictionary<string, decimal>();
-
- List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
- Dictionary<string, int> innerEventprice = new Dictionary<string, int>();
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- {
- #region 核算活动
- int n2 = input.OrderDetailList.Count + 1;
- if (input.UseActList != null && input.UseActList.Count > 0)
- {
- //遍历所有选中的活动
- foreach (UseActInput act in input.UseActList)
- {
- UseActivity += act.id + ",";
- //满赠
- //if (act.type == 1)
- //{
- // string[] productidlist = act.gift.Split(',');
- // foreach (string giftid in productidlist)
- // {
- // T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
- // if (m != null)
- // {
- // T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- // modelDetail.F_ProductName = m.F_ProductName;
- // modelDetail.F_ProductId = m.F_ProductId;
- // modelDetail.F_Specifications = m.F_Specifications;
- // modelDetail.F_ProductShortName = m.F_ProductShortName;
- // modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- // modelDetail.F_OrderId = input.F_Id;
- // modelDetail.F_Count = 1;
- // modelDetail.F_Price = 0.00M;
- // modelDetail.F_DealPrice = 0.00M;
- // modelDetail.F_Sort = n2;
- // modelDetail.F_Remark = "赠品-活动:" + act.id;
- // modelDetail.F_AddUser = modelOrder.F_AddUser;
- // modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- // modelDetail.F_TotlePrice = 0.00M;
- // modelDetail.F_Activity = act.id;
- // modelDetail.F_AddTime = DateTime.Now.AddSeconds(30);
- // modelDetailList.Add(modelDetail);
- // n2++;
- // }
- // }
- //}
- ////生日赠
- //else
- if (act.type == 2)
- {
- UseActivity2 += act.gift + ",";
- }
- //满减
- else if (act.type == 3)
- {
- ActivityMoney += act.money;
- if (string .IsNullOrEmpty (Eventprice))
- Eventprice= "" + act.id + "," + act.money;
- else
- Eventprice+= "|" + act.id + "," + act.money;
- }
- else if (act.type == 4)
- {
- UseActivity4 += act.gift + ",";
- innerCompute.Add(act.gift, act.money);
- innerEventprice.Add(act.gift, act.id);
- }
- }
- UseActivity = UseActivity.Trim(',');
- }
- #endregion
- #region 核算商品
- modelOrder.F_IsZeroCommodity = 0;
- int n = 1;
- foreach (OrderDetailInput m in input.OrderDetailList)
- {
- T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
- if (modelProduct == null) return Error("在售商品不存在");
- if (modelProduct.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
- {
- return Error("商品已下架:" + m.F_ProductName);
- }
- if (!modelOrder.F_Type.Contains("售后"))
- {
- // List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(modelProduct.F_ProductId, "新乡仓");
- if (modelProduct.F_MinimumStock + m.F_Count > modelProduct.F_Stock1 )
- {
- return Error(m.F_ProductName + "数量库存低于" + modelProduct.F_MinimumStock + "不能添加");
- }
- }
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = modelProduct.F_ProductName;
- modelDetail.F_ProductId = modelProduct.F_ProductId;
- modelDetail.F_Specifications = modelProduct.F_Specifications;
- modelDetail.F_ProductShortName = modelProduct.F_ProductShortName;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = m.F_Count;
- modelDetail.F_Price = modelProduct.F_MemberPrice;
- //参加活动特价
- if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
- {
- if (innerCompute.ContainsKey(modelProduct.F_ProductId))
- {
- ActivityMoney += innerCompute[modelProduct.F_ProductId] * m.F_Count;
- if (!string .IsNullOrEmpty (Eventprice))
- Eventprice += "|" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
- else
- Eventprice += "" + innerEventprice[modelProduct.F_ProductId] + "," + innerCompute[modelProduct.F_ProductId] * m.F_Count;
- }
- }
- modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
- //参加生日
- if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
- {
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Remark = "生日赠品-活动:";
- }
- if (modelProduct.F_ClassName == "袜子" && modelDetail.F_DealPrice == 0)
- {
- modelOrder.F_IsZeroCommodity = 1;
- }
- modelDetail.F_Sort = n;
- modelDetail.F_AddTime = DateTime.Now;
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
- modelDetail.F_Activity = 0;
- if (modelProduct.F_Tag.IndexOf(".") > -1 && !string.IsNullOrEmpty(UseActivity))
- {
- string[] tagarry = modelProduct.F_Tag.Split(',');
- string[] actlist = UseActivity.Split(',');
- string tag = tagarry.First(a => a.StartsWith(".")).ToString();
- 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 + ",")));
- //此商品参加活动
- if (modelactive != null)
- {
- modelDetail.F_Activity = modelactive.F_ID;
- }
- }
- totle += modelDetail.F_TotlePrice;
- modelDetailList.Add(modelDetail);
- n++;
- }
- #endregion
- modelOrder.F_TotlePrice = totle;
- modelOrder.F_ActivityMoney = ActivityMoney;
- modelOrder.F_Eventprice = Eventprice;
-
- modelOrder.F_UseActivity = UseActivity;
-
- }
- else
- {
- //不传商品 表明不修改商品信息 不重新计算商品
- }
-
- modelOrder.F_ExpressFee = input.F_ExpressFee;
- //直接提交 锁库存
- T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
- if (modelscore == null)
- {
- modelscore = new T_Cus_ScoreSet();
- modelscore.F_Start = 0;
- modelscore.F_StartDebit = 1;
- modelscore.F_DebitPercent = 1000;
- }
- #region 提交 更改状态 库存 积分
-
- if (input.F_State == 1)
- {
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- { }
- else
- { return Error("请选择订购商品"); }
- if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
- {
- return Error("收件人电话不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_AddTown))
- {
- return Error("收件人地址不能为空");
- }
- if (string.IsNullOrEmpty(modelOrder.F_Address))
- {
- return Error("收件人详细地址不能为空");
- }
- // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
- if (modelDetailList != null && modelDetailList.Count > 0)
- {
- foreach (var it in modelDetailList)
- {
- T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == it.F_ProductId);
- if (t_Bus_Product != null)
- {
- // List<EBossStock> listStock = await busOrderFunctionController.GetStock(it.F_ProductId, "山西仓");
- //List<EBossStock> listStock1 = await busOrderFunctionController.GetStock(it.F_ProductId, "新乡仓");
- //t_Bus_Product.F_UseNumber += it.F_Count;
- //if (listStock1!=null && listStock1.Count >0)
- //{
- // if (t_Bus_Product.F_UseNumber > listStock1[0].qty)
- // {
- // return Error("提交失败,可配量不足.");
- // }
- // else
- // {
- // Productlist.Add(t_Bus_Product);
- // }
- //}
- //else
- // return Error("提交失败,可配量不足.");
- }
- else
- {
- return Error("提交失败,商品不存在");
- }
- }
- // await bus_productRepository.UpdateList(Productlist);
- }
- modelOrder.F_SubmitTime = DateTime.Now;
- if (modelOrder.F_IsPayment > 0 || modelOrder.F_PayType != "货到付款")
- modelOrder.F_State = 7;
- else
- modelOrder.F_State = 1;
- modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
- }
- // if (modelscore.F_Start == 1)
- // {
- //订单完成后计算积分
- // modelOrder.F_Score = -0.01M;
- // }
- // else
- // { //订单完成后也不计算积分
- // modelOrder.F_Score = 0.00M;
- // }
- // if (modelscore.F_StartDebit == 0 || modelOrder.F_VipId == 0)
- // {
- // modelOrder.F_UseScore = 0;
- // }
- // string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
- // if (strStock != "1")
- // { return Error(strStock); }
- // modelOrder.F_SubmitTime = DateTime.Now;
- // }
- #endregion
- string count = UserLogin.UserName + "修改订单";
- if (!modelOrder.F_Type.Contains("售后"))
- {
-
- string a = string.Format("{0:f0}", Math.Floor(modelOrder.F_UseScore / modelscore.F_DebitPercent));
- modelOrder.F_Discount = int.Parse(a);
- modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney -int .Parse (a) + input.F_ExpressFee;
- modelvip.F_UseGift -= modelOrder.F_UseGift;
- if (input.OrderUserGift != null && input.OrderUserGift.Count > 0)
- {
- decimal moneys = 0.00M;
- if (modelvip.F_Money != null)
- {
- moneys = (decimal)modelvip.F_Money + modelOrder.F_ShouldPrice;
- }
- else
- moneys = modelOrder.F_ShouldPrice;
- int b = 0;
- if (moneys > 3000)
- {
- decimal fund = moneys - 3000;
- string c = string.Format("{0:f0}", Math.Floor(fund / 2000));
- b = int.Parse(c) + 1 - modelvip.F_UseGift;
- }
- int n2 = 0;
- foreach (var m in input.OrderUserGift)
- {
- T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
- modelDetail.F_ProductName = m.F_ProductName;
- modelDetail.F_ProductId = m.F_ProductId;
- modelDetail.F_Specifications = m.F_Specifications;
- modelDetail.F_ProductShortName = m.F_ProductShortName;
- modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- modelDetail.F_OrderId = input.F_Id;
- modelDetail.F_Count = 1;
- modelDetail.F_Price = 0.00M;
- modelDetail.F_DealPrice = 0.00M;
- modelDetail.F_Sort = n2;
- modelDetail.F_Remark = "满赠营销";
- modelDetail.F_AddUser = modelOrder.F_AddUser;
- modelDetail.F_AddUserName = modelOrder.F_AddUserName;
- modelDetail.F_TotlePrice = 0.00M;
- modelDetail.F_Activity = 0;
- modelDetail.F_AddTime = DateTime.Now;
- modelDetailList.Add(modelDetail);
- n2++;
- }
- if (n2 > b)
- {
- return Error("该会员最多可赠送" + b + "件赠品");
- }
- else
- {
- modelvip.F_UseGift += n2;
- modelOrder.F_UseGift = n2;
- }
- }
- if (modelvip != null)
- {
- modelvip.F_Score -= modelOrder.F_UseScore;
- await cus_vip_infoRepository.Update(modelvip);
- }
- if (input.F_State == 1)
- {
- if (modelOrder.F_State == 1)
- count += "进入客服待分仓";
- else if (modelOrder.F_State == 7)
- count += "进入客服待付款待审核";
- }
- else
- count += "进入销售待提交";
- }
- if (input.F_IsPayment > 0 || input.F_PayType != "货到付款")
- {
- try
- {
- if (string.IsNullOrEmpty(input.F_PayType))
- return Error("请输入打款方式");
- if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkKF))
- input.OrderMoney.F_RemarkKF = "";
- if (string.IsNullOrEmpty(input.OrderMoney.F_RemarkXS))
- input.OrderMoney.F_RemarkXS = "";
- if (input.OrderMoney.F_PayTime == null)
- return Error("请输入打款时间");
- if (input.OrderMoney.F_Money <= 0)
- return Error("请输入付款金额");
-
- #region 验证参数 必填项
- Expression<Func<T_Bus_OrderMoney, bool>> eq = a => a.F_OrderId == input.F_Id;
- //var modelOrderMoen = await busOrderMoneyRepository.GetListALL(eq, o => o.F_AddTime, OrderByType.Asc);
- var modelOrderMoen = await busOrderMoneyRepository.GetListALL(x => x.F_OrderId == modelOrder.F_Id && x.F_Type == 1);
- T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
- if (modelOrderMoen != null && modelOrderMoen.Count > 0)
- {
- modelOrderMoeny = modelOrderMoen.FirstOrDefault();
- }
- modelOrder.F_RealPrice = input.OrderMoney.F_Money;
- #endregion
- ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input.OrderMoney);
- modelOrderMoeny.F_AddUserId = UserLogin.UserId.ObjToInt();
- modelOrderMoeny.F_UserName = UserLogin.UserName;
- modelOrderMoeny.F_OrderId = input.F_Id;
- modelOrderMoeny.F_MoneyBak = modelOrderMoeny.F_Money;
- modelOrderMoeny.F_State = 0;
- modelOrderMoeny.F_Type = 1;
- if (modelOrderMoen != null && modelOrderMoen.Count > 0)
- {
- if (!await busOrderMoneyRepository.Update(modelOrderMoeny))
- return Error("付款失败");
- }
- else
- {
- modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-", "");
- if (!await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
- return Error("付款失败");
- }
- }
- catch (Exception ex)
- { return Error(ex.Message); }
- }
- //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));
- //modelOrder.F_RealPrice = dt.Rows[0][0].ObjToDecimal() ;
- //if (modelOrder.F_ShouldPrice > 0)
- //{
- // if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
- // modelOrder.F_PayState = 1;
- // else
- // modelOrder.F_PayState = 0;
- //}
- //else
- //{
- // if (modelOrder.F_ShouldPrice >= modelOrder.F_RealPrice)
- // modelOrder.F_PayState = 3;
- // else
- // modelOrder.F_PayState = 2;
- //}
- //待付款 客服审核付款情况后改为已付款
- int t = await AddLog(modelOrder.F_Id, count, UserLogin.UserCode , modelOrder.F_State);
- if (t >0)
- {
- if (await bus_OrderRepository.Update(modelOrder))
- {
- if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
- {
- //删除之前订单商品,重新添加
- if (await bus_OrderDetailRepository.Delete(q => q.F_OrderId == modelOrder.F_Id))
- {
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- return Success("订单生成成功");
- else
- return Error("订单操作失败,请重试1!");
- }
- else
- {
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- return Success("订单生成成功2");
- else
- return Error("订单操作失败,请重试2!");
- }
- }
- else if (input.OrderUserGift != null && input.OrderUserGift.Count > 0)
- {
- //删除之前订单商品,重新添加
- if (await bus_OrderDetailRepository.Delete(q => q.F_OrderId == modelOrder.F_Id
- &&q .F_Remark == "满赠营销"))
- {
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- return Success("订单生成成功");
- else
- return Error("订单操作失败,请重试1!");
- }
- else
- {
- if (await bus_OrderDetailRepository.AddMany(modelDetailList))
- return Success("订单生成成功2");
- else
- return Error("订单操作失败,请重试2!");
- }
- }
- else { return Success("成功"); }
- }
- }
- return Error("订单添加失败,请重试!");
- }
-
- #endregion
- /// <summary>
- /// 根据商品组合 获取符合的所有活动
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("getact")]
- public async Task<IActionResult> GetAct([FromBody]List<OrderDetailInput> input)
- {
- decimal def = 0.00M;
- if (input==null&& input.Count<=0)
- return Error("请选择商品/数量");
- //统计活动金额是否符合条件 满减
- Dictionary<int, decimal> acttype3 = new Dictionary<int, decimal>();
- //内部计算
- Dictionary<int, decimal> innerCompute = new Dictionary<int, decimal>();
- //选择活动
- Dictionary<int, string> chooseact = new Dictionary<int, string>();
- List<UseActInput> actlist = new List<UseActInput>();
- Dictionary<string , string> MarketingDic = new Dictionary<string, string>();
- List<T_Sys_Marketing> t_Sys_Marketings = new List<T_Sys_Marketing>();
- foreach (var m in input)
- {
- T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
- if (modelProduct != null)
- {
- if (modelProduct.F_OnSaleEnd < DateTime.Now && UserLogin.RoleCode != "SH")
- {
- return Error("商品已下架:" + modelProduct.F_ProductName);
- }
- if (modelProduct.F_Tag.IndexOf(".") > -1)
- {
- string[] tagarry = modelProduct.F_Tag.Split(',');
- foreach (var it in tagarry)
- {
- var Marketing = await bus_MarketingRepository.GetListALL(q => q.F_IsDelete == 0 && q.F_Commodity==
- it && q.F_StartTime <= DateTime.Now && q.F_EndTime >= DateTime.Now && q.F_IsDelete == 0);
- if (Marketing!=null&& Marketing.Count >0)
- {
- T_Sys_Marketing modelactive = Marketing.FirstOrDefault();
- //if (modelactive.F_Type == 1)
- //{
- // //满赠
- // //判断此人是否有参与活动的资格 默认暂不筛选
- // if (chooseact.ContainsKey(modelactive.F_ID))
- // continue;
- // if (innerCompute.ContainsKey(modelactive.F_ID))
- // {
- // innerCompute[modelactive.F_ID] = (decimal)modelProduct.F_MemberPrice * m.F_Count + innerCompute[modelactive.F_ID].ObjToDecimal();
- // }
- // else
- // {
- // innerCompute.Add(modelactive.F_ID, (decimal)modelProduct.F_MemberPrice * m.F_Count);
- // }
- // if (modelactive.F_Money.ObjToDecimal() <= (decimal)innerCompute[modelactive.F_ID])
- // {
- // chooseact.Add(modelactive.F_ID, "1_" + modelactive.F_Gift);
- // actlist.Add(new UseActInput { id = modelactive.F_ID, type = 1, gift = modelactive.F_Gift, money = def, actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
- // }
- //}
- //else
- if (modelactive.F_Type == 2)
- {
- // 生日
- //TODO 判断此人是否有参与活动的资格 默认暂不筛选
- if (chooseact.ContainsKey(modelactive.F_ID))
- continue;
- chooseact.Add(modelactive.F_ID, "2_" + modelactive.F_Commodity);
- actlist.Add(new UseActInput { id = modelactive.F_ID, type = 2, gift = modelactive.F_Gift, money = def, actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
- }
- else if (modelactive.F_Type == 3)
- {
- //满减
- //判断此人是否有参与活动的资格 默认暂不筛选
- string[] AmountRange = modelactive.F_AmountRange.Split(',');
- if (modelactive.F_Describe == "按总件数")
- {
- if (innerCompute.ContainsKey(modelactive.F_ID))
- {
- innerCompute[modelactive.F_ID] = m.F_Count + innerCompute[modelactive.F_ID];
- }
- else
- {
- innerCompute.Add(modelactive.F_ID, m.F_Count);
- }
- for (int i = 0; i < AmountRange.Length; i++)
- {
- //符合满减某个条件
- if (innerCompute[modelactive.F_ID] >= AmountRange[i].ObjToDecimal())
- {
- if (acttype3.ContainsKey(modelactive.F_ID))
- {
- string a = string.Format("{0:f0}", Math.Floor(innerCompute[modelactive.F_ID] / AmountRange[i].ObjToDecimal()));
- acttype3[modelactive.F_ID] = modelactive.F_Money.Split(',')[i].ObjToDecimal() * int.Parse(a);
- actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.money = modelactive.F_Money.Split(',')[i].ObjToDecimal() * int.Parse(a); } });
- }
- else
- {
- string a = string.Format("{0:f0}", Math.Floor(innerCompute[modelactive.F_ID] / AmountRange[i].ObjToDecimal()));
- acttype3.Add(modelactive.F_ID, modelactive.F_Money.Split(',')[i].ObjToDecimal() * int.Parse(a));
- 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 });
- }
-
- }
- }
- }
- else
- {
- if (innerCompute.ContainsKey(modelactive.F_ID))
- {
- innerCompute[modelactive.F_ID] = (decimal)modelProduct.F_MemberPrice * m.F_Count + innerCompute[modelactive.F_ID];
- }
- else
- {
- innerCompute.Add(modelactive.F_ID, (decimal)modelProduct.F_MemberPrice * m.F_Count);
- }
- for (int i = 0; i < AmountRange.Length; i++)
- {
- //符合满减某个条件
- if (innerCompute[modelactive.F_ID] >= AmountRange[i].ObjToDecimal())
- {
- if (acttype3.ContainsKey(modelactive.F_ID))
- {
- //当前减免金额大于之前发赋值,替换掉
- if (modelactive.F_Money.Split(',')[i].ObjToDecimal() > acttype3[modelactive.F_ID])
- {
- acttype3[modelactive.F_ID] = modelactive.F_Money.Split(',')[i].ObjToDecimal();
- actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.money = modelactive.F_Money.Split(',')[i].ObjToDecimal(); } });
- }
- }
- else
- {
- //满足条件,赋值满减金额 减的金额
- acttype3.Add(modelactive.F_ID, modelactive.F_Money.Split(',')[i].ObjToDecimal());
- 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 });
- }
- }
- }
- }
- }
- else if (modelactive.F_Type == 4)
- {
- //限时特惠
- //判断此人是否有参与活动的资格 默认暂不筛选
- if (chooseact.ContainsKey(modelactive.F_ID))
- {
- chooseact[modelactive.F_ID] = chooseact[modelactive.F_ID] + "," + m.F_ProductId.ToString();
- actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.gift = q.gift + m.F_ProductId.ToString(); } });
- }
- else
- {
- chooseact.Add(modelactive.F_ID, "4_" + m.F_ProductId.ToString());
- 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 });
- }
- }
- }
- }
- }
- }
- else
- {
- return Error("商品不存在" + modelProduct.F_ProductName);
- }
- }
-
- return Success("参与活动", actlist);
- }
- /// <summary>
- /// 获取订单详情
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("getorderdetail")]
- public async Task<IActionResult> GetOrderDetail(string orderid)
- {
- if (string.IsNullOrEmpty(orderid))
- return Error("请输入订单号");
- T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == orderid);
- OrderInput modelreturn = new OrderInput();
- if (modelOrder != null)
- {
- ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(modelreturn, modelOrder);
- List<OrderDetailInput> modeldetailreturn = new List<OrderDetailInput>();
- List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id
- &&q .F_Remark!="满赠营销", o => o.F_Sort, OrderByType.Asc);
- if (detaillist != null)
- {
- foreach (T_Bus_OrderDetail m in detaillist)
- {
- OrderDetailInput model = new OrderDetailInput();
- model.F_ProductName = m.F_ProductName;
- model.F_ProductId = m.F_ProductId;
- model.F_Specifications = m.F_Specifications;
- model.F_ProductShortName = m.F_ProductShortName;
- model.F_Id = m.F_Id;
- model.F_OrderId = m.F_OrderId;
- model.F_Count = m.F_Count;
- model.F_Price = m.F_Price;
- model.F_DealPrice = m.F_DealPrice;
- model.F_Sort = m.F_Sort;
- model.F_AddTime = m.F_AddTime;
- model.F_Remark = m.F_Remark;
- model.F_AddUser = m.F_AddUser;
- model.F_AddUserName = m.F_ProductName;
- model.F_TotlePrice = m.F_TotlePrice;
- model.F_Activity = m.F_Activity;
- modeldetailreturn.Add(model);
- }
- }
- modelreturn.OrderDetailList = modeldetailreturn;
- List<OrderDetailInput> modelUserGift = new List<OrderDetailInput>();
- List<T_Bus_OrderDetail> detaillistgife = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id
- && q.F_Remark == "满赠营销", o => o.F_Sort, OrderByType.Asc);
- if (detaillist != null)
- {
- foreach (T_Bus_OrderDetail m in detaillistgife)
- {
- OrderDetailInput model = new OrderDetailInput();
- model.F_ProductName = m.F_ProductName;
- model.F_ProductId = m.F_ProductId;
- model.F_Specifications = m.F_Specifications;
- model.F_ProductShortName = m.F_ProductShortName;
- model.F_Id = m.F_Id;
- model.F_OrderId = m.F_OrderId;
- model.F_Count = m.F_Count;
- model.F_Price = m.F_Price;
- model.F_DealPrice = m.F_DealPrice;
- model.F_Sort = m.F_Sort;
- model.F_AddTime = m.F_AddTime;
- model.F_Remark = m.F_Remark;
- model.F_AddUser = m.F_AddUser;
- model.F_AddUserName = m.F_ProductName;
- model.F_TotlePrice = m.F_TotlePrice;
- model.F_Activity = m.F_Activity;
- modelUserGift.Add(model);
- }
- }
- modelreturn.OrderUserGift = modelUserGift;
- var useraccount =await _sys_useraccountRepository.GetSingle(x => x.F_UserId == modelOrder.F_Belong);
- if (useraccount!=null )
- {
- modelreturn.F_BelongName = useraccount.F_UserName;
- modelreturn.F_GroupName = useraccount.F_Group ;
- modelreturn.F_CoreName = useraccount.F_Team ;
- }
- modelreturn.UseActList = new List<UseActInput>();
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_ID", ConditionalType = ConditionalType.In , FieldValue = modelOrder.F_UseActivity });
- List<T_Sys_Marketing> modelactiveList = await bus_MarketingRepository.GetListALL(conModels, "F_ID DESC");
- Dictionary<string, string> innerEventprice = new Dictionary<string, string >();
- if (modelactiveList != null && modelactiveList.Count > 0)
- {
- if (!string.IsNullOrEmpty(modelOrder.F_Eventprice))
- {
- string[] Eventprice = modelOrder.F_Eventprice.Split('|');
- foreach (var it in Eventprice)
- {
- try
- {
- string[] sprit = it.Split(',');
- innerEventprice.Add(sprit[0], sprit[1]);
- }
- catch
- {
- }
- }
- }
- if (!string.IsNullOrEmpty(modelOrder.F_Eventprice))
- {
- foreach (T_Sys_Marketing modelactive in modelactiveList)
- {
- modelreturn.UseActList.Add(new UseActInput
- {
- id = modelactive.F_ID,
- type = modelactive.F_Type,
- gift = modelactive.F_Gift,
- money = decimal.Parse(innerEventprice[modelactive.F_ID.ToString()]),
- actname = modelactive.F_Name,
- actdes = modelactive.F_PromotionRules
- });
- }
- }
- else
- {
- foreach (T_Sys_Marketing modelactive in modelactiveList)
- {
- modelreturn.UseActList.Add(new UseActInput
- {
- id = modelactive.F_ID,
- type = modelactive.F_Type,
- gift = modelactive.F_Gift,
- money = modelOrder.F_ActivityMoney,
- actname = modelactive.F_Name,
- actdes = modelactive.F_PromotionRules
- });
- }
- }
- }
- // modelreturn.UseActList = actlist;
- }
- else
- return Error("订单不存在");
- Expression<Func<T_Bus_Orderlogs , bool>> eq = a => a.F_WoID == orderid;
- var ItemList = await busOrderlogsRepository.GetListALL(eq, o => o.F_CreateTime , OrderByType.Desc );
- Expression<Func<T_Bus_ChatLog, bool>> aq = a => a.F_WoID == orderid;
- aq = aq.And(a => a.F_IsDelete == 0);
- var modelOrderMoen = await busOrderMoneyRepository.GetListALL(x => x.F_OrderId == modelOrder.F_Id && x.F_Type == 1);
- modelreturn.OrderMoney = new OrderMoneyInput();
- if (modelOrderMoen!=null && modelOrderMoen.Count >0)
- {
- ModelConvertHelper<OrderMoneyInput, T_Bus_OrderMoney>.ModeToModel(modelreturn.OrderMoney, modelOrderMoen.FirstOrDefault());
- }
- V_Cus_VipInfo vip = new V_Cus_VipInfo();
- if (modelOrder.F_VipId >0)
- {
- vip = await cus_vip_infoRepository .GetSingleV(x => x.F_ID == modelOrder.F_VipId && x.F_State == (int)EnumDelState.Enabled);
- }
- if (UserLogin.RoleCode == "XS")
- {
- aq = aq.And(a => a.F_IsSo ==1);
- }
- aq = aq.And(a => a.F_State == 0);
- var ChatList = await bus_ChatLogRepository.GetListALL(aq, o => o.F_AddTime , OrderByType.Asc);
- var obj = new
- {
- modelreturn,
- ItemList,
- ChatList,
- vip
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取订单分页列表
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("getorderlistbypage")]
- public async Task<IActionResult> GetXSOrderListByPage(OrderInput input,string keywords,int State = -1)
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- #region 条件筛选
- if (State > 0)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.NotIn, FieldValue = "0,2" });
- }
- if (input.F_State > -2)
- {
- if (input.F_State == 14)
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.In, FieldValue = "1,4,7" });
- else
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = input.F_State.ToString() });
- }
- if (!string.IsNullOrEmpty(input .F_SubmitUser ))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_SubmitUser", ConditionalType = ConditionalType.Like , FieldValue = input.F_SubmitUser });
- }
-
- //根据角色展示列表
- if (UserLogin.RoleCode == "XS")
- {
- conModels.Add(new ConditionalCollections()
- {
- ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
- {
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_AddUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Belong", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId })
- }
- } );
- }
- else if (UserLogin.RoleCode == "KF" && input.F_State != 1)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_CheckUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
- }
- else if (UserLogin.RoleCode == "KG" && input.F_State != 3)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
- //OR conModels.Add(new ConditionalModel() { FieldName = "F_SendUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
- }
- else if (UserLogin .RoleCode == "ZXFZR")
- {
- var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == UserLogin.UserId .ObjToInt());
- conModels.Add(new ConditionalModel() { FieldName = "F_Core", ConditionalType = ConditionalType.Equal, FieldValue = useraccount.F_DeptTeamId.ToString() });
- }
- else if (UserLogin.RoleCode == "XZFZR")
- {
- var useraccount = await _sys_useraccountRepository.GetSingle(x => x.F_UserId == UserLogin.UserId.ObjToInt());
- conModels.Add(new ConditionalModel() { FieldName = "F_Group", ConditionalType = ConditionalType.Equal, FieldValue = useraccount.F_GroupId .ToString() });
- }
- if (input.F_Core > 0)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Core", ConditionalType = ConditionalType.Like, FieldValue = input.F_Core.ToString() });
- }
- if (input.F_Group > 0)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Group", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Group.ToString () });
- }
- if (!string .IsNullOrEmpty (input.F_BelongName))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_BelongName", ConditionalType = ConditionalType.Equal, FieldValue = input.F_BelongName });
- }
- if (!string.IsNullOrEmpty(input.F_ADFrom))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Like, FieldValue = input.F_ADFrom });
- }
- if (!string.IsNullOrEmpty(input.F_Type))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Type });
- }
- if (!string.IsNullOrEmpty(input.F_Id))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Like, FieldValue = input.F_Id });
- }
- if (input .F_IsZeroCommodity>-1)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_IsZeroCommodity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_IsZeroCommodity.ToString () });
- }
- if (!string.IsNullOrEmpty(input.F_Customer))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Like, FieldValue = input.F_Customer });
- }
- if (input.F_Media > 0)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Media", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Media.ToString () });
- }
- if (input.F_Status > -1)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Status", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Status.ToString() });
- }
- if (!string.IsNullOrEmpty(keywords))
- {
- conModels.Add(new ConditionalCollections()
- {
- ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
- {
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Addressee", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_AddPhone", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_CustomerTel", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Like, FieldValue = keywords }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Like, FieldValue = keywords })
- }
- });
- }
- if (input.F_VipId>0)
- {
- var model = await cus_vip_infoRepository.GetSingleV(x => x.F_ID == input.F_VipId && x.F_State == (int)EnumDelState.Enabled);
- if (model == null)
- return Error("会员不存在");
- var modellist = await cus_vip_infoRepository.GetListALL(x => x.F_ParentID == input.F_VipId && x.F_State == (int)EnumDelState.Delete);
- if (modellist != null || modellist.Count> 0)
- {
- string msgvip = input.F_VipId.ToString();
- foreach (var it in modellist)
- {
- msgvip+=","+ it.F_ID ;
- }
- conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.In, FieldValue = msgvip });
- }
- else
- conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.Equal, FieldValue = input.F_VipId.ToString() });
- }
- if (!string.IsNullOrEmpty(input.F_CustomerPhone))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Like , FieldValue = input.F_CustomerPhone });
- }
- if (!string.IsNullOrEmpty(input.F_TrackingNo))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Like, FieldValue = input.F_TrackingNo });
- }
- if (!string.IsNullOrEmpty(input.F_AddProvince))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_AddProvince", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddProvince });
- }
- if (!string.IsNullOrEmpty(input.F_AddCity))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_AddCity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddCity });
- }
- if (!string.IsNullOrEmpty(input.F_AddArea))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_AddArea", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddArea });
- }
- if (!string.IsNullOrEmpty(input.F_AddTown))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTown", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddTown });
- }
- if (!string.IsNullOrEmpty(input.F_Express))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Express", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Express });
- }
- if (!string.IsNullOrEmpty(input.F_PayType))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_PayType", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayType });
- }
- if (!string.IsNullOrEmpty(input.F_Stock))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Stock", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Stock });
- }
- if (input.F_PayState > -1)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
- }
- if (input.SearchEndTime != null)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
- }
- if (input.SearchStartTime != null)
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
- }
- #endregion
- RefAsync<int> recordCount = 0;
- PageData<T_Bus_Order> list = await bus_OrderRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = recordCount }, " F_AddTime DESC");
- PageData<OrderInput> returnobj = new PageData<OrderInput>() { Totals = list.Totals };
- List<OrderInput> returnlist = new List<OrderInput>();
- foreach (T_Bus_Order t in list.Rows)
- {
- OrderInput m = new OrderInput();
- ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(m, t);
- List<OrderDetailInput> orderDetailInputs = new List<OrderDetailInput>();
- #region 遍历订单商品
- List<T_Bus_OrderDetail> orderDetails = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == t.F_Id);
- if (orderDetails != null)
- {
- foreach (T_Bus_OrderDetail t1 in orderDetails)
- {
- OrderDetailInput m1 = new OrderDetailInput();
- ModelConvertHelper<OrderDetailInput, T_Bus_OrderDetail>.ModeToModel(m1, t1);
- orderDetailInputs.Add(m1);
- }
- }
- #endregion
- m.OrderDetailList = orderDetailInputs;
- m.IsSale = busAfterSaleRepository.GetListALL(x => x.F_OrderId == t.F_Id).Result!=null
- ? busAfterSaleRepository.GetListALL(x => x.F_OrderId == t.F_Id).Result.Count :0;
-
- returnlist.Add(m);
- }
- returnobj.Rows = returnlist;
- return Success("成功", returnobj);
- }
- /// <summary>
- /// 撤回未审核订单
- /// </summary>
- /// <param name="orderid">订单号</param>
- /// <param name="state">订单状态 -1无效 0暂存 1提交 2KF退回 3通过 4KG退回 5已分拣 6已发货</param>
- /// <param name="remark">客服备注</param>
- /// <returns></returns>
- [HttpPost("cancelorder")]
- public async Task<IActionResult> CancelOrder(string orderids, int state = 0)
- {
- try
- {
- //状态变化 积分变化 处理时间人变化 库存变化 备注
- T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(orderids))
- return Error("请选择订单号");
- if (state != 0)
- return Error("请选择操作类型");
- string[] orderid = orderids.Split(',');
- string msg = "";
- #endregion
- List<T_Bus_Orderlogs> logs = new List<T_Bus_Orderlogs>();
- List<T_Bus_Order> orders = new List<T_Bus_Order>();
- foreach (var it in orderid)
- {
- T_Bus_Orderlogs t_Bus_Orderlogs = new T_Bus_Orderlogs();
- T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == it && new int[] {1, 3, 7 }.Contains(q.F_State));
- if (modelOrder == null)
- {
- msg +="订单"+ it + "已审核";
- continue;
- }
- else
- {
- if (modelOrder.F_State ==1)
- {
- List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id, o => o.F_Sort, OrderByType.Asc);
- // List<T_Bus_Product> Productlist = new List<T_Bus_Product>();
- if (detaillist != null && detaillist.Count > 0)
- {
- foreach (var iv in detaillist)
- {
- T_Bus_Product t_Bus_Product = await bus_productRepository.GetSingle(x => x.F_ProductId == iv.F_ProductId);
- if (t_Bus_Product != null)
- {
- // t_Bus_Product.F_UseNumber -= iv.F_Count;
- // Productlist.Add(t_Bus_Product);
- }
- else
- {
- msg += "订单" + modelOrder.F_Id + "退回失败,商品不存在.";
- continue;
- }
- }
- //if (Productlist != null && Productlist.Count > 0)
- //{
- // if (!await bus_productRepository.UpdateList(Productlist))
- // {
- // msg += "订单" + modelOrder.F_Id + "退回失败";
- // continue;
- // }
- // }
- //else
- //{
- // msg += "订单" + modelOrder.F_Id + "退回失败,请选择商品";
- // continue;
- //}
- }
- }
- modelOrder.F_TrackingNo = "";
- modelOrder.F_Express = "";
- modelOrder.F_IsExpress = 0;
- modelOrder.F_Stock = "";
- modelOrder.F_State = state;
- t_Bus_Orderlogs.F_WoID = modelOrder.F_Id;
- t_Bus_Orderlogs.F_CreateUser = UserLogin.UserCode;
- t_Bus_Orderlogs.F_CreateTime = DateTime.Now;
- t_Bus_Orderlogs.F_OptContent = UserLogin.UserName + "撤回订单,流转销售待提交";
- t_Bus_Orderlogs.F_WoState = modelOrder.F_State;
- logs.Add(t_Bus_Orderlogs);
- orders.Add(modelOrder);
- }
-
- }
- // string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 0, null);
- // if (strStock != "1")
- // return Error(strStock);
- // modelOrder.F_State = 0;
- // modelOrder.F_Score = 0.00M;
- if (msg =="")
- {
- if (await bus_OrderRepository.UpdateList(orders))
- {
- await busOrderlogsRepository.AddMany (logs);
- return Success("订单成功审核!");
- }
- }
- else
- return Error(msg);
- return Error("订单审核失败,请汇报技术支持!");
- }
- catch (Exception ex)
- { return Error(ex.Message); }
- }
- [HttpPost("ordermoney")]
- public async Task<IActionResult> OrderMoney(OrderMoneyInput input)
- {
- try
- {
- #region 验证参数 必填项
- if (string.IsNullOrEmpty(input.F_OrderId))
- return Error("请输入订单号");
- if (string.IsNullOrEmpty(input.F_PayUser))
- return Error("请输入打款人");
- if (string.IsNullOrEmpty(input.F_PayType))
- return Error("请输入打款方式");
- if (string.IsNullOrEmpty(input.F_RemarkKF))
- input.F_RemarkKF = "";
- if (string.IsNullOrEmpty(input.F_RemarkXS))
- input.F_RemarkXS = "";
- if (input.F_PayTime==null)
- return Error("请输入打款时间");
- if (input.F_Money <= 0)
- return Error("请输入金额");
- #endregion
- T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
- ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input);
- modelOrderMoeny.F_AddUserId =UserLogin.UserId.ObjToInt();
- modelOrderMoeny.F_UserName = UserLogin.UserName;
- modelOrderMoeny.F_MoneyBak= modelOrderMoeny.F_Money;
- modelOrderMoeny.F_State= 0;
- modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-","");
- if (await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
- return Success("成功!");
- return Error("失败!");
- }
- catch (Exception ex)
- { return Error(ex.Message); }
- }
- private async Task<int> AddLog(string WoID,string count,string user,int state)
- {
- T_Bus_Orderlogs logs = new T_Bus_Orderlogs();
- logs.F_WoID = WoID;
- logs.F_WoState = state;
- logs.F_OptContent = count;
- logs.F_CreateUser = user;
- logs.F_CreateTime = DateTime .Now ;
- var res =await busOrderlogsRepository.Add(logs);
- return res;
- }
- }
- }
|