130 lines
5.9 KiB
PHP
130 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use think\Config;
|
|
use fast\Random;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
/**
|
|
* 导出接口
|
|
*/
|
|
class Export extends Api
|
|
{
|
|
|
|
public function workers(){
|
|
$WAREHOUSEID = $this->auth->warehouseid;
|
|
$params=$this->request->post();
|
|
$workDate2 = explode("|",$params['workDate']);
|
|
$spreadsheet = new Spreadsheet();
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
|
|
$title = '团购工作台流水';
|
|
$worksheet->setTitle($title);
|
|
$time = strtotime($workDate2[0]." 00:00:00");
|
|
$time2 = strtotime($workDate2[1]." 00:00:00");
|
|
//echo $time;
|
|
$workersModel = new \app\common\model\wms\Wokes;
|
|
$list = $workersModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->whereBetween("workDate",[intval($time),intval($time2)])->select();
|
|
//print_r($list);die();
|
|
$users = [];
|
|
|
|
foreach ($list as $r){
|
|
array_push($users,$r['userId']);
|
|
}
|
|
$users = array_unique($users);
|
|
|
|
$wmsuserModel = new \app\common\model\wms\User;
|
|
$wmsuser = $wmsuserModel->where('userID','in',$users)->select();
|
|
$works = [];
|
|
$works2 = [];
|
|
$works3 = [];
|
|
$works4 = [];
|
|
$works5 = [];
|
|
$works6 = [];
|
|
foreach ($list as $r){
|
|
$name = '';
|
|
foreach ($wmsuser as $rr){
|
|
if($rr['userID']==$r['userId']){
|
|
$name = $rr['name'];
|
|
}
|
|
}
|
|
//团购打包
|
|
if(strpos($r['grabnum'],'B')>-1 && $r['dabaos']>0){
|
|
array_push($works,[$name,$r['dabaos'],$r['grabnum'],date("Y-m-d",$r['workDate']),date("Y-m-d H:i:s",$r['createtime']),date("Y-m-d H:i:s",$r['updatetime']),$r['workers'],$r['GOODSCOUNT'],substr_count($r['items'],"|"),$r['items']]);
|
|
|
|
}
|
|
//团购复核
|
|
if(strpos($r['grabnum'],'B')>-1 && $r['fuhe']>0){
|
|
array_push($works2,[$name,$r['fuhe'],$r['grabnum'],date("Y-m-d",$r['workDate']),$r['GOODSCOUNT'],substr_count($r['items'],"|"),$r['items']]);
|
|
}
|
|
//团购拣货
|
|
if(strpos($r['grabnum'],'B')>-1 && $r['picks']>0){
|
|
array_push($works3,[$name,$r['picks'],$r['grabnum'],date("Y-m-d",$r['workDate']),$r['GOODSCOUNT'],substr_count($r['items'],"|"),$r['items'],date("Y-m-d H:i:s",$r['createtime'])]);
|
|
}
|
|
//散单拣货
|
|
if(strpos($r['grabnum'],'B')===FALSE && $r['picks']>0){
|
|
array_push($works4,[$name,$r['picks'],$r['grabnum'],$r['POSTNUM'],date("Y-m-d",$r['workDate']),$r['GOODSCOUNT'],substr_count($r['items'],"|"),$r['items']]);
|
|
}
|
|
//散单复核
|
|
if(strpos($r['grabnum'],'B')===FALSE && $r['fuhe']>0){
|
|
array_push($works5,[$name,$r['fuhe'],$r['grabnum'],$r['POSTNUM'],date("Y-m-d",$r['workDate']),$r['GOODSCOUNT'],substr_count($r['items'],"|"),$r['items']]);
|
|
}
|
|
//散单打包
|
|
if(strpos($r['grabnum'],'B')===FALSE && $r['dabaos']>0){
|
|
//echo strpos($r['grabnum'],'B').'<br>';
|
|
array_push($works6,[$name,$r['dabaos'],$r['grabnum'],$r['POSTNUM'],date("Y-m-d",$r['workDate']),$r['GOODSCOUNT'],substr_count($r['items'],"|"),$r['items']]);
|
|
}
|
|
}
|
|
//die();
|
|
$worksheet2 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, '团购复核流水');
|
|
$worksheet3 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, '团购拣货流水');
|
|
$worksheet4 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, '散单拣货流水');
|
|
$worksheet5 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, '散单复核流水');
|
|
$worksheet6 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, '散单打包流水');
|
|
//print_r($workers);die();
|
|
$worksheet->fromArray(
|
|
[
|
|
['工作台','波次订单数','波次号','生产日期','开始时间','结束时间','成员','商品数量','SKU数量','订单明细']
|
|
], '', 'A1' );
|
|
$worksheet->fromArray($works, '', 'A2' );
|
|
$worksheet2->fromArray(
|
|
[
|
|
['操作人','波次订单数','波次号','生产日期','商品数量','SKU数量','订单明细']
|
|
], '', 'A1' );
|
|
$worksheet2->fromArray($works2, '', 'A2' );
|
|
$worksheet3->fromArray(
|
|
[
|
|
['操作人','波次订单数','波次号','生产日期','商品数量','SKU数量','订单明细','生产时间']
|
|
], '', 'A1' );
|
|
$worksheet3->fromArray($works3, '', 'A2' );
|
|
$worksheet4->fromArray(
|
|
[
|
|
['操作人','波次订单数','波次号','快递号','生产日期','商品数量','SKU数量','订单明细']
|
|
], '', 'A1' );
|
|
$worksheet4->fromArray($works4, '', 'A2' );
|
|
$worksheet5->fromArray(
|
|
[
|
|
['操作人','波次订单数','波次号','快递号','生产日期','商品数量','SKU数量','订单明细']
|
|
], '', 'A1' );
|
|
$worksheet5->fromArray($works5, '', 'A2' );
|
|
$worksheet6->fromArray(
|
|
[
|
|
['操作人','波次订单数','波次号','快递号','生产日期','商品数量','SKU数量','订单明细']
|
|
], '', 'A1' );
|
|
$worksheet6->fromArray($works6, '', 'A2' );
|
|
$spreadsheet->addSheet($worksheet2);
|
|
$spreadsheet->addSheet($worksheet3);
|
|
$spreadsheet->addSheet($worksheet4);
|
|
$spreadsheet->addSheet($worksheet5);
|
|
$spreadsheet->addSheet($worksheet6);
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
header('Content-Disposition: attachment;filename=Excel导出.xlsx');
|
|
header('Cache-Control: max-age=0');
|
|
|
|
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
$write->save('php://output');
|
|
}
|
|
}
|