SaleReport.php 182 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631
  1. <?php
  2. namespace app\admin\controller;
  3. //use app\abutment\model\SupplierRelationUser;
  4. //use app\abutment\model\SupplierUser;
  5. use think\facade\Db;
  6. //前端报表处理类
  7. class SaleReport extends Base
  8. {
  9. //订单来源:1直接下单,2咨询,3项目,4平台,5有赞,6售后补换货,7报备转单,8支付渠道9采销录单10结算录单
  10. private $all_order_type = [1 => '备库', 2 => '非库存', 3 => '咨询采反', 4 => '报备转单'];//订单类型
  11. private $all_stock = [0 => '非库存品', 1 => '库存品'];//是否库存品
  12. private $all_sale_status = [0 => '待发货', 1 => '待发货完成', 2 => '发货已完成', 3 => '订单已取消'];//订单状态(sale表里的status)
  13. private $is_addrs = [0 => '是', 1 => '否'];//是否一地(数据库中存的是'是否多地',逻辑相反)
  14. private $is_custom = [0 => '否', 1 => '是'];//是否定制
  15. private $consult_info_status = [1 => '招标进行中', 2 => '招标已结束', 3 => '等待议价结果', 4 => '确认商品', 5 => '成功转单', 6 => '取消转单', 7 => '招标已暂停'];//状态
  16. private $noble_metal = [1 => '18K', 2 => '24K', 3 => '白银'];//贵金属种类
  17. private $all_order_return_status = [1 => '待业务审核', 2 => '待采购审核', 3 => '待设置仓库', 4 => '待客户退货', 5 => '售后已完成', 6 => '业务已驳回', 7 => '采购已驳回', 8 => '申请已取消'];
  18. private $is_activity = [0 => '不参与活动', 1 => '参与活动'];
  19. private $good_type = [1 => '正常商品', 2 => '赠品', 3 => '样品'];
  20. private $sale_diff_status = [1 => '修改销售额', 2 => '不修改销售额'];
  21. private $is_receive = [0 => '未收到', 1 => '收到'];
  22. private $bargain_order_status = [1 => '待主管审批', 2 => '待财务专员审批', 3 => '待财务主管审批', 4 => '审批通过', 5 => '主管驳回', 6 => '财务主管驳回', 7 => '已取消议价'];
  23. private $order_out_status = [0 => '待采购备货', 1 => '待库管发货', 2 => '已发货待收货', 3 => '已收货', 4 => '已全部退货'];
  24. private $except_code = [0 => [1 => '退货', 2 => '补发'], 1 => [1 => '退货', 2 => '换货'],];//期望意愿
  25. private $order_back_status = [0 => '待申请', 1 => '待验收', 2 => '待验收审核', 3 => '待业务审核', 4 => '完成退货'];
  26. private $order_source = [0 => '备库下单', 1 => '直接下单', 2 => '咨询下单', 3 => '项目下单', 4 => '平台导入',5=>'有赞转单',6=>"售后补换货",7=>'报备转单',8=>'支付渠道',9=>'采销录单',10=>'结算录单'];
  27. private $plat_type = [0=>"无",1=>"ToB",2=>"ToC"];
  28. //【一、管理报表】1.日报_列表
  29. public function consultDay()
  30. {
  31. $param = $this->request->only(['token', 'date' => date('Y-m-d')], 'post', 'trim');
  32. $rs_1 = Db::name('consult_info')
  33. ->alias('ci')
  34. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  35. ->where([
  36. ['ci.is_del', '=', 0],
  37. ['ci.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  38. ])
  39. ->group('co.createrid,co.creater')
  40. ->column('COUNT(ci.id) 当日咨询单数量,SUM(ci.budget_price*ci.num) 金额,co.creater 创建人', 'co.createrid');
  41. $rs_2 = Db::name('sale')
  42. ->where([
  43. ['is_del', '=', 0],
  44. ['addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  45. ])
  46. ->group('apply_id,apply_name')
  47. ->column('COUNT(id) 当日下单数量,SUM(total_price) 金额,apply_name 创建人', 'apply_id');
  48. $rs_3 = Db::name('order_out')
  49. ->alias('oo')
  50. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  51. ->where([
  52. ['oo.status', '=', 3],
  53. ['oo.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  54. ])
  55. ->group('oo.apply_id,oo.apply_name')
  56. ->column('COUNT(oo.id) 当日签收数量,SUM(s.total_price) 金额,oo.apply_name 创建人', 'oo.apply_id');
  57. $rs_4 = Db::name('order_return')
  58. ->alias('or')
  59. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  60. ->where([
  61. ['or.is_del', '=', 0],
  62. ['or.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  63. ])
  64. ->group('or.apply_id,or.apply_name')
  65. ->column('COUNT(or.id) 单日售后单数,SUM(s.total_price) 金额,or.apply_name 创建人', 'or.apply_id');
  66. $all_ids = array_unique(array_merge(array_keys($rs_1), array_keys($rs_2), array_keys($rs_3), array_keys($rs_4)));
  67. $all_company = get_company_name_by_uid($all_ids);//获取创建人的所属部门
  68. $list = [];
  69. foreach ($all_ids as $id) {
  70. $val = [];
  71. if (isset($rs_1[$id]['创建人'])) $val['creater'] = $rs_1[$id]['创建人'];
  72. elseif (isset($rs_2[$id]['创建人'])) $val['creater'] = $rs_2[$id]['创建人'];
  73. elseif (isset($rs_3[$id]['创建人'])) $val['creater'] = $rs_3[$id]['创建人'];
  74. elseif (isset($rs_4[$id]['创建人'])) $val['creater'] = $rs_4[$id]['创建人'];
  75. else $val['creater'] = '';
  76. $val['creater_company'] = $all_company[$id] ?? '';//get_company_name_by_uid($id);//获取创建人的所属部门
  77. $val['consult_num'] = isset($rs_1[$id]['当日咨询单数量']) ? $rs_1[$id]['当日咨询单数量'] : '';
  78. $val['consult_money'] = isset($rs_1[$id]['金额']) ? $rs_1[$id]['金额'] : '';
  79. $val['sale_num'] = isset($rs_2[$id]['当日下单数量']) ? $rs_2[$id]['当日下单数量'] : '';
  80. $val['sale_money'] = isset($rs_2[$id]['金额']) ? $rs_2[$id]['金额'] : '';
  81. $val['receipt_num'] = isset($rs_3[$id]['当日签收数量']) ? $rs_3[$id]['当日签收数量'] : '';
  82. $val['receipt_money'] = isset($rs_3[$id]['金额']) ? $rs_3[$id]['金额'] : '';
  83. $val['invoice_num'] = '';
  84. $val['invoice_money'] = '';
  85. $val['after_sales_num'] = isset($rs_4[$id]['单日售后单数']) ? $rs_4[$id]['单日售后单数'] : '';
  86. $val['after_sales_money'] = isset($rs_4[$id]['金额']) ? $rs_4[$id]['金额'] : '';
  87. $val['payment_num'] = '';
  88. $val['payment_money'] = '';
  89. $list[] = $val;
  90. }
  91. return app_show(0, '请求成功', ['list' => $list]);
  92. }
  93. //【一、管理报表】1.日报_导出
  94. public function consultDayExport()
  95. {
  96. $param = $this->request->only(['token', 'date' => date('Y-m-d')], 'post', 'trim');
  97. $rs_1 = Db::name('consult_info')
  98. ->alias('ci')
  99. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  100. ->where([
  101. ['ci.is_del', '=', 0],
  102. ['ci.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  103. ])
  104. ->group('co.createrid,co.creater')
  105. ->column('COUNT(ci.id) 当日咨询单数量,SUM(ci.budget_price*ci.num) 金额,co.creater 创建人', 'co.createrid');
  106. $rs_2 = Db::name('sale')
  107. ->where([
  108. ['is_del', '=', 0],
  109. ['addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  110. ])
  111. ->group('apply_id,apply_name')
  112. ->column('COUNT(id) 当日下单数量,SUM(total_price) 金额,apply_name 创建人', 'apply_id');
  113. $rs_3 = Db::name('order_out')
  114. ->alias('oo')
  115. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  116. ->where([
  117. ['oo.status', '=', 3],
  118. ['oo.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  119. ])
  120. ->group('oo.apply_id,oo.apply_name')
  121. ->column('COUNT(oo.id) 当日签收数量,SUM(s.total_price) 金额,oo.apply_name 创建人', 'oo.apply_id');
  122. $rs_4 = Db::name('order_return')
  123. ->alias('or')
  124. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  125. ->where([
  126. ['or.is_del', '=', 0],
  127. ['or.addtime', 'between', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59']],
  128. ])
  129. ->group('or.apply_id,or.apply_name')
  130. ->column('COUNT(or.id) 单日售后单数,SUM(s.total_price) 金额,or.apply_name 创建人', 'or.apply_id');
  131. $all_ids = array_unique(array_merge(array_keys($rs_1), array_keys($rs_2), array_keys($rs_3), array_keys($rs_4)));
  132. $all_company = get_company_name_by_uid($all_ids);//获取创建人的所属部门
  133. $list = [];
  134. foreach ($all_ids as $id) {
  135. $val = [];
  136. if (isset($rs_1[$id]['创建人'])) $val['创建人'] = $rs_1[$id]['创建人'];
  137. elseif (isset($rs_2[$id]['创建人'])) $val['创建人'] = $rs_2[$id]['创建人'];
  138. elseif (isset($rs_3[$id]['创建人'])) $val['创建人'] = $rs_3[$id]['创建人'];
  139. elseif (isset($rs_4[$id]['创建人'])) $val['创建人'] = $rs_4[$id]['创建人'];
  140. else $val['创建人'] = '';
  141. $val['创建人部门'] = $all_company[$id] ?? '';
  142. $val['当日咨询单数量'] = isset($rs_1[$id]['当日咨询单数量']) ? $rs_1[$id]['当日咨询单数量'] : '';
  143. $val['当日咨询单金额'] = isset($rs_1[$id]['金额']) ? $rs_1[$id]['金额'] : '';
  144. $val['当日下单数量'] = isset($rs_2[$id]['当日下单数量']) ? $rs_2[$id]['当日下单数量'] : '';
  145. $val['当日下单金额'] = isset($rs_2[$id]['金额']) ? $rs_2[$id]['金额'] : '';
  146. $val['当日签收数量'] = isset($rs_3[$id]['当日签收数量']) ? $rs_3[$id]['当日签收数量'] : '';
  147. $val['当日签收金额'] = isset($rs_3[$id]['金额']) ? $rs_3[$id]['金额'] : '';
  148. $val['当日申报发票数量'] = '';
  149. $val['当日申报发票金额'] = '';
  150. $val['单日售后单数'] = isset($rs_4[$id]['单日售后单数']) ? $rs_4[$id]['单日售后单数'] : '';
  151. $val['单日售后金额'] = isset($rs_4[$id]['金额']) ? $rs_4[$id]['金额'] : '';
  152. $val['当日回款单数'] = '';
  153. $val['当日回款金额'] = '';
  154. $list[] = $val;
  155. }
  156. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  157. excelSave('咨询单报表' . date('YmdHis'), array_keys($list[0]), $list);
  158. }
  159. //【一、管理报表】2.竞价反馈报表
  160. public function consultInfo()
  161. {
  162. $param = $this->request->only([
  163. 'token',
  164. 'start_date' => '',
  165. 'end_date' => '',
  166. 'page' => 1,
  167. 'size' => 15,
  168. ], 'post', 'trim');
  169. $where = [['ci.is_del', '=', 0]];
  170. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  171. $count = Db::name('consult_info')
  172. ->alias('ci')
  173. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  174. ->leftJoin('unit u', 'u.id=ci.unit')
  175. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  176. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  177. ->where($where)
  178. ->order('ci.addtime', 'desc')
  179. ->count('ci.id');
  180. $data = Db::name('consult_info')
  181. ->alias('ci')
  182. ->field('co.creater,ci.addtime,ci.infoNo,cb.bidNo,"" companyName,ci.good_name,ci.num,u.unit,ci.budget_price,cb.id bid_id,ci.status,0 itemid,co.createrid,co.khNo')
  183. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  184. ->leftJoin('unit u', 'u.id=ci.unit')
  185. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  186. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  187. ->where($where)
  188. ->page($param['page'], $param['size'])
  189. ->order('ci.addtime', 'desc')
  190. ->cursor();
  191. $userCommon = \app\admin\common\User::getIns();
  192. $list = $customer_tmp = $company_tmp = $customer2_tmp = [];
  193. foreach ($data as $value) {
  194. $value['total_fee'] = round($value['budget_price'] * $value['num'], 2);
  195. $value['is_bids'] = is_null($value['bid_id']) ? '否' : '是';
  196. $value['is_zhuandan'] = $value['status'] == 5 ? '是' : '否';//5成功转单
  197. if (!isset($customer2_tmp[$value['khNo']])) {
  198. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
  199. $customer2_tmp[$value['khNo']] = [
  200. 'itemid' => $temp['data']['itemid'],
  201. 'companyName' => $temp['data']['companyName'],
  202. ];
  203. }
  204. $value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
  205. $value['companyName'] = $customer2_tmp[$value['khNo']]['companyName'];
  206. if (!empty($value['itemid'])) {
  207. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  208. $value['first_customer_org'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  209. $value['second_customer_org'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  210. }
  211. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = $value['createrid'];//get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  212. // $value['creater_company'] = $company_tmp[$value['createrid']] ?? '';
  213. $list[] = $value;
  214. }
  215. $all_company = get_company_name_by_uid(array_values($company_tmp));
  216. foreach ($list as &$val) {
  217. $val['creater_company'] = $all_company[$val['createrid']] ?? '';
  218. }
  219. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  220. }
  221. //【一、管理报表】2.竞价反馈报表_导出
  222. public function consultInfoExport()
  223. {
  224. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  225. $where = [['ci.is_del', '=', 0]];
  226. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  227. $data = Db::name('consult_info')
  228. ->alias('ci')
  229. ->field('co.creater 创建人,"" 创建人部门,ci.addtime 竞价时间,ci.infoNo 竞价单号,cb.bidNo 反馈编号,"" 一级企业,"" 二级企业,"" 客户名称,ci.good_name 产品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,cb.id 是否采反,ci.status 是否转单,co.createrid,co.khNo')
  230. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  231. ->leftJoin('unit u', 'u.id=ci.unit')
  232. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  233. ->where($where)
  234. ->order('ci.addtime', 'desc')
  235. ->cursor();
  236. $userCommon = \app\admin\common\User::getIns();
  237. $list = $customer_tmp = $company_tmp = $customer2_tmp = [];
  238. foreach ($data as $value) {
  239. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = $value['createrid'];//get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  240. // $value['创建人部门'] = $company_tmp[$value['createrid']] ?? '';
  241. $value['金额'] = round($value['单价'] * $value['数量'], 2);
  242. $value['是否采反'] = is_null($value['是否采反']) ? '否' : '是';
  243. $value['是否转单'] = $value['是否转单'] == 5 ? '是' : '否';//5成功转单
  244. if (!isset($customer2_tmp[$value['khNo']])) {
  245. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
  246. $customer2_tmp[$value['khNo']] = [
  247. 'itemid' => $temp['data']['itemid'],
  248. 'companyName' => $temp['data']['companyName'],
  249. ];
  250. }
  251. $value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
  252. $value['客户名称'] = $customer2_tmp[$value['khNo']]['companyName'];
  253. if (!empty($value['itemid'])) {
  254. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  255. $value['一级企业'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  256. $value['二级企业'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  257. }
  258. // unset($value['createrid']);
  259. unset($value['itemid']);
  260. unset($value['khNo']);
  261. $list[] = $value;
  262. }
  263. $all_company = get_company_name_by_uid(array_values($company_tmp));
  264. foreach ($list as &$val) {
  265. $val['创建人部门'] = $all_company[$val['createrid']] ?? '';
  266. unset($val['createrid']);
  267. }
  268. unset($customer_tmp);
  269. unset($company_tmp);
  270. unset($customer2_tmp);
  271. unset($all_company);
  272. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  273. excelSave('竞价反馈报表' . date('YmdHis'), array_keys($list[0]), $list);
  274. }
  275. //【一、管理报表】2.1.竞价单报表
  276. public function consultInfoNew()
  277. {
  278. $param = $this->request->only([
  279. 'token',
  280. 'start_date' => '',
  281. 'end_date' => '',
  282. 'page' => 1,
  283. 'size' => 15,
  284. ], 'post', 'trim');
  285. $where = [['ci.is_del', '=', 0]];
  286. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  287. $count = Db::name('consult_info')
  288. ->alias('ci')
  289. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  290. ->leftJoin('unit u', 'u.id=ci.unit')
  291. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  292. ->where($where)
  293. ->order('ci.addtime', 'desc')
  294. ->count('ci.id');
  295. $data = Db::name('consult_info')
  296. ->alias('ci')
  297. ->field('co.creater,ci.addtime,ci.infoNo,"" companyName,ci.good_name,ci.num,u.unit,ci.budget_price,ci.status,0 itemid,co.createrid,co.khNo')
  298. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  299. ->leftJoin('unit u', 'u.id=ci.unit')
  300. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  301. ->where($where)
  302. ->page($param['page'], $param['size'])
  303. ->order('ci.addtime', 'desc')
  304. ->cursor();
  305. $userCommon = \app\admin\common\User::getIns();
  306. $list = $customer_tmp = $company_tmp = $customer2_tmp = [];
  307. foreach ($data as $value) {
  308. $value['total_fee'] = round($value['budget_price'] * $value['num'], 2);
  309. $value['is_zhuandan'] = $value['status'] == 5 ? '是' : '否';//5成功转单
  310. if (!isset($customer2_tmp[$value['khNo']])) {
  311. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
  312. $customer2_tmp[$value['khNo']] = [
  313. 'itemid' => $temp['data']['itemid'],
  314. 'companyName' => $temp['data']['companyName'],
  315. ];
  316. }
  317. $value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
  318. $value['companyName'] = $customer2_tmp[$value['khNo']]['companyName'];
  319. if (!empty($value['itemid'])) {
  320. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  321. $value['first_customer_org'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  322. $value['second_customer_org'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  323. }
  324. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = $value['createrid'];//get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  325. // $value['creater_company'] = $company_tmp[$value['createrid']] ?? '';
  326. $list[] = $value;
  327. }
  328. $all_company = get_company_name_by_uid(array_values($company_tmp));
  329. foreach ($list as &$val) {
  330. $val['creater_company'] = $all_company[$val['createrid']] ?? '';
  331. // unset($val['createrid']);
  332. }
  333. unset($customer_tmp);
  334. unset($company_tmp);
  335. unset($customer2_tmp);
  336. unset($all_company);
  337. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  338. }
  339. //【一、管理报表】2.1.竞价单报表_导出
  340. public function consultInfoNewExport()
  341. {
  342. $param = $this->request->only([
  343. 'token',
  344. 'start_date' => '',
  345. 'end_date' => '',
  346. ], 'post', 'trim');
  347. $where = [['ci.is_del', '=', 0]];
  348. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  349. $data = Db::name('consult_info')
  350. ->alias('ci')
  351. ->field('co.creater 创建人,"" 创建人部门,ci.addtime 竞价时间,ci.infoNo 竞价单号,"" 一级企业,"" 二级企业,"" 客户名称,ci.good_name 产品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,ci.status 是否转单,co.createrid,co.khNo')
  352. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  353. ->leftJoin('unit u', 'u.id=ci.unit')
  354. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  355. ->where($where)
  356. ->order('ci.addtime', 'desc')
  357. ->cursor();
  358. $userCommon = \app\admin\common\User::getIns();
  359. $list = $customer_tmp = $company_tmp = $customer2_tmp = [];
  360. foreach ($data as $value) {
  361. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = $value['createrid'];//get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  362. // $value['创建人部门'] = $company_tmp[$value['createrid']] ?? '';
  363. $value['金额'] = round($value['单价'] * $value['数量'], 2);
  364. $value['是否转单'] = $value['是否转单'] == 5 ? '是' : '否';//5成功转单
  365. if (!isset($customer2_tmp[$value['khNo']])) {
  366. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
  367. $customer2_tmp[$value['khNo']] = [
  368. 'itemid' => $temp['data']['itemid'],
  369. 'companyName' => $temp['data']['companyName'],
  370. ];
  371. }
  372. $value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
  373. $value['客户名称'] = $customer2_tmp[$value['khNo']]['companyName'];
  374. if (!empty($value['itemid'])) {
  375. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  376. $value['一级企业'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  377. $value['二级企业'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  378. }
  379. // unset($value['createrid']);
  380. unset($value['itemid']);
  381. unset($value['khNo']);
  382. $list[] = $value;
  383. }
  384. $all_company = get_company_name_by_uid(array_values($company_tmp));
  385. foreach ($list as &$val) {
  386. $val['创建人部门'] = $all_company[$val['createrid']] ?? '';
  387. unset($val['createrid']);
  388. }
  389. unset($customer_tmp);
  390. unset($company_tmp);
  391. unset($customer2_tmp);
  392. unset($all_company);
  393. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  394. excelSave('竞价单报表' . date('YmdHis'), array_keys($list[0]), $list);
  395. }
  396. //【一、管理报表】3.订单报表
  397. public function saleList()
  398. {
  399. $param = $this->request->only(['token','depart_id'=>'', 'plat_type'=>'', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  400. $where = [['s.is_del', '=', 0]];
  401. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  402. if ($param['depart_id'] != ''){
  403. $uidArr = get_company_item_user_by_name('',$param['depart_id']);
  404. $where[] = ['a.apply_id', 'in',$uidArr];
  405. }
  406. if ($param['plat_type'] !== ''){
  407. $plat =Db::name('platform')->where(['use_type'=>$param['plat_type'],'is_del'=>0])->column('id');
  408. $where[] = ['a.platform_id', 'in',$plat];
  409. }
  410. $count = Db::name('sale')
  411. ->alias('s')
  412. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  413. ->where($where)
  414. ->count('s.id');
  415. $data = Db::name('sale')
  416. ->alias('s')
  417. ->field('s.apply_name,s.addtime,s.orderCode,"" companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.is_stock,s.order_type,s.good_code,s.apply_id,s.cat_id,s.customer_code')
  418. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  419. ->where($where)
  420. ->page($param['page'], $param['size'])
  421. ->order('s.addtime', 'desc')
  422. ->cursor();
  423. $userCommon = \app\admin\common\User::getIns();
  424. $list = $cat_tmp = $customer2_tmp = $company_tmp = [];
  425. foreach ($data as $value) {
  426. if (!isset($customer2_tmp[$value['customer_code']])) {
  427. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  428. $customer2_tmp[$value['customer_code']] = [
  429. 'itemid' => $temp['data']['itemid'],
  430. 'companyName' => $temp['data']['companyName'],
  431. ];
  432. }
  433. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  434. $value['companyName'] = $customer2_tmp[$value['customer_code']]['companyName'];
  435. if (!empty($value['itemid'])) {
  436. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  437. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  438. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  439. }
  440. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['unit'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  441. else $value['unit'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  442. $value['is_stock'] = isset($this->all_stock[$value['is_stock']]) ? $this->all_stock[$value['is_stock']] : '';
  443. $value['order_type'] = isset($this->all_order_type[$value['order_type']]) ? $this->all_order_type[$value['order_type']] : '';
  444. if (!isset($company_tmp[$value['apply_id']])) $company_tmp[$value['apply_id']] = $value['apply_id'];
  445. // $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  446. if (!isset($cat_tmp[$value['cat_id']])) $cat_tmp[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
  447. $value['cat_name'] = $cat_tmp[$value['cat_id']] ?? '';
  448. $list[] = $value;
  449. }
  450. $all_company = get_company_name_by_uid(array_values($company_tmp));
  451. foreach ($list as &$val) {
  452. $val['creater_company'] = $all_company[$val['apply_id']] ?? '';
  453. }
  454. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  455. }
  456. //【一、管理报表】3.订单报表_导出
  457. public function saleExport()
  458. {
  459. $param = $this->request->only(['token',"depart_id"=>"", "plat_type"=>"",'start_date' => '', 'end_date' => ''], 'post', 'trim');
  460. $where = [['s.is_del', '=', 0]];
  461. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  462. if ($param['depart_id'] != ''){
  463. $uidArr = get_company_item_user_by_name('',$param['depart_id']);
  464. $where[] = ['a.apply_id', 'in',$uidArr];
  465. }
  466. if ($param['plat_type'] !== ''){
  467. $plat =Db::name("platform")->where(["use_type"=>$param['plat_type'],"is_del"=>0])->column("id");
  468. $where[] = ['a.platform_id', 'in',$plat];
  469. }
  470. $data = Db::name('sale')
  471. ->alias('s')
  472. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,"" 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,s.is_stock 是否库存,s.order_type 订单类型,s.good_code,s.apply_id,s.cat_id,s.customer_code')
  473. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  474. ->where($where)
  475. ->order('s.addtime', 'desc')
  476. ->cursor();
  477. $userCommon = \app\admin\common\User::getIns();
  478. $list = $tmp_customer = $tmp_item = $cat_tmp = $customer2_tmp = [];
  479. foreach ($data as $value) {
  480. if (!isset($customer2_tmp[$value['customer_code']])) {
  481. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  482. $customer2_tmp[$value['customer_code']] = [
  483. 'itemid' => $temp['data']['itemid'],
  484. 'companyName' => $temp['data']['companyName'],
  485. ];
  486. }
  487. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  488. $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
  489. if (!empty($value['itemid'])) {
  490. if (!isset($tmp_customer[$value['itemid']])) $tmp_customer[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  491. // $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  492. $value['一级企业'] = isset($tmp_customer[$value['itemid']][1]) ? $tmp_customer[$value['itemid']][1] : '';
  493. $value['二级企业'] = isset($tmp_customer[$value['itemid']][2]) ? $tmp_customer[$value['itemid']][2] : '';
  494. }
  495. if ($value['订单类型'] == 3 || $value['订单类型'] == 4) {
  496. $value['单位'] = Db::name("good_zixun")
  497. ->alias('gz')
  498. ->leftJoin('unit u', 'u.id=gz.good_unit')
  499. ->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])
  500. ->value('u.unit');
  501. } else {
  502. $value['单位'] = Db::name('good_basic')
  503. ->alias('gb')
  504. ->leftJoin('unit u', 'u.id=gb.good_unit')
  505. ->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])
  506. ->value('u.unit');
  507. }
  508. $value['是否库存'] = isset($this->all_stock[$value['是否库存']]) ? $this->all_stock[$value['是否库存']] : '';
  509. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  510. if (!isset($tmp_item[$value['apply_id']])) $tmp_item[$value['apply_id']] = $value['apply_id'];//get_company_name_by_uid($value['apply_id']);
  511. // $value['创建人所属部门'] = $tmp_item[$value['apply_id']];//获取创建人的所属部门
  512. if (!isset($cat_tmp[$value['cat_id']])) $cat_tmp[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
  513. $value['分类'] = $cat_tmp[$value['cat_id']] ?? '';
  514. unset($value['itemid']);
  515. // unset($value['apply_id']);
  516. unset($value['good_code']);
  517. unset($value['cat_id']);
  518. unset($value['customer_code']);
  519. $list[] = $value;
  520. }
  521. $all_company = get_company_name_by_uid(array_values($tmp_item));
  522. foreach ($list as &$val) {
  523. $val['创建人所属部门'] = $all_company[$val['apply_id']] ?? '';
  524. unset($val['apply_id']);
  525. }
  526. unset($tmp_customer);
  527. unset($tmp_item);
  528. unset($cat_tmp);
  529. unset($customer2_tmp);
  530. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  531. excelSave('订单报表' . date('YmdHis'), array_keys($list[0]), $list);
  532. }
  533. //【一、管理报表】4.未发货报表_列表
  534. public function saleNotOut()
  535. {
  536. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_arrive_date' => '', 'end_arrive_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  537. $where = [['s.is_del', '=', 0], ['out.status', '=', 1]];
  538. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  539. if ($param['start_arrive_date'] != '' && $param['end_arrive_date'] != '') $where[] = ['s.arrive_time', 'between', [$param['start_arrive_date'] . ' 00:00:00', $param['end_arrive_date'] . ' 23:59:59']];
  540. $count = Db::name('sale')
  541. ->alias('s')
  542. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  543. ->where($where)
  544. ->order('s.addtime', 'desc')
  545. ->count('s.id');
  546. $data = Db::name('sale')
  547. ->alias('s')
  548. ->field('s.apply_name,s.addtime,s.orderCode,"" companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.arrive_time,s.good_code,s.skuCode,s.is_stock,s.order_type,s.apply_id,s.customer_code')
  549. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  550. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  551. ->where($where)
  552. ->page($param['page'], $param['size'])
  553. ->order('s.addtime', 'desc')
  554. ->cursor();
  555. $userCommon = \app\admin\common\User::getIns();
  556. $list = $customer2_tmp = $company_tmp = [];
  557. foreach ($data as $value) {
  558. if (!isset($customer2_tmp[$value['customer_code']])) {
  559. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  560. $customer2_tmp[$value['customer_code']] = [
  561. 'itemid' => $temp['data']['itemid']??"",
  562. 'companyName' => $temp['data']['companyName'],
  563. ];
  564. }
  565. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  566. $value['companyName'] = $customer2_tmp[$value['customer_code']]['companyName'];
  567. if (!empty($value['itemid'])) {
  568. $customer_org1 = array_column(get_top_customer_org($value['itemid'])??[], 'name', 'level');
  569. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  570. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  571. }
  572. if ($value['order_type'] == 3 || $value['order_type'] == 4) {
  573. $value['unit'] = Db::name("good_zixun")
  574. ->alias('gz')
  575. ->leftJoin('unit u', 'u.id=gz.good_unit')
  576. ->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])
  577. ->value('u.unit');
  578. } else {
  579. $value['unit'] = Db::name('good_basic')
  580. ->alias('gb')
  581. ->leftJoin('unit u', 'u.id=gb.good_unit')
  582. ->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])
  583. ->value('u.unit');
  584. }
  585. if (!isset($company_tmp[$value['apply_id']])) $company_tmp[$value['apply_id']] = $value['apply_id'];
  586. // $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  587. $list[] = $value;
  588. }
  589. $all_company = get_company_name_by_uid(array_values($company_tmp));
  590. foreach ($list as &$val) {
  591. $val['creater_company'] = $all_company[$val['apply_id']] ?? '';
  592. // unset($val['createrid']);
  593. }
  594. unset($customer2_tmp);
  595. unset($company_tmp);
  596. return app_show(0, '请求成功', ['count' => $count, 'list' => $list]);
  597. }
  598. //【一、管理报表】4.未发货报表_导出
  599. public function saleNotOutExport()
  600. {
  601. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_arrive_date' => '', 'end_arrive_date' => ''], 'post', 'trim');
  602. $where = [['s.is_del', '=', 0], ['out.status', '=', 1]];
  603. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  604. if ($param['start_arrive_date'] != '' && $param['end_arrive_date'] != '') $where[] = ['s.arrive_time', 'between', [$param['start_arrive_date'] . ' 00:00:00', $param['end_arrive_date'] . ' 23:59:59']];
  605. $data = Db::name('sale')
  606. ->alias('s')
  607. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,"" 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,s.arrive_time 承诺发货时间,s.good_code,s.skuCode,s.is_stock,s.order_type,s.apply_id,s.customer_code')
  608. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  609. ->where($where)
  610. ->order('s.addtime', 'desc')
  611. ->cursor();
  612. $userCommon = \app\admin\common\User::getIns();
  613. $list = $customer2_tmp = $company_tmp =$depart= [];
  614. foreach ($data as $value) {
  615. if (!isset($customer2_tmp[$value['customer_code']])) {
  616. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  617. $customer2_tmp[$value['customer_code']] = [
  618. 'itemid' => $temp['data']['itemid']??"",
  619. 'companyName' => $temp['data']['companyName'],
  620. ];
  621. }
  622. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  623. $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
  624. if (!empty($value['itemid'])) {
  625. $customer_org1 = array_column(get_top_customer_org($value['itemid'])??[], 'name', 'level');
  626. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  627. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  628. }
  629. if (!isset($depart[$value['apply_id']])) {
  630. $depart[$value['apply_id']] =get_company_name_by_uid($value['apply_id']);
  631. }
  632. $value['创建人所属部门'] = $depart[$value['apply_id']] ?? '';
  633. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['单位'] = Db::name("good_zixun")->alias('gz')
  634. ->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  635. else $value['单位'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  636. if (!isset($company_tmp[$value['apply_id']])) $company_tmp[$value['apply_id']] = $value['apply_id'];
  637. $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  638. unset($value['itemid']);
  639. unset($value['good_code']);
  640. unset($value['order_type']);
  641. unset($value['apply_id']);
  642. unset($value['customer_code']);
  643. $list[] = $value;
  644. }
  645. unset($customer2_tmp);
  646. unset($company_tmp);
  647. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  648. excelSave('未发货报表' . date('YmdHis'), array_keys($list[0]), $list);
  649. }
  650. //【一、管理报表】5.未签收报表
  651. public function saleNotSigned()
  652. {
  653. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  654. $where = [['oo.is_del', '=', 0], ['oo.status', '=', 2], ['s.is_del', '=', 0]];
  655. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  656. $count = Db::name('order_out')
  657. ->alias('oo')
  658. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  659. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  660. // ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  661. ->where($where)
  662. ->count('oo.id');
  663. $data = Db::name('order_out')
  664. ->alias('oo')
  665. ->field('oo.id,s.apply_name,s.addtime,s.orderCode,"" companyName,s.good_name,s.good_num,s.sale_price,s.total_price,oo.sendtime,s.good_code,s.order_type,s.apply_id,s.customer_code')
  666. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  667. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  668. // ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  669. ->where($where)
  670. ->page($param['page'], $param['size'])
  671. ->order('s.addtime', 'desc')
  672. ->cursor();
  673. $userCommon = \app\admin\common\User::getIns();
  674. $list = $customer2_tmp = $uid_tmp = [];
  675. foreach ($data as $value) {
  676. if (!isset($customer2_tmp[$value['customer_code']])) {
  677. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  678. $customer2_tmp[$value['customer_code']] = [
  679. 'itemid' => $temp['data']['itemid'],
  680. 'companyName' => $temp['data']['companyName'],
  681. ];
  682. }
  683. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  684. $value['companyName'] = $customer2_tmp[$value['customer_code']]['companyName'];
  685. if (!empty($value['itemid'])) {
  686. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  687. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  688. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  689. }
  690. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['unit'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u',
  691. 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  692. else $value['unit'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  693. if (!isset($uid_tmp[$value['apply_id']])) $uid_tmp[$value['apply_id']] = $value['apply_id'];//get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  694. // $value['creater_company'] = $uid_tmp[$value['apply_id']];
  695. $list[] = $value;
  696. }
  697. $all_company = get_company_name_by_uid(array_values($uid_tmp));
  698. foreach ($list as &$val) {
  699. $val['creater_company'] = $all_company[$val['apply_id']] ?? '';
  700. // unset($val['apply_id']);
  701. }
  702. unset($customer2_tmp);
  703. unset($uid_tmp);
  704. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  705. }
  706. //【一、管理报表】5.未签收报表_导出
  707. public function saleNotSignedExport()
  708. {
  709. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  710. $where = [['s.is_del', '=', 0], ['oo.status', '=', 2]];
  711. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  712. // $data = Db::name('order_out')
  713. // ->alias('oo')
  714. // ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,oo.sendtime 发货时间,csi.itemid,s.good_code,s.order_type,s.apply_id')
  715. // ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  716. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  717. // ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  718. // ->where($where)
  719. // ->order('s.addtime', 'desc')
  720. // ->cursor('oo.id');
  721. // $list = [];
  722. // foreach ($data as $value) {
  723. //
  724. // if (!empty($value['itemid'])) {
  725. // $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  726. // $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  727. // $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  728. // }
  729. //
  730. // if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['单位'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  731. // else $value['单位'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  732. //
  733. // $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  734. //
  735. // unset($value['itemid']);
  736. // unset($value['good_code']);
  737. // unset($value['order_type']);
  738. // unset($value['apply_id']);
  739. //
  740. // $list[] = $value;
  741. // }
  742. $list = $this->saleNotSignedExportTemp($where);
  743. excelSave('未签收报表' . date('YmdHis'), ['创建人', '创建人所属部门', '下单时间', '订单号', '一级企业', '二级企业', '客户名称', '商品名称', '数量', '单位', '单价', '金额', '发货时间'], $list);
  744. }
  745. //针对"【一、管理报表】5.未签收报表_导出"数据量太大
  746. private function saleNotSignedExportTemp(array $where = [])
  747. {
  748. $data = Db::name('order_out')
  749. ->alias('oo')
  750. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,"" 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,oo.sendtime 发货时间,s.good_code,s.order_type,s.apply_id,s.customer_code')
  751. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  752. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  753. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  754. ->where($where)
  755. ->order('s.addtime', 'desc')
  756. ->cursor();
  757. $userCommon = \app\admin\common\User::getIns();
  758. $customer2_tmp = $uid_tmp = [];
  759. foreach ($data as $value) {
  760. if (!isset($customer2_tmp[$value['customer_code']])) {
  761. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  762. $customer2_tmp[$value['customer_code']] = [
  763. 'itemid' => $temp['data']['itemid'],
  764. 'companyName' => $temp['data']['companyName'],
  765. ];
  766. }
  767. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  768. $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
  769. if (!empty($value['itemid'])) {
  770. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  771. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  772. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  773. }
  774. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['单位'] = Db::name("good_zixun")->alias('gz')
  775. ->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  776. else $value['单位'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  777. if (!isset($uid_tmp[$value['apply_id']])) $uid_tmp[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  778. $value['创建人所属部门'] = $uid_tmp[$value['apply_id']];
  779. unset($value['itemid']);
  780. unset($value['good_code']);
  781. unset($value['order_type']);
  782. unset($value['apply_id']);
  783. unset($value['customer_code']);
  784. yield $value;
  785. }
  786. }
  787. //【一、管理报表】6.售后报表
  788. public function orderReturn()
  789. {
  790. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  791. $where = [['or.is_del', '=', 0]];
  792. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  793. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  794. $count = Db::name('order_return')
  795. ->alias('or')
  796. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  797. // ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  798. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  799. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  800. ->where($where)
  801. ->count('or.id');
  802. $data = Db::name('order_return')
  803. ->alias('or')
  804. ->field('or.addtime,or.apply_name,or.orderCode,"" companyName,or.good_name,or.total_num,s.sale_price,s.total_price,or.updatetime,ri.result,or.status,or.good_code,or.order_type,or.apply_id,or.customer_code')
  805. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  806. // ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  807. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  808. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  809. ->where($where)
  810. ->page($param['page'], $param['size'])
  811. ->order('s.addtime', 'desc')
  812. ->cursor();
  813. $userCommon = \app\admin\common\User::getIns();
  814. $list = $customer2_tmp = $company_tmp = [];
  815. foreach ($data as $value) {
  816. if (!isset($customer2_tmp[$value['customer_code']])) {
  817. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  818. $customer2_tmp[$value['customer_code']] = [
  819. 'itemid' => $temp['data']['itemid'],
  820. 'companyName' => $temp['data']['companyName'],
  821. ];
  822. }
  823. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  824. $value['companyName'] = $customer2_tmp[$value['customer_code']]['companyName'];
  825. if (!empty($value['itemid'])) {
  826. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  827. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  828. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  829. }
  830. if (!isset($company_tmp[$value['apply_id']])) $company_tmp[$value['apply_id']] = $value['apply_id'];
  831. // $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  832. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['unit'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  833. else $value['unit'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  834. $value['is_finish'] = $value['status'] == 5 ? '已完结' : '未完结';
  835. $value['status'] = isset($this->all_order_return_status[$value['status']]) ? $this->all_order_return_status[$value['status']] : '';
  836. $list[] = $value;
  837. }
  838. $all_company = get_company_name_by_uid(array_values($company_tmp));
  839. foreach ($list as &$val) {
  840. $val['creater_company'] = $all_company[$val['apply_id']] ?? '';
  841. unset($val['apply_id']);
  842. }
  843. unset($customer2_tmp);
  844. unset($company_tmp);
  845. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  846. }
  847. //【一、管理报表】6.售后报表_导出
  848. public function orderReturnExport()
  849. {
  850. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => ''], 'post', 'trim');
  851. $where = [['or.is_del', '=', 0]];
  852. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  853. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  854. $data = Db::name('order_return')
  855. ->alias('or')
  856. ->field('or.addtime 售后时间,or.apply_name 创建人,"" 创建人部门,or.orderCode 订单号,"" 一级企业,"" 二级企业,"" 客户名称,or.good_name 商品名称,or.total_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,or.updatetime 签收时间,ri.result 异常原因,or.status 异常状态,"" 是否完结,or.good_code,or.order_type,or.apply_id,or.customer_code')
  857. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  858. // ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  859. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  860. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  861. ->where($where)
  862. ->order('s.addtime', 'desc')
  863. ->cursor();
  864. $userCommon = \app\admin\common\User::getIns();
  865. $list = $customer2_tmp = $company_tmp = [];
  866. foreach ($data as $value) {
  867. if (!isset($customer2_tmp[$value['customer_code']])) {
  868. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  869. $customer2_tmp[$value['customer_code']] = [
  870. 'itemid' => $temp['data']['itemid'],
  871. 'companyName' => $temp['data']['companyName'],
  872. ];
  873. }
  874. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  875. $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
  876. if (!empty($value['itemid'])) {
  877. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  878. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  879. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  880. }
  881. if ($value['order_type'] == 3 || $value['order_type'] == 4) $value['单位'] = Db::name("good_zixun")->alias('gz')->leftJoin('unit u', 'u.id=gz.good_unit')->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])->value('u.unit');
  882. else $value['单位'] = Db::name('good_basic')->alias('gb')->leftJoin('unit u', 'u.id=gb.good_unit')->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])->value('u.unit');
  883. if (!isset($company_tmp[$value['apply_id']])) $company_tmp[$value['apply_id']] = $value['apply_id'];
  884. // $value['创建人部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  885. $value['是否完结'] = $value['异常状态'] == 5 ? '已完结' : '未完结';
  886. $value['异常状态'] = isset($this->all_order_return_status[$value['异常状态']]) ? $this->all_order_return_status[$value['异常状态']] : '';
  887. unset($value['itemid']);
  888. unset($value['good_code']);
  889. unset($value['order_type']);
  890. // unset($value['apply_id']);
  891. unset($value['customer_code']);
  892. $list[] = $value;
  893. }
  894. $all_company = get_company_name_by_uid(array_values($company_tmp));
  895. foreach ($list as &$val) {
  896. $val['创建人部门'] = $all_company[$val['apply_id']] ?? '';
  897. unset($val['apply_id']);
  898. }
  899. unset($customer2_tmp);
  900. unset($company_tmp);
  901. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  902. excelSave('售后报表' . date('YmdHis'), array_keys($list[0]), $list);
  903. }
  904. //【一、管理报表】7.产品热销排行
  905. public function goodRankingList()
  906. {
  907. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  908. $where = [['s.is_del', '=', 0]];
  909. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  910. $count = Db::name('sale')
  911. ->alias('s')
  912. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  913. ->where($where)
  914. ->group('s.good_code')
  915. ->count('s.id');
  916. $data = Db::name('sale')
  917. ->alias('s')
  918. // ->field('s.good_code,s.good_name,SUM(s.good_num) total_num,SUM(s.total_price) total_price,s.cat_id,s.customer_code')
  919. ->field('s.good_code,SUM(s.good_num) total_num,SUM(s.total_price) total_price')
  920. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  921. ->where($where)
  922. ->group('s.good_code')//存疑,此处原本是根据csi.itemid分组的
  923. ->page($param['page'], $param['size'])
  924. ->order('total_num', 'desc')
  925. ->select()
  926. ->toArray();
  927. $replenish = Db::name('sale')
  928. ->where(['is_del' => 0, 'good_code' => array_unique(array_column($data, 'good_code'))])
  929. ->column('good_name,cat_id,customer_code', 'good_code');
  930. $userCommon = \app\admin\common\User::getIns();
  931. $list = $customer2_tmp = [];
  932. foreach ($data as $value) {
  933. $value['good_name'] = $replenish[$value['good_code']]['good_name'] ?? '';
  934. $value['cat_id'] = $replenish[$value['good_code']]['cat_id'] ?? '';
  935. $value['customer_code'] = $replenish[$value['good_code']]['customer_code'] ?? '';
  936. if (!isset($customer2_tmp[$value['customer_code']])) {
  937. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  938. $customer2_tmp[$value['customer_code']] = [
  939. 'itemid' => $temp['data']['itemid'],
  940. 'companyName' => $temp['data']['companyName'],
  941. ];
  942. }
  943. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  944. // $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
  945. if (!empty($value['itemid'])) {
  946. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  947. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  948. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  949. }
  950. $value['cat'] = implode('/', array_column(made($value['cat_id']), 'name'));
  951. $list[] = $value;
  952. }
  953. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  954. }
  955. //【一、管理报表】7.产品热销排行_导出
  956. public function goodRankingListExport()
  957. {
  958. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  959. $where = [['s.is_del', '=', 0]];
  960. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  961. $data = Db::name('sale')
  962. ->alias('s')
  963. ->field('s.good_code,"" 产品品类,"" 产品名称,SUM(s.good_num) total_num,"" 数量,SUM(s.total_price) 金额,0 cat_id,"" customer_code,"" 一级企业,"" 二级企业')
  964. ->where($where)
  965. ->group('s.good_code')//存疑,此处原本是根据csi.itemid分组的
  966. ->order('total_num', 'desc')
  967. ->cursor();
  968. $replenish = Db::name('sale')
  969. ->alias('s')
  970. ->where($where)
  971. ->column('good_name 产品名称,cat_id,customer_code', 'good_code');
  972. $userCommon = \app\admin\common\User::getIns();
  973. $list = $customer2_tmp = [];
  974. foreach ($data as $value) {
  975. // $tmp=Db::name('sale')
  976. // ->field('good_name 产品名称,cat_id,customer_code')
  977. // ->where(['is_del'=>0,'good_code'=>$value['good_code']])
  978. // ->findOrEmpty();
  979. $value = array_merge($value, $replenish[$value['good_code']]);
  980. if (!isset($customer2_tmp[$value['customer_code']])) {
  981. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  982. $customer2_tmp[$value['customer_code']] = [
  983. 'itemid' => $temp['data']['itemid'],
  984. 'companyName' => $temp['data']['companyName'],
  985. ];
  986. }
  987. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  988. // $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
  989. if (!empty($value['itemid'])) {
  990. $customer_org1 = array_column(get_top_customer_org($value['itemid']) ?? [], 'name', 'level');
  991. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  992. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  993. }
  994. $value['产品品类'] = implode('/', array_column(made($value['cat_id']), 'name'));
  995. $value['数量'] = $value['total_num'];
  996. unset($value['good_code']);
  997. unset($value['itemid']);
  998. unset($value['cat_id']);
  999. unset($value['total_num']);
  1000. unset($value['customer_code']);
  1001. $list[] = $value;
  1002. }
  1003. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1004. excelSave('产品热销排行' . date('YmdHis'), array_keys($list[0]), $list);
  1005. }
  1006. //【三、咨询单导出明细】
  1007. public function consultDetailed()
  1008. {
  1009. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  1010. $where = [['ci.is_del', '=', 0]];
  1011. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1012. if ($param['use_desc'] != '') $where[] = ['ci.use_desc', 'like', '%' . $param['use_desc'] . '%'];
  1013. $count = Db::name('consult_info')
  1014. ->alias('ci')
  1015. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
  1016. ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
  1017. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1018. ->leftJoin('brand b', 'b.id=ci.brand_id')
  1019. ->leftJoin('unit u', 'u.id=ci.unit')
  1020. ->where($where)
  1021. ->order('ci.addtime', 'desc')
  1022. ->count('ci.id');
  1023. $data = Db::name('consult_info')
  1024. ->alias('ci')
  1025. ->field('ci.addtime,co.salesman,"" name,ci.infoNo,"" companyName,ci.use_desc,ci.good_name,b.brand_name,
  1026. ci.model,s.good_code,ci.cat_id,ci.budget_price,u.unit,ci.num,s.sale_price,ci.arrival_time,ci.is_addrs,
  1027. ci.is_custom,ci.remark,ci.status,ci.bargain_code,s.orderCode,co.khNo,co.saleid')
  1028. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
  1029. ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
  1030. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1031. ->leftJoin('brand b', 'b.id=ci.brand_id')
  1032. ->leftJoin('unit u', 'u.id=ci.unit')
  1033. ->where($where)
  1034. ->page($param['page'], $param['size'])
  1035. ->order('ci.addtime', 'desc')
  1036. ->cursor();
  1037. $userCommon = \app\admin\common\User::getIns();
  1038. $list = $customer2_tmp = $tmp=[];
  1039. foreach ($data as $value) {
  1040. if (!isset($tmp[$value['saleid']])) $tmp[$value['saleid']] = get_company_name_by_uid($value['saleid']);
  1041. $value['name']=$tmp[$value['saleid']] ?? '';
  1042. if (!isset($customer2_tmp[$value['khNo']])) {
  1043. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
  1044. $customer2_tmp[$value['khNo']] = [
  1045. 'itemid' => $temp['data']['itemid'] ?? 0,
  1046. 'companyName' => $temp['data']['companyName'] ?? '',
  1047. ];
  1048. }
  1049. $value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
  1050. $value['companyName'] = $customer2_tmp[$value['khNo']]['companyName'];
  1051. if (!empty($value['itemid'])) {
  1052. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  1053. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  1054. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  1055. }
  1056. $cat = made($value['cat_id']);
  1057. $value['first_cat_name'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  1058. $value['budget_total_price'] = round($value['budget_price'] * $value['num'], 2);
  1059. $value['is_addrs'] = isset($this->is_addrs[$value['is_addrs']]) ? $this->is_addrs[$value['is_addrs']] : '';
  1060. $value['is_custom'] = isset($this->is_custom[$value['is_custom']]) ? $this->is_custom[$value['is_custom']] : '';
  1061. $value['status'] = isset($this->consult_info_status[$value['status']]) ? $this->consult_info_status[$value['status']] : '';
  1062. $list[] = $value;
  1063. }
  1064. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1065. }
  1066. //【三、咨询单导出明细】_导出
  1067. public function consultDetailedExport()
  1068. {
  1069. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => ''], 'post', 'trim');
  1070. $where = [['ci.is_del', '=', 0]];
  1071. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1072. if ($param['use_desc'] != '') $where[] = ['ci.use_desc', 'like', '%' . $param['use_desc'] . '%'];
  1073. $data = Db::name('consult_info')
  1074. ->alias('ci')
  1075. ->field('ci.addtime 咨询时间,co.salesman 业务员,"" 业务部门,cb.infoNo 咨询单号,"" 一级组织,"" 二级组织,"" 客户名称,ci.use_desc 产品用途,ci.good_name 产品名称,b.brand_name 品牌,ci.model 型号,s.good_code 产品编码,"" 一级分类,ci.cat_id,ci.budget_price 预算单价,u.unit 单位,ci.num 需求数量,"" 预算总价,s.sale_price 单价,ci.arrival_time 要求到货时间,ci.is_addrs 是否一地,ci.is_custom 定制,ci.remark 咨询备注,ci.status 竞单状态,ci.bargain_code 上次咨询单单号,s.orderCode 销售订单编号,co.khNo,co.saleid')
  1076. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
  1077. ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
  1078. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  1079. // ->leftJoin('depart_user du', 'du.uid=co.saleid AND du.is_del=0')
  1080. // ->leftJoin('company_item item', 'item.id=du.itemid')
  1081. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  1082. ->leftJoin('brand b', 'b.id=ci.brand_id')
  1083. ->leftJoin('unit u', 'u.id=ci.unit')
  1084. ->where($where)
  1085. ->order('ci.addtime', 'desc')
  1086. ->cursor();
  1087. $userCommon = \app\admin\common\User::getIns();
  1088. $list = $customer2_tmp = [];
  1089. foreach ($data as $value) {
  1090. if (!isset($tmp[$value['saleid']])) $tmp[$value['saleid']] = get_company_name_by_uid($value['saleid']);
  1091. $value['业务部门']=$tmp[$value['saleid']] ?? '';
  1092. if (!isset($customer2_tmp[$value['khNo']])) {
  1093. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
  1094. $customer2_tmp[$value['khNo']] = [
  1095. 'itemid' => $temp['data']['itemid'] ?? 0,
  1096. 'companyName' => $temp['data']['companyName'] ?? '',
  1097. ];
  1098. }
  1099. $value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
  1100. $value['客户名称'] = $customer2_tmp[$value['khNo']]['companyName'];
  1101. if (!empty($value['itemid'])) {
  1102. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  1103. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  1104. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  1105. }
  1106. $cat = made($value['cat_id']);
  1107. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  1108. $value['预算总价'] = round($value['预算单价'] * $value['需求数量'], 2);
  1109. $value['是否一地'] = isset($this->is_addrs[$value['是否一地']]) ? $this->is_addrs[$value['是否一地']] : '';
  1110. $value['定制'] = isset($this->is_custom[$value['定制']]) ? $this->is_custom[$value['定制']] : '';
  1111. $value['竞单状态'] = isset($this->consult_info_status[$value['竞单状态']]) ? $this->consult_info_status[$value['竞单状态']] : '';
  1112. unset($value['itemid']);
  1113. unset($value['cat_id']);
  1114. unset($value['khNo']);
  1115. unset($value['saleid']);
  1116. $list[] = $value;
  1117. }
  1118. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1119. excelSave('咨询单导出明细' . date('YmdHis'), array_keys($list[0]), $list);
  1120. }
  1121. //【四、工差明细表】
  1122. public function saleDiff()
  1123. {
  1124. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  1125. $where = [['pd.is_del', '=', 0]];
  1126. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['pd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1127. $count = Db::name('purchease_diff')
  1128. ->alias('pd')
  1129. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  1130. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  1131. ->leftJoin('order_num on', 'on.cgdNo=pd.cgdNo')
  1132. ->leftJoin('sale s', 's.orderCode=on.orderCode')
  1133. ->where($where)
  1134. ->order('pd.addtime', 'desc')
  1135. ->count('pd.id');
  1136. $data = Db::name('purchease_diff')
  1137. ->alias('pd')
  1138. ->field('pd.addtime,sd.diffCode,sd.orderCode,pd.apply_name,pd.apply_id,po.addtime poaddtime,pd.good_name,"" companyName,pd.good_num,pd.sale_price,pd.good_weight,pd.diff_weight,pd.diff_price,sd.status,po.order_type,po.spuCode,s.apply_name sale_apply_name,s.apply_id sale_apply_id,s.customer_code')
  1139. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  1140. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  1141. ->leftJoin('order_num on', 'on.cgdNo=pd.cgdNo')
  1142. ->leftJoin('sale s', 's.orderCode=on.orderCode')
  1143. ->where($where)
  1144. ->page($param['page'], $param['size'])
  1145. ->order('pd.addtime', 'desc')
  1146. ->cursor();
  1147. $list = $codes = $uid_tmp = [];
  1148. foreach ($data as $value) {
  1149. if (!isset($codes[$value['customer_code']])) $codes[$value['customer_code']] = $value['customer_code'];
  1150. if ($value['order_type'] == 3 || $value['order_type'] == 4) $noble_metal = Db::name("good_zixun")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->value('noble_metal');
  1151. else $noble_metal = Db::name('good_basic')->where(['spuCode' => $value['spuCode'], 'is_del' => 0])->value('noble_metal');
  1152. if (!isset($uid_tmp[$value['apply_id']])) $uid_tmp[$value['apply_id']] = $value['apply_id'];
  1153. if (!isset($uid_tmp[$value['sale_apply_id']])) $uid_tmp[$value['sale_apply_id']] = $value['sale_apply_id'];
  1154. // $value['apply_company'] = $uid_tmp[$value['apply_id']];
  1155. // $value['sale_apply_company'] = $uid_tmp[$value['sale_apply_id']];
  1156. $value['noble_metal'] = isset($this->noble_metal[$noble_metal]) ? $this->noble_metal[$noble_metal] : '';
  1157. $value['total_price'] = round($value['sale_price'], $value['good_num'], 2);
  1158. $value['is_update_sale'] = isset($this->sale_diff_status[$value['status']]) ? $this->sale_diff_status[$value['status']] : '';
  1159. $list[] = $value;
  1160. }
  1161. $userCommon = \app\admin\common\User::getIns();
  1162. $names = $userCommon->handle('getCodeAndName', ['code' => array_values($codes)]);
  1163. $all_company = get_company_name_by_uid(array_values($uid_tmp));
  1164. foreach ($list as &$val) {
  1165. $val['companyName'] = $names['data'][$val['customer_code']] ?? '';
  1166. $val['apply_company'] = $all_company[$val['apply_id']] ?? '';
  1167. $val['sale_apply_company'] = $all_company[$val['sale_apply_id']] ?? '';
  1168. }
  1169. unset($codes);
  1170. unset($uid_tmp);
  1171. unset($all_company);
  1172. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1173. }
  1174. //【四、工差明细表】_导出
  1175. public function saleDiffExport()
  1176. {
  1177. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  1178. $where = [['pd.is_del', '=', 0]];
  1179. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['pd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1180. $data = Db::name('purchease_diff')
  1181. ->alias('pd')
  1182. ->field('pd.addtime 发起时间,sd.diffCode 工差单号,sd.orderCode 关联确认单,pd.apply_name 创建人,"" 部门,pd.apply_id,po.addtime 确认单下单日期,pd.good_name 产品名称,"" 客户名称,"" 贵金属种类,pd.good_num 下单数量,pd.sale_price 单价,"" 总额,pd.good_weight 商品总重量,pd.diff_weight 工差重量,pd.diff_price 销售工差总费用,sd.status 是否修改销售额,s.apply_name 销售人员,s.apply_id sale_apply_id,"" 销售部门,po.order_type,po.spuCode,s.customer_code')
  1183. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  1184. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  1185. ->leftJoin('order_num on', 'on.cgdNo=pd.cgdNo')
  1186. ->leftJoin('sale s', 's.orderCode=on.orderCode')
  1187. // ->leftJoin('customer_info ci', 'ci.companyNo=s.customer_code')
  1188. ->where($where)
  1189. ->order('pd.addtime', 'desc')
  1190. ->cursor();
  1191. $list = $codes = $uid_tmp = [];
  1192. foreach ($data as $value) {
  1193. if (!isset($codes[$value['customer_code']])) $codes[$value['customer_code']] = $value['customer_code'];
  1194. if ($value['order_type'] == 3 || $value['order_type'] == 4) $noble_metal = Db::name("good_zixun")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->value('noble_metal');
  1195. else $noble_metal = Db::name('good_basic')->where(['spuCode' => $value['spuCode'], 'is_del' => 0])->value('noble_metal');
  1196. if (!isset($uid_tmp[$value['apply_id']])) $uid_tmp[$value['apply_id']] = $value['apply_id'];
  1197. if (!isset($uid_tmp[$value['sale_apply_id']])) $uid_tmp[$value['sale_apply_id']] = $value['sale_apply_id'];
  1198. // $value['部门'] = $uid_tmp[$value['apply_id']];
  1199. // $value['销售部门'] = $uid_tmp[$value['sale_apply_id']];
  1200. $value['贵金属种类'] = isset($this->noble_metal[$noble_metal]) ? $this->noble_metal[$noble_metal] : '';
  1201. $value['总额'] = round($value['单价'], $value['下单数量'], 2);
  1202. $value['是否修改销售额'] = isset($this->sale_diff_status[$value['是否修改销售额']]) ? $this->sale_diff_status[$value['是否修改销售额']] : '';
  1203. // unset($value['apply_id']);
  1204. unset($value['order_type']);
  1205. unset($value['spuCode']);
  1206. // unset($value['sale_apply_id']);
  1207. $list[] = $value;
  1208. }
  1209. $userCommon = \app\admin\common\User::getIns();
  1210. $names = $userCommon->handle('getCodeAndName', ['code' => array_values($codes)]);
  1211. $all_company = get_company_name_by_uid(array_values($uid_tmp));
  1212. foreach ($list as &$val) {
  1213. $val['客户名称'] = $names['data'][$val['customer_code']] ?? '';
  1214. $val['部门'] = $all_company[$val['apply_id']] ?? '';
  1215. $val['销售部门'] = $all_company[$val['sale_apply_id']] ?? '';
  1216. unset($val['customer_code']);
  1217. unset($val['apply_id']);
  1218. unset($val['sale_apply_id']);
  1219. }
  1220. unset($codes);
  1221. unset($uid_tmp);
  1222. unset($all_company);
  1223. unset($names);
  1224. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1225. excelSave('工差明细表' . date('YmdHis'), array_keys($list[0]), $list);
  1226. }
  1227. //【五、退货明细表】
  1228. public function thData()
  1229. {
  1230. $param = $this->request->only(['token', 'start_date' => '',"companyNo"=>"", 'end_date' => '', 'page' => 1, 'size'
  1231. => 15], 'post', 'trim');
  1232. $where = [['thd.is_del', '=', 0]];
  1233. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['thd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1234. if($param['companyNo'] != '') $where[] = ["s.supplierNo","=",$param['companyNo']];
  1235. $count = Db::name('th_data')
  1236. ->alias('thd')
  1237. ->leftJoin('sale s', 's.orderCode=thd.orderCode')
  1238. ->where($where)
  1239. ->order('thd.addtime', 'desc')
  1240. ->count('thd.id');
  1241. $data = Db::name('th_data')
  1242. ->alias('thd')
  1243. ->field('thd.id,thd.th_type,
  1244. thd.addtime return_time,thd.thCode,"" outCode,"" status,s.apply_name,s.apply_id apply_company,thd.orderCode,s.addtime,s.customerName companyName,s.good_name,s.sale_price,s.wsend_num,thd.th_num,thd.th_fee,"" contactor,"" mobile,"" addr,"" result')
  1245. ->leftJoin('sale s', 's.orderCode=thd.orderCode')
  1246. ->where($where)
  1247. ->page($param['page'],$param['size'])
  1248. ->order('thd.addtime', 'desc')
  1249. ->select()
  1250. ->toArray();
  1251. $th_types = ["1"=>[],"2"=>[],"3"=>[],"4"=>[]];
  1252. foreach ($data as $value) {
  1253. $th_types[$value['th_type']][] = $value['thCode'];
  1254. }
  1255. $all_order_return = Db::name('order_return')
  1256. ->alias('or')
  1257. ->withAttr('status', function ($val) {
  1258. return isset($this->all_order_return_status[$val]) ? $this->all_order_return_status[$val] : '';
  1259. })
  1260. ->leftJoin('order_out oo', 'oo.outCode=or.outCode')
  1261. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  1262. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1263. ->where('or.is_del', 0)
  1264. ->whereIn('or.returnCode', $th_types[2])
  1265. ->column('or.id,or.outCode,or.status,or.apply_id,or.apply_name,oa.contactor,oa.mobile,oa.addr,ri.result,oa.addr_code', 'or.returnCode');
  1266. $all_order_back = Db::name('order_back')
  1267. ->alias('ob')
  1268. ->where('ob.is_del', 0)
  1269. ->whereIn('ob.thNo', $th_types[3])
  1270. ->withAttr('status', function ($val) {
  1271. return isset($this->order_back_status[$val]) ? $this->order_back_status[$val] : '';
  1272. })
  1273. ->leftJoin('order_out oo', 'oo.outCode=ob.outCode')
  1274. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  1275. ->leftJoin('result_info ri', 'ri.result_code=ob.return_code')
  1276. ->column('ob.id,ob.outCode,ob.status,ob.apply_id,ob.apply_name,oa.contactor,oa.mobile,oa.addr,ri.result,oa.addr_code', 'thNo');
  1277. $list = [];
  1278. $all_uids = array_unique(array_merge(array_column($all_order_return, 'apply_id'), array_column
  1279. ($all_order_back, 'apply_id'), array_column($data, 'apply_company')));
  1280. $all_company = get_company_name_by_uid($all_uids);
  1281. // $userCommon = \app\admin\common\User::getIns();
  1282. // $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_column($data, 'customer_code'))]);
  1283. foreach ($data as $value) {
  1284. if ($value['th_type'] == 2) {
  1285. $value['outCode'] = isset($all_order_return[$value['thCode']]['outCode']) ? $all_order_return[$value['thCode']]['outCode'] : '';
  1286. $value['status'] = isset($all_order_return[$value['thCode']]['status']) ? $all_order_return[$value['thCode']]['status'] : '';
  1287. $value['apply_name'] = isset($all_order_return[$value['thCode']]['apply_name']) ? $all_order_return[$value['thCode']]['apply_name'] : '';
  1288. $value['apply_company'] = $all_company[$all_order_return[$value['thCode']]['apply_id'] ?? 0] ?? '';//isset($all_order_return[$value['thCode']]['apply_company']) ? $all_order_return[$value['thCode']]['apply_company'] : '';
  1289. $value['contactor'] = isset($all_order_return[$value['thCode']]['contactor']) ? $all_order_return[$value['thCode']]['contactor'] : '';
  1290. $value['mobile'] = isset($all_order_return[$value['thCode']]['mobile']) ? $all_order_return[$value['thCode']]['mobile'] : '';
  1291. $value['addr'] = isset($all_order_return[$value['thCode']]['addr']) ? $all_order_return[$value['thCode']]['addr'] : '';
  1292. $value['result'] = isset($all_order_return[$value['thCode']]['result']) ? $all_order_return[$value['thCode']]['result'] : '';
  1293. } elseif ($value['th_type'] == 3) {
  1294. $value['outCode'] = isset($all_order_back[$value['thCode']]['outCode']) ? $all_order_back[$value['thCode']]['outCode'] : '';
  1295. $value['status'] = isset($all_order_back[$value['thCode']]['status']) ? $all_order_back[$value['thCode']]['status'] : '';
  1296. $value['apply_name'] = isset($all_order_back[$value['thCode']]['apply_name']) ? $all_order_back[$value['thCode']]['apply_name'] : '';
  1297. $value['apply_company'] = $all_company[$all_order_back[$value['thCode']]['apply_id'] ?? 0] ?? '';//isset($all_order_back[$value['thCode']]['apply_company']) ? $all_order_back[$value['thCode']]['apply_company'] : '';
  1298. $value['contactor'] = isset($all_order_back[$value['thCode']]['contactor']) ? $all_order_back[$value['thCode']]['contactor'] : '';
  1299. $value['mobile'] = isset($all_order_back[$value['thCode']]['mobile']) ? $all_order_back[$value['thCode']]['mobile'] : '';
  1300. $value['addr'] = isset($all_order_back[$value['thCode']]['addr']) ? $all_order_back[$value['thCode']]['addr'] : '';
  1301. $value['result'] = isset($all_order_back[$value['thCode']]['result']) ? $all_order_back[$value['thCode']]['result'] : '';
  1302. }else{
  1303. $value['apply_company'] = $all_company[$value['apply_company'] ?? 0] ?? '';
  1304. $value['status'] = $value['th_type']==1?"销售退货完成":"取消订单完成";
  1305. $value['result'] = $value['th_type']==1?"销售退货":"取消订单";
  1306. }
  1307. $list[] = $value;
  1308. }
  1309. unset($names);
  1310. unset($all_uids);
  1311. unset($all_company);
  1312. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1313. }
  1314. //【五、退货明细表】
  1315. public function thDataExport()
  1316. {
  1317. $param = $this->request->only(['token', 'start_date' => '','companyNo'=>"", 'end_date' => ''], 'post', 'trim');
  1318. $where = [['thd.is_del', '=', 0]];
  1319. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['thd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1320. if ($param['companyNo'] != '')
  1321. $where[]=[
  1322. 's.supplierNo' ,
  1323. '=' ,
  1324. $param['companyNo']
  1325. ];
  1326. $data = Db::name('th_data')
  1327. ->alias('thd')
  1328. ->field('thd.id,thd.th_type,thd.addtime 退货时间,thd.thCode 退货单号,"" 发货申请单编码,"" 退货单状态,
  1329. s.apply_name 创建人,s.apply_id 部门,thd.orderCode 确认单编号,s.addtime 下单日期,s.customerName 客户名称,
  1330. s.good_name 产品名称,s.good_code 商品成本编号,s.is_stock 商品类型,s.order_source 订单来源,s.sale_price 单价,
  1331. s.supplierName 业务公司,s.good_num 下单数量,s.wsend_num 未发货数量,thd.th_num 退货数量,thd.th_fee 退货销售货款,
  1332. "" 发货单联系人,"" 发货单联系人电话,"" 发货单地址,"" 退货原因')
  1333. ->leftJoin('sale s', 's.orderCode=thd.orderCode')
  1334. ->where($where)
  1335. ->order('thd.addtime', 'desc')
  1336. ->select()
  1337. ->toArray();
  1338. $th_types = ["1"=>[],"2"=>[],"3"=>[],"4"=>[]];
  1339. foreach ($data as $value) {
  1340. $th_types[$value['th_type']][] = $value['退货单号'];
  1341. }
  1342. $all_order_return = Db::name('order_return')
  1343. ->alias('or')
  1344. ->withAttr('退货单状态', function ($val) {
  1345. return isset($this->all_order_return_status[$val]) ? $this->all_order_return_status[$val] : '';
  1346. })
  1347. ->leftJoin('order_out oo', 'oo.outCode=or.outCode')
  1348. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  1349. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1350. ->where('or.is_del', 0)
  1351. ->whereIn('or.returnCode', $th_types[2])
  1352. ->column('or.id,or.outCode 发货申请单编码,or.status 退货单状态,or.apply_id,or.apply_name 创建人,"" 部门,oa.contactor 发货单联系人,oa.mobile 发货单联系人电话,oa.addr 发货单地址,ri.result 退货原因,oa.addr_code', 'or.returnCode');
  1353. $all_order_back = Db::name('order_back')
  1354. ->alias('ob')
  1355. ->where('ob.is_del', 0)
  1356. ->whereIn('ob.thNo', $th_types[3])
  1357. ->withAttr('退货单状态', function ($val) {
  1358. return isset($this->order_back_status[$val]) ? $this->order_back_status[$val] : '';
  1359. })
  1360. ->leftJoin('order_out oo', 'oo.outCode=ob.outCode')
  1361. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  1362. ->leftJoin('result_info ri', 'ri.result_code=ob.return_code')
  1363. ->column('ob.id,ob.outCode 发货申请单编码,ob.status 退货单状态,ob.apply_id,ob.apply_name 创建人,"" 部门,oa.contactor 发货单联系人,oa.mobile 发货单联系人电话,oa.addr 发货单地址,ri.result 退货原因,oa.addr_code', 'thNo');
  1364. $list = [];
  1365. // $userCommon = \app\admin\common\User::getIns();
  1366. // $names = $userCommon->handle('getCodeAndName', ['code' => array_column($data, 'customer_code')]);
  1367. $all_uids = array_unique(array_merge(array_column($all_order_return, 'apply_id'), array_column
  1368. ($all_order_back, 'apply_id'), array_column($data, '部门')));
  1369. $all_company = get_company_name_by_uid($all_uids);
  1370. foreach ($data as $value) {
  1371. if ($value['th_type'] == 2) {
  1372. $value['发货申请单编码'] = isset($all_order_return[$value['退货单号']]['发货申请单编码']) ? $all_order_return[$value['退货单号']]['发货申请单编码'] : '';
  1373. $value['退货单状态'] = isset($all_order_return[$value['退货单号']]['退货单状态']) ? $all_order_return[$value['退货单号']]['退货单状态'] : '';
  1374. $value['创建人'] = isset($all_order_return[$value['退货单号']]['创建人']) ? $all_order_return[$value['退货单号']]['创建人'] : '';
  1375. $value['部门'] = $all_company[$all_order_return[$value['退货单号']]['apply_id'] ?? 0] ?? '';//isset($all_order_return[$value['退货单号']]['部门']) ? $all_order_return[$value['退货单号']]['部门'] : '';
  1376. $value['发货单联系人'] = isset($all_order_return[$value['退货单号']]['发货单联系人']) ? $all_order_return[$value['退货单号']]['发货单联系人'] : '';
  1377. $value['发货单联系人电话'] = isset($all_order_return[$value['退货单号']]['发货单联系人电话']) ? $all_order_return[$value['退货单号']]['发货单联系人电话'] : '';
  1378. $value['发货单地址'] = isset($all_order_return[$value['退货单号']]['发货单地址']) ? $all_order_return[$value['退货单号']]['发货单地址'] : '';
  1379. $value['退货原因'] = isset($all_order_return[$value['退货单号']]['退货原因']) ? $all_order_return[$value['退货单号']]['退货原因'] : '';
  1380. } elseif ($value['th_type'] == 3) {
  1381. $value['发货申请单编码'] = isset($all_order_back[$value['退货单号']]['发货申请单编码']) ? $all_order_back[$value['退货单号']]['发货申请单编码'] : '';
  1382. $value['退货单状态'] = isset($all_order_back[$value['退货单号']]['退货单状态']) ? $all_order_back[$value['退货单号']]['退货单状态'] : '';
  1383. $value['创建人'] = isset($all_order_back[$value['退货单号']]['创建人']) ? $all_order_back[$value['退货单号']]['创建人'] : '';
  1384. $value['部门'] = $all_company[$all_order_back[$value['退货单号']]['apply_id'] ?? 0] ?? '';//isset($all_order_back[$value['退货单号']]['部门']) ? $all_order_back[$value['退货单号']]['部门'] : '';
  1385. $value['发货单联系人'] = isset($all_order_back[$value['退货单号']]['发货单联系人']) ? $all_order_back[$value['退货单号']]['发货单联系人'] : '';
  1386. $value['发货单联系人电话'] = isset($all_order_back[$value['退货单号']]['发货单联系人电话']) ? $all_order_back[$value['退货单号']]['发货单联系人电话'] : '';
  1387. $value['发货单地址'] = isset($all_order_back[$value['退货单号']]['发货单地址']) ? $all_order_back[$value['退货单号']]['发货单地址'] : '';
  1388. $value['退货原因'] = isset($all_order_back[$value['退货单号']]['退货原因']) ? $all_order_back[$value['退货单号']]['退货原因'] : '';
  1389. }else{
  1390. $value['部门'] = $all_company[$value['部门'] ?? 0] ?? '';
  1391. $value['退货单状态'] = $value['th_type']==1?"销售退货完成":"取消订单完成";
  1392. $value['退货原因'] = $value['th_type']==1?"销售退货":"取消订单";
  1393. }
  1394. $value['商品类型'] = $value['商品类型']==1?'库存':'非库存';
  1395. $value['订单来源'] = \app\admin\model\Sale::$order_source[$value['订单来源']];
  1396. // $value['客户名称'] = $names['data'][$value['customer_code']];
  1397. unset($value['id']);
  1398. unset($value['th_type']);
  1399. unset($value['customer_code']);
  1400. $list[] = $value;
  1401. }
  1402. unset($all_uids);
  1403. unset($all_company);
  1404. unset($names);
  1405. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1406. excelSave('退货明细表' . date('YmdHis'), array_keys($list[0]), $list);
  1407. }
  1408. //【六、售后明细表】
  1409. public function orderReturnDetailed()
  1410. {
  1411. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  1412. $where = [['or.is_del', '=', 0]];
  1413. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1414. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  1415. $count = Db::name('order_return')
  1416. ->alias('or')
  1417. // ->leftJoin('customer_info c', 'c.companyNo=or.customer_code')
  1418. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  1419. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1420. ->where($where)
  1421. ->order('or.addtime', 'desc')
  1422. ->count('or.id');
  1423. $data = Db::name('order_return')
  1424. ->alias('or')
  1425. ->field('or.addtime,or.returnCode,or.apply_name,or.apply_id,or.outCode,or.total_num,or.status,or.orderCode,"" companyName,or.good_name,s.sale_price,or.is_receive,or.error_num,ri.result result_desc,or.error_remark,or.except_code,or.customer_code')
  1426. // ->leftJoin('customer_info c', 'c.companyNo=or.customer_code')
  1427. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  1428. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1429. ->where($where)
  1430. ->page($param['page'], $param['size'])
  1431. ->order('or.addtime', 'desc')
  1432. ->cursor();
  1433. $userCommon = \app\admin\common\User::getIns();
  1434. $list = $customer2_tmp = $uid_tmp = [];
  1435. foreach ($data as $value) {
  1436. $value['status'] = isset($this->all_order_return_status[$value['status']]) ? $this->all_order_return_status[$value['status']] : '';
  1437. $value['except_code'] = isset($this->except_code[$value['is_receive']][$value['except_code']]) ? $this->except_code[$value['is_receive']][$value['except_code']] : '';
  1438. $value['is_receive'] = isset($this->is_receive[$value['is_receive']]) ? $this->is_receive[$value['is_receive']] : '';
  1439. if (!isset($uid_tmp[$value['apply_id']])) $uid_tmp[$value['apply_id']] = $value['apply_id'];;//get_company_name_by_uid($value['apply_id']);
  1440. // $value['apply_company'] = $uid_tmp[$value['apply_id']];
  1441. $value['error_total_price'] = round($value['error_num'] * $value['sale_price'], 2);
  1442. if (!isset($customer2_tmp[$value['customer_code']])) {
  1443. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  1444. $customer2_tmp[$value['customer_code']] = [
  1445. 'itemid' => $temp['data']['itemid'],
  1446. 'companyName' => $temp['data']['companyName'],
  1447. ];
  1448. }
  1449. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  1450. $value['companyName'] = $customer2_tmp[$value['customer_code']]['companyName'];
  1451. if (!empty($value['itemid'])) {
  1452. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  1453. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  1454. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  1455. }
  1456. $list[] = $value;
  1457. }
  1458. $all_company = get_company_name_by_uid(array_values($uid_tmp));
  1459. foreach ($list as &$val) {
  1460. $val['apply_company'] = $all_company[$val['apply_id']] ?? '';
  1461. // unset($val['apply_id']);
  1462. }
  1463. unset($customer2_tmp);
  1464. unset($uid_tmp);
  1465. unset($all_company);
  1466. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1467. }
  1468. //【六、售后明细表】
  1469. public function orderReturnDetailedExport()
  1470. {
  1471. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => ''], 'post', 'trim');
  1472. $where = [['or.is_del', '=', 0]];
  1473. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1474. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  1475. $data = Db::name('order_return')
  1476. ->alias('or')
  1477. ->field('or.addtime 售后时间,or.returnCode 售后申请编号,or.apply_name 申请人,or.apply_id,"" 部门,or.outCode 发货申请编号,or.total_num 发货数量,or.status 处理状态,or.orderCode 订单号,"" 一级组织,"" 二级组织,"" 客户名称,or.good_name 商品名称,s.sale_price 销售单价,"" 异常金额,or.is_receive 收货情况,or.error_num 异常数量,ri.result 异常原因,or.error_remark 异常备注,or.except_code 期望意愿,or.customer_code')
  1478. // ->leftJoin('customer_info c', 'c.companyNo=or.customer_code')
  1479. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  1480. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1481. ->where($where)
  1482. ->order('or.addtime', 'desc')
  1483. ->cursor();
  1484. $userCommon = \app\admin\common\User::getIns();
  1485. $list = $customer2_tmp = $uid_tmp = [];
  1486. foreach ($data as $value) {
  1487. $value['处理状态'] = isset($this->all_order_return_status[$value['处理状态']]) ? $this->all_order_return_status[$value['处理状态']] : '';
  1488. if (!isset($uid_tmp[$value['apply_id']])) $uid_tmp[$value['apply_id']] = $value['apply_id'];//get_company_name_by_uid($value['apply_id']);
  1489. // $value['部门'] = $uid_tmp[$value['apply_id']];
  1490. $value['异常金额'] = round($value['异常数量'] * $value['销售单价'], 2);
  1491. if (!isset($customer2_tmp[$value['customer_code']])) {
  1492. $temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
  1493. $customer2_tmp[$value['customer_code']] = [
  1494. 'itemid' => $temp['data']['itemid'],
  1495. 'companyName' => $temp['data']['companyName'],
  1496. ];
  1497. }
  1498. $value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
  1499. $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
  1500. if (!empty($value['itemid'])) {
  1501. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  1502. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  1503. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  1504. }
  1505. $value['期望意愿'] = isset($this->except_code[$value['收货情况']][$value['期望意愿']]) ? $this->except_code[$value['收货情况']][$value['期望意愿']] : '';
  1506. $value['收货情况'] = isset($this->is_receive[$value['收货情况']]) ? $this->is_receive[$value['收货情况']] : '';
  1507. // unset($value['apply_id']);
  1508. unset($value['itemid']);
  1509. unset($value['customer_code']);
  1510. $list[] = $value;
  1511. }
  1512. $all_company = get_company_name_by_uid(array_values($uid_tmp));
  1513. foreach ($list as &$val) {
  1514. $val['部门'] = $all_company[$val['apply_id']] ?? '';
  1515. unset($val['apply_id']);
  1516. }
  1517. unset($customer2_tmp);
  1518. unset($uid_tmp);
  1519. unset($all_company);
  1520. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1521. excelSave('售后明细表' . date('YmdHis'), array_keys($list[0]), $list);
  1522. }
  1523. //【七、议价明细表】
  1524. public function bargainOrder()
  1525. {
  1526. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  1527. $where = [['bo.is_del', '=', 0]];
  1528. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['bo.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1529. $count = Db::name('bargain_order')
  1530. ->alias('bo')
  1531. ->leftJoin('consult_info ci', 'ci.infoNo=bo.infoNo')
  1532. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1533. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  1534. ->leftJoin('result_info ri', 'ri.result_code=bo.result_info_id')
  1535. ->where($where)
  1536. ->order('bo.addtime', 'desc')
  1537. ->count('bo.id');
  1538. $data = Db::name('bargain_order')
  1539. ->alias('bo')
  1540. ->field('bo.addtime,bo.bargainNo,bo.infoNo,bo.status,bo.bidsNo,"" companyName,ci.good_name,bo.creater,bo.createrid,bo.sale_price,bo.after_price,ri.result result_desc,bo.bargain_remark,co.khNo')
  1541. ->leftJoin('consult_info ci', 'ci.infoNo=bo.infoNo')
  1542. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1543. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  1544. ->leftJoin('result_info ri', 'ri.result_code=bo.result_info_id')
  1545. ->where($where)
  1546. ->page($param['page'], $param['size'])
  1547. ->order('bo.addtime', 'desc')
  1548. ->cursor();
  1549. $list = $codes = $uid_tmp = [];
  1550. foreach ($data as $value) {
  1551. $value['status'] = isset($this->bargain_order_status[$value['status']]) ? $this->bargain_order_status[$value['status']] : '';
  1552. if (!isset($uid_tmp[$value['createrid']])) $uid_tmp[$value['createrid']] = $value['createrid'];//get_company_name_by_uid($value['createrid']);
  1553. // $value['creater_company'] = $uid_tmp[$value['createrid']];
  1554. if (!isset($codes[$value['khNo']])) $codes[$value['khNo']] = $value['khNo'];
  1555. $list[] = $value;
  1556. }
  1557. //补充客户名称
  1558. $userCommon = \app\admin\common\User::getIns();
  1559. $names = $userCommon->handle('getCodeAndName', ['code' => $codes]);
  1560. $all_company = get_company_name_by_uid(array_values($uid_tmp));
  1561. foreach ($list as &$val) {
  1562. $val['companyName'] = $names['data'][$val['khNo']];
  1563. $val['creater_company'] = $all_company[$val['createrid']] ?? '';
  1564. }
  1565. unset($codes);
  1566. unset($uid_tmp);
  1567. unset($userCommon);
  1568. unset($names);
  1569. unset($all_company);
  1570. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1571. }
  1572. //【七、议价明细表】
  1573. public function bargainOrderExport()
  1574. {
  1575. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => ''], 'post', 'trim');
  1576. $where = [['bo.is_del', '=', 0]];
  1577. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['bo.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1578. $data = Db::name('bargain_order')
  1579. ->alias('bo')
  1580. ->field('bo.addtime 议价时间,bo.bargainNo 议价编号,bo.infoNo 咨询单编号,bo.status 议价单状态,bo.bidsNo 采返商品编号,"" 客户名称,ci.good_name 商品名称,bo.creater 申请人,"" 部门,bo.createrid,bo.sale_price 议价前售价,bo.after_price 期望售价,ri.result 议价原因,bo.bargain_remark 议价备注,co.khNo')
  1581. ->leftJoin('consult_info ci', 'ci.infoNo=bo.infoNo')
  1582. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1583. // ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  1584. ->leftJoin('result_info ri', 'ri.result_code=bo.result_info_id')
  1585. ->where($where)
  1586. ->order('bo.addtime', 'desc')
  1587. ->cursor();
  1588. $list = $codes = $uid_tmp = [];
  1589. foreach ($data as $value) {
  1590. if (!isset($codes[$value['khNo']])) $codes[$value['khNo']] = $value['khNo'];
  1591. if (!isset($uid_tmp[$value['createrid']])) $uid_tmp[$value['createrid']] = $value['createrid'];//get_company_name_by_uid($value['createrid']);
  1592. $value['议价单状态'] = isset($this->bargain_order_status[$value['议价单状态']]) ? $this->bargain_order_status[$value['议价单状态']] : '';
  1593. // $value['部门'] = $uid_tmp[$value['createrid']];
  1594. // unset($value['createrid']);
  1595. $list[] = $value;
  1596. }
  1597. //补充客户名称
  1598. $userCommon = \app\admin\common\User::getIns();
  1599. $names = $userCommon->handle('getCodeAndName', ['code' => $codes]);
  1600. $all_company = get_company_name_by_uid(array_values($uid_tmp));
  1601. foreach ($list as &$val) {
  1602. $val['客户名称'] = $names['data'][$val['khNo']];
  1603. $val['部门'] = $all_company[$val['createrid']] ?? '';
  1604. unset($val['createrid']);
  1605. unset($val['khNo']);
  1606. }
  1607. unset($codes);
  1608. unset($uid_tmp);
  1609. unset($userCommon);
  1610. unset($names);
  1611. unset($all_company);
  1612. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1613. excelSave('议价明细表' . date('YmdHis'), array_keys($list[0]), $list);
  1614. }
  1615. //【八、延时发货申请单统计】
  1616. public function orderOutNotAddr()
  1617. {
  1618. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1619. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 2], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==2 延迟发货,a.status==4 已全部退货
  1620. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1621. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1622. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1623. // if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1624. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1625. $count = Db::name('order_out')
  1626. ->alias('a')
  1627. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1628. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1629. ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
  1630. ->order("a.addtime desc")
  1631. ->where($where)
  1632. ->count('a.id');
  1633. $data = Db::name('order_out')
  1634. ->alias('a')
  1635. ->field('a.addtime,a.orderCode,os.cgdNo,"" company,a.apply_name,a.apply_id,a.status,a.send_num,b.good_code,b.good_name,"" companyName,b.wsend_num,b.skuCode,b.order_type,""person,b.customer_code,b.supplierNo companyNo,b.supNo as supplierNo')
  1636. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1637. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1638. ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
  1639. ->page($param['page'], $param['size'])
  1640. ->where($where)
  1641. ->order("a.addtime desc")
  1642. ->cursor();
  1643. $list = $tmp_apply = $tmp_cat = $tmp_person = $tmp_codes = [];
  1644. $userCommon = \app\admin\common\User::getIns();
  1645. foreach ($data as $value) {
  1646. if (!isset($tmp_apply[$value['apply_id']])) $tmp_apply[$value['apply_id']] = $value['apply_id'];
  1647. if (!isset($tmp_codes[$value['customer_code']])) $tmp_codes[$value['customer_code']] = $value['customer_code'];
  1648. if (!isset($tmp_codes[$value['companyNo']])) $tmp_codes[$value['companyNo']] = $value['companyNo'];
  1649. if (!isset($tmp_person[$value['supplierNo']])) {
  1650. $tmp = $userCommon->handle('sInfo', ['code' => $value['supplierNo']]);
  1651. $tmp_person[$value['supplierNo']] = $tmp['data']['person']??"";
  1652. }
  1653. $value['person'] = $tmp_person[$value['supplierNo']];
  1654. if ($value['order_type'] == 3 || $value['order_type'] == 4) {
  1655. $goon = Db::name("good_zixun")
  1656. ->field('id,cat_id,customized')
  1657. ->where(["spuCode" => $value['good_code'], "is_del" => 0])
  1658. ->find();
  1659. } else {
  1660. $goon = Db::name('good_platform')
  1661. ->alias('a')
  1662. ->field('a.id,b.cat_id,b.customized')
  1663. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  1664. ->where(['a.is_del' => 0, 'a.skuCode' => $value['skuCode']])
  1665. ->find();
  1666. }
  1667. if (!isset($tmp_cat[$goon['cat_id']])) $tmp_cat[$goon['cat_id']] = implode('/', array_column(made($goon['cat_id']), 'name'));
  1668. $value['cat'] = $tmp_cat[$goon['cat_id']];
  1669. $value['send_date'] = date('Y-m-d H:i:s', strtotime($value['addtime']) + $goon['customized'] * 24 * 3600);
  1670. $value['status'] = isset($this->order_out_status[$value['status']]) ? $this->order_out_status[$value['status']] : '';
  1671. $list[] = $value;
  1672. }
  1673. $names = $userCommon->handle('getCodeAndName', ['code' => $tmp_codes]);
  1674. $apply_company = get_company_name_by_uid($tmp_apply);
  1675. foreach ($list as &$val) {
  1676. $val['companyName'] = $names['data'][$val['customer_code']] ?? '';
  1677. $val['company'] = $names['data'][$val['companyNo']] ?? '';
  1678. $val['apply_company'] = $apply_company[$val['apply_id']] ?? '';
  1679. }
  1680. unset($tmp_apply);
  1681. unset($tmp_cat);
  1682. unset($tmp_person);
  1683. unset($tmp_codes);
  1684. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1685. }
  1686. //【八、延时发货申请单统计】
  1687. public function orderOutNotAddrExport()
  1688. {
  1689. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1690. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 2], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==2 延迟发货,a.status==4 已全部退货
  1691. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1692. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1693. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1694. // if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1695. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1696. $data = Db::name('order_out')
  1697. ->alias('a')
  1698. ->field('a.addtime 下单时间,a.orderCode 订单编号,os.cgdNo 采购单编号,"" 公司名称,a.apply_name 申请人,"" 部门,a.apply_id,a.status 状态,a.send_num 出库总数,"" 商品分类,b.good_code 商品编码,b.good_name 商品名称,"" 客户名称,b.wsend_num 未发货数量,"" 应发货日期,b.skuCode,b.order_type 订单类型,"" 采购员,b.customer_code,b.supplierNo companyNo,b.supNo as supplierNo')
  1699. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1700. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1701. ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
  1702. ->where($where)
  1703. ->order("a.addtime desc")
  1704. ->cursor();
  1705. $userCommon = \app\admin\common\User::getIns();
  1706. $list = $tmp_apply = $tmp_cat = $tmp_person = $tmp_codes = [];
  1707. foreach ($data as $value) {
  1708. if (!isset($tmp_codes[$value['customer_code']])) $tmp_codes[$value['customer_code']] = $value['customer_code'];
  1709. if (!isset($tmp_codes[$value['companyNo']])) $tmp_codes[$value['companyNo']] = $value['companyNo'];
  1710. if (!isset($tmp_apply[$value['apply_id']])) $tmp_apply[$value['apply_id']] = $value['apply_id'];// get_company_name_by_uid($value['apply_id']);
  1711. if (!isset($tmp_person[$value['supplierNo']])) {
  1712. $tmp = $userCommon->handle('sInfo', ['code' => $value['supplierNo']]);
  1713. $tmp_person[$value['supplierNo']] = $tmp['data']['person']??"";
  1714. }
  1715. $value['采购员'] = $tmp_person[$value['supplierNo']];
  1716. if ($value['订单类型'] == 3 || $value['订单类型'] == 4) {
  1717. $goon = Db::name("good_zixun")
  1718. ->field('id,cat_id,customized')
  1719. ->where(["spuCode" => $value['商品编码'], "is_del" => 0])
  1720. ->find();
  1721. } else {
  1722. $goon = Db::name('good_platform')
  1723. ->alias('a')
  1724. ->field('a.id,b.cat_id,b.customized')
  1725. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  1726. ->where(['a.is_del' => 0, 'a.skuCode' => $value['skuCode']])
  1727. ->find();
  1728. }
  1729. if (!isset($tmp_cat[$goon['cat_id']])) $tmp_cat[$goon['cat_id']] = implode('/', array_column(made($goon['cat_id']), 'name'));
  1730. $value['商品分类'] = $tmp_cat[$goon['cat_id']];
  1731. $value['应发货日期'] = date('Y-m-d H:i:s', strtotime($value['下单时间']) + $goon['customized'] * 24 * 3600);
  1732. $value['状态'] = isset($this->order_out_status[$value['状态']]) ? $this->order_out_status[$value['状态']] : '';
  1733. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  1734. // unset($value['apply_id']);
  1735. unset($value['skuCode']);
  1736. $list[] = $value;
  1737. }
  1738. $names = $userCommon->handle('getCodeAndName', ['code' => $tmp_codes]);
  1739. $apply_company = get_company_name_by_uid(array_values($tmp_apply));
  1740. foreach ($list as &$val) {
  1741. $val['客户名称'] = $names['data'][$val['customer_code']] ?? '';
  1742. $val['公司名称'] = $names['data'][$val['companyNo']] ?? '';
  1743. $value['部门'] = $apply_company[$val['apply_id']] ?? '';
  1744. unset($val['customer_code']);
  1745. unset($val['companyNo']);
  1746. unset($val['apply_id']);
  1747. }
  1748. unset($tmp_apply);
  1749. unset($tmp_cat);
  1750. unset($tmp_person);
  1751. unset($tmp_codes);
  1752. unset($names);
  1753. unset($apply_company);
  1754. unset($userCommon);
  1755. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1756. excelSave('延时发货申请单' . date('YmdHis'), array_keys($list[0]), $list);
  1757. }
  1758. //【九、直接发货申请单统计 】
  1759. public function orderOutAddr()
  1760. {
  1761. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1762. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 1], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==1 直接发货
  1763. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1764. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1765. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1766. // if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1767. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1768. $count = Db::name('order_out')
  1769. ->alias('a')
  1770. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1771. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1772. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
  1773. ->leftJoin("order_addr oa", "oa.id=a.addrid")
  1774. // ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1775. // ->leftJoin("company_item ci", "ci.id=u.itemid")
  1776. // ->leftJoin("supplier c", "c.code=po.supplierNo")
  1777. ->where($where)
  1778. ->order("a.addtime desc")
  1779. ->count('a.id');
  1780. $data = Db::name('order_out')
  1781. ->alias('a')
  1782. ->field('a.addtime,a.orderCode,a.sendtime,a.outCode,a.status,b.good_name,b.sale_price,a.send_num,a.apply_name,"" apply_company,"" cgder,a.post_name,a.post_code,oa.contactor,oa.mobile,oa.addr,oa.addr_code,a.remark,b.order_type,po.supplierNo,a.apply_id')
  1783. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1784. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1785. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
  1786. ->leftJoin("order_addr oa", "oa.id=a.addrid")
  1787. // ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1788. // ->leftJoin("company_item ci", "ci.id=u.itemid")
  1789. // ->leftJoin("supplier c", "c.code=po.supplierNo")
  1790. ->where($where)
  1791. ->page($param['page'], $param['size'])
  1792. ->order("a.addtime desc")
  1793. ->cursor();
  1794. $list = $tmp = [];
  1795. foreach ($data as $value) {
  1796. if (!isset($tmp[$value['apply_id']])) $tmp[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
  1797. $value['apply_company']=$tmp[$value['apply_id']] ?? '';
  1798. $value['send_total_price'] = round($value['send_num'] * $value['sale_price'], 2);
  1799. $value['status'] = isset($this->order_out_status[$value['status']]) ? $this->order_out_status[$value['status']] : '';
  1800. //拼接省市区
  1801. if (!json_decode($value['addr_code'])) {
  1802. $temp = explode(',', $value['addr_code']);
  1803. $value['addr_code'] = json_encode(['provice_code' => $temp[0] ?? '', 'city_code' => $temp[1] ?? '', 'area_code' => $temp[2] ?? '']);
  1804. }
  1805. $value['addr'] = GetAddr($value['addr_code']) . $value['addr'];
  1806. if (!isset($tmp[$value['supplierNo']])) $tmp[$value['supplierNo']] = $value['supplierNo'];
  1807. $list[] = $value;
  1808. }
  1809. $person = \app\admin\common\User::getIns()->handle('sGetList', ['more_code' => array_values($tmp), 'size' => count($tmp)]);
  1810. $person = array_column($person['data']['list'], 'person', 'code');
  1811. foreach ($list as &$value) {
  1812. $value['cgder'] = $person[$value['supplierNo']] ?? '';
  1813. }
  1814. unset($tmp);
  1815. unset($person);
  1816. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1817. }
  1818. //【九、直接发货申请单统计-导出】
  1819. public function orderOutAddrExport()
  1820. {
  1821. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'order_type' => ''], 'post', 'trim');
  1822. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 1], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==1 直接发货
  1823. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1824. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1825. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1826. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1827. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1828. $data = Db::name('order_out')
  1829. ->alias('a')
  1830. ->field('a.addtime 下单日期,a.orderCode 订单编号,a.sendtime 发货时间,a.outCode 发货申请单号,a.status 发货申请单状态,b.good_name 商品名称,b.sale_price 产品单价,a.send_num 发货数量,"" 发货申请单总价,a.apply_name 申请人,"" 部门,"" 采购员,a.post_name 快递公司,a.post_code 快递单号,oa.contactor 收货人,oa.mobile 收货电话,oa.addr 收货地址,oa.addr_code,a.remark 备注,b.order_type 订单类型,po.supplierNo,a.apply_id')
  1831. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1832. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1833. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
  1834. ->leftJoin("order_addr oa", "oa.id=a.addrid")
  1835. // ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1836. // ->leftJoin("company_item ci", "ci.id=u.itemid")
  1837. // ->leftJoin("supplier c", "c.code=po.supplierNo")
  1838. ->where($where)
  1839. ->order("a.addtime desc")
  1840. ->cursor();
  1841. $list = $tmp = [];
  1842. foreach ($data as $value) {
  1843. if (!isset($tmp[$value['apply_id']])) $tmp[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
  1844. $value['部门']=$tmp[$value['apply_id']] ?? '';
  1845. $value['发货申请单总价'] = round(bcmul($value['发货数量'], $value['产品单价'], 3), 2);
  1846. $value['发货申请单状态'] = isset($this->order_out_status[$value['发货申请单状态']]) ? $this->order_out_status[$value['发货申请单状态']] : '';
  1847. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  1848. //拼接省市区
  1849. if (!json_decode($value['addr_code'])) {
  1850. $temp = explode(',', $value['addr_code']);
  1851. $value['addr_code'] = json_encode(['provice_code' => $temp[0] ?? '', 'city_code' => $temp[1] ?? '', 'area_code' => $temp[2] ?? '']);
  1852. }
  1853. $value['收货地址'] = GetAddr($value['addr_code']) . $value['收货地址'];
  1854. if (!isset($tmp[$value['supplierNo']])) $tmp[$value['supplierNo']] = $value['supplierNo'];
  1855. unset($value['addr_code']);
  1856. unset($value['apply_id']);
  1857. $list[] = $value;
  1858. }
  1859. $person = \app\admin\common\User::getIns()->handle('sGetList', ['more_code' => array_values($tmp), 'size' => count($tmp)]);
  1860. $person = array_column($person['data']['list'], 'person', 'code');
  1861. foreach ($list as &$value) {
  1862. $value['采购员'] = $person[$value['supplierNo']] ?? '';
  1863. }
  1864. unset($tmp);
  1865. unset($person);
  1866. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1867. excelSave('直接发货申请单统计' . date('YmdHis'), array_keys($list[0]), $list);
  1868. }
  1869. //【十、无地址销售订单】
  1870. //@todo 待处理,2023-02-08 此处用户及所属部门应该修改,但是困难之处在于数据是依据u.nickname分组的,是否可以按照a.apply_id分组,并在查询之后补充用户昵称和所属部门?
  1871. public function saleNotAddr()
  1872. {
  1873. $param = $this->request->only(['token',
  1874. 'start_date' => '',
  1875. 'end_date' => '',
  1876. 'status' => '',
  1877. 'apply_company' => '',
  1878. "supplierNo"=>"",
  1879. "depart_id"=>"",
  1880. "companyNo"=>"",
  1881. 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1882. $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0], ['a.status', '<>', 3], ['a.send_status', '<>', 3]];
  1883. //send_type==2 延迟发货
  1884. if ($param['depart_id'] != ''){
  1885. $uidArr = get_company_item_user_by_name("",$param['depart_id']);
  1886. $where[] = ['a.apply_id', 'in',$uidArr];
  1887. }
  1888. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1889. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1890. // if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1891. if ($param['order_type'] != '') $where[] = ['a.order_type', '=', $param['order_type']];
  1892. if ($param['supplierNo'] != '') $where[] = ['a.supNo', 'like', "%{$param['supplierNo']}%"];
  1893. if ($param['companyNo'] != '') $where[] = ['a.supplierNo', 'like',"%{$param['companyNo']}%"];
  1894. $count_row = Db::name('sale')
  1895. ->alias('a')
  1896. ->where($where)
  1897. ->where('a.good_num-a.th_num > ifnull((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)')
  1898. ->count();
  1899. $data = Db::name('sale')
  1900. ->alias('a')
  1901. ->field("a.id,
  1902. a.orderCode,
  1903. a.order_type,
  1904. a.good_code,
  1905. a.skuCode,
  1906. good_name,
  1907. a.good_num,
  1908. a.th_num,
  1909. a.send_num,
  1910. a.wsend_num,
  1911. a.status,
  1912. a.good_num-a.th_num - IFNULL((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0) not_addr_address_good_num,
  1913. a.apply_name nickname,
  1914. a.apply_id,
  1915. a.addtime")
  1916. ->where($where)
  1917. ->page($param['page'], $param['size'])
  1918. ->order("a.addtime desc")
  1919. ->where('a.good_num-a.th_num > ifnull((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)')
  1920. ->select()
  1921. ->toArray();
  1922. $applyAr = array_unique(array_column($data,"apply_id")) ;
  1923. $depart =get_company_name_by_uid($applyAr);
  1924. foreach ($data as &$value){
  1925. $value['name']=$depart[$value['apply_id']]??"";
  1926. $value['month']=date("m",strtotime($value['addtime']));
  1927. }
  1928. return app_show(0, '请求成功', ['list' => $data, 'count' => $count_row]);
  1929. }
  1930. //【十、无地址销售订单-导出】
  1931. public function saleNotAddrExport()
  1932. {
  1933. $param = $this->request->only(['token',
  1934. 'start_date' => '',
  1935. 'end_date' => '',
  1936. "supplierNo"=>"",
  1937. "companyNo"=>"",
  1938. "depart_id"=>"",
  1939. 'status' => '',
  1940. 'apply_company' => '',
  1941. 'order_type' => ''], 'post', 'trim');
  1942. $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0], ['a.status', '<>', 3],['a.send_status', '<>', 3]];//send_type==2 延迟发货
  1943. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1944. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1945. if ($param['depart_id'] != ''){
  1946. $uidArr = get_company_item_user_by_name("",$param['depart_id']);
  1947. $where[] = ['a.apply_id', 'in',$uidArr];
  1948. }
  1949. // if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1950. if ($param['order_type'] != '') $where[] = ['a.order_type', '=', $param['order_type']];
  1951. if ($param['supplierNo'] != '') $where[] = ['a.supNo', 'like', "%{$param['supplierNo']}%"];
  1952. if ($param['companyNo'] != '') $where[] = ['a.supplierNo', 'like',"%{$param['companyNo']}%"];
  1953. $data = Db::name('sale')
  1954. ->alias('a')
  1955. ->field("a.orderCode 订单编号,a.order_type 订单类型,
  1956. a.good_code 商品成本编码,a.skuCode 商品上线编码,a.good_name 商品名称,a.supplierName 业务公司,a.sale_price 商品单价,
  1957. a.good_num 购买数量,a.send_num 已发货数量,a.wsend_num 未发货数量,a.status 订单状态,
  1958. a.apply_name 申请人名称,a.apply_id 申请人所属部门,
  1959. a.good_num-a.th_num - IFNULL((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0) 无地址数量,
  1960. '' 下单月份,
  1961. a.addtime")
  1962. ->where($where)
  1963. ->where( "a.good_num-a.th_num > IFNULL((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0) ")
  1964. ->order("a.addtime desc")
  1965. ->select();
  1966. $list = [];
  1967. $depart=[];
  1968. foreach ($data as $value) {
  1969. if(!isset($depart[$value['申请人所属部门']])){
  1970. $departArr =get_company_name_by_uid($value['申请人所属部门']);
  1971. $depart[$value['申请人所属部门']] = $departArr??"";
  1972. }
  1973. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  1974. $value['订单状态'] = isset($this->all_sale_status[$value['订单状态']]) ? $this->all_sale_status[$value['订单状态']] : '';
  1975. $value['申请人所属部门']=$depart[$value['申请人所属部门']]??"";
  1976. $value['下单月份']=date("m",strtotime($value['addtime']));
  1977. unset($value['addtime']);
  1978. $list[] = $value;
  1979. }
  1980. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1981. excelSave('无地址销售订单列表' . date('YmdHis'), array_keys($list[0]), $list);
  1982. }
  1983. //【十一、销售订单商品类型】
  1984. public function saleMonth()
  1985. {
  1986. $param = $this->request->only(['token', 'apply_company' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1987. $where = [['a.is_del', '=', 0]];
  1988. // if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1989. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1990. $data = Db::name('sale')
  1991. ->alias('a')
  1992. ->field('a.id,a.order_type,a.apply_id')
  1993. // ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1994. // ->leftJoin("company_item ci", "ci.id=u.itemid")
  1995. ->where($where)
  1996. ->cursor();
  1997. $list = $tmp=[];
  1998. $total = ['name' => '总计', 'tag_1' => 0, 'tag_2' => 0, 'tag_3' => 0, 'tag_total' => 0];
  1999. foreach ($data as $val) {
  2000. if (!isset($tmp[$val['apply_id']])) $tmp[$val['apply_id']] = get_company_name_by_uid($val['apply_id']);
  2001. $val['company_name']=$tmp[$val['apply_id']] ?? '';
  2002. if (!isset($list[$val['company_name']])) $list[$val['company_name']] = [
  2003. 'name' => $val['company_name'],
  2004. 'tag_1' => 0,
  2005. 'tag_2' => 0,
  2006. 'tag_3' => 0,
  2007. 'tag_total' => 0,
  2008. ];
  2009. $list[$val['company_name']]['tag_' . $val['order_type']]++;
  2010. $list[$val['company_name']]['tag_total']++;
  2011. $total['tag_' . $val['order_type']]++;
  2012. $total['tag_total']++;
  2013. }
  2014. $list = array_merge($list);//重置下标
  2015. $list[] = $total;
  2016. return app_show(0, '请求成功', $list);
  2017. }
  2018. //【十一、销售订单商品类型-导出】
  2019. public function saleMonthExport()
  2020. {
  2021. $param = $this->request->only(['token', 'apply_company' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2022. $where = [['a.is_del', '=', 0]];
  2023. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  2024. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2025. $data = Db::name('sale')
  2026. ->alias('a')
  2027. ->field('a.id,a.order_type,a.apply_id')
  2028. // ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  2029. // ->leftJoin("company_item ci", "ci.id=u.itemid")
  2030. ->where($where)
  2031. ->cursor();
  2032. $list =$tmp= [];
  2033. $total = ['部门' => '总计', '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
  2034. foreach ($data as $k => $val) {
  2035. if (!isset($tmp[$val['apply_id']])) $tmp[$val['apply_id']] = get_company_name_by_uid($val['apply_id']);
  2036. $val['company_name']=$tmp[$val['apply_id']] ?? '';
  2037. if (!isset($list[$val['company_name']])) $list[$val['company_name']] = ['部门' => $val['company_name'], '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
  2038. switch ($val['order_type']) {
  2039. case 1:
  2040. $list[$val['company_name']]['库存品']++;
  2041. $total['库存品']++;
  2042. break;
  2043. case 2:
  2044. $list[$val['company_name']]['非库存品']++;
  2045. $total['非库存品']++;
  2046. break;
  2047. case 3:
  2048. $list[$val['company_name']]['咨询采反']++;
  2049. $total['咨询采反']++;
  2050. break;
  2051. }
  2052. $list[$val['company_name']]['总计']++;
  2053. $total['总计']++;
  2054. }
  2055. $list = array_merge($list);//重置下标
  2056. $list[] = $total;
  2057. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  2058. excelSave('销售订单商品类型' . date('YmdHis'), array_keys($list[0]), $list);
  2059. }
  2060. //【十二、采购订单发货维度表】
  2061. public function orderOutMonth()
  2062. {
  2063. $param = $this->request->only(['token', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2064. $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
  2065. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2066. $data = Db::name('order_out')
  2067. ->alias('a')
  2068. ->field('a.id,b.order_type,b.cat_id,d.supplierNo')
  2069. ->leftJoin('sale b', 'b.orderCode=a.orderCode')
  2070. ->leftJoin('order_send c', 'c.outCode=a.outCode')
  2071. ->leftJoin('purchease_order d', 'd.cgdNo=c.cgdNo')
  2072. ->where($where)
  2073. ->cursor();
  2074. $list = [];
  2075. // $total = ['cat_1' => '总计', 'cat_2' => '', 'cat_3' => '', 'tag_1' => 0, 'tag_2' => 0, 'tag_3' => 0, 'tag_supplier' => 0, 'tag_person' => 0, 'tag_logistics' => 0, 'tag_total' => 0];
  2076. // $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
  2077. // ->group('supplierNo')
  2078. // ->column('supplierNo');
  2079. $has_sup_acc = checkHasAccountBySupplierNos();
  2080. foreach ($data as $val) {
  2081. if (!isset($list[$val['cat_id']])) {
  2082. $cat = made($val['cat_id']);
  2083. $list[$val['cat_id']] = [
  2084. 'cat_1' => $cat[0]['name'] ?? '',
  2085. 'cat_2' => $cat[1]['name'] ?? '',
  2086. 'cat_3' => $cat[2]['name'] ?? '',
  2087. 'tag_1' => 0,
  2088. 'tag_2' => 0,
  2089. 'tag_3' => 0,
  2090. 'tag_supplier' => 0,
  2091. 'tag_person' => 0,
  2092. 'tag_logistics' => 0,
  2093. ];
  2094. }
  2095. switch ($val['order_type']) {
  2096. case 1:
  2097. //库存品,物流岗发
  2098. $list[$val['cat_id']]['tag_logistics']++;
  2099. break;
  2100. case 2: //非库存品
  2101. case 3: //咨询采反
  2102. if (in_array($val['supplierNo'], $has_sup_acc)) $list[$val['cat_id']]['tag_supplier']++;
  2103. else $list[$val['cat_id']]['tag_person']++;
  2104. break;
  2105. }
  2106. $list[$val['cat_id']]['tag_' . $val['order_type']]++;
  2107. // $list[$val['cat_id']]['tag_total']++;
  2108. // $total['tag_' . $val['order_type']]++;
  2109. // $total['tag_total']++;
  2110. }
  2111. $list = array_merge($list);//重置下标
  2112. // $list[] = $total;
  2113. return app_show(0, '请求成功', $list);
  2114. }
  2115. //【十二、采购订单发货维度表-导出】
  2116. public function orderOutMonthExport()
  2117. {
  2118. $param = $this->request->only(['token', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2119. $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
  2120. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2121. $data = Db::name('order_out')
  2122. ->alias('a')
  2123. ->field('a.id,b.order_type,b.cat_id,d.supplierNo')
  2124. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  2125. ->leftJoin('order_send c', 'c.outCode=a.outCode')
  2126. ->leftJoin('purchease_order d', 'd.cgdNo=c.cgdNo')
  2127. ->where($where)
  2128. ->cursor();
  2129. $has_sup_acc = checkHasAccountBySupplierNos();
  2130. // $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
  2131. // ->group('supplierNo')
  2132. // ->column('supplierNo');
  2133. $list = [];
  2134. // $total = ['一级分类' => '总计', '二级分类' => '', '三级分类' => '', '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
  2135. foreach ($data as $val) {
  2136. if (!isset($list[$val['cat_id']])) {
  2137. $cat = made($val['cat_id']);
  2138. $list[$val['cat_id']] = [
  2139. '一级分类' => $cat[0]['name'] ?? '',
  2140. '二级分类' => $cat[1]['name'] ?? '',
  2141. '三级分类' => $cat[2]['name'] ?? '',
  2142. '库存品' => 0,
  2143. '非库存品' => 0,
  2144. '咨询采反' => 0,
  2145. '供应商发货' => 0,
  2146. '负责人发货' => 0,
  2147. '物流岗发货' => 0,
  2148. // '总计' => 0,
  2149. ];
  2150. }
  2151. switch ($val['order_type']) {
  2152. case 1:
  2153. $list[$val['cat_id']]['库存品']++;
  2154. // $total['库存品']++;
  2155. //物流岗发
  2156. $list[$val['cat_id']]['物流岗发货']++;
  2157. break;
  2158. case 2:
  2159. $list[$val['cat_id']]['非库存品']++;
  2160. // $total['非库存品']++;
  2161. if (in_array($val['supplierNo'], $has_sup_acc)) $list[$val['cat_id']]['供应商发货']++;
  2162. else $list[$val['cat_id']]['负责人发货']++;
  2163. break;
  2164. case 3:
  2165. $list[$val['cat_id']]['咨询采反']++;
  2166. if (in_array($val['supplierNo'], $has_sup_acc)) $list[$val['cat_id']]['供应商发货']++;
  2167. else $list[$val['cat_id']]['负责人发货']++;
  2168. // $total['咨询采反']++;
  2169. break;
  2170. }
  2171. // $list[$val['cat_id']]['总计']++;
  2172. // $total['总计']++;
  2173. }
  2174. $list = array_merge($list);//重置下标
  2175. // $list[] = $total;
  2176. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  2177. excelSave('采购订单发货维度表' . date('YmdHis'), array_keys($list[0]), $list);
  2178. }
  2179. //【十三、供应商采购订单情况】
  2180. public function purcheaseOrderMonth()
  2181. {
  2182. $param = $this->request->only(['token',
  2183. 'supplierNo' => '',
  2184. 'companyNo' => '',
  2185. 'supplier_name' => '',
  2186. 'status' => '',
  2187. 'person_id' => '',
  2188. 'start_day' => date('Y-m-01'),
  2189. 'end_day' => date('Y-m-t')], 'post', 'trim');
  2190. $where = [['a.is_del', '=', 0]];
  2191. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  2192. if ($param['companyNo'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  2193. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  2194. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2195. if($param['status']!==''){
  2196. $where[]=["a.status","=",$param['status']];
  2197. }
  2198. if($param['person_id']!==''){
  2199. $where[]=["a.cgder_id","=",$param['person_id']];
  2200. }
  2201. $data = Db::name('purchease_order')
  2202. ->alias('a')
  2203. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  2204. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  2205. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  2206. ->where($where)
  2207. ->group("a.supplierNo,a.supplier_name,a.order_type,p.use_type,a.order_source,a.status")
  2208. ->field("a.supplierNo,a.supplier_name,a.order_type,p.use_type,a.order_source,a.status,count(a.id) as total_cgd,sum(a.total_fee-a.th_fee) as total_fee,sum(a.wsend_num*a.good_price) as wtotal_fee")
  2209. ->select()
  2210. ->toArray();
  2211. $list = [];
  2212. $total = ['supplier_name' => '总计',
  2213. "is_supplier"=>'',//是否开通供应商端
  2214. "person"=>'', //供应商负责人
  2215. 'total_cgd' => 0,//订单总量
  2216. 'total_fee' => 0,//订单总金额
  2217. 'dtotal_fee' => 0,//待确认订单总金额
  2218. 'dtotal_cgd' => 0,//待确认订单总量
  2219. 'wtotal_fee' => 0,//待入库订单总金额
  2220. 'wtotal_cgd' => 0,//待入库订单总量
  2221. 'tag_1' => 0,//库存品
  2222. 'tag_2' => 0,//非库存品
  2223. 'tag_c' => 0,//to C
  2224. 'tag_b' => 0,//to B
  2225. 'tag_zx' => 0,//咨询采反总数
  2226. ];
  2227. $supArr=array_unique(array_column($data,'supplierNo'));
  2228. $supplier =checkHasAccountBySupplierNos($supArr);
  2229. $pers =get_personid_by_supplierNo($supArr,"person");
  2230. foreach ($data as $val) {
  2231. if (!isset($list[$val['supplierNo']])) {
  2232. $list[$val['supplierNo']] = [
  2233. 'supplier_name' => $val['supplier_name'],
  2234. "is_supplier"=>isset($supplier[$val['supplierNo']]) ?'是' :'否',//是否开通供应商端
  2235. "person"=>$pers[$val['supplierNo']]??"", //供应商负责人
  2236. 'total_cgd' => 0,//订单总量
  2237. 'total_fee' => 0,//订单总金额
  2238. 'dtotal_fee' => 0,//待确认订单总金额
  2239. 'dtotal_cgd' => 0,//待确认订单总量
  2240. 'wtotal_fee' => 0,//待入库订单总金额
  2241. 'wtotal_cgd' => 0,//待入库订单总量
  2242. 'tag_1' => 0,//库存品
  2243. 'tag_2' => 0,//非库存品
  2244. 'tag_c' => 0,//to C
  2245. 'tag_b' => 0,//to B
  2246. 'tag_zx' => 0,//咨询采反总数
  2247. ];
  2248. }
  2249. switch ($val['order_type']) {
  2250. case 1:
  2251. //库存品
  2252. if ($val['order_source'] == 0) {
  2253. $list[$val['supplierNo']]['tag_1']+=$val['total_cgd'];
  2254. $total['tag_1']+=$val['total_cgd'];
  2255. }
  2256. break;
  2257. case 2:
  2258. //非库存品
  2259. $list[$val['supplierNo']]['tag_2']+=$val['total_cgd'];
  2260. $total['tag_2']+=$val['total_cgd'];
  2261. break;
  2262. case 3:
  2263. //咨询采反
  2264. // if ($val['order_source'] == 2) {
  2265. $list[$val['supplierNo']]['tag_zx']+=$val['total_cgd'];
  2266. $total['tag_zx']+=$val['total_cgd'];
  2267. // }
  2268. break;
  2269. }
  2270. switch ($val['use_type']) {
  2271. case 1:
  2272. //to B
  2273. $list[$val['supplierNo']]['tag_b']+=$val['total_cgd'];
  2274. $total['tag_b']+=$val['total_cgd'];
  2275. break;
  2276. case 2:
  2277. //to C
  2278. $list[$val['supplierNo']]['tag_c']+=$val['total_cgd'];
  2279. $total['tag_c']+=$val['total_cgd'];
  2280. break;
  2281. }
  2282. switch ($val['status']) {
  2283. case 0:
  2284. //to B
  2285. $list[$val['supplierNo']]['dtotal_cgd']+=$val['total_cgd'];
  2286. $list[$val['supplierNo']]['dtotal_fee']=bcadd($list[$val['supplierNo']]['dtotal_fee'] , $val['total_fee'],2);
  2287. $total['dtotal_cgd']+=$val['total_cgd'];
  2288. $total['dtotal_fee']=bcadd( $total['dtotal_fee'], $val['total_fee'],2);
  2289. break;
  2290. case 1:
  2291. case 2:
  2292. //to C
  2293. $list[$val['supplierNo']]['wtotal_cgd']+=$val['total_cgd'];
  2294. $list[$val['supplierNo']]['wtotal_fee']=bcadd( $list[$val['supplierNo']]['wtotal_fee'], $val['wtotal_fee'],2);
  2295. $total['wtotal_cgd']+=$val['total_cgd'];
  2296. $total['wtotal_fee']=bcadd( $total['wtotal_fee'], $val['wtotal_fee'],2);
  2297. break;
  2298. }
  2299. $list[$val['supplierNo']]['total_cgd']+=$val['total_cgd'];
  2300. $list[$val['supplierNo']]['total_fee']=bcadd( $list[$val['supplierNo']]['total_fee'], $val['total_fee'],2);
  2301. $total['total_cgd']+=$val['total_cgd'];
  2302. $total['total_fee']=bcadd( $total['total_fee'], $val['total_fee'],2);
  2303. }
  2304. // $list = array_merge($list);//重置下标,关联数组,下标是字符,无法通过array_merge方法重置下标
  2305. $list[] =$total;
  2306. return app_show(0, '请求成功', array_values($list));
  2307. }
  2308. //【十三、供应商采购订单情况-导出】
  2309. public function purcheaseOrderMonthExport()
  2310. {
  2311. $param = $this->request->only(['token', 'supplierNo' => '', 'companyNo' => '', 'supplier_name' => '','status' => '',
  2312. 'person_id' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2313. $where = [['a.is_del', '=', 0]];
  2314. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  2315. if ($param['companyNo'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  2316. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  2317. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2318. if($param['status']!==''){
  2319. $where[]=["a.status","=",$param['status']];
  2320. }
  2321. if($param['person_id']!==''){
  2322. $where[]=["a.cgder_id","=",$param['person_id']];
  2323. }
  2324. $data = Db::name('purchease_order')
  2325. ->alias('a')
  2326. ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type')
  2327. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  2328. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  2329. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  2330. ->where($where)
  2331. ->group("a.supplierNo,a.supplier_name,a.order_type,p.use_type,a.order_source,a.status")
  2332. ->field("a.supplierNo,a.supplier_name,a.order_type,p.use_type,a.order_source,a.status,count(a.id) as total_cgd,sum(a.total_fee-a.th_fee) as total_fee,sum(a.wsend_num*a.good_price) as wtotal_fee")
  2333. ->select()
  2334. ->toArray();
  2335. $list = $tmp = [];
  2336. $total = [
  2337. '供应商名称' => '总计',
  2338. '是否开通供应商端'=>'',
  2339. '供应商负责人'=>'',
  2340. '采购订单总金额' => 0,
  2341. '采购订单总量' => 0,
  2342. '待确认采购订单总金额' => 0,
  2343. '待确认采购订单总数量' => 0,
  2344. '待入库采购订单总金额' => 0,
  2345. '待入库采购订单总数量' => 0,
  2346. '库存品' => 0,
  2347. '非库存品' => 0,
  2348. '采返商品' =>0,
  2349. 'ToC平台' => 0,
  2350. 'ToB平台' => 0,
  2351. ];
  2352. $supArr=array_unique(array_column($data,'supplierNo'));
  2353. $supplier =checkHasAccountBySupplierNos($supArr);
  2354. $pers =get_personid_by_supplierNo($supArr,"person");
  2355. foreach ($data as $val) {
  2356. if (!isset($list[$val['supplierNo']])) {
  2357. $list[$val['supplierNo']] = [
  2358. '采购方' => $val['supplier_name'],
  2359. '是否开通供应商端'=>isset($supplier[$val['supplierNo']]) ?'是' :'否',
  2360. '供应商负责人'=>$pers[$val['supplierNo']]??"",
  2361. '采购订单总金额' => 0,
  2362. '采购订单总量' => 0,
  2363. '待确认采购订单总金额' => 0,
  2364. '待确认采购订单总数量' => 0,
  2365. '待入库采购订单总金额' => 0,
  2366. '待入库采购订单总数量' => 0,
  2367. '库存品' => 0,
  2368. '非库存品' => 0,
  2369. '采返商品' =>0,
  2370. 'ToC平台' => 0,
  2371. 'ToB平台' => 0,
  2372. ];
  2373. }
  2374. switch ($val['order_type']) {
  2375. case 1:
  2376. //库存品
  2377. if ($val['order_source'] == 0) {
  2378. $list[$val['supplierNo']]['库存品']+=$val['total_cgd'];
  2379. $total['库存品']+=$val['total_cgd'];
  2380. }
  2381. break;
  2382. case 2:
  2383. //非库存品
  2384. $list[$val['supplierNo']]['非库存品']+=$val['total_cgd'];
  2385. $total['非库存品']+=$val['total_cgd'];
  2386. break;
  2387. case 3:
  2388. //咨询采反
  2389. // if ($val['order_source'] == 2) {
  2390. $list[$val['supplierNo']]['采返商品']+=$val['total_cgd'];
  2391. $total['采返商品']+=$val['total_cgd'];
  2392. // }
  2393. break;
  2394. }
  2395. switch ($val['use_type']) {
  2396. case 1:
  2397. //to B
  2398. $list[$val['supplierNo']]['ToB平台']+=$val['total_cgd'];
  2399. $total['ToB平台']+=$val['total_cgd'];
  2400. break;
  2401. case 2:
  2402. //to C
  2403. $list[$val['supplierNo']]['ToC平台']+=$val['total_cgd'];
  2404. $total['ToC平台']+=$val['total_cgd'];
  2405. break;
  2406. }
  2407. switch ($val['status']) {
  2408. case 0:
  2409. //to B
  2410. $list[$val['supplierNo']]['待确认采购订单总数量']+=$val['total_cgd'];
  2411. $list[$val['supplierNo']]['待确认采购订单总金额']+=$val['total_fee'];
  2412. $total['待确认采购订单总数量']+=$val['total_cgd'];
  2413. $total['待确认采购订单总金额']+=$val['total_fee'];
  2414. break;
  2415. case 1:
  2416. case 2:
  2417. //to C
  2418. $list[$val['supplierNo']]['待入库采购订单总数量']+=$val['total_cgd'];
  2419. $list[$val['supplierNo']]['待入库采购订单总金额']+=$val['wtotal_fee'];
  2420. $total['待入库采购订单总数量']+=$val['total_cgd'];
  2421. $total['待入库采购订单总金额']+=$val['wtotal_fee'];
  2422. break;
  2423. }
  2424. $list[$val['supplierNo']]['采购订单总量']+=$val['total_cgd'];
  2425. $list[$val['supplierNo']]['采购订单总金额']+=$val['total_fee'];
  2426. $total['采购订单总量']+=$val['total_cgd'];
  2427. $total['采购订单总金额']+=$val['total_fee'];
  2428. }
  2429. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  2430. excelSave('供应商采购订单情况' . date('YmdHis'), array_keys($total), $list);
  2431. }
  2432. //【十四、供应商负责人采购订单情况】
  2433. public function purcheaseOrderPersonMonth()
  2434. {
  2435. $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'flag' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2436. $where = [['a.is_del', '=', 0]];
  2437. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  2438. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  2439. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2440. if ($param['flag'] != '') {
  2441. // $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
  2442. // ->group('supplierNo')
  2443. // ->column('supplierNo');
  2444. $has_sup_acc = checkHasAccountBySupplierNos();
  2445. if ($param['flag'] == 1) $where[] = ['a.supplierNo', 'in', array_keys($has_sup_acc)];//1.开通账号的
  2446. else $where[] = ['a.supplierNo', 'not in', array_keys($has_sup_acc)];//2.未开通账号的
  2447. }
  2448. $data = Db::name('purchease_order')
  2449. ->alias('a')
  2450. ->where($where)
  2451. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  2452. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  2453. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  2454. ->group("a.cgder_id,a.cgder,a.order_type,p.use_type,a.order_source")
  2455. ->field("a.cgder_id,a.cgder,a.order_type,p.use_type,a.order_source,count(a.id) as total_cgd")
  2456. ->select()
  2457. ->toArray();
  2458. // var_dump($data);
  2459. $list = [];
  2460. $total = ['person' => '总计', 'total_cgd' => 0, 'tag_1' => 0, 'tag_2' => 0, 'tag_c' => 0, 'tag_b' => 0, 'tag_zx' => 0, 'tag_else' => 0];
  2461. $list[]=&$total;
  2462. foreach ($data as $val) {
  2463. if(!isset($list[$val['cgder_id']]))$list[$val['cgder_id']]=['person' => '', 'total_cgd' => 0, 'tag_1' => 0, 'tag_2' => 0, 'tag_c' => 0, 'tag_b' => 0, 'tag_zx' => 0, 'tag_else' => 0];
  2464. $list[$val['cgder_id']]['person']=$val['cgder'];
  2465. $list[$val['cgder_id']]['total_cgd']+=$val['total_cgd'];
  2466. switch ($val['order_type']) {
  2467. case 1:
  2468. //库存品
  2469. $list[$val['cgder_id']]['tag_1']+=$val['total_cgd'];
  2470. $total['tag_1']+=$val['total_cgd'];
  2471. break;
  2472. case 2:
  2473. //非库存品
  2474. $list[$val['cgder_id']]['tag_2']+=$val['total_cgd'];
  2475. $total['tag_2']+=$val['total_cgd'];
  2476. break;
  2477. case 3:
  2478. //咨询采反
  2479. if ($val['order_source'] == 2) {
  2480. $list[$val['cgder_id']]['tag_zx']+=$val['total_cgd'];
  2481. $total['tag_zx']+=$val['total_cgd'];
  2482. } else {
  2483. $list[$val['cgder_id']]['tag_else']+=$val['total_cgd'];
  2484. $total['tag_else']+=$val['total_cgd'];
  2485. }
  2486. break;
  2487. }
  2488. switch ($val['use_type']) {
  2489. case 1:
  2490. //to B
  2491. $list[$val['cgder_id']]['tag_b']+=$val['total_cgd'];
  2492. $total['tag_b']+=$val['total_cgd'];
  2493. break;
  2494. case 2:
  2495. //to C
  2496. $list[$val['cgder_id']]['tag_c']+=$val['total_cgd'];
  2497. $total['tag_c']+=$val['total_cgd'];
  2498. break;
  2499. }
  2500. $total['total_cgd'] +=$val['total_cgd'];
  2501. }
  2502. $list=array_values($list);
  2503. return app_show(0, '请求成功', $list);
  2504. }
  2505. //【十四、供应商负责人采购订单情况-导出】
  2506. public function purcheaseOrderPersonMonthExport()
  2507. {
  2508. $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'flag' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2509. $where = [['a.is_del', '=', 0]];
  2510. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  2511. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  2512. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2513. if ($param['flag'] != '') {
  2514. $has_sup_acc = checkHasAccountBySupplierNos();
  2515. if ($param['flag'] == 1) $where[] = ['a.supplierNo', 'in', array_keys($has_sup_acc)];//1.开通账号的
  2516. else $where[] = ['a.supplierNo', 'not in', array_keys($has_sup_acc)];//2.未开通账号的
  2517. }
  2518. $data = Db::name('purchease_order')
  2519. ->alias('a')
  2520. ->where($where)
  2521. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  2522. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  2523. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  2524. ->group("a.cgder_id,a.cgder,a.order_type,p.use_type,a.order_source")
  2525. ->field("a.cgder_id,a.cgder,a.order_type,p.use_type,a.order_source,count(a.id) as total_cgd")
  2526. ->select()
  2527. ->toArray();
  2528. $list = [];
  2529. $total = ['采购方' => '总计', '订单总量' => 0, '库存品' => 0, '非库存品' => 0, 'toC' => 0, 'toB' => 0, '反馈单数合计' => 0, '采销录单采反' => 0];
  2530. foreach ($data as $val) {
  2531. if (!isset($list[$val['personid']])) {
  2532. $list[$val['cgder_id']] = [
  2533. '采购方' => $val['cgder'],
  2534. '订单总量' => 0,//订单总量
  2535. '库存品' => 0,//库存品
  2536. '非库存品' => 0,//非库存品
  2537. 'toC' => 0,//to C
  2538. 'toB' => 0,//to B
  2539. '反馈单数合计' => 0,//咨询采反总数
  2540. '采销录单采反' => 0,//采销录单采反
  2541. ];
  2542. }
  2543. switch ($val['order_type']) {
  2544. case 1:
  2545. //库存品
  2546. if ($val['order_source'] == 0) {
  2547. $list[$val['cgder_id']]['库存品']+=$val['total_cgd'];
  2548. $total['库存品']+=$val['total_cgd'];
  2549. }
  2550. break;
  2551. case 2:
  2552. //非库存品
  2553. $list[$val['cgder_id']]['非库存品']+=$val['total_cgd'];
  2554. $total['非库存品']+=$val['total_cgd'];
  2555. break;
  2556. case 3:
  2557. //咨询采反
  2558. if($val['order_source'] == 2){
  2559. $list[$val['supplierNo']]['反馈单数合计']+=$val['total_cgd'];
  2560. $total['反馈单数合计']+=$val['total_cgd'];
  2561. } else {
  2562. $list[$val['cgder_id']]['采销录单采反']+=$val['total_cgd'];
  2563. $total['采销录单采反']+=$val['total_cgd'];
  2564. }
  2565. break;
  2566. }
  2567. switch ($val['use_type']) {
  2568. case 1:
  2569. //to B
  2570. $list[$val['cgder_id']]['toB']+=$val['total_cgd'];
  2571. $total['toB']+=$val['total_cgd'];
  2572. break;
  2573. case 2:
  2574. //to C
  2575. $list[$val['cgder_id']]['toC']+=$val['total_cgd'];
  2576. $total['toC']+=$val['total_cgd'];
  2577. break;
  2578. }
  2579. $list[$val['cgder_id']]['订单总量']+=$val['total_cgd'];
  2580. $total['订单总量']+=$val['total_cgd'];
  2581. }
  2582. $list[] = $total;
  2583. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  2584. excelSave('供应商负责人采购订单情况' . date('YmdHis'), array_keys($total), $list);
  2585. }
  2586. //竞价单反馈情况
  2587. public function FeedBackBySupplier(){
  2588. $param = $this->request->only([
  2589. 'supplierNo' => '',
  2590. 'companyNo' => '',
  2591. 'companyName' => '',
  2592. 'supplier_name' => '',
  2593. 'start_day' => date('Y-m-01'),
  2594. 'end_day' => date('Y-m-t')], 'post', 'trim');
  2595. $where = [['a.is_del', '=', 0]];
  2596. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  2597. if ($param['supplier_name'] != '') $where[] = ['a.supplierName', 'like', '%' . $param['supplier_name'] . '%'];
  2598. if ($param['companyNo'] != '') $where[] = ['b.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  2599. if ($param['companyName'] != '') $where[] = ['b.companyName', 'like', '%' . $param['companyName'] . '%'];
  2600. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2601. $list =Db::name("consult_bids")->alias("a")
  2602. ->leftJoin("consult_order b","a.zxNo=b.zxNo")
  2603. ->leftJoin("consult_info c","a.infoNo=c.infoNo")
  2604. ->leftJoin("platform d","b.platform_code=d.id")
  2605. ->where($where)
  2606. ->group("a.supplierNo,d.use_type")
  2607. ->field("a.supplierNo,a.supplierName,d.use_type,count(a.id) feed_num,sum(c.num) good_num,sum(c.num*a.total_fee) total_price,a.cgder")->select()->toArray();
  2608. $data=[];
  2609. $supArr =array_column($list,"supplierNo");
  2610. $supp=checkHasAccountBySupplierNos($supArr);
  2611. $nmer =["supplierName"=>'合计',"is_supplier"=>"","person"=>"","feed_num"=>0,"good_num"=>0,"total_price"=>0,"toc"=>0,"tob"=>0];
  2612. $data[]=&$nmer;
  2613. foreach ($list as $value){
  2614. if(!isset($data[$value['supplierNo']])){
  2615. $data[$value['supplierNo']]=[
  2616. "supplierName"=>$value['supplierName'],
  2617. "is_supplier"=>isset($supp[$value['supplierNo']])?'是':'否',
  2618. "person"=>$value['cgder'],
  2619. "feed_num"=>0,
  2620. "good_num"=>0,
  2621. "total_price"=>0,
  2622. "toc"=>0,
  2623. "tob"=>0
  2624. ];
  2625. }
  2626. switch ($value['use_type']){
  2627. case 1:
  2628. $data[$value['supplierNo']]['tob']= bcadd($data[$value['supplierNo']]['tob'],$value['feed_num'],2);
  2629. $nmer['tob']=bcadd($nmer['tob'],$value['feed_num'],2);
  2630. break;
  2631. case 2:
  2632. $data[$value['supplierNo']]['toc']=bcadd($data[$value['supplierNo']]['toc'],$value['feed_num'],2);
  2633. $nmer['toc']=bcadd($nmer['toc'],$value['feed_num'],2);
  2634. break;
  2635. }
  2636. $data[$value['supplierNo']]['feed_num']=bcadd($data[$value['supplierNo']]['feed_num'],$value['feed_num'],2);
  2637. $data[$value['supplierNo']]['good_num']=bcadd($data[$value['supplierNo']]['good_num'],$value['good_num'],2);
  2638. $data[$value['supplierNo']]['total_price']=bcadd($data[$value['supplierNo']]['total_price'],$value['total_price'],2);
  2639. $nmer['feed_num']=bcadd($value['feed_num'],$nmer['feed_num'],2);
  2640. $nmer['good_num']=bcadd($value['good_num'],$nmer['good_num'],2);
  2641. $nmer['total_price']=bcadd($value['total_price'],$nmer['total_price'],2);
  2642. }
  2643. return app_show(0, '请求成功', array_values($data));
  2644. }
  2645. //当日库存销售情况
  2646. public function saleStock(){
  2647. $param = $this->request->only([
  2648. 'supplierNo' => '',
  2649. 'companyNo' => '',
  2650. 'companyName' => '',
  2651. 'supplier_name' => '',
  2652. 'good_name' => '',
  2653. 'page' => 1,
  2654. 'size' => 15,
  2655. 'start_day' => date('Y-m-01'),
  2656. 'end_day' => date('Y-m-t')
  2657. ], 'post', 'trim');
  2658. $where = [['a.is_del', '=', 0],["a.is_stock","=","1"]];
  2659. if ($param['supplierNo'] != '') $where[] = ['a.supNo', 'like', '%' . $param['supplierNo'] . '%'];
  2660. if ($param['supplier_name'] != '') $where[] = ['a.supName', 'like', '%' . $param['supplier_name'] . '%'];
  2661. if ($param['companyNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['companyNo'] . '%'];
  2662. if ($param['companyName'] != '') $where[] = ['a.supplierName', 'like', '%' . $param['companyName'] . '%'];
  2663. if ($param['good_name'] != '') $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
  2664. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2665. $count = Db::name('sale')
  2666. ->alias('a')
  2667. ->where($where)->group("a.good_code")
  2668. ->count('a.id');
  2669. $list=Db::name("sale")->alias("a")
  2670. ->leftJoin('order_num on', 'a.orderCode=on.orderCode')
  2671. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  2672. ->where($where)
  2673. ->page($param['page'], $param['size'])
  2674. ->order('a.addtime', 'desc')
  2675. ->field("a.good_code,a.good_name,sum(a.good_num) as good_num,a.sale_price,a.is_stock,sum(a.send_num) as send_num,0 stock_num,a.supplierName,po.good_price,sum(po.total_fee) total_fee")
  2676. ->group("a.good_code")
  2677. ->cursor();
  2678. $data=[];
  2679. foreach ($list as $value){
  2680. $value['stock_num'] = Db::name("good_stock")->where("spuCode",$value['good_code'])->sum("usable_stock");
  2681. if($value['is_stock']==1){
  2682. $value['good_price'] = Db::name("purchease_order")->where(["spuCode"=>$value['good_code'],"order_source"=>0])->order('id desc')->value("good_price",0);
  2683. $value['total_fee'] = bcmul($value['good_price'],$value['good_num'],2);
  2684. }
  2685. $data[]= $value;
  2686. }
  2687. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  2688. }
  2689. //当日库存销售情况导出
  2690. public function saleStockExport(){
  2691. $param = $this->request->only([
  2692. 'supplierNo' => '',
  2693. 'companyNo' => '',
  2694. 'companyName' => '',
  2695. 'supplier_name' => '',
  2696. 'good_name' => '',
  2697. 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2698. $where = [['a.is_del', '=', 0],["a.is_stock","=","1"]];
  2699. if ($param['supplierNo'] != '') $where[] = ['a.supNo', 'like', '%' . $param['supplierNo'] . '%'];
  2700. if ($param['supplier_name'] != '') $where[] = ['a.supName', 'like', '%' . $param['supplier_name'] . '%'];
  2701. if ($param['companyNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['companyNo'] . '%'];
  2702. if ($param['companyName'] != '') $where[] = ['a.supplierName', 'like', '%' . $param['companyName'] . '%'];
  2703. if ($param['good_name'] != '') $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
  2704. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2705. $list=Db::name("sale")->alias("a")
  2706. ->leftJoin('order_num on', 'a.orderCode=on.orderCode')
  2707. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  2708. ->where($where)
  2709. ->order('a.addtime', 'desc')
  2710. ->group("a.good_code")
  2711. ->field("a.good_code 商品编号,a.good_name 产品名称,sum(a.good_num) 当日库存销售,a.is_stock,sum(a.send_num) 当日库存发货,0 当日剩余可用库存,a.supplierName 业务公司,po.good_price 库存采购单价,sum(po.total_fee) 当日库存消耗金额")
  2712. ->cursor();
  2713. $data=[];
  2714. foreach ($list as $value){
  2715. $value['当日剩余可用库存'] = Db::name("good_stock")->where("spuCode",$value['商品编号'])->sum("usable_stock");
  2716. if($value['is_stock']==1){
  2717. $value['库存采购单价'] = Db::name("purchease_order")->where(["spuCode"=>$value['商品编号'],"order_source"=>0])->order('id desc')->value("good_price",0);
  2718. $value['当日库存消耗金额'] = bcmul($value['库存采购单价'],$value['当日库存销售'],2);
  2719. }
  2720. unset($value['is_stock']);
  2721. $data[]= $value;
  2722. }
  2723. if (empty($data)) $data[] = ['没有相关可导出的数据'];
  2724. excelSave('订单报表' . date('YmdHis'), array_keys($data[0]), $data);
  2725. }
  2726. //待库管发货
  2727. public function OutChildList(){
  2728. $param = $this->request->only([
  2729. 'supplierNo' => '',
  2730. 'companyNo' => '',
  2731. 'companyName' => '',
  2732. 'supplier_name' => '',
  2733. 'depart_id' => '',
  2734. 'person_id' => '',
  2735. 'page' => 1,
  2736. 'size' => 15,
  2737. // 'start_day' => date('Y-m-01'),
  2738. // 'end_day' => date('Y-m-t'),
  2739. 'order_start_day' => date('Y-m-01'),
  2740. 'order_end_day' => date('Y-m-t')],
  2741. 'post', 'trim');
  2742. $where = [['a.is_del', '=', 0],["a.status","in",[0,1]]];
  2743. if ($param['depart_id'] != ''){
  2744. $uidArr = get_company_item_user_by_name("",$param['depart_id']);
  2745. $where[] = ['a.apply_id', 'in',$uidArr];
  2746. }
  2747. if($param['person_id'] != '') {
  2748. $where[] = ['c.cgderid', '=',$param['person_id']];
  2749. }
  2750. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  2751. if ($param['supplier_name'] != '') $where[] = ['a.supplierName', 'like', '%' . $param['supplier_name'] . '%'];
  2752. if ($param['companyNo'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  2753. if ($param['companyName'] != '') $where[] = ['a.companyName', 'like', '%' . $param['companyName'] . '%'];
  2754. // if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2755. if ($param['order_start_day'] != '' && $param['order_end_day'] != '') $where[] = ['a.addtime', 'between',
  2756. [$param['order_start_day'] . ' 00:00:00', $param['order_end_day'] . ' 23:59:59']];
  2757. $count = Db::name("order_out_child")->alias("a")->leftJoin('sale c','a.orderCode=c.orderCode')->where($where)->count();
  2758. $list = Db::name("order_out_child")
  2759. ->alias("a")
  2760. ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
  2761. ->leftJoin("sale c","a.orderCode=c.orderCode")
  2762. ->leftJoin("order_send d","a.outCode=d.outCode")
  2763. ->page($param['page'],$param['size'])
  2764. ->where($where)
  2765. ->field("a.outChildCode,a.outCode,a.orderCode,a.supplierNo,a.supplierName,a.companyNo,a.companyName,a.customer_code,a.customer_name,
  2766. a.status,a.order_type,a.order_source,a.num,a.wsm_code,b.name,a.spuCode,a.skuCode,a.good_name,c.addtime,a.apply_name,a.apply_id,c.platform_id,a.post_name,
  2767. a.post_code,a.post_fee,a.addrid,d.cgdNo,c.remark,datediff(now(),a.addtime) sx,b.contactor_name")
  2768. ->select()
  2769. ->toArray();
  2770. $supArr =array_unique( array_column($list,"supplierNo"));
  2771. $platArr =array_unique(array_column($list,"platform_id"));
  2772. $AddrArr =array_unique(array_column($list,"addrid"));
  2773. $applyArr =array_unique(array_column($list,"apply_id"));
  2774. $supp=checkHasAccountBySupplierNos($supArr);
  2775. $preson = get_personid_by_supplierNo($supArr,"person");
  2776. $plafrom = Db::name("platform")->where("id","in",$platArr)->column("use_type","id");
  2777. $addr = Db::name("order_addr")->where("id","in",$AddrArr)->column("addr,addr_code,contactor,mobile","id");
  2778. $depart = get_company_name_by_uid($applyArr);
  2779. // $depart = $applyRe['data']??[];
  2780. foreach ($list as &$value){
  2781. $value['is_supplier'] = isset($supp[$value['supplierNo']])?'已开通':'未开通';
  2782. $value['person'] = $preson[$value['supplierNo']]??"";
  2783. $value['platform_type'] = $plafrom[$value['platform_id']]??"0";
  2784. $value['addr'] = "";
  2785. $value['addr_contactor'] = "";
  2786. $value['addr_mobile'] ="";
  2787. $value['report_sx'] =report_sx($value['sx']);
  2788. if(isset($addr[$value['addrid']])){
  2789. if($addr[$value['addrid']]['addr_code']!=''){
  2790. if (!json_decode($addr[$value['addrid']]['addr_code'])) {
  2791. $temp = explode(',', $addr[$value['addrid']]['addr_code']);
  2792. $addr[$value['addrid']]['addr_code'] = json_encode(['provice_code' => $temp[0] ?? '', 'city_code' => $temp[1] ?? '', 'area_code' => $temp[2] ?? '']);
  2793. }
  2794. $value['addr'] = GetAddr($addr[$value['addrid']]['addr_code']) . $addr[$value['addrid']]['addr'];
  2795. }else{
  2796. $value['addr'] = $addr[$value['addrid']]['addr'];
  2797. }
  2798. $value['addr_contactor'] = $addr[$value['addrid']]['contactor'];
  2799. $value['addr_mobile'] =$addr[$value['addrid']]['mobile'];
  2800. }
  2801. $value['depart']=$depart[$value['apply_id']]??"";
  2802. }
  2803. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  2804. }
  2805. //待库管发货
  2806. public function OutChildExport(){
  2807. $param = $this->request->only([
  2808. 'supplierNo' => '',
  2809. 'companyNo' => '',
  2810. 'companyName' => '',
  2811. 'depart_id' => '',
  2812. 'person_id' => '',
  2813. 'supplier_name' => '',
  2814. // 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t'),
  2815. 'order_start_day' => date('Y-m-01'), 'order_end_day' => date('Y-m-t'),
  2816. ], 'post', 'trim');
  2817. $where = [['a.is_del', '=', 0],["a.status","in",[0,1]]];
  2818. if ($param['depart_id'] != ''){
  2819. $uidArr = get_company_item_user_by_name("",$param['depart_id']);
  2820. $where[] = ['a.apply_id', 'in',$uidArr];
  2821. }
  2822. if($param['person_id'] != '') {
  2823. $where[] = ['c.cgderid', '=',$param['person_id']];
  2824. }
  2825. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  2826. if ($param['supplier_name'] != '') $where[] = ['a.supplierName', 'like', '%' . $param['supplier_name'] . '%'];
  2827. if ($param['companyNo'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  2828. if ($param['companyName'] != '') $where[] = ['a.companyName', 'like', '%' . $param['companyName'] . '%'];
  2829. // if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2830. if ($param['order_start_day'] != '' && $param['order_end_day'] != '') $where[] = ['a.addtime', 'between',
  2831. [$param['order_start_day'] . ' 00:00:00', $param['order_end_day'] . ' 23:59:59']];
  2832. $list = Db::name("order_out_child")
  2833. ->alias("a")
  2834. ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
  2835. ->leftJoin("sale c","a.orderCode=c.orderCode")
  2836. ->leftJoin("order_send d","a.outCode=d.outCode")
  2837. ->where($where)
  2838. ->field("a.outChildCode 发货工单号,a.outCode 发货单编号,a.orderCode 销售订单号,'' 是否开通供应商端,a.status 状态,a.order_type 商品类型,a.order_source 订单来源,
  2839. a.num 总数量,a.wsm_code 仓库编号,b.name 仓库名称,a.spuCode 商品成本编号,a.skuCode 商品上线编号,a.good_name 商品名称,
  2840. a.companyNo 业务公司编号,a.companyName 业务公司名称,a.customer_code 客户编号,a.customer_name 客户名称,a.supplierNo 供应商编号,a.supplierName 供应商名称,
  2841. c.addtime 下单时间,a.apply_name 申请人,a.apply_id 申请人部门,c.platform_id 对接类型,a.post_name 物流公司,a.post_code 物流编号,a.post_fee 物流费用,
  2842. a.addrid,'' 收货地址,'' 收货联系人,'' 联系方式, d.cgdNo 采购单号,c.remark 备注,datediff(now(),a.addtime) 时效,b.contactor_name 仓库负责人,'' 供应商负责人")
  2843. ->select()
  2844. ->toArray();
  2845. $supArr =array_unique( array_column($list,'供应商编号'));
  2846. $platArr =array_unique(array_column($list,'对接类型'));
  2847. $AddrArr =array_unique(array_column($list,'addrid'));
  2848. $applyArr =array_unique(array_column($list,'申请人部门'));
  2849. $supp=checkHasAccountBySupplierNos($supArr);
  2850. $preson = get_personid_by_supplierNo($supArr,"person");
  2851. $plafrom = Db::name("platform")->where("id","in",$platArr)->column("use_type","id");
  2852. $addr = Db::name("order_addr")->where("id","in",$AddrArr)->column("addr,addr_code,contactor,mobile","id");
  2853. $depart = get_company_name_by_uid($applyArr);
  2854. $childstatus = [0=>"待确认",1=>"待发货"];
  2855. foreach ($list as &$value){
  2856. $value['是否开通供应商端'] = isset($supp[$value['供应商编号']])?'已开通':'未开通';
  2857. $value['供应商负责人'] = $preson[$value['供应商编号']]??"";
  2858. $value['对接类型'] =$this->plat_type[$plafrom[$value['对接类型']]??"0"];
  2859. $value['商品类型'] = $this->all_order_type[$value['商品类型']]??"";
  2860. $value['订单来源'] = $this->order_source[$value['订单来源']]??"";
  2861. $value['收货地址'] = "";
  2862. $value['收货联系人'] = "";
  2863. $value['联系方式'] ="";
  2864. $value['时效'] =report_sx($value['时效']);
  2865. $value['状态'] = $childstatus[$value['状态']]??"";
  2866. if(isset($addr[$value['addrid']])){
  2867. if($addr[$value['addrid']]['addr_code']!=''){
  2868. if (!json_decode($addr[$value['addrid']]['addr_code'])) {
  2869. $temp = explode(',', $addr[$value['addrid']]['addr_code']);
  2870. $addr[$value['addrid']]['addr_code'] = json_encode(['provice_code' => $temp[0] ?? '', 'city_code' => $temp[1] ?? '', 'area_code' => $temp[2] ?? '']);
  2871. }
  2872. $value['收货地址'] = GetAddr($addr[$value['addrid']]['addr_code']) . $addr[$value['addrid']]['addr'];
  2873. }else{
  2874. $value['收货地址'] = $addr[$value['addrid']]['addr'];
  2875. }
  2876. $value['收货联系人'] = $addr[$value['addrid']]['contactor'];
  2877. $value['联系方式'] =$addr[$value['addrid']]['mobile'];
  2878. }
  2879. $value['申请人部门']=$depart[$value['申请人部门']]??"";
  2880. unset($value['addrid']);
  2881. }
  2882. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  2883. excelSave('订单报表' . date('YmdHis'), array_keys($list[0]), $list);
  2884. }
  2885. //待采购备货
  2886. public function OrderOutBk(){
  2887. $param = $this->request->only([
  2888. 'supplierNo' => '',
  2889. 'companyNo' => '',
  2890. 'companyName' => '',
  2891. 'supplier_name' => '',
  2892. 'depart_id' => '',
  2893. 'person_id' => '',
  2894. 'page' => 1,
  2895. 'size' => 15,
  2896. 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2897. $where = [['a.is_del', '=', 0],['a.status', '=', 0]];
  2898. if ($param['supplierNo'] != '') $where[] = ['b.supNo', 'like', '%' . $param['supplierNo'] . '%'];
  2899. if ($param['supplier_name'] != '') $where[] = ['b.supName', 'like', '%' . $param['supplier_name'] . '%'];
  2900. if ($param['companyNo'] != '') $where[] = ['b.supplierNo', 'like', '%' . $param['companyNo'] . '%'];
  2901. if ($param['companyName'] != '') $where[] = ['b.supplierName', 'like', '%' . $param['companyName'] . '%'];
  2902. if ($param['depart_id'] != ''){
  2903. $uidArr = get_company_item_user_by_name("",$param['depart_id']);
  2904. $where[] = ['a.apply_id', 'in',$uidArr];
  2905. }
  2906. if($param['person_id'] != '') {
  2907. $where[] = ['b.cgderid', '=',$param['person_id']];
  2908. }
  2909. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2910. $count= Db::name("order_out")->alias("a")
  2911. ->leftJoin("sale b","a.orderCode=b.orderCode")
  2912. ->leftJoin("order_num c","a.orderCode = c.orderCode")
  2913. ->leftJoin("order_addr d","a.addrid = d.id")->where($where)->count("a.id");
  2914. $list =Db::name("order_out")->alias("a")
  2915. ->leftJoin("sale b","a.orderCode=b.orderCode")
  2916. ->leftJoin("order_num c","a.orderCode = c.orderCode")
  2917. ->leftJoin("order_addr d","a.addrid = d.id")
  2918. ->field("a.outCode,a.orderCode,c.cgdNo,a.send_num,b.platform_id,a.status,b.order_type,b.order_source,supName,b.cat_id,b.good_code,b.good_name
  2919. ,b.customerName,b.customer_code,b.supplierName,b.supplierNo,d.contactor,d.mobile,a.post_name,a.post_code,a.post_fee,'' send_time,
  2920. a.apply_id,a.apply_name,a.addtime,b.addtime createdTime,datediff(now(),a.addtime) sx,b.cgder")
  2921. ->page($param['page'],$param['size'])
  2922. ->where($where)
  2923. ->select()->toArray();
  2924. $data=[];
  2925. $platArr =array_unique(array_column($list,"platform_id"));
  2926. $applyArr = array_unique(array_column($list,"apply_id")) ;
  2927. $catArr =array_column($list,"cat_id");
  2928. $plafrom = Db::name("platform")->where("id","in",$platArr)->column("use_type","id");
  2929. $cat = Db::name("cat")->where("id","in",$catArr)->column("search","id");
  2930. $depart= get_company_name_by_uid($applyArr);
  2931. // $depart = $applyRe['data']??[];
  2932. foreach ($list as $item) {
  2933. $item['platform_type'] = $this->plat_type[$plafrom[$item['platform_id']]??0];
  2934. $item['depart'] = $depart[$item['apply_id']]??"";
  2935. $item['order_source'] = $this->order_source[$item['order_source']]??"";
  2936. $item['order_type'] = $this->all_order_type[$item['order_type']]??"";
  2937. $item['cat_name'] = $cat[$item['cat_id']]??"";
  2938. $item['report_sx'] =report_sx($item['sx']);
  2939. $data[]=$item;
  2940. }
  2941. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  2942. }
  2943. //待采购备货
  2944. public function OrderOutExport(){
  2945. $param = $this->request->only([
  2946. 'supplierNo' => '',
  2947. 'companyNo' => '',
  2948. 'companyName' => '',
  2949. "depart_id"=>"",
  2950. "person_id"=>"",
  2951. 'supplier_name' => '',
  2952. 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  2953. $where = [['a.is_del', '=', 0],['a.status', '=', 0]];
  2954. if ($param['supplierNo'] != '') $where[] = ['b.supNo', 'like', '%' . $param['supplierNo'] . '%'];
  2955. if ($param['supplier_name'] != '') $where[] = ['b.supName', 'like', '%' . $param['supplier_name'] . '%'];
  2956. if ($param['companyNo'] != '') $where[] = ['b.supplierNo', 'like', '%' . $param['companyNo'] . '%'];
  2957. if ($param['companyName'] != '') $where[] = ['b.supplierName', 'like', '%' . $param['companyName'] . '%'];
  2958. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  2959. if ($param['depart_id'] != ''){
  2960. $uidArr = get_company_item_user_by_name("",$param['depart_id']);
  2961. $where[] = ['a.apply_id', 'in',$uidArr];
  2962. }
  2963. if($param['person_id'] != '') {
  2964. $where[] = ['b.cgderid', '=',$param['person_id']];
  2965. }
  2966. $list =Db::name("order_out")->alias("a")
  2967. ->leftJoin("sale b","a.orderCode=b.orderCode")
  2968. ->leftJoin("order_num c","a.orderCode = c.orderCode")
  2969. ->leftJoin("order_addr d","a.addrid = d.id")
  2970. ->field("
  2971. a.outCode 发货单编号,
  2972. a.orderCode 订单编号,
  2973. c.cgdNo 采购单编号,
  2974. a.send_num 发货数量,
  2975. b.platform_id 平台类型,
  2976. a.status 状态,
  2977. b.order_type 商品类型,
  2978. b.order_source 订单来源,
  2979. supName 供应商,
  2980. b.cat_id 商品分类,
  2981. b.good_code 商品编号,
  2982. b.good_name 商品名称,
  2983. b.customerName 客户名称,
  2984. b.customer_code 客户编号,
  2985. b.supplierName 业务公司名称,
  2986. b.supplierNo 业务公司编号,
  2987. d.contactor 收货联系人,
  2988. d.mobile 联系方式,
  2989. a.post_name 快递公司,
  2990. a.post_code 快递编号,
  2991. a.post_fee 快递费用,
  2992. '' 发货时间,
  2993. a.apply_id 申请人部门,
  2994. a.apply_name 申请人,
  2995. a.addtime 添加时间,
  2996. b.addtime 下单日期,
  2997. datediff(now(),a.addtime) 时效,
  2998. b.cgder 供应商负责人")
  2999. ->where($where)
  3000. ->cursor();
  3001. $data=[];
  3002. // $platArr =array_column($list,"平台类型");
  3003. // $applyArr =array_column($list,"申请人部门");
  3004. // $catArr =array_column($list,"商品分类");
  3005. // $plafrom = Db::name("platform")->where("id",'in',$platArr)->column("use_type","id");
  3006. // $cat = Db::name("cat")->where("id",'in',$catArr)->column("search","id");
  3007. // $depart = get_company_name_by_uid($applyArr);
  3008. $depart=[];
  3009. $cat=[];
  3010. $plafrom=[];
  3011. foreach ($list as $item) {
  3012. if(!isset($depart[$item['申请人部门']])){
  3013. $temp=get_company_name_by_uid($item['申请人部门']);
  3014. $depart[$item['申请人部门']]=$temp;
  3015. }
  3016. if(!isset($cat[$item['商品分类']])){
  3017. $cat[$item['商品分类']]= Db::name("cat")->where("id",$item['商品分类'])->value("search","");
  3018. }
  3019. if(!isset($plafrom[$item['平台类型']])){
  3020. $plafrom[$item['平台类型']]= Db::name("platform")->where("id",$item['平台类型'])->value("use_type","0");
  3021. }
  3022. $item['平台类型'] = $this->plat_type[$plafrom[$item['平台类型']]];
  3023. $item['申请人部门'] = $depart[$item['申请人部门']]??"";
  3024. $item['状态'] = $this->order_out_status[$item['状态']]??"";
  3025. $item['订单来源'] = $this->order_source[$item['订单来源']]??"";
  3026. $item['商品类型'] = $this->all_order_type[$item['商品类型']]??"";
  3027. $item['商品分类'] = $cat[$item['商品分类']]??"";
  3028. $item['时效'] =report_sx($item['时效']);
  3029. $data[]=$item;
  3030. }
  3031. if (empty($data)) $data[] = ['没有相关可导出的数据'];
  3032. excelSave('订单报表' . date('YmdHis'), array_keys($data[0]), $data);
  3033. }
  3034. }