SaleReportByRelaComNo.php 161 KB

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