SaleReport.php 154 KB

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