Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
php_frq_api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
335dfec3
authored
Mar 05, 2021
by
hcy001
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'master' of
ssh://119.23.72.7:22611/q578953158/php_frq_api
parents
3feea549
758697a6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
156 additions
and
0 deletions
app/Http/Controllers/ApiController.php
app/Model/QuoteModel.php
config/quote.php
app/Http/Controllers/ApiController.php
View file @
335dfec3
...
@@ -160,4 +160,11 @@ class ApiController extends Controller
...
@@ -160,4 +160,11 @@ class ApiController extends Controller
Export
((
new
QuoteModel
())
->
add
(
$input
));
Export
((
new
QuoteModel
())
->
add
(
$input
));
}
}
// 批量导入报价
public
function
ApiImportQuote
(
$input
,
$id
)
{
Export
((
new
QuoteModel
())
->
import
(
$input
));
}
}
}
app/Model/QuoteModel.php
View file @
335dfec3
...
@@ -11,6 +11,7 @@ use App\Model\OplogModel;
...
@@ -11,6 +11,7 @@ use App\Model\OplogModel;
use
App\Model\UserModel
;
use
App\Model\UserModel
;
use
App\Http\Controllers\PermController
;
use
App\Http\Controllers\PermController
;
use
RedisDB
;
use
RedisDB
;
use
Excel
;
//报价
//报价
class
QuoteModel
extends
Model
class
QuoteModel
extends
Model
...
@@ -236,6 +237,140 @@ class QuoteModel extends Model
...
@@ -236,6 +237,140 @@ class QuoteModel extends Model
return
[
0
,
'新增报价成功'
];
return
[
0
,
'新增报价成功'
];
}
}
// 报价导入
public
function
import
(
$input
)
{
$file
=
$_FILES
[
'file'
];
// $request->file('file')
$filePath
=
$file
[
'tmp_name'
];
// 临时路径
// 获取导入内容
$excel
=
[];
Excel
::
load
(
$filePath
,
function
(
$reader
)
use
(
&
$excel
){
$data
=
$reader
->
getSheet
(
0
);
$excel
=
$data
->
toArray
();
},
'GBK'
);
if
(
empty
(
$excel
))
return
[
1
,
'未获取到模板内容,请检查模板内容数据格式'
];
$map
=
Config
(
'quote.import_quote_map'
);
if
(
count
(
$map
)
!=
count
(
$excel
[
0
]))
return
[
2
,
'导入模板错误'
];
$excel
=
$this
->
handleExcelData
(
$excel
,
$map
);
// 处理数据
$valid
=
$this
->
excelValid
(
$excel
);
// 验证excel内容
if
(
$valid
[
0
]
!=
0
)
return
$valid
;
array_shift
(
$excel
);
// 删除第一行
// 插入到报价表 -- 状态:草稿
try
{
foreach
(
$excel
as
&
$v
)
{
$v
[
'currency'
]
=
$v
[
'currency'
]
==
'RMB'
?
1
:
2
;
$v
[
'inquiry_id'
]
=
$input
[
'inquiry_id'
];
$v
[
'inquiry_sn'
]
=
$input
[
'inquiry_sn'
];
$v
[
'inquiry_items_id'
]
=
$input
[
'inquiry_items_id'
];
$v
[
'status'
]
=
0
;
}
$res
=
$this
->
create
(
$excel
);
if
(
$res
===
false
)
return
[
1
,
'添加报价草稿失败'
];
$UserModel
=
new
UserModel
;
$data
=
[];
$data
[
'types'
]
=
2
;
$data
[
'relation_id'
]
=
$input
[
'inquiry_items_id'
];
$data
[
'relation_sn'
]
=
''
;
$data
[
'content'
]
=
'批量导入报价,添加到草稿'
;
$data
[
'create_uid'
]
=
$input
[
'user_id'
];
$data
[
'create_name'
]
=
$UserModel
->
FinduserInfoName
(
$input
[
'user_id'
]);
OplogModel
::
log
(
$data
);
}
catch
(
Exception
$e
)
{
return
[
1
,
$e
->
getMessage
()];
}
return
[
0
,
'批量导入报价成功'
];
}
// 处理导入内容---赋上字段
public
function
handleExcelData
(
$excel
,
$map
)
{
$goods_info
=
array_map
(
function
(
$val
)
use
(
$map
)
{
foreach
(
$val
as
$k
=>
$v
)
{
$tmp
[
$map
[
$k
]]
=
trim
(
$v
);
}
return
$tmp
;
},
$excel
);
return
$goods_info
;
}
// 验证导入excel
public
function
excelValid
(
$excel
)
{
$count
=
count
(
$excel
);
if
(
$count
==
1
)
return
[
3
,
'未填写报价信息'
];
// 获取excel菜单栏必填项
$required
=
array_filter
(
$excel
[
0
],
function
(
$v
)
{
return
strpos
(
$v
,
'*'
)
===
false
?
false
:
true
;
});
$required_keys
=
array_keys
(
$required
);
// 必填项keys
$err
=
[];
// 提示信息
array_walk
(
$excel
,
function
(
$val
,
$key
)
use
(
$required
,
$required_keys
,
&
$err
)
{
// 跳过第一条
if
(
$key
!=
0
)
{
if
(
$val
[
'price_origin'
]
<=
0
)
{
$err
[]
=
'第'
.
(
$key
+
1
)
.
'行,单价等于或小于0'
;
return
;
}
if
(
!
preg_match
(
'/^\d{0,9}(\.\d{0,6})?$/'
,
$val
[
'price_origin'
]))
{
$err
[]
=
'第'
.
(
$key
+
1
)
.
'行,单价格式错误'
;
return
;
}
if
(
$val
[
'price_rmb'
]
<=
0
)
{
$err
[]
=
'第'
.
(
$key
+
1
)
.
'行,含税价格等于或小于0'
;
return
;
}
if
(
!
preg_match
(
'/^\d{0,9}(\.\d{0,6})?$/'
,
$val
[
'price_rmb'
]))
{
$err
[]
=
'第'
.
(
$key
+
1
)
.
'行,含税价格格式错误'
;
return
;
}
if
(
!
preg_match
(
'/\d/'
,
intval
(
$val
[
'quote_number'
])))
{
$err
[]
=
'第'
.
(
$key
+
1
)
.
'行,报价数量格式错误,请填写整数'
;
return
;
}
if
(
intval
(
$val
[
'quote_number'
])
<=
0
)
{
$err
[]
=
'第'
.
(
$key
+
1
)
.
'行,报价数量等于或小于0'
;
return
;
}
foreach
(
$val
as
$k
=>
$v
)
{
if
(
in_array
(
$k
,
$required_keys
))
{
if
(
empty
(
$v
))
{
// 若必填项值为空,返回提示信息
$err
[]
=
$required
[
$k
]
.
'列,第'
.
(
$key
+
1
)
.
'行不能为空'
;
break
;
}
}
}
}
});
if
(
!
empty
(
$err
))
return
[
1
,
implode
(
'; '
,
$err
)];
return
[
0
,
'验证成功'
];
}
...
...
config/quote.php
View file @
335dfec3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
return
[
return
[
'quote_status'
=>
[
// 报价状态
'quote_status'
=>
[
// 报价状态
-
1
=>
'已撤销'
,
-
1
=>
'已撤销'
,
0
=>
'草稿'
,
1
=>
'已报价'
,
1
=>
'已报价'
,
2
=>
'已选中'
,
2
=>
'已选中'
,
3
=>
'已确认'
,
3
=>
'已确认'
,
...
@@ -9,4 +10,17 @@ return [
...
@@ -9,4 +10,17 @@ return [
'quote_tax_rate'
=>
'0.13'
,
// 报价税率
'quote_tax_rate'
=>
'0.13'
,
// 报价税率
'import_quote_map'
=>
[
// 导入报价映射
'goods_name'
,
'brand_name'
,
'quote_number'
,
'supplier_name'
,
'currency'
,
'price_origin'
,
'price_rmb'
,
'price_other'
,
'batch'
,
'delivery_time'
,
],
];
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment