SaleReport.php 119 KB

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