SaleReport.php 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477
  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('ci.is_del', 0)
  33. ->whereBetween('ci.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  34. ->group('co.createrid,co.creater')
  35. ->column('COUNT(ci.id) 当日咨询单数量,SUM(ci.budget_price*ci.num) 金额,co.creater 创建人', 'co.createrid');
  36. $rs_2 = Db::name('sale')
  37. ->where('is_del', 0)
  38. ->whereBetween('addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  39. ->group('apply_id,apply_name')
  40. ->column('COUNT(id) 当日下单数量,SUM(total_price) 金额,apply_name 创建人', 'apply_id');
  41. $rs_3 = Db::name('order_out')
  42. ->alias('oo')
  43. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  44. ->where(['oo.status' => 3])
  45. ->whereBetween('oo.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  46. ->group('oo.apply_id,oo.apply_name')
  47. ->column('COUNT(oo.id) 当日签收数量,SUM(s.total_price) 金额,oo.apply_name 创建人', 'oo.apply_id');
  48. $rs_4 = Db::name('order_return')
  49. ->alias('or')
  50. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  51. ->where(['or.is_del' => 0])
  52. ->whereBetween('or.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  53. ->group('or.apply_id,or.apply_name')
  54. ->column('COUNT(or.id) 单日售后单数,SUM(s.total_price) 金额,or.apply_name 创建人', 'or.apply_id');
  55. $all_ids = array_unique(array_merge(array_keys($rs_1), array_keys($rs_2), array_keys($rs_3), array_keys($rs_4)));
  56. $list = [];
  57. foreach ($all_ids as $id) {
  58. $val = [];
  59. if (isset($rs_1[$id]['创建人'])) $val['creater'] = $rs_1[$id]['创建人'];
  60. elseif (isset($rs_2[$id]['创建人'])) $val['creater'] = $rs_2[$id]['创建人'];
  61. elseif (isset($rs_3[$id]['创建人'])) $val['creater'] = $rs_3[$id]['创建人'];
  62. elseif (isset($rs_4[$id]['创建人'])) $val['creater'] = $rs_4[$id]['创建人'];
  63. else $val['creater'] = '';
  64. $val['creater_company'] = get_company_name_by_uid($id);//获取创建人的所属部门
  65. $val['consult_num'] = isset($rs_1[$id]['当日咨询单数量']) ? $rs_1[$id]['当日咨询单数量'] : '';
  66. $val['consult_money'] = isset($rs_1[$id]['金额']) ? $rs_1[$id]['金额'] : '';
  67. $val['sale_num'] = isset($rs_2[$id]['当日下单数量']) ? $rs_2[$id]['当日下单数量'] : '';
  68. $val['sale_money'] = isset($rs_2[$id]['金额']) ? $rs_2[$id]['金额'] : '';
  69. $val['receipt_num'] = isset($rs_3[$id]['当日签收数量']) ? $rs_3[$id]['当日签收数量'] : '';
  70. $val['receipt_money'] = isset($rs_3[$id]['金额']) ? $rs_3[$id]['金额'] : '';
  71. $val['invoice_num'] = '';
  72. $val['invoice_money'] = '';
  73. $val['after_sales_num'] = isset($rs_4[$id]['单日售后单数']) ? $rs_4[$id]['单日售后单数'] : '';
  74. $val['after_sales_money'] = isset($rs_4[$id]['金额']) ? $rs_4[$id]['金额'] : '';
  75. $val['payment_num'] = '';
  76. $val['payment_money'] = '';
  77. $list[] = $val;
  78. }
  79. return app_show(0, '请求成功', ['list' => $list]);
  80. }
  81. //【一、管理报表】1.日报_导出
  82. public function consultDayExport()
  83. {
  84. $param = $this->request->only(['token', 'date' => date('Y-m-d')], 'post', 'trim');
  85. $rs_1 = Db::name('consult_info')
  86. ->alias('ci')
  87. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  88. ->where('ci.is_del', 0)
  89. ->whereBetween('ci.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  90. ->group('co.createrid,co.creater')
  91. ->column('COUNT(ci.id) 当日咨询单数量,SUM(ci.budget_price*ci.num) 金额,co.creater 创建人', 'co.createrid');
  92. $rs_2 = Db::name('sale')
  93. ->where('is_del', 0)
  94. ->whereBetween('addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  95. ->group('apply_id,apply_name')
  96. ->column('COUNT(id) 当日下单数量,SUM(total_price) 金额,apply_name 创建人', 'apply_id');
  97. $rs_3 = Db::name('order_out')
  98. ->alias('oo')
  99. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  100. ->where(['oo.status' => 3])
  101. ->whereBetween('oo.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  102. ->group('oo.apply_id,oo.apply_name')
  103. ->column('COUNT(oo.id) 当日签收数量,SUM(s.total_price) 金额,oo.apply_name 创建人', 'oo.apply_id');
  104. $rs_4 = Db::name('order_return')
  105. ->alias('or')
  106. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  107. ->where(['or.is_del' => 0])
  108. ->whereBetween('or.addtime', [$param['date'] . ' 00:00:00', $param['date'] . ' 23:59:59'])
  109. ->group('or.apply_id,or.apply_name')
  110. ->column('COUNT(or.id) 单日售后单数,SUM(s.total_price) 金额,or.apply_name 创建人', 'or.apply_id');
  111. $all_ids = array_unique(array_merge(array_keys($rs_1), array_keys($rs_2), array_keys($rs_3), array_keys($rs_4)));
  112. $list = [];
  113. foreach ($all_ids as $id) {
  114. $val = [];
  115. if (isset($rs_1[$id]['创建人'])) $val['创建人'] = $rs_1[$id]['创建人'];
  116. elseif (isset($rs_2[$id]['创建人'])) $val['创建人'] = $rs_2[$id]['创建人'];
  117. elseif (isset($rs_3[$id]['创建人'])) $val['创建人'] = $rs_3[$id]['创建人'];
  118. elseif (isset($rs_4[$id]['创建人'])) $val['创建人'] = $rs_4[$id]['创建人'];
  119. else $val['创建人'] = '';
  120. $val['创建人部门'] = get_company_name_by_uid($id);//获取创建人的所属部门
  121. $val['当日咨询单数量'] = isset($rs_1[$id]['当日咨询单数量']) ? $rs_1[$id]['当日咨询单数量'] : '';
  122. $val['当日咨询单金额'] = isset($rs_1[$id]['金额']) ? $rs_1[$id]['金额'] : '';
  123. $val['当日下单数量'] = isset($rs_2[$id]['当日下单数量']) ? $rs_2[$id]['当日下单数量'] : '';
  124. $val['当日下单金额'] = isset($rs_2[$id]['金额']) ? $rs_2[$id]['金额'] : '';
  125. $val['当日签收数量'] = isset($rs_3[$id]['当日签收数量']) ? $rs_3[$id]['当日签收数量'] : '';
  126. $val['当日签收金额'] = isset($rs_3[$id]['金额']) ? $rs_3[$id]['金额'] : '';
  127. $val['当日申报发票数量'] = '';
  128. $val['当日申报发票金额'] = '';
  129. $val['单日售后单数'] = isset($rs_4[$id]['单日售后单数']) ? $rs_4[$id]['单日售后单数'] : '';
  130. $val['单日售后金额'] = isset($rs_4[$id]['金额']) ? $rs_4[$id]['金额'] : '';
  131. $val['当日回款单数'] = '';
  132. $val['当日回款金额'] = '';
  133. $list[] = $val;
  134. }
  135. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  136. excelSave('咨询单报表' . date('YmdHis'), array_keys($list[0]), $list);
  137. }
  138. //【一、管理报表】2.竞价反馈报表
  139. public function consultInfo()
  140. {
  141. $param = $this->request->only([
  142. 'token',
  143. 'start_date' => '',
  144. 'end_date' => '',
  145. 'page' => 1,
  146. 'size' => 15,
  147. ], 'post', 'trim');
  148. $where = [['ci.is_del', '=', 0]];
  149. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  150. $count = Db::name('consult_info')
  151. ->alias('ci')
  152. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  153. ->leftJoin('unit u', 'u.id=ci.unit')
  154. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  155. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  156. ->where($where)
  157. ->order('ci.addtime', 'desc')
  158. ->count('ci.id');
  159. $data = Db::name('consult_info')
  160. ->alias('ci')
  161. ->field('co.creater,ci.addtime,ci.infoNo,cb.bidNo,csi.companyName,ci.good_name,ci.num,u.unit,ci.budget_price,cb.id bid_id,ci.status,csi.itemid,co.createrid')
  162. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  163. ->leftJoin('unit u', 'u.id=ci.unit')
  164. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  165. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  166. ->where($where)
  167. ->page($param['page'], $param['size'])
  168. ->order('ci.addtime', 'desc')
  169. ->cursor();
  170. $list = $customer_tmp = $company_tmp = [];
  171. foreach ($data as $value) {
  172. $value['total_fee'] = round($value['budget_price'] * $value['num'], 2);
  173. $value['is_bids'] = is_null($value['bid_id']) ? '否' : '是';
  174. $value['is_zhuandan'] = $value['status'] == 5 ? '是' : '否';//5成功转单
  175. if (!empty($value['itemid'])) {
  176. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  177. $value['first_customer_org'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  178. $value['second_customer_org'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  179. }
  180. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  181. $value['creater_company'] = $company_tmp[$value['createrid']] ?? '';
  182. $list[] = $value;
  183. }
  184. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  185. }
  186. //【一、管理报表】2.竞价反馈报表_导出
  187. public function consultInfoExport()
  188. {
  189. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  190. $where = [['ci.is_del', '=', 0]];
  191. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  192. $data = Db::name('consult_info')
  193. ->alias('ci')
  194. ->field('co.creater 创建人,"" 创建人部门,ci.addtime 竞价时间,ci.infoNo 竞价单号,cb.bidNo 反馈编号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,ci.good_name 产品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,cb.id 是否采反,ci.status 是否转单,csi.itemid,co.createrid')
  195. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  196. ->leftJoin('unit u', 'u.id=ci.unit')
  197. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  198. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
  199. ->where($where)
  200. ->order('ci.addtime', 'desc')
  201. ->cursor();
  202. $list = $customer_tmp = $company_tmp = [];
  203. foreach ($data as $value) {
  204. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  205. $value['创建人部门'] = $company_tmp[$value['createrid']] ?? '';
  206. $value['金额'] = round($value['单价'] * $value['数量'], 2);
  207. $value['是否采反'] = is_null($value['是否采反']) ? '否' : '是';
  208. $value['是否转单'] = $value['是否转单'] == 5 ? '是' : '否';//5成功转单
  209. if (!empty($value['itemid'])) {
  210. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  211. $value['一级企业'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  212. $value['二级企业'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  213. }
  214. unset($value['createrid']);
  215. unset($value['itemid']);
  216. $list[] = $value;
  217. }
  218. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  219. excelSave('竞价反馈报表' . date('YmdHis'), array_keys($list[0]), $list);
  220. }
  221. //【一、管理报表】2.1.竞价单报表
  222. public function consultInfoNew()
  223. {
  224. $param = $this->request->only([
  225. 'token',
  226. 'start_date' => '',
  227. 'end_date' => '',
  228. 'page' => 1,
  229. 'size' => 15,
  230. ], 'post', 'trim');
  231. $where = [['ci.is_del', '=', 0]];
  232. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  233. $count = Db::name('consult_info')
  234. ->alias('ci')
  235. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  236. ->leftJoin('unit u', 'u.id=ci.unit')
  237. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  238. ->where($where)
  239. ->order('ci.addtime', 'desc')
  240. ->count('ci.id');
  241. $data = Db::name('consult_info')
  242. ->alias('ci')
  243. ->field('co.creater,ci.addtime,ci.infoNo,csi.companyName,ci.good_name,ci.num,u.unit,ci.budget_price,ci.status,csi.itemid,co.createrid')
  244. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  245. ->leftJoin('unit u', 'u.id=ci.unit')
  246. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  247. ->where($where)
  248. ->page($param['page'], $param['size'])
  249. ->order('ci.addtime', 'desc')
  250. ->cursor();
  251. $list = $customer_tmp = $company_tmp = [];
  252. foreach ($data as $value) {
  253. $value['total_fee'] = round($value['budget_price'] * $value['num'], 2);
  254. $value['is_zhuandan'] = $value['status'] == 5 ? '是' : '否';//5成功转单
  255. if (!empty($value['itemid'])) {
  256. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  257. $value['first_customer_org'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  258. $value['second_customer_org'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  259. }
  260. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  261. $value['creater_company'] = $company_tmp[$value['createrid']] ?? '';
  262. $list[] = $value;
  263. }
  264. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  265. }
  266. //【一、管理报表】2.1.竞价单报表_导出
  267. public function consultInfoNewExport()
  268. {
  269. $param = $this->request->only([
  270. 'token',
  271. 'start_date' => '',
  272. 'end_date' => '',
  273. ], 'post', 'trim');
  274. $where = [['ci.is_del', '=', 0]];
  275. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  276. $data = Db::name('consult_info')
  277. ->alias('ci')
  278. ->field('co.creater 创建人,"" 创建人部门,ci.addtime 竞价时间,ci.infoNo 竞价单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,ci.good_name 产品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,ci.status 是否转单,csi.itemid,co.createrid')
  279. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  280. ->leftJoin('unit u', 'u.id=ci.unit')
  281. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  282. ->where($where)
  283. ->order('ci.addtime', 'desc')
  284. ->cursor();
  285. $list = $customer_tmp = $company_tmp = [];
  286. foreach ($data as $value) {
  287. if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
  288. $value['创建人部门'] = $company_tmp[$value['createrid']] ?? '';
  289. $value['金额'] = round($value['单价'] * $value['数量'], 2);
  290. $value['是否转单'] = $value['是否转单'] == 5 ? '是' : '否';//5成功转单
  291. if (!empty($value['itemid'])) {
  292. if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  293. $value['一级企业'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
  294. $value['二级企业'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
  295. }
  296. unset($value['createrid']);
  297. unset($value['itemid']);
  298. $list[] = $value;
  299. }
  300. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  301. excelSave('竞价单报表' . date('YmdHis'), array_keys($list[0]), $list);
  302. }
  303. //【一、管理报表】3.订单报表
  304. public function saleList()
  305. {
  306. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  307. $where = [['s.is_del', '=', 0]];
  308. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  309. $count = Db::name('sale')
  310. ->alias('s')
  311. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  312. ->where($where)
  313. ->count('s.id');
  314. $data = Db::name('sale')
  315. ->alias('s')
  316. ->field('s.apply_name,s.addtime,s.orderCode,csi.companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.is_stock,s.order_type,csi.itemid,s.good_code,s.apply_id,s.cat_id,s.pay_id')
  317. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  318. ->where($where)
  319. ->page($param['page'], $param['size'])
  320. ->order('s.addtime', 'desc')
  321. ->cursor();
  322. $list = $cat_tmp = [];
  323. foreach ($data as $value) {
  324. if (!empty($value['itemid'])) {
  325. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  326. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  327. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  328. }
  329. if ($value['order_type'] == 3) $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');
  330. 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');
  331. $value['is_stock'] = isset($this->all_stock[$value['is_stock']]) ? $this->all_stock[$value['is_stock']] : '';
  332. $value['order_type'] = isset($this->all_order_type[$value['order_type']]) ? $this->all_order_type[$value['order_type']] : '';
  333. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  334. $value['pay_id'] = Db::name("pay")->where(["id"=>$value['pay_id']])->value("pay_name",'');
  335. if (!isset($cat_tmp[$value['cat_id']])) $cat_tmp[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
  336. $value['cat_name'] = $cat_tmp[$value['cat_id']] ?? '';
  337. $list[] = $value;
  338. }
  339. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  340. }
  341. //【一、管理报表】3.订单报表_导出
  342. public function saleExport()
  343. {
  344. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  345. $where = [['s.is_del', '=', 0]];
  346. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  347. $data = Db::name('sale')
  348. ->alias('s')
  349. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,s.is_stock 是否库存,s.order_type 订单类型,csi.itemid,s.good_code,s.apply_id,s.cat_id')
  350. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  351. ->where($where)
  352. ->order('s.addtime', 'desc')
  353. ->cursor();
  354. $list = $tmp_customer = $tmp_item = $cat_tmp = [];
  355. foreach ($data as $value) {
  356. if (!empty($value['itemid'])) {
  357. if (!isset($tmp_customer[$value['itemid']])) $tmp_customer[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  358. // $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  359. $value['一级企业'] = isset($tmp_customer[$value['itemid']][1]) ? $tmp_customer[$value['itemid']][1] : '';
  360. $value['二级企业'] = isset($tmp_customer[$value['itemid']][2]) ? $tmp_customer[$value['itemid']][2] : '';
  361. }
  362. if ($value['订单类型'] == 3 || $value['订单类型'] == 4) {
  363. $value['单位'] = Db::name("good_zixun")
  364. ->alias('gz')
  365. ->leftJoin('unit u', 'u.id=gz.good_unit')
  366. ->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])
  367. ->value('u.unit');
  368. } else {
  369. $value['单位'] = Db::name('good_basic')
  370. ->alias('gb')
  371. ->leftJoin('unit u', 'u.id=gb.good_unit')
  372. ->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])
  373. ->value('u.unit');
  374. }
  375. $value['是否库存'] = isset($this->all_stock[$value['是否库存']]) ? $this->all_stock[$value['是否库存']] : '';
  376. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  377. if (!isset($tmp_item[$value['apply_id']])) $tmp_item[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
  378. $value['创建人所属部门'] = $tmp_item[$value['apply_id']];//获取创建人的所属部门
  379. if (!isset($cat_tmp[$value['cat_id']])) $cat_tmp[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
  380. $value['分类'] = $cat_tmp[$value['cat_id']] ?? '';
  381. unset($value['itemid']);
  382. unset($value['apply_id']);
  383. unset($value['good_code']);
  384. unset($value['cat_id']);
  385. $list[] = $value;
  386. }
  387. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  388. excelSave('订单报表' . date('YmdHis'), array_keys($list[0]), $list);
  389. }
  390. //【一、管理报表】4.未发货报表_列表
  391. public function saleNotOut()
  392. {
  393. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_arrive_date' => '', 'end_arrive_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  394. $where = [['s.is_del', '=', 0], ['out.status', '=', 1]];
  395. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  396. 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']];
  397. $count = Db::name('sale')
  398. ->alias('s')
  399. ->field('s.apply_name,s.addtime,s.orderCode,csi.companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.arrive_time,csi.itemid,s.good_code,s.order_type,s.apply_id')
  400. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  401. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  402. ->where($where)
  403. ->order('s.addtime', 'desc')
  404. ->count('s.id');
  405. $data = Db::name('sale')
  406. ->alias('s')
  407. ->field('s.apply_name,s.addtime,s.orderCode,csi.companyName,s.good_name,s.good_num,s.sale_price,s.total_price,s.arrive_time,csi.itemid,s.good_code,s.order_type,s.apply_id')
  408. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  409. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  410. ->where($where)
  411. ->page($param['page'], $param['size'])
  412. ->order('s.addtime', 'desc')
  413. ->cursor();
  414. $list = [];
  415. foreach ($data as $value) {
  416. if (!empty($value['itemid'])) {
  417. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  418. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  419. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  420. }
  421. if ($value['order_type'] == 3) {
  422. $value['unit'] = Db::name("good_zixun")
  423. ->alias('gz')
  424. ->leftJoin('unit u', 'u.id=gz.good_unit')
  425. ->where(["gz.spuCode" => $value['good_code'], "gz.is_del" => 0])
  426. ->value('u.unit');
  427. } else {
  428. $value['unit'] = Db::name('good_basic')
  429. ->alias('gb')
  430. ->leftJoin('unit u', 'u.id=gb.good_unit')
  431. ->where(["gb.spuCode" => $value['good_code'], "gb.is_del" => 0])
  432. ->value('u.unit');
  433. }
  434. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  435. $list[] = $value;
  436. }
  437. return app_show(0, '请求成功', ['count' => $count, 'list' => $list]);
  438. }
  439. //【一、管理报表】4.未发货报表_导出
  440. public function saleNotOutExport()
  441. {
  442. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_arrive_date' => '', 'end_arrive_date' => ''], 'post', 'trim');
  443. $where = [['s.is_del', '=', 0], ['out.status', '=', 1]];
  444. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  445. 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']];
  446. $data = Db::name('sale')
  447. ->alias('s')
  448. ->field('s.apply_name 创建人,"" 创建人所属部门,s.addtime 下单时间,s.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,s.good_name 商品名称,s.good_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,s.arrive_time 承诺发货时间,csi.itemid,s.good_code,s.order_type,s.apply_id')
  449. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  450. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  451. ->where($where)
  452. ->order('s.addtime', 'desc')
  453. ->cursor();
  454. $list = [];
  455. foreach ($data as $value) {
  456. if (!empty($value['itemid'])) {
  457. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  458. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  459. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  460. }
  461. if ($value['order_type'] == 3) $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');
  462. 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');
  463. $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  464. unset($value['itemid']);
  465. unset($value['good_code']);
  466. unset($value['order_type']);
  467. unset($value['apply_id']);
  468. $list[] = $value;
  469. }
  470. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  471. excelSave('未发货报表' . date('YmdHis'), array_keys($list[0]), $list);
  472. }
  473. //【一、管理报表】5.未签收报表
  474. public function saleNotSigned()
  475. {
  476. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  477. $where = [['oo.is_del', '=', 0], ['oo.status', '=', 2], ['s.is_del', '=', 0]];
  478. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  479. $count = Db::name('order_out')
  480. ->alias('oo')
  481. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  482. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  483. // ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  484. ->where($where)
  485. ->count('oo.id');
  486. $data = Db::name('order_out')
  487. ->alias('oo')
  488. ->field('oo.id,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')
  489. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  490. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  491. // ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  492. ->where($where)
  493. ->page($param['page'], $param['size'])
  494. ->order('s.addtime', 'desc')
  495. ->cursor();
  496. $list = [];
  497. foreach ($data as $value) {
  498. if (!empty($value['itemid'])) {
  499. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  500. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  501. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  502. }
  503. if ($value['order_type'] == 3) $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');
  504. 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');
  505. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  506. $list[] = $value;
  507. }
  508. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  509. }
  510. //【一、管理报表】5.未签收报表_导出
  511. public function saleNotSignedExport()
  512. {
  513. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  514. $where = [['s.is_del', '=', 0], ['oo.status', '=', 2]];
  515. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  516. // $data = Db::name('order_out')
  517. // ->alias('oo')
  518. // ->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')
  519. // ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  520. // ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  521. // ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  522. // ->where($where)
  523. // ->order('s.addtime', 'desc')
  524. // ->cursor('oo.id');
  525. // $list = [];
  526. // foreach ($data as $value) {
  527. //
  528. // if (!empty($value['itemid'])) {
  529. // $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  530. // $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  531. // $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  532. // }
  533. //
  534. // 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');
  535. // 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');
  536. //
  537. // $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  538. //
  539. // unset($value['itemid']);
  540. // unset($value['good_code']);
  541. // unset($value['order_type']);
  542. // unset($value['apply_id']);
  543. //
  544. // $list[] = $value;
  545. // }
  546. $list = $this->saleNotSignedExportTemp($where);
  547. excelSave('未签收报表' . date('YmdHis'), ['创建人', '创建人所属部门', '下单时间', '订单号', '一级企业', '二级企业', '客户名称', '商品名称', '数量', '单位', '单价', '金额', '发货时间'], $list);
  548. }
  549. //针对"【一、管理报表】5.未签收报表_导出"数据量太大
  550. private function saleNotSignedExportTemp(array $where = [])
  551. {
  552. $data = Db::name('order_out')
  553. ->alias('oo')
  554. ->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')
  555. ->leftJoin('sale s', 's.orderCode=oo.orderCode')
  556. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  557. ->leftJoin('order_out out', 'out.orderCode=s.orderCode AND out.is_del=0')
  558. ->where($where)
  559. ->order('s.addtime', 'desc')
  560. ->cursor();
  561. foreach ($data as $value) {
  562. if (!empty($value['itemid'])) {
  563. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  564. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  565. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  566. }
  567. if ($value['order_type'] == 3) $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');
  568. 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');
  569. $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  570. unset($value['itemid']);
  571. unset($value['good_code']);
  572. unset($value['order_type']);
  573. unset($value['apply_id']);
  574. yield $value;
  575. }
  576. }
  577. //【一、管理报表】6.售后报表
  578. public function orderReturn()
  579. {
  580. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  581. $where = [['or.is_del', '=', 0]];
  582. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  583. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  584. $count = Db::name('order_return')
  585. ->alias('or')
  586. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  587. ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  588. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  589. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  590. ->where($where)
  591. ->count('or.id');
  592. $data = Db::name('order_return')
  593. ->alias('or')
  594. ->field('or.addtime,or.apply_name,or.orderCode,csi.companyName,or.good_name,or.total_num,s.sale_price,s.total_price,or.updatetime,ri.result,or.status,csi.itemid,or.good_code,or.order_type,or.apply_id')
  595. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  596. ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  597. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  598. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  599. ->where($where)
  600. ->page($param['page'], $param['size'])
  601. ->order('s.addtime', 'desc')
  602. ->cursor();
  603. $list = [];
  604. foreach ($data as $value) {
  605. if (!empty($value['itemid'])) {
  606. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  607. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  608. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  609. }
  610. $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  611. 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');
  612. 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');
  613. $value['is_finish'] = $value['status'] == 5 ? '已完结' : '未完结';
  614. $value['status'] = isset($this->all_order_return_status[$value['status']]) ? $this->all_order_return_status[$value['status']] : '';
  615. $list[] = $value;
  616. }
  617. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  618. }
  619. //【一、管理报表】6.售后报表_导出
  620. public function orderReturnExport()
  621. {
  622. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => ''], 'post', 'trim');
  623. $where = [['or.is_del', '=', 0]];
  624. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  625. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  626. $data = Db::name('order_return')
  627. ->alias('or')
  628. ->field('or.addtime 售后时间,or.apply_name 创建人,"" 创建人部门,or.orderCode 订单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,or.good_name 商品名称,or.total_num 数量,"" 单位,s.sale_price 单价,s.total_price 金额,or.updatetime 签收时间,ri.result 异常原因,or.status 异常状态,"" 是否完结,csi.itemid,or.good_code,or.order_type,or.apply_id')
  629. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  630. ->leftJoin('customer_info csi', 'csi.companyNo=or.customer_code')
  631. ->leftJoin('order_out out', 'out.orderCode=s.orderCode')
  632. ->leftJoin('result_info ri', 'ri.id=or.error_code')
  633. ->where($where)
  634. ->order('s.addtime', 'desc')
  635. ->cursor();
  636. $list = [];
  637. foreach ($data as $value) {
  638. if (!empty($value['itemid'])) {
  639. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  640. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  641. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  642. }
  643. 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');
  644. 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');
  645. $value['创建人部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
  646. $value['是否完结'] = $value['异常状态'] == 5 ? '已完结' : '未完结';
  647. $value['异常状态'] = isset($this->all_order_return_status[$value['异常状态']]) ? $this->all_order_return_status[$value['异常状态']] : '';
  648. unset($value['itemid']);
  649. unset($value['good_code']);
  650. unset($value['order_type']);
  651. unset($value['apply_id']);
  652. $list[] = $value;
  653. }
  654. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  655. excelSave('售后报表' . date('YmdHis'), array_keys($list[0]), $list);
  656. }
  657. //【一、管理报表】7.产品热销排行
  658. public function goodRankingList()
  659. {
  660. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  661. $where = [['s.is_del', '=', 0]];
  662. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  663. $count = Db::name('sale')
  664. ->alias('s')
  665. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  666. ->where($where)
  667. ->group('s.good_code,s.good_name,csi.itemid,s.cat_id')
  668. ->count('s.id');
  669. $data = Db::name('sale')
  670. ->alias('s')
  671. ->field('s.good_code,s.good_name,SUM(s.good_num) total_num,SUM(s.total_price) total_price,csi.itemid,s.cat_id')
  672. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  673. ->where($where)
  674. ->group('s.good_code,s.good_name,csi.itemid,s.cat_id')
  675. ->page($param['page'], $param['size'])
  676. ->order('total_num', 'desc')
  677. ->cursor();
  678. $list = [];
  679. foreach ($data as $value) {
  680. if (!empty($value['itemid'])) {
  681. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  682. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  683. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  684. }
  685. $value['cat'] = implode('/', array_column(made($value['cat_id']), 'name'));
  686. $list[] = $value;
  687. }
  688. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  689. }
  690. //【一、管理报表】7.产品热销排行_导出
  691. public function goodRankingListExport()
  692. {
  693. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  694. $where = [['s.is_del', '=', 0]];
  695. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['s.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  696. $data = Db::name('sale')
  697. ->alias('s')
  698. ->field('s.good_code,"" 产品品类,s.good_name 产品名称,SUM(s.good_num) total_num,"" 数量,SUM(s.total_price) 金额,csi.itemid,s.cat_id')
  699. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  700. ->where($where)
  701. ->group('s.good_code,s.good_name,csi.itemid,s.cat_id')
  702. ->order('total_num', 'desc')
  703. ->cursor();
  704. $list = [];
  705. foreach ($data as $value) {
  706. if (!empty($value['itemid'])) {
  707. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  708. $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  709. $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  710. }
  711. $value['产品品类'] = implode('/', array_column(made($value['cat_id']), 'name'));
  712. $value['数量'] = $value['total_num'];
  713. unset($value['good_code']);
  714. unset($value['itemid']);
  715. unset($value['cat_id']);
  716. unset($value['total_num']);
  717. $list[] = $value;
  718. }
  719. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  720. excelSave('产品热销排行' . date('YmdHis'), array_keys($list[0]), $list);
  721. }
  722. //【三、咨询单导出明细】
  723. public function consultDetailed()
  724. {
  725. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  726. $where = [['ci.is_del', '=', 0]];
  727. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  728. if ($param['use_desc'] != '') $where[] = ['ci.use_desc', 'like', '%' . $param['use_desc'] . '%'];
  729. $count = Db::name('consult_info')
  730. ->alias('ci')
  731. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
  732. ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
  733. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  734. ->leftJoin('depart_user du', 'du.uid=co.saleid AND du.is_del=0')
  735. ->leftJoin('company_item item', 'item.id=du.itemid')
  736. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  737. ->leftJoin('brand b', 'b.id=ci.brand_id')
  738. ->leftJoin('unit u', 'u.id=ci.unit')
  739. ->where($where)
  740. ->order('ci.addtime', 'desc')
  741. ->count('ci.id');
  742. $data = Db::name('consult_info')
  743. ->alias('ci')
  744. ->field('ci.addtime,co.salesman,item.name,cb.infoNo,csi.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,csi.itemid,s.orderCode')
  745. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
  746. ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
  747. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  748. ->leftJoin('depart_user du', 'du.uid=co.saleid AND du.is_del=0')
  749. ->leftJoin('company_item item', 'item.id=du.itemid')
  750. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  751. ->leftJoin('brand b', 'b.id=ci.brand_id')
  752. ->leftJoin('unit u', 'u.id=ci.unit')
  753. ->where($where)
  754. ->page($param['page'], $param['size'])
  755. ->order('ci.addtime', 'desc')
  756. ->cursor();
  757. $list = [];
  758. foreach ($data as $value) {
  759. if (!empty($value['itemid'])) {
  760. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  761. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  762. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  763. }
  764. $cat = made($value['cat_id']);
  765. $value['first_cat_name'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  766. $value['budget_total_price'] = round($value['budget_price'] * $value['num'], 2);
  767. $value['is_addrs'] = isset($this->is_addrs[$value['is_addrs']]) ? $this->is_addrs[$value['is_addrs']] : '';
  768. $value['is_custom'] = isset($this->is_custom[$value['is_custom']]) ? $this->is_custom[$value['is_custom']] : '';
  769. $value['status'] = isset($this->consult_info_status[$value['status']]) ? $this->consult_info_status[$value['status']] : '';
  770. $list[] = $value;
  771. }
  772. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  773. }
  774. //【三、咨询单导出明细】
  775. public function consultDetailedExport()
  776. {
  777. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => ''], 'post', 'trim');
  778. $where = [['ci.is_del', '=', 0]];
  779. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  780. if ($param['use_desc'] != '') $where[] = ['ci.use_desc', 'like', '%' . $param['use_desc'] . '%'];
  781. $data = Db::name('consult_info')
  782. ->alias('ci')
  783. ->field('ci.addtime 咨询时间,co.salesman 业务员,item.name 业务部门,cb.infoNo 咨询单号,"" 一级组织,"" 二级组织,csi.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 销售订单编号,csi.itemid')
  784. ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
  785. ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
  786. ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
  787. ->leftJoin('depart_user du', 'du.uid=co.saleid AND du.is_del=0')
  788. ->leftJoin('company_item item', 'item.id=du.itemid')
  789. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  790. ->leftJoin('brand b', 'b.id=ci.brand_id')
  791. ->leftJoin('unit u', 'u.id=ci.unit')
  792. ->where($where)
  793. ->order('ci.addtime', 'desc')
  794. ->cursor();
  795. $list = [];
  796. foreach ($data as $value) {
  797. if (!empty($value['itemid'])) {
  798. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  799. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  800. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  801. }
  802. $cat = made($value['cat_id']);
  803. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  804. $value['预算总价'] = round($value['预算单价'] * $value['需求数量'], 2);
  805. $value['是否一地'] = isset($this->is_addrs[$value['是否一地']]) ? $this->is_addrs[$value['是否一地']] : '';
  806. $value['定制'] = isset($this->is_custom[$value['定制']]) ? $this->is_custom[$value['定制']] : '';
  807. $value['竞单状态'] = isset($this->consult_info_status[$value['竞单状态']]) ? $this->consult_info_status[$value['竞单状态']] : '';
  808. unset($value['itemid']);
  809. unset($value['cat_id']);
  810. $list[] = $value;
  811. }
  812. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  813. excelSave('咨询单导出明细' . date('YmdHis'), array_keys($list[0]), $list);
  814. }
  815. //【四、工差明细表】
  816. public function saleDiff()
  817. {
  818. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  819. $where = [['pd.is_del', '=', 0]];
  820. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['pd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  821. $count = Db::name('purchease_diff')
  822. ->alias('pd')
  823. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  824. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  825. ->leftJoin('order_num on', 'on.cgdNo=pd.cgdNo')
  826. ->leftJoin('sale s', 's.orderCode=on.orderCode')
  827. ->leftJoin('customer_info ci', 'ci.companyNo=s.customer_code')
  828. ->where($where)
  829. ->order('pd.addtime', 'desc')
  830. ->count('pd.id');
  831. $data = Db::name('purchease_diff')
  832. ->alias('pd')
  833. ->field('pd.addtime,sd.diffCode,sd.orderCode,pd.apply_name,pd.apply_id,po.addtime poaddtime,pd.good_name,ci.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')
  834. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  835. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  836. ->leftJoin('order_num on', 'on.cgdNo=pd.cgdNo')
  837. ->leftJoin('sale s', 's.orderCode=on.orderCode')
  838. ->leftJoin('customer_info ci', 'ci.companyNo=s.customer_code')
  839. ->where($where)
  840. ->page($param['page'], $param['size'])
  841. ->order('pd.addtime', 'desc')
  842. ->cursor();
  843. $list = [];
  844. foreach ($data as $value) {
  845. if ($value['order_type'] == 3) $noble_metal = Db::name("good_zixun")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->value('noble_metal');
  846. else $noble_metal = Db::name('good_basic')->where(['spuCode' => $value['spuCode'], 'is_del' => 0])->value('noble_metal');
  847. $value['apply_company'] = get_company_name_by_uid($value['apply_id']);
  848. $value['sale_apply_company'] = get_company_name_by_uid($value['sale_apply_id']);
  849. $value['noble_metal'] = isset($this->noble_metal[$noble_metal]) ? $this->noble_metal[$noble_metal] : '';
  850. $value['total_price'] = round($value['sale_price'], $value['good_num'], 2);
  851. $value['is_update_sale'] = isset($this->sale_diff_status[$value['status']]) ? $this->sale_diff_status[$value['status']] : '';
  852. $list[] = $value;
  853. }
  854. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  855. }
  856. //【四、工差明细表】
  857. public function saleDiffExport()
  858. {
  859. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  860. $where = [['pd.is_del', '=', 0]];
  861. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['pd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  862. $data = Db::name('purchease_diff')
  863. ->alias('pd')
  864. ->field('pd.addtime 发起时间,sd.diffCode 工差单号,sd.orderCode 关联确认单,pd.apply_name 创建人,"" 部门,pd.apply_id,po.addtime 确认单下单日期,pd.good_name 产品名称,ci.companyName 客户名称,"" 贵金属种类,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')
  865. ->leftJoin('sale_diff sd', 'sd.cgd_diffid=pd.id')
  866. ->leftJoin('purchease_order po', 'po.cgdNo=pd.cgdNo')
  867. ->leftJoin('order_num on', 'on.cgdNo=pd.cgdNo')
  868. ->leftJoin('sale s', 's.orderCode=on.orderCode')
  869. ->leftJoin('customer_info ci', 'ci.companyNo=s.customer_code')
  870. ->where($where)
  871. ->order('pd.addtime', 'desc')
  872. ->cursor();
  873. $list = [];
  874. foreach ($data as $value) {
  875. if ($value['order_type'] == 3) $noble_metal = Db::name("good_zixun")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->value('noble_metal');
  876. else $noble_metal = Db::name('good_basic')->where(['spuCode' => $value['spuCode'], 'is_del' => 0])->value('noble_metal');
  877. $value['部门'] = get_company_name_by_uid($value['apply_id']);
  878. $value['销售部门'] = get_company_name_by_uid($value['sale_apply_id']);
  879. $value['贵金属种类'] = isset($this->noble_metal[$noble_metal]) ? $this->noble_metal[$noble_metal] : '';
  880. $value['总额'] = round($value['单价'], $value['下单数量'], 2);
  881. $value['是否修改销售额'] = isset($this->sale_diff_status[$value['是否修改销售额']]) ? $this->sale_diff_status[$value['是否修改销售额']] : '';
  882. unset($value['apply_id']);
  883. unset($value['order_type']);
  884. unset($value['spuCode']);
  885. unset($value['sale_apply_id']);
  886. $list[] = $value;
  887. }
  888. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  889. excelSave('工差明细表' . date('YmdHis'), array_keys($list[0]), $list);
  890. }
  891. //【五、退货明细表】
  892. public function thData()
  893. {
  894. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  895. $where = [['thd.is_del', '=', 0], ['thd.th_type', 'in', [2, 3]]];
  896. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['thd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  897. $count = Db::name('th_data')
  898. ->alias('thd')
  899. ->leftJoin('sale s', 's.orderCode=thd.orderCode')
  900. ->leftJoin('customer_info c', 'c.companyNo=s.customer_code')
  901. ->where($where)
  902. ->order('thd.addtime', 'desc')
  903. ->count('thd.id');
  904. $data = Db::name('th_data')
  905. ->alias('thd')
  906. ->field('thd.id,thd.th_type,thd.addtime return_time,thd.thCode,"" outCode,"" status,"" apply_name,"" apply_company,thd.orderCode,s.addtime,c.companyName,s.good_name,s.sale_price,s.wsend_num,s.th_num,s.th_fee,"" contactor,"" mobile,"" addr,"" result')
  907. ->leftJoin('sale s', 's.orderCode=thd.orderCode')
  908. ->leftJoin('customer_info c', 'c.companyNo=s.customer_code')
  909. ->where($where)
  910. ->order('thd.addtime', 'desc')
  911. ->select()
  912. ->toArray();
  913. $th_types = [];
  914. foreach ($data as $value) {
  915. $th_types[$value['th_type']][] = $value['thCode'];
  916. }
  917. $all_order_return = Db::name('order_return')
  918. ->alias('or')
  919. ->withAttr('status', function ($val) {
  920. return isset($this->all_order_return_status[$val]) ? $this->all_order_return_status[$val] : '';
  921. })
  922. ->withAttr('apply_company', function ($val, $da) {
  923. return get_company_name_by_uid($da['apply_id']);
  924. })
  925. ->leftJoin('order_out oo', 'oo.outCode=or.outCode')
  926. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  927. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  928. ->where('or.is_del', 0)
  929. ->whereIn('or.returnCode', $th_types[2])
  930. ->column('or.id,or.outCode,or.status,or.apply_id,or.apply_name,"" apply_company,oa.contactor,oa.mobile,oa.addr,ri.result,oa.addr_code', 'or.returnCode');
  931. $all_order_back = Db::name('order_back')
  932. ->alias('ob')
  933. ->where('ob.is_del', 0)
  934. ->whereIn('ob.thNo', $th_types[3])
  935. ->withAttr('status', function ($val) {
  936. return isset($this->order_back_status[$val]) ? $this->order_back_status[$val] : '';
  937. })
  938. ->withAttr('apply_company', function ($val, $da) {
  939. return get_company_name_by_uid($da['apply_id']);
  940. })
  941. ->leftJoin('order_out oo', 'oo.outCode=ob.outCode')
  942. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  943. ->leftJoin('result_info ri', 'ri.result_code=ob.return_code')
  944. ->column('ob.id,ob.outCode,ob.status,ob.apply_id,ob.apply_name,"" apply_company,oa.contactor,oa.mobile,oa.addr,ri.result,oa.addr_code', 'thNo');
  945. $list = [];
  946. foreach ($data as $value) {
  947. if ($value['th_type'] == 2) {
  948. $value['outCode'] = isset($all_order_return[$value['thCode']]['outCode']) ? $all_order_return[$value['thCode']]['outCode'] : '';
  949. $value['status'] = isset($all_order_return[$value['thCode']]['status']) ? $all_order_return[$value['thCode']]['status'] : '';
  950. $value['apply_name'] = isset($all_order_return[$value['thCode']]['apply_name']) ? $all_order_return[$value['thCode']]['apply_name'] : '';
  951. $value['apply_company'] = isset($all_order_return[$value['thCode']]['apply_company']) ? $all_order_return[$value['thCode']]['apply_company'] : '';
  952. $value['contactor'] = isset($all_order_return[$value['thCode']]['contactor']) ? $all_order_return[$value['thCode']]['contactor'] : '';
  953. $value['mobile'] = isset($all_order_return[$value['thCode']]['mobile']) ? $all_order_return[$value['thCode']]['mobile'] : '';
  954. $value['addr'] = isset($all_order_return[$value['thCode']]['addr']) ? $all_order_return[$value['thCode']]['addr'] : '';
  955. $value['result'] = isset($all_order_return[$value['thCode']]['result']) ? $all_order_return[$value['thCode']]['result'] : '';
  956. } elseif ($value['th_type'] == 3) {
  957. $value['outCode'] = isset($all_order_back[$value['thCode']]['outCode']) ? $all_order_back[$value['thCode']]['outCode'] : '';
  958. $value['status'] = isset($all_order_back[$value['thCode']]['status']) ? $all_order_back[$value['thCode']]['status'] : '';
  959. $value['apply_name'] = isset($all_order_back[$value['thCode']]['apply_name']) ? $all_order_back[$value['thCode']]['apply_name'] : '';
  960. $value['apply_company'] = isset($all_order_back[$value['thCode']]['apply_company']) ? $all_order_back[$value['thCode']]['apply_company'] : '';
  961. $value['contactor'] = isset($all_order_back[$value['thCode']]['contactor']) ? $all_order_back[$value['thCode']]['contactor'] : '';
  962. $value['mobile'] = isset($all_order_back[$value['thCode']]['mobile']) ? $all_order_back[$value['thCode']]['mobile'] : '';
  963. $value['addr'] = isset($all_order_back[$value['thCode']]['addr']) ? $all_order_back[$value['thCode']]['addr'] : '';
  964. $value['result'] = isset($all_order_back[$value['thCode']]['result']) ? $all_order_back[$value['thCode']]['result'] : '';
  965. }
  966. $list[] = $value;
  967. }
  968. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  969. }
  970. //【五、退货明细表】
  971. public function thDataExport()
  972. {
  973. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
  974. $where = [['thd.is_del', '=', 0], ['thd.th_type', 'in', [2, 3]]];
  975. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['thd.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  976. $data = Db::name('th_data')
  977. ->alias('thd')
  978. ->field('thd.id,thd.th_type,thd.addtime 退货时间,thd.thCode 退货单号,"" 发货申请单编码,"" 退货单状态,"" 创建人,"" 部门,thd.orderCode 确认单编号,s.addtime 下单日期,c.companyName 客户名称,s.good_name 产品名称,s.sale_price 单价,s.wsend_num 未发货数量,s.th_num 退货数量,s.th_fee 退货销售货款,"" 发货单联系人,"" 发货单联系人电话,"" 发货单地址,"" 退货原因')
  979. ->leftJoin('sale s', 's.orderCode=thd.orderCode')
  980. ->leftJoin('customer_info c', 'c.companyNo=s.customer_code')
  981. ->where($where)
  982. ->order('thd.addtime', 'desc')
  983. ->select()
  984. ->toArray();
  985. $th_types = [];
  986. foreach ($data as $value) {
  987. $th_types[$value['th_type']][] = $value['退货单号'];
  988. }
  989. $all_order_return = Db::name('order_return')
  990. ->alias('or')
  991. ->withAttr('退货单状态', function ($val) {
  992. return isset($this->all_order_return_status[$val]) ? $this->all_order_return_status[$val] : '';
  993. })
  994. ->withAttr('部门', function ($val, $da) {
  995. return get_company_name_by_uid($da['apply_id']);
  996. })
  997. ->leftJoin('order_out oo', 'oo.outCode=or.outCode')
  998. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  999. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1000. ->where('or.is_del', 0)
  1001. ->whereIn('or.returnCode', $th_types[2])
  1002. ->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');
  1003. $all_order_back = Db::name('order_back')
  1004. ->alias('ob')
  1005. ->where('ob.is_del', 0)
  1006. ->whereIn('ob.thNo', $th_types[3])
  1007. ->withAttr('退货单状态', function ($val) {
  1008. return isset($this->order_back_status[$val]) ? $this->order_back_status[$val] : '';
  1009. })
  1010. ->withAttr('部门', function ($val, $da) {
  1011. return get_company_name_by_uid($da['apply_id']);
  1012. })
  1013. ->leftJoin('order_out oo', 'oo.outCode=ob.outCode')
  1014. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  1015. ->leftJoin('result_info ri', 'ri.result_code=ob.return_code')
  1016. ->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');
  1017. $list = [];
  1018. foreach ($data as $value) {
  1019. if ($value['th_type'] == 2) {
  1020. $value['发货申请单编码'] = isset($all_order_return[$value['退货单号']]['发货申请单编码']) ? $all_order_return[$value['退货单号']]['发货申请单编码'] : '';
  1021. $value['退货单状态'] = isset($all_order_return[$value['退货单号']]['退货单状态']) ? $all_order_return[$value['退货单号']]['退货单状态'] : '';
  1022. $value['创建人'] = isset($all_order_return[$value['退货单号']]['创建人']) ? $all_order_return[$value['退货单号']]['创建人'] : '';
  1023. $value['部门'] = isset($all_order_return[$value['退货单号']]['部门']) ? $all_order_return[$value['退货单号']]['部门'] : '';
  1024. $value['发货单联系人'] = isset($all_order_return[$value['退货单号']]['发货单联系人']) ? $all_order_return[$value['退货单号']]['发货单联系人'] : '';
  1025. $value['发货单联系人电话'] = isset($all_order_return[$value['退货单号']]['发货单联系人电话']) ? $all_order_return[$value['退货单号']]['发货单联系人电话'] : '';
  1026. $value['发货单地址'] = isset($all_order_return[$value['退货单号']]['发货单地址']) ? $all_order_return[$value['退货单号']]['发货单地址'] : '';
  1027. $value['退货原因'] = isset($all_order_return[$value['退货单号']]['退货原因']) ? $all_order_return[$value['退货单号']]['退货原因'] : '';
  1028. } elseif ($value['th_type'] == 3) {
  1029. $value['发货申请单编码'] = isset($all_order_back[$value['退货单号']]['发货申请单编码']) ? $all_order_back[$value['退货单号']]['发货申请单编码'] : '';
  1030. $value['退货单状态'] = isset($all_order_back[$value['退货单号']]['退货单状态']) ? $all_order_back[$value['退货单号']]['退货单状态'] : '';
  1031. $value['创建人'] = isset($all_order_back[$value['退货单号']]['创建人']) ? $all_order_back[$value['退货单号']]['创建人'] : '';
  1032. $value['部门'] = isset($all_order_back[$value['退货单号']]['部门']) ? $all_order_back[$value['退货单号']]['部门'] : '';
  1033. $value['发货单联系人'] = isset($all_order_back[$value['退货单号']]['发货单联系人']) ? $all_order_back[$value['退货单号']]['发货单联系人'] : '';
  1034. $value['发货单联系人电话'] = isset($all_order_back[$value['退货单号']]['发货单联系人电话']) ? $all_order_back[$value['退货单号']]['发货单联系人电话'] : '';
  1035. $value['发货单地址'] = isset($all_order_back[$value['退货单号']]['发货单地址']) ? $all_order_back[$value['退货单号']]['发货单地址'] : '';
  1036. $value['退货原因'] = isset($all_order_back[$value['退货单号']]['退货原因']) ? $all_order_back[$value['退货单号']]['退货原因'] : '';
  1037. }
  1038. unset($value['id']);
  1039. unset($value['th_type']);
  1040. $list[] = $value;
  1041. }
  1042. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1043. excelSave('退货明细表' . date('YmdHis'), array_keys($list[0]), $list);
  1044. }
  1045. //【六、售后明细表】
  1046. public function orderReturnDetailed()
  1047. {
  1048. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  1049. $where = [['or.is_del', '=', 0]];
  1050. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1051. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  1052. $count = Db::name('order_return')
  1053. ->alias('or')
  1054. ->leftJoin('customer_info c', 'c.companyNo=or.customer_code')
  1055. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  1056. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1057. ->where($where)
  1058. ->order('or.addtime', 'desc')
  1059. ->count('or.id');
  1060. $data = Db::name('order_return')
  1061. ->alias('or')
  1062. ->field('or.addtime,or.returnCode,or.apply_name,or.apply_id,or.outCode,or.total_num,or.status,or.orderCode,c.companyName,or.good_name,s.sale_price,or.is_receive,or.error_num,ri.result result_desc,or.error_remark,or.except_code,c.itemid')
  1063. ->leftJoin('customer_info c', 'c.companyNo=or.customer_code')
  1064. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  1065. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1066. ->where($where)
  1067. ->page($param['page'], $param['size'])
  1068. ->order('or.addtime', 'desc')
  1069. ->cursor();
  1070. $list = [];
  1071. foreach ($data as $value) {
  1072. $value['status'] = isset($this->all_order_return_status[$value['status']]) ? $this->all_order_return_status[$value['status']] : '';
  1073. $value['except_code'] = isset($this->except_code[$value['is_receive']][$value['except_code']]) ? $this->except_code[$value['is_receive']][$value['except_code']] : '';
  1074. $value['is_receive'] = isset($this->is_receive[$value['is_receive']]) ? $this->is_receive[$value['is_receive']] : '';
  1075. $value['apply_company'] = get_company_name_by_uid($value['apply_id']);
  1076. $value['error_total_price'] = round($value['error_num'] * $value['sale_price'], 2);
  1077. if (!empty($value['itemid'])) {
  1078. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  1079. $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  1080. $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  1081. }
  1082. $list[] = $value;
  1083. }
  1084. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1085. }
  1086. //【六、售后明细表】
  1087. public function orderReturnDetailedExport()
  1088. {
  1089. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => ''], 'post', 'trim');
  1090. $where = [['or.is_del', '=', 0]];
  1091. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['or.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1092. if ($param['status'] != '') $where[] = ['or.status', '=', $param['status']];
  1093. $data = Db::name('order_return')
  1094. ->alias('or')
  1095. ->field('or.addtime 售后时间,or.returnCode 售后申请编号,or.apply_name 申请人,or.apply_id,"" 部门,or.outCode 发货申请编号,or.total_num 发货数量,or.status 处理状态,or.orderCode 订单号,"" 一级组织,"" 二级组织,c.companyName 客户名称,or.good_name 商品名称,s.sale_price 销售单价,"" 异常金额,or.is_receive 收货情况,or.error_num 异常数量,ri.result 异常原因,or.error_remark 异常备注,or.except_code 期望意愿,c.itemid')
  1096. ->leftJoin('customer_info c', 'c.companyNo=or.customer_code')
  1097. ->leftJoin('sale s', 's.orderCode=or.orderCode')
  1098. ->leftJoin('result_info ri', 'ri.result_code=or.error_code')
  1099. ->where($where)
  1100. ->order('or.addtime', 'desc')
  1101. ->cursor();
  1102. $list = [];
  1103. foreach ($data as $value) {
  1104. $value['处理状态'] = isset($this->all_order_return_status[$value['处理状态']]) ? $this->all_order_return_status[$value['处理状态']] : '';
  1105. $value['部门'] = get_company_name_by_uid($value['apply_id']);
  1106. $value['异常金额'] = round($value['异常数量'] * $value['销售单价'], 2);
  1107. if (!empty($value['itemid'])) {
  1108. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  1109. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  1110. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  1111. }
  1112. $value['期望意愿'] = isset($this->except_code[$value['收货情况']][$value['期望意愿']]) ? $this->except_code[$value['收货情况']][$value['期望意愿']] : '';
  1113. $value['收货情况'] = isset($this->is_receive[$value['收货情况']]) ? $this->is_receive[$value['收货情况']] : '';
  1114. unset($value['apply_id']);
  1115. unset($value['itemid']);
  1116. $list[] = $value;
  1117. }
  1118. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1119. excelSave('售后明细表' . date('YmdHis'), array_keys($list[0]), $list);
  1120. }
  1121. //【七、议价明细表】
  1122. public function bargainOrder()
  1123. {
  1124. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
  1125. $where = [['bo.is_del', '=', 0]];
  1126. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['bo.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1127. $count = Db::name('bargain_order')
  1128. ->alias('bo')
  1129. ->leftJoin('consult_info ci', 'ci.infoNo=bo.infoNo')
  1130. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1131. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  1132. ->leftJoin('result_info ri', 'ri.result_code=bo.result_info_id')
  1133. ->where($where)
  1134. ->order('bo.addtime', 'desc')
  1135. ->count('bo.id');
  1136. $data = Db::name('bargain_order')
  1137. ->alias('bo')
  1138. ->field('bo.addtime,bo.bargainNo,bo.infoNo,bo.status,bo.bidsNo,csi.companyName,ci.good_name,bo.creater,bo.createrid,bo.sale_price,bo.after_price,ri.result result_desc,bo.bargain_remark')
  1139. ->leftJoin('consult_info ci', 'ci.infoNo=bo.infoNo')
  1140. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1141. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  1142. ->leftJoin('result_info ri', 'ri.result_code=bo.result_info_id')
  1143. ->where($where)
  1144. ->page($param['page'], $param['size'])
  1145. ->order('bo.addtime', 'desc')
  1146. ->cursor();
  1147. $list = [];
  1148. foreach ($data as $value) {
  1149. $value['status'] = isset($this->bargain_order_status[$value['status']]) ? $this->bargain_order_status[$value['status']] : '';
  1150. $value['creater_company'] = get_company_name_by_uid($value['createrid']);
  1151. $list[] = $value;
  1152. }
  1153. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1154. }
  1155. //【七、议价明细表】
  1156. public function bargainOrderExport()
  1157. {
  1158. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => ''], 'post', 'trim');
  1159. $where = [['bo.is_del', '=', 0]];
  1160. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['bo.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1161. $data = Db::name('bargain_order')
  1162. ->alias('bo')
  1163. ->field('bo.addtime 议价时间,bo.bargainNo 议价编号,bo.infoNo 咨询单编号,bo.status 议价单状态,bo.bidsNo 采返商品编号,csi.companyName 客户名称,ci.good_name 商品名称,bo.creater 申请人,"" 部门,bo.createrid,bo.sale_price 议价前售价,bo.after_price 期望售价,ri.result 议价原因,bo.bargain_remark 议价备注')
  1164. ->leftJoin('consult_info ci', 'ci.infoNo=bo.infoNo')
  1165. ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
  1166. ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
  1167. ->leftJoin('result_info ri', 'ri.result_code=bo.result_info_id')
  1168. ->where($where)
  1169. ->order('bo.addtime', 'desc')
  1170. ->cursor();
  1171. $list = [];
  1172. foreach ($data as $value) {
  1173. $value['议价单状态'] = isset($this->bargain_order_status[$value['议价单状态']]) ? $this->bargain_order_status[$value['议价单状态']] : '';
  1174. $value['部门'] = get_company_name_by_uid($value['createrid']);
  1175. unset($value['createrid']);
  1176. $list[] = $value;
  1177. }
  1178. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1179. excelSave('议价明细表' . date('YmdHis'), array_keys($list[0]), $list);
  1180. }
  1181. //【八、延时发货申请单统计】
  1182. public function orderOutNotAddr()
  1183. {
  1184. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1185. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 2], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==2 延迟发货,a.status==4 已全部退货
  1186. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1187. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1188. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1189. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1190. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1191. $count = Db::name('order_out')
  1192. ->alias('a')
  1193. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1194. ->leftJoin("customer_info v", "v.companyNo=b.customer_code")
  1195. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1196. ->leftJoin("business bus", "bus.companyNo=b.supplierNo")
  1197. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1198. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1199. ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
  1200. ->leftJoin("supplier e", "e.code=d.supplierNo")->where($where)
  1201. ->order("a.addtime desc")
  1202. ->count('a.id');
  1203. $data = Db::name('order_out')
  1204. ->alias('a')
  1205. ->field('a.addtime,a.orderCode,os.cgdNo,bus.company,a.apply_name,a.apply_id,a.status,a.send_num,b.good_code,b.good_name,v.companyName,b.wsend_num,b.skuCode,b.order_type,e.person')
  1206. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1207. ->leftJoin("customer_info v", "v.companyNo=b.customer_code")
  1208. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1209. ->leftJoin("business bus", "bus.companyNo=b.supplierNo")
  1210. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1211. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1212. ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
  1213. ->leftJoin("supplier e", "e.code=d.supplierNo")->where($where)
  1214. ->page($param['page'], $param['size'])
  1215. ->order("a.addtime desc")
  1216. ->cursor();
  1217. $list = $tmp_apply = $tmp_cat = [];
  1218. foreach ($data as $value) {
  1219. if (!isset($tmp_apply[$value['apply_id']])) $tmp_apply[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
  1220. $value['apply_company'] = $tmp_apply[$value['apply_id']];
  1221. if ($value['order_type'] == 3 || $value['order_type'] == 4) {
  1222. $goon = Db::name("good_zixun")
  1223. ->field('id,cat_id,customized')
  1224. ->where(["spuCode" => $value['good_code'], "is_del" => 0])
  1225. ->find();
  1226. } else {
  1227. $goon = Db::name('good_platform')
  1228. ->alias('a')
  1229. ->field('a.id,b.cat_id,b.customized')
  1230. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  1231. ->where(['a.is_del' => 0, 'a.skuCode' => $value['skuCode']])
  1232. ->find();
  1233. }
  1234. if (!isset($tmp_cat[$goon['cat_id']])) $tmp_cat[$goon['cat_id']] = implode('/', array_column(made($goon['cat_id']), 'name'));
  1235. $value['cat'] = $tmp_cat[$goon['cat_id']];
  1236. $value['send_date'] = date('Y-m-d H:i:s', strtotime($value['addtime']) + $goon['customized'] * 24 * 3600);
  1237. $value['status'] = isset($this->order_out_status[$value['status']]) ? $this->order_out_status[$value['status']] : '';
  1238. $list[] = $value;
  1239. }
  1240. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1241. }
  1242. //【八、延时发货申请单统计】
  1243. public function orderOutNotAddrExport()
  1244. {
  1245. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1246. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 2], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==2 延迟发货,a.status==4 已全部退货
  1247. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1248. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1249. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1250. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1251. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1252. $data = Db::name('order_out')
  1253. ->alias('a')
  1254. ->field('a.addtime 下单时间,a.orderCode 订单编号,os.cgdNo 采购单编号,bus.company 公司名称,a.apply_name 申请人,"" 部门,a.apply_id,a.status 状态,a.send_num 出库总数,"" 商品分类,b.good_code 商品编码,b.good_name 商品名称,v.companyName 客户名称,b.wsend_num 未发货数量,"" 应发货日期,b.skuCode,b.order_type 订单类型,e.person 采购员')
  1255. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1256. ->leftJoin("customer_info v", "v.companyNo=b.customer_code")
  1257. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1258. ->leftJoin("business bus", "bus.companyNo=b.supplierNo")
  1259. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1260. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1261. ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
  1262. ->leftJoin("supplier e", "e.code=d.supplierNo")
  1263. ->where($where)
  1264. ->order("a.addtime desc")
  1265. ->cursor();
  1266. $list = $tmp_apply = $tmp_cat = [];
  1267. foreach ($data as $value) {
  1268. if (!isset($tmp_apply[$value['apply_id']])) $tmp_apply[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
  1269. $value['部门'] = $tmp_apply[$value['apply_id']];
  1270. if ($value['订单类型'] == 3 || $value['订单类型'] == 4) {
  1271. $goon = Db::name("good_zixun")
  1272. ->field('id,cat_id,customized')
  1273. ->where(["spuCode" => $value['商品编码'], "is_del" => 0])
  1274. ->find();
  1275. } else {
  1276. $goon = Db::name('good_platform')
  1277. ->alias('a')
  1278. ->field('a.id,b.cat_id,b.customized')
  1279. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  1280. ->where(['a.is_del' => 0, 'a.skuCode' => $value['skuCode']])
  1281. ->find();
  1282. }
  1283. if (!isset($tmp_cat[$goon['cat_id']])) $tmp_cat[$goon['cat_id']] = implode('/', array_column(made($goon['cat_id']), 'name'));
  1284. $value['商品分类'] = $tmp_cat[$goon['cat_id']];
  1285. $value['应发货日期'] = date('Y-m-d H:i:s', strtotime($value['下单时间']) + $goon['customized'] * 24 * 3600);
  1286. $value['状态'] = isset($this->order_out_status[$value['状态']]) ? $this->order_out_status[$value['状态']] : '';
  1287. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  1288. unset($value['apply_id']);
  1289. unset($value['skuCode']);
  1290. $list[] = $value;
  1291. }
  1292. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1293. excelSave('延时发货申请单' . date('YmdHis'), array_keys($list[0]), $list);
  1294. }
  1295. //【九、直接发货申请单统计 】
  1296. public function orderOutAddr()
  1297. {
  1298. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1299. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 1], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==1 直接发货
  1300. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1301. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1302. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1303. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1304. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1305. $count = Db::name('order_out')
  1306. ->alias('a')
  1307. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1308. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1309. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
  1310. ->leftJoin("order_addr oa", "oa.id=a.addrid")
  1311. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1312. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1313. ->leftJoin("supplier c", "c.code=po.supplierNo")
  1314. ->where($where)
  1315. ->order("a.addtime desc")
  1316. ->count('a.id');
  1317. $data = Db::name('order_out')
  1318. ->alias('a')
  1319. ->field('a.addtime,a.orderCode,a.sendtime,a.outCode,a.status,b.good_name,b.sale_price,a.send_num,a.apply_name,ci.name apply_company,c.person cgder,a.post_name,a.post_code,oa.contactor,oa.mobile,oa.addr,oa.addr_code,a.remark,b.order_type')
  1320. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1321. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1322. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
  1323. ->leftJoin("order_addr oa", "oa.id=a.addrid")
  1324. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1325. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1326. ->leftJoin("supplier c", "c.code=po.supplierNo")
  1327. ->where($where)
  1328. ->page($param['page'], $param['size'])
  1329. ->order("a.addtime desc")
  1330. ->cursor();
  1331. $list = [];
  1332. foreach ($data as $value) {
  1333. $value['send_total_price'] = round($value['send_num'] * $value['sale_price'], 2);
  1334. $value['status'] = isset($this->order_out_status[$value['status']]) ? $this->order_out_status[$value['status']] : '';
  1335. //拼接省市区
  1336. if (!json_decode($value['addr_code'])) {
  1337. $temp = explode(',', $value['addr_code']);
  1338. $value['addr_code'] = json_encode(['provice_code' => $temp[0] ?? '', 'city_code' => $temp[1] ?? '', 'area_code' => $temp[2] ?? '']);
  1339. }
  1340. $value['addr'] = GetAddr($value['addr_code']) . $value['addr'];
  1341. $list[] = $value;
  1342. }
  1343. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  1344. }
  1345. //【九、直接发货申请单统计-导出】
  1346. public function orderOutAddrExport()
  1347. {
  1348. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'order_type' => ''], 'post', 'trim');
  1349. $where = [['a.is_del', '=', 0], ['b.send_type', '=', 1], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==1 直接发货
  1350. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1351. if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
  1352. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1353. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1354. if ($param['order_type'] != '') $where[] = ['b.order_type', '=', $param['order_type']];
  1355. $data = Db::name('order_out')
  1356. ->alias('a')
  1357. ->field('a.addtime 下单日期,a.orderCode 订单编号,a.sendtime 发货时间,a.outCode 发货申请单号,a.status 发货申请单状态,b.good_name 商品名称,b.sale_price 产品单价,a.send_num 发货数量,"" 发货申请单总价,a.apply_name 申请人,ci.name 部门,c.person 采购员,a.post_name 快递公司,a.post_code 快递单号,oa.contactor 收货人,oa.mobile 收货电话,oa.addr 收货地址,oa.addr_code,a.remark 备注,b.order_type 订单类型')
  1358. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1359. ->leftJoin("order_send os", "os.outCode=a.outCode")
  1360. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
  1361. ->leftJoin("order_addr oa", "oa.id=a.addrid")
  1362. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1363. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1364. ->leftJoin("supplier c", "c.code=po.supplierNo")
  1365. ->where($where)
  1366. ->order("a.addtime desc")
  1367. ->cursor();
  1368. $list = [];
  1369. foreach ($data as $value) {
  1370. $value['发货申请单总价'] = round(bcmul($value['发货数量'], $value['产品单价'], 3), 2);
  1371. $value['发货申请单状态'] = isset($this->order_out_status[$value['发货申请单状态']]) ? $this->order_out_status[$value['发货申请单状态']] : '';
  1372. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  1373. //拼接省市区
  1374. if (!json_decode($value['addr_code'])) {
  1375. $temp = explode(',', $value['addr_code']);
  1376. $value['addr_code'] = json_encode(['provice_code' => $temp[0] ?? '', 'city_code' => $temp[1] ?? '', 'area_code' => $temp[2] ?? '']);
  1377. }
  1378. $value['收货地址'] = GetAddr($value['addr_code']) . $value['收货地址'];
  1379. unset($value['addr_code']);
  1380. $list[] = $value;
  1381. }
  1382. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1383. excelSave('直接发货申请单统计' . date('YmdHis'), array_keys($list[0]), $list);
  1384. }
  1385. //【十、无地址销售订单】
  1386. public function saleNotAddr()
  1387. {
  1388. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
  1389. $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0], ['a.status', '<>', 3]];//send_type==2 延迟发货
  1390. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1391. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1392. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1393. if ($param['order_type'] != '') $where[] = ['a.order_type', '=', $param['order_type']];
  1394. $count = Db::name('sale')
  1395. ->alias('a')
  1396. ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
  1397. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1398. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1399. ->where($where)
  1400. ->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')
  1401. ->having('a.good_num > SUM(IFNULL(b.receipt_quantity,0)) ')
  1402. ->count('a.id');
  1403. $cgd_sql = Db::name('sale')
  1404. ->alias('a')
  1405. ->field('a.orderCode')
  1406. ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
  1407. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0 AND u.status=1")
  1408. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1409. ->where($where)
  1410. ->order("a.addtime desc")
  1411. ->buildSql();
  1412. $cgd = Db::name('order_num')
  1413. ->alias('a')
  1414. ->leftJoin("purchease_order d", "d.cgdNo=a.cgdNo")
  1415. ->leftJoin("supplier e", "e.code=d.supplierNo")
  1416. ->where('a.orderCode IN ' . $cgd_sql)
  1417. ->column('e.person', 'a.orderCode');
  1418. $data = Db::name('sale')
  1419. ->alias('a')
  1420. ->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')
  1421. ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
  1422. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1423. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1424. ->withAttr('person', function ($val, $da) use ($cgd) {
  1425. return $cgd[$da['orderCode']] ?? '';
  1426. })
  1427. ->where($where)
  1428. ->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')
  1429. ->having('not_addr_address_good_num > 0 ')
  1430. ->page($param['page'], $param['size'])
  1431. ->order("a.addtime desc")
  1432. ->select()
  1433. ->toArray();
  1434. return app_show(0, '请求成功', ['list' => $data, 'count' => $count]);
  1435. }
  1436. //【十、无地址销售订单-导出】
  1437. public function saleNotAddrExport()
  1438. {
  1439. $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'apply_company' => '', 'order_type' => ''], 'post', 'trim');
  1440. $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0], ['a.status', '<>', 3]];//send_type==2 延迟发货
  1441. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
  1442. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  1443. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1444. if ($param['order_type'] != '') $where[] = ['a.order_type', '=', $param['order_type']];
  1445. $data = Db::name('sale')
  1446. ->alias('a')
  1447. ->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 无地址数量,"" 采购员')
  1448. ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
  1449. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0 AND u.status=1")
  1450. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1451. ->where($where)
  1452. ->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')
  1453. ->having('无地址数量 > 0')
  1454. ->order("a.addtime desc")
  1455. ->cursor();
  1456. $cgd_sql = Db::name('sale')
  1457. ->alias('a')
  1458. ->field('a.orderCode')
  1459. ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
  1460. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0 AND u.status=1")
  1461. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1462. ->where($where)
  1463. ->order("a.addtime desc")
  1464. ->buildSql();
  1465. $cgd = Db::name('order_num')
  1466. ->alias('a')
  1467. ->leftJoin("purchease_order d", "d.cgdNo=a.cgdNo")
  1468. ->leftJoin("supplier e", "e.code=d.supplierNo")
  1469. ->where('a.orderCode IN ' . $cgd_sql)
  1470. ->column('e.person', 'a.orderCode');
  1471. $list = [];
  1472. foreach ($data as $value) {
  1473. $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
  1474. $value['订单状态'] = isset($this->all_sale_status[$value['订单状态']]) ? $this->all_sale_status[$value['订单状态']] : '';
  1475. $value['采购员'] = $cgd[$value['订单编号']] ?? '';
  1476. $list[] = $value;
  1477. }
  1478. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1479. excelSave('无地址销售订单列表' . date('YmdHis'), array_keys($list[0]), $list);
  1480. }
  1481. //【十一、销售订单商品类型】
  1482. public function saleMonth()
  1483. {
  1484. $param = $this->request->only(['token', 'apply_company' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1485. $where = [['a.is_del', '=', 0]];
  1486. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1487. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1488. $data = Db::name('sale')
  1489. ->alias('a')
  1490. ->field('a.id,a.order_type,u.itemid,ci.name')
  1491. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1492. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1493. ->where($where)
  1494. ->cursor();
  1495. $list = [];
  1496. $total = ['name' => '总计', 'tag_1' => 0, 'tag_2' => 0, 'tag_3' => 0, 'tag_total' => 0];
  1497. foreach ($data as $val) {
  1498. if (!isset($list[$val['itemid']])) $list[$val['itemid']] = [
  1499. 'name' => $val['name'],
  1500. 'tag_1' => 0,
  1501. 'tag_2' => 0,
  1502. 'tag_3' => 0,
  1503. 'tag_total' => 0,
  1504. ];
  1505. $list[$val['itemid']]['tag_' . $val['order_type']]++;
  1506. $list[$val['itemid']]['tag_total']++;
  1507. $total['tag_' . $val['order_type']]++;
  1508. $total['tag_total']++;
  1509. }
  1510. $list = array_merge($list);//重置下标
  1511. $list[] = $total;
  1512. return app_show(0, '请求成功', $list);
  1513. }
  1514. //【十一、销售订单商品类型-导出】
  1515. public function saleMonthExport()
  1516. {
  1517. $param = $this->request->only(['token', 'apply_company' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1518. $where = [['a.is_del', '=', 0]];
  1519. if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
  1520. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1521. $data = Db::name('sale')
  1522. ->alias('a')
  1523. ->field('a.id,a.order_type,u.itemid,ci.name')
  1524. ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
  1525. ->leftJoin("company_item ci", "ci.id=u.itemid")
  1526. ->where($where)
  1527. ->cursor();
  1528. $list = [];
  1529. $total = ['部门' => '总计', '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
  1530. foreach ($data as $k => $val) {
  1531. if (!isset($list[$val['itemid']])) $list[$val['itemid']] = ['部门' => $val['name'], '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
  1532. switch ($val['order_type']) {
  1533. case 1:
  1534. $list[$val['itemid']]['库存品']++;
  1535. $total['库存品']++;
  1536. break;
  1537. case 2:
  1538. $list[$val['itemid']]['非库存品']++;
  1539. $total['非库存品']++;
  1540. break;
  1541. case 3:
  1542. $list[$val['itemid']]['咨询采反']++;
  1543. $total['咨询采反']++;
  1544. break;
  1545. }
  1546. $list[$val['itemid']]['总计']++;
  1547. $total['总计']++;
  1548. }
  1549. $list = array_merge($list);//重置下标
  1550. $list[] = $total;
  1551. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1552. excelSave('销售订单商品类型' . date('YmdHis'), array_keys($list[0]), $list);
  1553. }
  1554. //【十二、采购订单发货维度表】
  1555. public function orderOutMonth()
  1556. {
  1557. $param = $this->request->only(['token', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1558. $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
  1559. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1560. $data = Db::name('order_out')
  1561. ->alias('a')
  1562. ->field('a.id,b.order_type,b.cat_id,d.supplierNo')
  1563. ->leftJoin('sale b', 'b.orderCode=a.orderCode')
  1564. ->leftJoin('order_send c', 'c.outCode=a.outCode')
  1565. ->leftJoin('purchease_order d', 'd.cgdNo=c.cgdNo')
  1566. ->where($where)
  1567. ->cursor();
  1568. $list = [];
  1569. // $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];
  1570. $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
  1571. ->group('supplierNo')
  1572. ->column('supplierNo');
  1573. foreach ($data as $val) {
  1574. if (!isset($list[$val['cat_id']])) {
  1575. $cat = made($val['cat_id']);
  1576. $list[$val['cat_id']] = [
  1577. 'cat_1' => $cat[0]['name'] ?? '',
  1578. 'cat_2' => $cat[1]['name'] ?? '',
  1579. 'cat_3' => $cat[2]['name'] ?? '',
  1580. 'tag_1' => 0,
  1581. 'tag_2' => 0,
  1582. 'tag_3' => 0,
  1583. 'tag_supplier' => 0,
  1584. 'tag_person' => 0,
  1585. 'tag_logistics' => 0,
  1586. ];
  1587. }
  1588. switch ($val['order_type']) {
  1589. case 1:
  1590. //库存品,物流岗发
  1591. $list[$val['cat_id']]['tag_logistics']++;
  1592. break;
  1593. case 2: //非库存品
  1594. case 3: //咨询采反
  1595. if (in_array($val['supplierNo'], $supplierNos)) $list[$val['cat_id']]['tag_supplier']++;
  1596. else $list[$val['cat_id']]['tag_person']++;
  1597. break;
  1598. }
  1599. $list[$val['cat_id']]['tag_' . $val['order_type']]++;
  1600. // $list[$val['cat_id']]['tag_total']++;
  1601. // $total['tag_' . $val['order_type']]++;
  1602. // $total['tag_total']++;
  1603. }
  1604. $list = array_merge($list);//重置下标
  1605. // $list[] = $total;
  1606. return app_show(0, '请求成功', $list);
  1607. }
  1608. //【十二、采购订单发货维度表-导出】
  1609. public function orderOutMonthExport()
  1610. {
  1611. $param = $this->request->only(['token', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1612. $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
  1613. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1614. $data = Db::name('order_out')
  1615. ->alias('a')
  1616. ->field('a.id,b.order_type,b.cat_id,d.supplierNo')
  1617. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  1618. ->leftJoin('order_send c', 'c.outCode=a.outCode')
  1619. ->leftJoin('purchease_order d', 'd.cgdNo=c.cgdNo')
  1620. ->where($where)
  1621. ->cursor();
  1622. $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
  1623. ->group('supplierNo')
  1624. ->column('supplierNo');
  1625. $list = [];
  1626. // $total = ['一级分类' => '总计', '二级分类' => '', '三级分类' => '', '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
  1627. foreach ($data as $val) {
  1628. if (!isset($list[$val['cat_id']])) {
  1629. $cat = made($val['cat_id']);
  1630. $list[$val['cat_id']] = [
  1631. '一级分类' => $cat[0]['name'] ?? '',
  1632. '二级分类' => $cat[1]['name'] ?? '',
  1633. '三级分类' => $cat[2]['name'] ?? '',
  1634. '库存品' => 0,
  1635. '非库存品' => 0,
  1636. '咨询采反' => 0,
  1637. '供应商发货' => 0,
  1638. '负责人发货' => 0,
  1639. '物流岗发货' => 0,
  1640. // '总计' => 0,
  1641. ];
  1642. }
  1643. switch ($val['order_type']) {
  1644. case 1:
  1645. $list[$val['cat_id']]['库存品']++;
  1646. // $total['库存品']++;
  1647. //物流岗发
  1648. $list[$val['cat_id']]['物流岗发货']++;
  1649. break;
  1650. case 2:
  1651. $list[$val['cat_id']]['非库存品']++;
  1652. // $total['非库存品']++;
  1653. if (in_array($val['supplierNo'], $supplierNos)) $list[$val['cat_id']]['供应商发货']++;
  1654. else $list[$val['cat_id']]['负责人发货']++;
  1655. break;
  1656. case 3:
  1657. $list[$val['cat_id']]['咨询采反']++;
  1658. if (in_array($val['supplierNo'], $supplierNos)) $list[$val['cat_id']]['供应商发货']++;
  1659. else $list[$val['cat_id']]['负责人发货']++;
  1660. // $total['咨询采反']++;
  1661. break;
  1662. }
  1663. // $list[$val['cat_id']]['总计']++;
  1664. // $total['总计']++;
  1665. }
  1666. $list = array_merge($list);//重置下标
  1667. // $list[] = $total;
  1668. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1669. excelSave('采购订单发货维度表' . date('YmdHis'), array_keys($list[0]), $list);
  1670. }
  1671. //【十三、供应商采购订单情况】
  1672. public function purcheaseOrderMonth()
  1673. {
  1674. $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1675. $where = [['a.is_del', '=', 0]];
  1676. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  1677. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  1678. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1679. $data = Db::name('purchease_order')
  1680. ->alias('a')
  1681. ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type')
  1682. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  1683. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  1684. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  1685. ->where($where)
  1686. ->cursor();
  1687. $list = $tmp = [];
  1688. $total = ['supplier_name' => '总计', 'total_cgd' => 0, 'tag_1' => 0, 'tag_2' => 0, 'tag_c' => 0, 'tag_b' => 0, 'tag_zx' => 0];
  1689. foreach ($data as $val) {
  1690. if (!isset($list[$val['supplierNo']])) {
  1691. $list[$val['supplierNo']] = [
  1692. 'supplier_name' => $val['supplier_name'],
  1693. 'total_cgd' => 0,//订单总量
  1694. 'tag_1' => 0,//库存品
  1695. 'tag_2' => 0,//非库存品
  1696. 'tag_c' => 0,//to C
  1697. 'tag_b' => 0,//to B
  1698. 'tag_zx' => 0,//咨询采反总数
  1699. ];
  1700. }
  1701. switch ($val['order_type']) {
  1702. case 1:
  1703. //库存品
  1704. if ($val['order_source'] == 0) {
  1705. $list[$val['supplierNo']]['tag_1']++;
  1706. $total['tag_1']++;
  1707. }
  1708. break;
  1709. case 2:
  1710. //非库存品
  1711. $list[$val['supplierNo']]['tag_2']++;
  1712. $total['tag_2']++;
  1713. case 3:
  1714. //咨询采反
  1715. if ($val['order_source'] == 2) {
  1716. $list[$val['supplierNo']]['tag_zx']++;
  1717. $total['tag_zx']++;
  1718. }
  1719. break;
  1720. }
  1721. switch ($val['use_type']) {
  1722. case 1:
  1723. //to B
  1724. $list[$val['supplierNo']]['tag_b']++;
  1725. $total['tag_b']++;
  1726. break;
  1727. case 2:
  1728. //to C
  1729. $list[$val['supplierNo']]['tag_c']++;
  1730. $total['tag_c']++;
  1731. break;
  1732. }
  1733. $list[$val['supplierNo']]['total_cgd']++;
  1734. $total['total_cgd']++;
  1735. }
  1736. // $list = array_merge($list);//重置下标,关联数组,下标是字符,无法通过array_merge方法重置下标
  1737. foreach ($list as $value) {
  1738. $tmp[] = $value;
  1739. }
  1740. $tmp[] = $total;
  1741. return app_show(0, '请求成功', $tmp);
  1742. }
  1743. //【十三、供应商采购订单情况-导出】
  1744. public function purcheaseOrderMonthExport()
  1745. {
  1746. $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1747. $where = [['a.is_del', '=', 0]];
  1748. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  1749. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  1750. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1751. $data = Db::name('purchease_order')
  1752. ->alias('a')
  1753. ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type')
  1754. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  1755. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  1756. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  1757. ->where($where)
  1758. ->cursor();
  1759. $list = $tmp = [];
  1760. $total = ['采购方' => '总计', '订单总量' => 0, '库存品' => 0, '非库存品' => 0, 'toC' => 0, 'toB' => 0, '反馈单数合计' => 0];
  1761. foreach ($data as $val) {
  1762. if (!isset($list[$val['supplierNo']])) {
  1763. $list[$val['supplierNo']] = [
  1764. '采购方' => $val['supplier_name'],
  1765. '订单总量' => 0,//订单总量
  1766. '库存品' => 0,//库存品
  1767. '非库存品' => 0,//非库存品
  1768. 'toC' => 0,//to C
  1769. 'toB' => 0,//to B
  1770. '反馈单数合计' => 0,//咨询采反总数
  1771. ];
  1772. }
  1773. switch ($val['order_type']) {
  1774. case 1:
  1775. //库存品
  1776. if ($val['order_source'] == 0) {
  1777. $list[$val['supplierNo']]['库存品']++;
  1778. $total['库存品']++;
  1779. }
  1780. break;
  1781. case 2:
  1782. //非库存品
  1783. $list[$val['supplierNo']]['非库存品']++;
  1784. $total['非库存品']++;
  1785. break;
  1786. case 3:
  1787. //咨询采反
  1788. if ($val['order_source'] == 2) {
  1789. $list[$val['supplierNo']]['反馈单数合计']++;
  1790. $total['反馈单数合计']++;
  1791. }
  1792. break;
  1793. }
  1794. switch ($val['use_type']) {
  1795. case 1:
  1796. //to B
  1797. $list[$val['supplierNo']]['toB']++;
  1798. $total['toB']++;
  1799. break;
  1800. case 2:
  1801. //to C
  1802. $list[$val['supplierNo']]['toC']++;
  1803. $total['toC']++;
  1804. break;
  1805. }
  1806. $list[$val['supplierNo']]['订单总量']++;
  1807. $total['订单总量']++;
  1808. }
  1809. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1810. excelSave('供应商采购订单情况' . date('YmdHis'), array_keys($total), $list);
  1811. }
  1812. //【十四、供应商负责人采购订单情况】
  1813. public function purcheaseOrderPersonMonth()
  1814. {
  1815. $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'flag' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1816. $where = [['a.is_del', '=', 0]];
  1817. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  1818. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  1819. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1820. if ($param['flag'] != '') {
  1821. $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
  1822. ->group('supplierNo')
  1823. ->column('supplierNo');
  1824. if ($param['flag'] == 1) $where[] = ['a.supplierNo', 'in', $supplierNos];//1.开通账号的
  1825. else $where[] = ['a.supplierNo', 'not in', $supplierNos];//2.未开通账号的
  1826. }
  1827. $data = Db::name('purchease_order')
  1828. ->alias('a')
  1829. ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type,c.personid,c.person')
  1830. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  1831. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  1832. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  1833. ->leftJoin("supplier c", "c.code=a.supplierNo AND c.is_del=0")
  1834. ->where($where)
  1835. ->cursor();
  1836. $list = [];
  1837. $total = ['person' => '总计', 'total_cgd' => 0, 'tag_1' => 0, 'tag_2' => 0, 'tag_c' => 0, 'tag_b' => 0, 'tag_zx' => 0];
  1838. foreach ($data as $val) {
  1839. if (!isset($list[$val['personid']])) {
  1840. $list[$val['personid']] = [
  1841. 'person' => $val['person'],
  1842. 'total_cgd' => 0,//订单总量
  1843. 'tag_1' => 0,//库存品
  1844. 'tag_2' => 0,//非库存品
  1845. 'tag_c' => 0,//to C
  1846. 'tag_b' => 0,//to B
  1847. 'tag_zx' => 0,//咨询采反总数
  1848. ];
  1849. }
  1850. switch ($val['order_type']) {
  1851. case 1:
  1852. //库存品
  1853. if ($val['order_source'] == 0) {
  1854. $list[$val['personid']]['tag_1']++;
  1855. $total['tag_1']++;
  1856. }
  1857. break;
  1858. case 2:
  1859. //非库存品
  1860. $list[$val['personid']]['tag_2']++;
  1861. $total['tag_2']++;
  1862. break;
  1863. case 3:
  1864. //咨询采反
  1865. if ($val['order_source'] == 2) {
  1866. $list[$val['personid']]['tag_zx']++;
  1867. $total['tag_zx']++;
  1868. }
  1869. break;
  1870. }
  1871. switch ($val['use_type']) {
  1872. case 1:
  1873. //to B
  1874. $list[$val['personid']]['tag_b']++;
  1875. $total['tag_b']++;
  1876. break;
  1877. case 2:
  1878. //to C
  1879. $list[$val['personid']]['tag_c']++;
  1880. $total['tag_c']++;
  1881. break;
  1882. }
  1883. $list[$val['personid']]['total_cgd']++;
  1884. $total['total_cgd']++;
  1885. }
  1886. $list = array_merge($list);//重置下标,关联数组,下标是字符,无法通过array_merge方法重置下标
  1887. $list[] = $total;
  1888. return app_show(0, '请求成功', $list);
  1889. }
  1890. //【十四、供应商负责人采购订单情况-导出】
  1891. public function purcheaseOrderPersonMonthExport()
  1892. {
  1893. $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'flag' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
  1894. $where = [['a.is_del', '=', 0]];
  1895. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  1896. if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
  1897. if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
  1898. if ($param['flag'] != '') {
  1899. $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
  1900. ->group('supplierNo')
  1901. ->column('supplierNo');
  1902. if ($param['flag'] == 1) $where[] = ['a.supplierNo', 'in', $supplierNos];//1.开通账号的
  1903. else $where[] = ['a.supplierNo', 'not in', $supplierNos];//2.未开通账号的
  1904. }
  1905. $data = Db::name('purchease_order')
  1906. ->alias('a')
  1907. ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type,c.personid,c.person')
  1908. ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
  1909. ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
  1910. ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
  1911. ->leftJoin("supplier c", "c.code=a.supplierNo AND c.is_del=0")
  1912. ->where($where)
  1913. ->cursor();
  1914. $list = [];
  1915. $total = ['采购方' => '总计', '订单总量' => 0, '库存品' => 0, '非库存品' => 0, 'toC' => 0, 'toB' => 0, '反馈单数合计' => 0];
  1916. foreach ($data as $val) {
  1917. if (!isset($list[$val['personid']])) {
  1918. $list[$val['personid']] = [
  1919. '采购方' => $val['person'],
  1920. '订单总量' => 0,//订单总量
  1921. '库存品' => 0,//库存品
  1922. '非库存品' => 0,//非库存品
  1923. 'toC' => 0,//to C
  1924. 'toB' => 0,//to B
  1925. '反馈单数合计' => 0,//咨询采反总数
  1926. ];
  1927. }
  1928. switch ($val['order_type']) {
  1929. case 1:
  1930. //库存品
  1931. if ($val['order_source'] == 0) {
  1932. $list[$val['personid']]['库存品']++;
  1933. $total['库存品']++;
  1934. }
  1935. break;
  1936. case 2:
  1937. //非库存品
  1938. $list[$val['personid']]['非库存品']++;
  1939. $total['非库存品']++;
  1940. break;
  1941. case 3:
  1942. //咨询采反
  1943. if ($val['order_source'] == 2) {
  1944. $list[$val['personid']]['反馈单数合计']++;
  1945. $total['反馈单数合计']++;
  1946. }
  1947. break;
  1948. }
  1949. switch ($val['use_type']) {
  1950. case 1:
  1951. //to B
  1952. $list[$val['personid']]['toB']++;
  1953. $total['toB']++;
  1954. break;
  1955. case 2:
  1956. //to C
  1957. $list[$val['personid']]['toC']++;
  1958. $total['toC']++;
  1959. break;
  1960. }
  1961. $list[$val['personid']]['订单总量']++;
  1962. $total['订单总量']++;
  1963. }
  1964. $list[] = $total;
  1965. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  1966. excelSave('供应商负责人采购订单情况' . date('YmdHis'), array_keys($total), $list);
  1967. }
  1968. }