mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-23 10:55:34 +08:00
86 lines
3.2 KiB
PHP
86 lines
3.2 KiB
PHP
<?php
|
||
/**
|
||
* Copyright © ShopeX (http://www.shopex.cn). All rights reserved.
|
||
* See LICENSE file for license details.
|
||
*/
|
||
|
||
class console_material_package_import {
|
||
const IMPORT_TITLE = [
|
||
'加工单名称' => 'mp_name',
|
||
'加工或拆包' => 'service_type',
|
||
'仓库编码' => 'branch_bn',
|
||
'单据备注' => 'memo',
|
||
'礼盒物料编码' => 'bm_bn',
|
||
'数量' => 'number',
|
||
];
|
||
|
||
/**
|
||
* 获取ExcelTitle
|
||
* @return mixed 返回结果
|
||
*/
|
||
public function getExcelTitle()
|
||
{
|
||
return ['加工单导入模板.xlsx',[
|
||
array_keys(self::IMPORT_TITLE)
|
||
]];
|
||
}
|
||
|
||
/**
|
||
* undocumented function
|
||
*
|
||
* @return void
|
||
* @author
|
||
**/
|
||
public function processExcelRow($import_file, $post)
|
||
{
|
||
$format = [];
|
||
// 读取文件
|
||
return kernel::single('omecsv_phpoffice')->import($import_file, function ($line, $buffer, $post, $highestRow) {
|
||
static $title;
|
||
|
||
if ($line == 1) {
|
||
$title = $buffer;
|
||
// 验证模板是否正确
|
||
if (array_filter($title) != array_keys(self::IMPORT_TITLE)) {
|
||
return [false, '导入模板不正确'];
|
||
}
|
||
return [true];
|
||
}
|
||
$buffer = array_combine(self::IMPORT_TITLE, array_slice($buffer, 0, count(self::IMPORT_TITLE)));
|
||
$branch_id = app::get('ome')->model('branch')->db_dump(['branch_bn'=>$buffer['branch_bn']], 'branch_id')['branch_id'];
|
||
if(empty($branch_id)) {
|
||
return [false, $buffer['branch_bn'].':仓库不存在或没有权限'];
|
||
}
|
||
$service_type = '1';
|
||
if(trim($buffer['service_type']) == '拆包') {
|
||
$service_type = '2';
|
||
}
|
||
$data = [
|
||
'mp_name' => trim($buffer['mp_name']),
|
||
'branch_id' => $branch_id,
|
||
'service_type' => $service_type,
|
||
'memo' => trim($buffer['memo']),
|
||
'business_type' => trim($post['business_type']),
|
||
];
|
||
if(app::get('console')->model('material_package')->db_dump(['mp_name'=>$data['mp_name'],'status'=>['1','2'],'branch_id' => $data['branch_id']], 'id')) {
|
||
return [false, $data['mp_name'].'加工单已经存在'];
|
||
}
|
||
$items = [];
|
||
$number = $buffer['number'];
|
||
foreach (app::get('material')->model('basic_material')->getList('*', ['material_bn' => $buffer['bm_bn'], 'type'=>'4']) as $v) {
|
||
$items[$v['bm_id']] = [
|
||
'bm_id' => $v['bm_id'],
|
||
'bm_bn' => $v['material_bn'],
|
||
'bm_name' => $v['material_name'],
|
||
'number' => $number,
|
||
];
|
||
}
|
||
if(empty($items)) {
|
||
return [false, $buffer['bm_bn'].':不存在该礼盒物料'];
|
||
}
|
||
$mpObj = app::get('console')->model('material_package');
|
||
list($rs, $rsData) = $mpObj->insertDataItems($data, $items, '导入');
|
||
return [$rs, $rsData['msg']];
|
||
}, $post, $format);
|
||
}
|
||
} |