NowReportHandle.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\Exception;
  8. use think\facade\Cache;
  9. use think\facade\Db;
  10. //处理报表预约记录,生成报表文件
  11. class NowReportHandle extends Command
  12. {
  13. //redis队列的key,在ReportReserve控制器中也有定义,要同步修改(轻易不要修改)
  14. private $key = 'cxreport';
  15. protected function configure()
  16. {
  17. // 指令配置
  18. $this->setName('"cxreport"')
  19. ->setDescription('定时处理报表预约,生成报表文件');
  20. }
  21. //处理报表预约记录,生成报表文件
  22. protected function execute(Input $input, Output $output)
  23. {
  24. try {
  25. ini_set("memory_limit","516M");
  26. $info = Cache::store('redis')->handler()->rpop($this->key);
  27. if ($info) {
  28. $info = json_decode($info, true);
  29. //不同的方法处理不同的脚本
  30. switch ($info['code']) {
  31. //退货台账-业务口径
  32. case 'A':
  33. $res = $this->A($info['start'], $info['end']);
  34. break;
  35. //库存日报及预警汇总表
  36. case 'B':
  37. $res = $this->B($info['start'], $info['end']);
  38. break;
  39. //退货台账
  40. case 'C':
  41. $res = $this->C($info['start'], $info['end']);
  42. break;
  43. //
  44. case 'D':
  45. $res = $this->D($info['start'], $info['end']);
  46. break;
  47. case 'E':
  48. $res = $this->E($info['start'], $info['end']);
  49. break;
  50. case 'F':
  51. $res = $this->F($info['start'], $info['end']);
  52. break;
  53. case 'G':
  54. //订单表导出
  55. $res = $this->G($info['start'], $info['end']);
  56. break;
  57. default:
  58. throw new Exception('暂不支持这个报表');
  59. }
  60. $file = excelSaveFile($res, $info['name'] . date('YmdHis'));
  61. Db::name('exec')
  62. ->where(['id' => $info['id'], 'status' => 1])//status==1 待处理
  63. ->update([
  64. 'status' => 2, //status==2 处理完成
  65. 'down_url' => $file,
  66. 'updatetime' => date('Y-m-d H:i:s'),
  67. 'expiretime' => date('Y-m-d H:i:s', strtotime('+7 day'))
  68. ]);
  69. $output->writeln('【' . $info['id'] . '】该预约记录处理成功');
  70. } else $output->writeln('没有可供处理的报表预约记录');
  71. } catch (Exception $exception) {
  72. $output->writeln($exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
  73. }
  74. }
  75. //退货台账-业务口径
  76. private function A(string $start_date = '', string $end_date = '')
  77. {
  78. $data = Db::name('order_back')
  79. ->alias('ob')
  80. ->field('ob.thNo 退货单号,ob.status 流程进度,ob.addtime 退货发起日期,"" 退货人所在部门,ob.apply_name 退货人,ob.return_num 退货数量,ob.total_fee 退货销售货款,ob.remark 退货备注,c.companyName 客户名称,ob.customer_code 客户编码,"" 一级组织,"" 二级组织,"" 三级组织,p.platform_name 平台名称,s.poNo PO编号,s.orderCode 确认单编号,s.order_type 确认单类型,s.addtime 确认单下单时间,"" 业务人员所在部门,ob.cgder 业务人员,s.good_code 确认单产品编号,ob.good_name 产品名称,s.skuCode 产品编码,"" 一级分类,0 售前记录总数,ob.apply_id,ob.cgderid,s.cat_id,c.itemid')
  81. ->leftJoin('sale s', 's.orderCode=ob.orderCode')
  82. ->leftJoin('customer_info c', 'c.companyNo=ob.customer_code AND c.is_del=0')
  83. ->leftJoin('platform p', 'p.id=ob.platform_id')
  84. ->where(['ob.is_del' => 0, 'ob.status' => 4])
  85. ->whereBetween('ob.addtime', [$start_date, $end_date])
  86. ->cursor();
  87. $all_status = [1 => '待业务审批', 2 => '待专员审批', 3 => '待主管审批', 4 => '退货完成', 5 => '业务驳回', 6 => '采购驳回', 7 => '专员审批不通过'];
  88. $all_order_type = [1 => '备库', 2 => '非库存', 3 => '咨询采反', 4 => '项目采反', 5 => '平台部订单库存品', 6 => '平台部订单非库存品'];
  89. $list = [];
  90. foreach ($data as $value) {
  91. $value['流程进度'] = isset($all_status[$value['流程进度']]) ? $all_status[$value['流程进度']] : '';
  92. if (!empty($value['itemid'])) {
  93. $customer_org1 = get_top_customer_org($value['itemid']);
  94. foreach ($customer_org1 as $vv) {
  95. switch ($vv['level']) {
  96. case 1:
  97. $value['一级组织'] = $vv['name'];
  98. break;
  99. case 2:
  100. $value['二级组织'] = $vv['name'];
  101. break;
  102. case 3:
  103. $value['三级组织'] = $vv['name'];
  104. break;
  105. }
  106. }
  107. }
  108. $value['退货人所在部门'] = get_company_name_by_uid($value['apply_id']);
  109. $value['业务人员所在部门'] = get_company_name_by_uid($value['cgderid']);
  110. $value['确认单类型'] = isset($all_order_type[$value['确认单类型']]) ? $all_order_type[$value['确认单类型']] : '';
  111. $top = made($value['cat_id']);
  112. $value['一级分类'] = isset($top[0]['name']) ? $top[0]['name'] : '';
  113. $value['售前记录总数'] = Db::name('sale_return')->where(['orderCode' => $value['确认单编号'], 'is_del' => 0, 'status' => 5])->count('id');
  114. unset($value['cat_id']);
  115. unset($value['itemid']);
  116. unset($value['apply_id']);
  117. unset($value['cgderid']);
  118. yield $list[] = $value;
  119. }
  120. return $list;
  121. }
  122. //库存预警汇总表
  123. private function B(string $start_date = '', string $end_date = '')
  124. {
  125. $data = Db::name('good_stock')
  126. ->alias('wgs')
  127. ->field(" wb.company '公司名称',
  128. wgs.spuCode '产品编号',
  129. cat_id '一级分类',
  130. good_name '产品名称',
  131. '' as '成本单价',
  132. wait_in_stock '待入库存数量',
  133. wait_out_stock '待出库存数量',
  134. usable_stock '可用库存数量',
  135. wait_out_stock+usable_stock '当前库存',
  136. '' as '可用库存金额',
  137. '' as '当前库存金额',
  138. '' as '保质期时间',
  139. '' as '库存天数',
  140. wgb.creater as 'CGD.采购员',
  141. '' as '备库单号',
  142. ws.`name` as '供应商名称',
  143. wwi.`name` as '仓库名称',
  144. '' as '最近入库时间'")
  145. ->leftJoin('warehouse_info wwi', 'wwi.wsm_code = wgs.wsm_code')
  146. ->leftJoin('business wb', 'wb.companyNo = wwi.companyNo')
  147. ->leftJoin('good_basic wgb', 'wgb.spuCode = wgs.spuCode')
  148. ->leftJoin('supplier ws', 'wwi.supplierNo = ws.`code`')
  149. ->where('wgs.is_del', 0)
  150. ->where('wgb.is_stock', 1)
  151. ->whereBetween('wgs.updatetime', [$start_date, $end_date])
  152. ->order('wgs.updatetime', 'desc')
  153. ->cursor();
  154. $list = [];
  155. foreach ($data as $value) {
  156. $cat = made($value['一级分类']);
  157. $value['一级分类'] = isset($cat[0]['name'])?$cat[0]['name']:"";
  158. $value['成本单价'] = Db::name('good_nake')
  159. ->where('spuCode', $value['产品编号'])
  160. ->order('min_num', 'asc')
  161. ->value('nake_total', '0');
  162. $value['可用库存金额'] = bcmul((string)$value['可用库存数量'] ?? '0', (string)$value['成本单价'] ?? '0', 2);
  163. $value['当前库存金额'] = bcmul((string)$value['当前库存'] ?? '0', (string)$value['成本单价'] ?? '0', 2);
  164. $value['最近入库时间'] =Db::name("purchease_order")->alias("a")->leftJoin("purchease_in c","a.cgdNo=c.cgdNo")->where(["spuCode"=>
  165. $value['产品编号'],"order_type"=>1,"order_source"=>0,"c.status"=>[4,6]])->order("a.addtime desc")->value("c
  166. .addtime","");
  167. $value['备库单号']=Db::name("purchease_order")->alias("a")->where(["spuCode"=>$value['产品编号'], "order_type"=>1,"order_source"=>0])->order("a.addtime desc")->value("a.bkcode","");
  168. if (!empty($value['最近入库时间'])) {
  169. $value['保质期时间'] = date('Y-m-d H:i:s', strtotime($value['最近入库时间']) + 31536000);//365天之后
  170. $value['库存天数'] = bcdiv((string)(time() - strtotime($value['最近入库时间'])), (string)(24 * 3600));//365天之后
  171. }
  172. yield $list[] = $value;
  173. }
  174. return $list;
  175. }
  176. //退货台账
  177. private function C(string $start_date = '', string $end_date = '')
  178. {
  179. $data = Db::name('th_data')
  180. ->alias('wtd')
  181. ->leftJoin('wsm_sale_return wsr', 'wtd.thCode = wsr.returnCode and wtd.th_type=1')
  182. ->leftJoin('order_return wor', 'wtd.thCode = wor.returnCode and wtd.th_type in (2,3)')
  183. ->leftJoin('sale ws', 'ws.orderCode=wtd.orderCode')
  184. ->leftJoin('business wb', ' ws.supplierNo=wb.companyNo')
  185. ->leftJoin('order_num won', 'won.orderCode=wtd.orderCode')
  186. ->leftJoin('purchease_order wpo', 'wpo.cgdNo=won.cgdNo')
  187. ->leftJoin('supplier wps', 'wps.code=wpo.supplierNo')
  188. ->leftJoin('customer_info wci', 'wci.companyNo =ws.customer_code')
  189. ->whereBetween('wtd.addtime', [$start_date, $end_date])
  190. ->field(" year(wtd.addtime) '年',
  191. month(wtd.addtime) '月',
  192. DAYOFMONTH(wtd.addtime) '日',
  193. wtd.addtime '退货单创建时间',
  194. wb.company '公司名称',
  195. thCode '退货单号',
  196. if(wtd.th_type=1,'售前','售后') '退货类型',
  197. '已完成' as '流程进度',
  198. wtd.apply_id '业务部门',
  199. wtd.apply_name '业务人员',
  200. wtd.orderCode '订单编号',
  201. ws.platform_id '平台类型',
  202. ws.platform_order '平台订单号',
  203. '' as '客户属性',
  204. wci.itemid as '分公司',
  205. wci.companyName '客户名称',
  206. wtd.spuCode '产品编码',
  207. '' as '财务核算码',
  208. '' as `一级分类`,
  209. '' as `二级分类`,
  210. wtd.cat_id as `三级分类`,
  211. wtd.good_name as '商品名称',
  212. ws.order_type as `单位`,
  213. wtd.th_num '退货数量',
  214. ws.sale_price '销售单价',
  215. wtd.th_fee '退货金额',
  216. ifnull(wsr.remark,wor.error_remark) as '退货备注',
  217. won.cgdNo '采购单单号',
  218. wpo.cgder '采购员',
  219. wpo.nake_fee '采购裸价',
  220. wpo.pakge_fee '包装费',
  221. wpo.delivery_fee '物流费',
  222. wpo.cert_fee '证书费',
  223. wpo.mark_fee '加标费',
  224. wpo.open_fee '开模费',
  225. wpo.diff_weight '工差',
  226. wpo.diff_fee '采购工差金额',
  227. wpo.good_price '成本合计',
  228. (wpo.good_price * wtd.th_num) '退货采购货款',
  229. '' as '税点',
  230. wpo.supplier_name '供应商名称',
  231. if(ws.is_stock=1,'是','否') '是否库存',
  232. '' as '发货方式',
  233. if(ifnull(wsr.is_th,wor.is_th)=0,'否','是') as '供应商是否同意退货',
  234. if(wps.pay_type='0','现结',if(wps.pay_type='1','月结',if(wps.pay_type='2','双月结',wps.pay_type))) as '付款方式'
  235. ")->cursor();
  236. $com = [];
  237. foreach ($data as $value) {
  238. $value['业务部门'] = get_company_name_by_uid(intval($value['业务部门']));
  239. $value['财务核算码']=Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  240. $comp =get_top_customer_org($value['分公司']);
  241. $value['客户属性']=isset($comp[0]['name'])?$comp[0]['name']:"";
  242. $value['分公司']=isset($comp[1]['name'])?$comp[1]['name']:"";
  243. $top = made($value['三级分类']);
  244. $value['一级分类'] = isset($top[0]['name']) ? $top[0]['name'] : '';
  245. $value['二级分类'] = isset($top[1]['name']) ? $top[1]['name'] : '';
  246. $value['三级分类'] = isset($top[2]['name']) ? $top[2]['name'] : '';
  247. if($value['单位']==3||$value['单位']==4){
  248. $good= Db::name("good_zixun")->where(["spuCode"=>$value['产品编码']])->find();
  249. }else{
  250. $good= Db::name("good_basic")->where(["spuCode"=>$value['产品编码']])->find();
  251. }
  252. $value['单位']=isset($good['good_unit'])?Db::name("unit")->where(["id"=>$good['good_unit']])->value('unit',''):"";
  253. $value['税点']=isset($good['tax'])?$good['tax'].'%':"";
  254. $value['平台类型']= Db::name("platform")->where(["id"=>$value['平台类型']])->value("platform_name",'');
  255. yield $com[] = $value;
  256. }
  257. return $com;
  258. }
  259. //出入库明细
  260. public function D($start,$end){
  261. $list =Db::name("order_out")->alias('woo')->leftJoin("sale a","a.orderCode=woo.orderCode")
  262. ->leftJoin("order_back wor","wor.outCode=woo.outCode and wor.status=4")
  263. ->leftJoin("order_num won","won.orderCode=a.orderCode")
  264. ->leftJoin("purchease_order wpo","wpo.cgdNo=won.cgdNo")
  265. ->leftJoin("good_basic wgb","wgb.spuCode=wpo.spuCode")
  266. ->leftJoin("good_zixun wgz","wgz.spuCode=wpo.spuCode")
  267. ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
  268. ->where('woo.status',">=", 2)
  269. ->whereBetween('woo.addtime', [$start, $end])
  270. ->field(" year(`a`.`addtime`) AS `年`,
  271. month(`a`.`addtime`) AS `月`,
  272. dayofmonth(`a`.`addtime`) AS `日`,
  273. a.supplierNo
  274. as '公司名称',
  275. a.apply_id '业务部门名称' ,
  276. a.apply_name as '业务人员',
  277. a.order_type as '订单类型',
  278. a.good_type as '商品类型',
  279. woo.outCode '发货编号',
  280. `woo`.`send_num` AS `本次发货数量`,
  281. `woo`.`sendtime` AS `本次发货时间`,
  282. `woo`.`orderCode` AS `确认单编号`,
  283. `a`.`good_code` AS `商品编号`,
  284. '' as '一级分类',
  285. '' as '二级分类',
  286. a.cat_id as '三级分类',
  287. '' as '财务核算编码',
  288. a.good_name as '商品名称',
  289. ifnull( `wgb`.`good_unit`, `wgz`.`good_unit` ) as '单位',
  290. `a`.`good_num` AS `下单数量`,
  291. `a`.`total_price` AS `销售货款`,
  292. `wpo`.`cgdNo` AS `采购单单号`,
  293. `wpo`.`cgder` AS `采购员`,
  294. `wpo`.`nake_fee` AS `采购裸价`,
  295. `wpo`.`mark_fee` AS `加标费`,
  296. `wpo`.`pakge_fee` AS `包装费`,
  297. `wpo`.`cert_fee` AS `证书费`,
  298. `wpo`.`open_fee` AS `开模费`,
  299. `wpo`.`teach_fee` AS `工艺费`,
  300. `wpo`.`delivery_fee` AS `物流费`,
  301. `wpo`.`good_price` AS `成本合计`,
  302. `wpo`.`total_fee` AS `采购货款`,
  303. ifnull( `wgb`.`tax`, `wgz`.`tax` )/100 AS `采购税点`,
  304. `ws`.`name` AS `供应商名称`,
  305. `wgb`.`is_stock` as '是否库存品',
  306. if (`wgb`.`is_stock`=1,wpo.bkcode,wpo.cgdNo) as '发货方式',
  307. ifnull( `wor`.`thNo`, '' ) AS `退货编号`,
  308. ifnull( `wor`.`return_num`, '' ) AS `退货数量`,
  309. round(( ifnull( `wor`.`return_num`, 0 ) * `a`.`sale_price` ), 2 ) as '退货金额',
  310. '' as '售前退货数量',
  311. `a`.`sale_price` as '售前退货金额'
  312. ")->cursor();
  313. $order_tyepe=["库存销售",'非库存销售','咨询销售','项目销售','平台库存销售','平台非库存销售'];
  314. $good_type=["常规商品",'赠品','样品'];
  315. $data=[];
  316. foreach($list as $value){
  317. $value['公司名称'] = Db::name("business")->where(["companyNo"=>$value['公司名称']])->value('company','');
  318. $value['业务部门名称'] = Db::name("depart_user")->alias("a")->leftJoin("company_item ci","a.itemid=ci.id")
  319. ->where(["a.uid"=>$value['业务部门名称'],"a.status"=>1,"a.is_del"=>0])->value('ci.name','');
  320. $value['订单类型'] = $order_tyepe[ $value['订单类型']-1];
  321. $value['商品类型'] = $good_type[ $value['商品类型']-1];
  322. $cat =made($value['三级分类']);
  323. $value['财务核算编码'] =Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  324. $value['一级分类']=isset($cat[0]['name'])?$cat[0]['name']:"";
  325. $value['二级分类']=isset($cat[1]['name'])?$cat[1]['name']:"";
  326. $value['三级分类']=isset($cat[2]['name'])?$cat[2]['name']:"";
  327. $value['单位']=Db::name("unit")->where(["id"=>$value['单位']])->value("unit",'');
  328. if($value['是否库存品']==1){
  329. $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b","a.cgdNo=b.cgdNo")
  330. ->where(["bkcode"=>$value['发货方式'],"order_type"=>1])->order("b.addtime desc")->value("b.sendtype",'');
  331. $value['是否库存品']='是';
  332. }else{
  333. $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b","a.cgdNo=b.cgdNo")
  334. ->where(["a.cgdNo"=>$value['发货方式']])->order("b.addtime desc")->value("b.sendtype",'');
  335. $value['是否库存品']='否';
  336. }
  337. $value['发货方式'] = $sendtype=1 ? '包邮':$sendtype=2 ? '自提':"";
  338. $value['售前退货数量'] = Db::name("sale_return")->where(["orderCode"=>$value['确认单编号']])->sum('num');
  339. $value['售前退货金额'] =round($value['售前退货数量']* $value['售前退货金额'],2);
  340. yield $data[] = $value;
  341. }
  342. $cgd =$this->GetWlb($start,$end);
  343. foreach ($cgd as $key=>$value){
  344. yield $data[] = $value;
  345. }
  346. return $data;
  347. }
  348. //备库单入库明细
  349. public function E($start,$end){
  350. $list =Db::name("purchease_in")->alias('wpi')->leftJoin("purchease_order wpo","wpo.cgdNo=wpi.cgdNo")
  351. ->leftJoin("purchease wp","wpo.bkcode=wp.bk_code")
  352. ->leftJoin("good_basic wgb","wgb.spuCode=wpo.spuCode")
  353. ->leftJoin("warehouse_info wwi","wwi.wsm_code = wpo.wsm_code")
  354. ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
  355. ->where('wpi.status',"in", [4,6])
  356. ->where('wpo.order_type',"=",1)
  357. ->where('wpo.order_source',"=",0)
  358. ->whereBetween('wpi.addtime', [$start, $end])
  359. ->field("wpo.companyNo '业务公司',
  360. bkcode '备库单号',
  361. wpi.wsm_in_code '入库单号',
  362. wpi.cgdNo '采购单号',
  363. wpo.spuCode '商品编号',
  364. '' as '一级分类',
  365. '' as '二级分类',
  366. wgb.cat_id as '三级分类',
  367. wgb.cat_id as '财务核算编号',
  368. wpo.good_name as '商品名称',
  369. if(wpi.status=4,wpi.send_num,wpi.wsm_num) '入库数量',
  370. round( if(wpi.status=4,wpi.send_num,wpi.wsm_num) * good_price, 2 ) '入库金额',
  371. wpo.updatetime '本次入库时间',
  372. wgb.tax/100 '采购税率',
  373. '' as '不含税入库金额',
  374. '' as '税额',
  375. wp.apply_id as '业务部门',
  376. wp.apply_name as '业务员',
  377. wpo.cgder as '采购员',
  378. nake_fee '成本裸价',
  379. wsm_type '仓库类型',
  380. ws.name '供应商名称',
  381. wwi.name '仓库名称'
  382. ")->cursor();
  383. $data=[];
  384. foreach($list as $value){
  385. $value['业务公司'] = Db::name("business")->where(["companyNo"=>$value['业务公司']])->value('company','');
  386. $value['业务部门'] = Db::name("depart_user")->alias("a")->leftJoin("company_item ci","a.itemid=ci.id")
  387. ->where(["a.uid"=>$value['业务部门'],"a.status"=>1,"a.is_del"=>0])->value('ci.name','');
  388. $cat =made($value['三级分类']);
  389. $value['财务核算编号'] =Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  390. $value['一级分类']=isset($cat[0]['name'])?$cat[0]['name']:"";
  391. $value['二级分类']=isset($cat[1]['name'])?$cat[1]['name']:"";
  392. $value['三级分类']=isset($cat[2]['name'])?$cat[2]['name']:"";
  393. $value['不含税入库金额']= round($value['入库金额']/(1+$value['采购税率']),2);
  394. $value['税额']= round(($value['入库金额']/(1+$value['采购税率'])) *$value['采购税率'],2);
  395. $value['仓库类型'] = Db::name("warehouse_type")->where(["id"=>$value['仓库类型']])->value("name",'');
  396. yield $data[] = $value;
  397. }
  398. return $data;
  399. }
  400. //库存出入库
  401. public function F($start,$end){
  402. $list =Db::name("order_out")->alias('woo')->leftJoin("sale a","a.orderCode=woo.orderCode")
  403. ->leftJoin("order_num won","won.orderCode=a.orderCode")
  404. ->leftJoin("order_back wor","wor.outCode=woo.outCode and wor.status=4")
  405. ->leftJoin("purchease_order wpo","wpo.cgdNo=won.cgdNo")
  406. ->leftJoin("good_basic wgb","wgb.spuCode=wpo.spuCode")
  407. ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
  408. ->leftJoin("warehouse_info wwi","wwi.wsm_code = wpo.wsm_code")
  409. ->where('woo.status',">=", 2)
  410. ->where('a.order_type',"=", 1)
  411. ->whereBetween('woo.addtime', [$start, $end])
  412. ->field("wpo.companyNo '业务公司',
  413. bkcode '备库单号',
  414. woo.orderCode '销售单号',
  415. woo.outCode '出库单号',
  416. wpo.cgdNo '采购单号',
  417. wpo.spuCode '商品编号',
  418. '' as '一级分类',
  419. '' as '二级分类',
  420. wgb.cat_id as '三级分类',
  421. wgb.cat_id as '财务核算编号',
  422. wpo.good_name as '商品名称',
  423. woo.send_num'出库数量',
  424. round( woo.send_num* wpo.good_price,2) '出库金额',
  425. woo.sendtime '本次出库时间',
  426. wgb.tax/100 '税率',
  427. '' as '不含税出库金额',
  428. ''as '税额',
  429. a.apply_id as '业务部门',
  430. a.apply_name as '业务员',
  431. wpo.cgder as '采购员',
  432. nake_fee '成本裸价',
  433. wor.return_num '出库退货数量',
  434. wwi.wsm_type '仓库类型',
  435. ws.name '供应商名称',
  436. wwi.name '仓库名称'
  437. ")->cursor();
  438. $data=[];
  439. foreach($list as $value){
  440. $value['业务公司'] = Db::name("business")->where(["companyNo"=>$value['业务公司']])->value('company','');
  441. $value['业务部门'] = Db::name("depart_user")->alias("a")->leftJoin("company_item ci","a.itemid=ci.id")
  442. ->where(["a.uid"=>$value['业务部门'],"a.status"=>1,"a.is_del"=>0])->value('ci.name','');
  443. $cat =made($value['三级分类']);
  444. $value['财务核算编号'] =Db::name("cat")->where(["id"=>$value['三级分类']])->value("fund_code",'');
  445. $value['一级分类']=isset($cat[0]['name'])?$cat[0]['name']:"";
  446. $value['二级分类']=isset($cat[1]['name'])?$cat[1]['name']:"";
  447. $value['三级分类']=isset($cat[2]['name'])?$cat[2]['name']:"";
  448. $value['不含税出库金额']= round($value['出库金额']/(1+$value['税率']),2);
  449. $value['税额']= round(($value['出库金额']/(1+$value['税率'])) *$value['税率'],2);
  450. $value['仓库类型'] = Db::name("warehouse_type")->where(["id"=>$value['仓库类型']])->value("name",'');
  451. yield $data[] = $value;
  452. }
  453. return $data;
  454. }
  455. //网络部出入库
  456. public function GetWlb($start,$end){
  457. $db =Db::connect("mysql3");
  458. $list =$db->name("cgd_info")
  459. ->where(['ShortText1617866362204'=>'客服确认单'])->whereBetweenTime('createdTime',$start,$end)->field(
  460. "year(createdTime) AS `年`,
  461. month(createdTime) AS `月`,
  462. dayofmonth(createdTime) AS `日`,
  463. ShortText1618270466672 '公司名称',
  464. department '业务部门',
  465. ownerName '业务人员',
  466. ShortText1617866362204 '订单类型',
  467. '' as '商品类型',
  468. '' as '发货编号',
  469. Number1618240600907 '本次发货数量',
  470. createdTime '本次发货时间',
  471. ShortText1617866360004 '确认单编号',
  472. ShortText1617861001482 '商品编号',
  473. ShortText1617865626160 '一级分类',
  474. ''as '二级分类',
  475. '' as '三级分类',
  476. '' as '财务核算编码',
  477. ShortText1617861966146 as '商品名称',
  478. ShortText1617865685744 as '单位',
  479. Number1618240600907 '下单数量',
  480. '' AS `销售货款`,
  481. ShortText1618315935182 as '采购单单号',
  482. ownerName '采购员',
  483. Number1617865804813 AS `采购裸价`,
  484. Number1617865807879 AS `加标费`,
  485. Number1617865810822 AS `包装费`,
  486. Number1617865813284 AS `证书费`,
  487. Number1617865816181 AS `开模费`,
  488. number1618240204358 AS `工艺费`,
  489. number1618240287778 AS `物流费`,
  490. Number1617865818517 AS `成本合计`,
  491. Number1618240685904 AS `采购货款`,
  492. ShortText1617865688485 AS `采购税点`,
  493. ShortText1620399144946 AS `供应商名称`,
  494. '否'as '是否库存品',
  495. '' as '发货方式',
  496. '' AS `退货编号`,
  497. '' AS `退货数量`,
  498. '' as '退货金额',
  499. '' as '售前退货数量',
  500. '' as '售前退货金额'
  501. ")->cursor();
  502. $data=[];
  503. foreach($list as $value){
  504. $value['销售货款'] = $db->name("qrd_info")->where(['sequenceNo'=>$value['确认单编号']])->value('Number1618248813613','');
  505. yield $data[] = $value;
  506. }
  507. return $data;
  508. }
  509. //【订单导出表】
  510. public function G(string $start_date = '', string $end_date = '')
  511. {
  512. $all_order_type = [1 => '备库', 2 => '非库存', 3 => '咨询采反', 4 => '项目采反', 5 => '平台部订单销售库存', 6 => '平台部订单销售非库存'];//订单类型
  513. $all_sale_status = [0 => '待发货', 1 => '待发货完成', 2 => '发货已完成', 3 => '订单已取消'];//订单状态(sale表里的status)
  514. $all_stock = [0 => '非库存品', 1 => '库存品'];//是否库存品
  515. $all_is_activity = [0 => '不参与活动', 1 => '参与活动'];
  516. $all_good_type = [1 => '正常商品', 2 => '赠品', 3 => '样品'];
  517. $data = Db::name('sale')
  518. ->alias('s')
  519. ->field('s.addtime 确认单下单时间,s.orderCode 订单编号,s.order_type 订单类型,s.status 订单状态,s.apply_name 创建人,ci.name 部门,b.company 销售方公司,"" 一级组织,"" 二级组织,csi.companyName 购买方公司,p.platform_name 所属平台,s.platform_order 平台订单号,s.poNo 其他单号,s.paytime 承诺回款时间,ou.order_use 订单用途,"" 活动类型,s.good_name 产品名称,"" 一级分类,gb.tax 税率,s.sale_price 销售单价,s.good_num 下单数量,s.total_price 销售总额,po.cgder 采购人,gb.customized 工期时间,s.arrive_time 要求到货时间,s.remark 备注,s.is_stock 是否库存品,csi.itemid,s.cat_id,s.is_activity,s.good_type')
  520. ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
  521. ->leftJoin('business b', 'b.companyNo=s.supplierNo')
  522. ->leftJoin('platform p', 'p.id=s.platform_id')
  523. ->leftJoin('good_basic gb', 'gb.spuCode=s.good_code')
  524. ->leftJoin('order_use ou', 'ou.id=s.use_order')
  525. ->leftJoin('depart_user u', 'u.uid=s.apply_id')
  526. ->leftJoin('company_item ci', 'ci.id=u.itemid')
  527. ->leftJoin('order_num on', 'on.orderCode=s.orderCode')
  528. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  529. ->where('s.is_del', 0)
  530. ->whereBetween('s.addtime', [$start_date, $end_date])
  531. ->order('s.addtime', 'desc')
  532. ->cursor();
  533. $list = [];
  534. foreach ($data as $value) {
  535. $value['订单类型'] = isset($all_order_type[$value['订单类型']]) ? $all_order_type[$value['订单类型']] : '';
  536. $value['订单状态'] = isset($all_sale_status[$value['订单状态']]) ? $all_sale_status[$value['订单状态']] : '';
  537. if (!empty($value['itemid'])) {
  538. $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
  539. $value['一级组织'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
  540. $value['二级组织'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
  541. }
  542. $cat = made($value['cat_id']);
  543. $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : '';
  544. $value['是否库存品'] = isset($all_stock[$value['是否库存品']]) ? $all_stock[$value['是否库存品']] : '';
  545. $is_activity = isset($all_is_activity[$value['is_activity']]) ? $all_is_activity[$value['is_activity']] : '';
  546. $good_type = isset($all_good_type[$value['good_type']]) ? $all_good_type[$value['good_type']] : '';
  547. $value['活动类型'] = $is_activity . '/' . $good_type;
  548. unset($value['good_code']);
  549. unset($value['itemid']);
  550. unset($value['cat_id']);
  551. unset($value['is_activity']);
  552. unset($value['good_type']);
  553. yield $list[] = $value;
  554. }
  555. return $list;
  556. }
  557. }