新增预订单导出功能
- 实现了预订单的导出功能,支持将预订单信息导出为标签 - 新增导出方法,处理导出逻辑,包括查询预订单信息、构建导出数据和调用导出服务 - 引入了相关模型和服务类,以支持导出功能的实现
This commit is contained in:
parent
ae38c2e571
commit
067f4183b8
@ -8,7 +8,13 @@ use app\admin\lists\beforehand_order\BeforehandOrderLists;
|
||||
use app\admin\lists\beforehand_order\BeforehandOrderTwoLists;
|
||||
use app\admin\lists\beforehand_order\BeforehandOrderThreeLists;
|
||||
use app\admin\logic\beforehand_order\BeforehandOrderLogic;
|
||||
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\service\xlsx\Beforehand;
|
||||
|
||||
/**
|
||||
* 预订单表控制器
|
||||
@ -57,10 +63,10 @@ class BeforehandOrderController extends BaseAdminController
|
||||
*/
|
||||
public function createOutboundOrder()
|
||||
{
|
||||
$params=$this->request->post();
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = BeforehandOrderLogic::createOutboundOrder($params);
|
||||
|
||||
|
||||
return $this->success('出库成功', [], 1, 1);
|
||||
}
|
||||
|
||||
@ -68,10 +74,11 @@ class BeforehandOrderController extends BaseAdminController
|
||||
* @notes 订单转预定单
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function orderTransferAdvanceOrder(){
|
||||
$params=$this->request->post();
|
||||
$params['admin_id']=$this->adminId;
|
||||
$params['mark']='订单转预定单';
|
||||
public function orderTransferAdvanceOrder()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$params['mark'] = '订单转预定单';
|
||||
$result = BeforehandOrderLogic::orderTransferAdvanceOrder($params);
|
||||
return $this->success('转单成功', [], 1, 1);
|
||||
}
|
||||
@ -119,4 +126,29 @@ class BeforehandOrderController extends BaseAdminController
|
||||
$result = BeforehandOrderLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出标签
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$outbound_id = BeforehandOrder::where('id', $params['id'])->value('outbound_id');
|
||||
if(!$outbound_id){
|
||||
return $this->fail('未生成出库单');
|
||||
}
|
||||
$warehouseOrder = WarehouseOrder::where('id', $outbound_id)->field('store_id,delivery_time')->find();
|
||||
$system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('name');
|
||||
$data = WarehouseProduct::where('oid', $outbound_id)->field('product_id,nums')->select()
|
||||
->each(function ($item) use ($system_store,$warehouseOrder) {
|
||||
$item['system_store'] = $system_store;
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find();
|
||||
$item['store_name'] = $find['store_name'];
|
||||
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']);
|
||||
})
|
||||
->toArray();
|
||||
$file_path=(new Beforehand())->export($data, $system_store);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
||||
|
41
app/common/service/xlsx/Beforehand.php
Normal file
41
app/common/service/xlsx/Beforehand.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service\xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class Beforehand
|
||||
{
|
||||
public function export($data,$system_store)
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// 合并单元格A1到K1
|
||||
$sheet->mergeCells('A1:B1');
|
||||
$kk1=1;
|
||||
$kk2=2;
|
||||
$kk3=3;
|
||||
$styleArray = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 16,
|
||||
],
|
||||
];
|
||||
foreach ($data as $k => $v) {
|
||||
$sheet->setCellValue('A' . ($k + $kk1), $v['system_store'])->getStyle('A'. ($k + $kk1))->applyFromArray($styleArray);
|
||||
$sheet->setCellValue('A' . ($k + $kk2), $v['store_name'])->getStyle('A'. ($k + $kk2))->applyFromArray($styleArray);
|
||||
$sheet->setCellValue('A' . ($k + $kk3), $v['unit_name'])->getStyle('A'. ($k + $kk3))->applyFromArray($styleArray);
|
||||
$kk1=$kk1+2;
|
||||
$kk2=$kk2+2;
|
||||
$kk3=$kk3+2;
|
||||
}
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$url = '/export/' . date('Y-m') . '/' . $system_store.'标签单-'.date('Y-m-d H:i') . '.xlsx';
|
||||
$file_path = public_path() . $url;
|
||||
// 保存文件到 public 下
|
||||
$writer->save($file_path);
|
||||
return getenv('APP_URL').$url;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user