Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
product_library_api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyi.chen
product_library_api
Commits
b3bc53fa
Commit
b3bc53fa
authored
Sep 30, 2024
by
wenyi.chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
线上
parent
35f9033a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
440 additions
and
1 deletions
+440
-1
app/api/controller/ProductAllocation - 副本.php
+317
-0
app/api/controller/ProductAllocation.php
+4
-1
app/api/controller/Test.php
+117
-0
app/api/route/api.php
+2
-0
No files found.
app/api/controller/ProductAllocation - 副本.php
0 → 100644
View file @
b3bc53fa
<?php
<?php
/**
* Create by wenyi
* E-mail: wesley_prc@163.com
* Description: data-collect-api
* Date: 2024/2/27 23:37
* Update: 2024/2/27 23:37
* 数据管理
*/
namespace
app\api\controller
;
use
app\common\model\redis\RedisModel
;
use
app\common\model\mysql\Product
as
ProductModel
;
use
app\common\model\mysql\EnterpriseInfo
as
EnterpriseInfoModel
;
use
app\common\model\mysql\ProductAllocation
as
ProductAllocationModel
;
use
app\common\model\mysql\Admin
as
AdminModel
;
use
PhpOffice\PhpSpreadsheet\IOFactory
;
use
PhpOffice\PhpSpreadsheet\Worksheet\Drawing
;
use
think\facade\Filesystem
;
use
PhpOffice\PhpSpreadsheet\Spreadsheet
;
use
PhpOffice\PhpSpreadsheet\Writer\Xlsx
;
use
think\facade\Db
;
class
ProductAllocation
extends
AuthBase
{
public
static
$name
=
'controller.ProductAllocation'
;
public
static
$productWhere
=
[];
/**
* 列表
* @return \josn|void
*/
public
function
list
()
{
try
{
// 数据接收
$page
=
input
(
"param.page"
,
0
,
"intval"
);
$limit
=
input
(
"param.limit"
,
10
,
"intval"
);
$inspect_status
=
input
(
"inspect_status"
);
$product_id
=
input
(
"product_id"
);
$product_name
=
input
(
"product_name"
);
$ProductAllocationModel
=
new
ProductAllocationModel
();
$where
=
[];
if
(
$this
->
userId
!=
1
){
$where
[]
=
[
'user_id'
,
'='
,
$this
->
userId
];
}
if
(
$product_id
){
self
::
$productWhere
[]
=
[
'productInfo.product_id'
,
'='
,
$product_id
];
}
// if($product_name){
// $where[] = ['t2.product_name', '=',$product_name];
// }
// if($inspect_status!=""){
// $where[] = ['t2.inspect_status', '=',$inspect_status];
// }
// $result = Db::table('product_allocation')
// ->alias('t1')
// ->join('product t2','t1.product_id=t2.id')
// ->join('admin t3','t1.user_id=t3.id')
// ->field('t1.status as product_allocation_status,t1.id as allocation_id,t1.*')
// ->field('t2.status as product_status,t2.*')
// ->field('t3.status as admin_status,t3.*')
// ->where($where)
// ->paginate([
// 'list_rows'=>$limit,
// 'page'=>$page
// ]);
$result
=
$ProductAllocationModel
->
withJoin
([
'productInfo'
=>
function
(
$query
){
$query
->
where
(
self
::
$productWhere
);
},
'adminInfo'
=>
function
(
$query
){
$query
->
where
(
'status'
,
1
)
->
field
(
"id,name"
);
},
])
->
where
(
$where
)
->
paginate
([
'list_rows'
=>
$limit
,
'page'
=>
$page
]);
if
(
$result
){
$result
=
$result
->
toArray
();
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
$result
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.null_data"
),
$result
);
}
}
catch
(
\Exception
$e
){
exception
(
$e
,
self
::
$name
.
'.list'
);
}
}
/**
* 产品人员分配
* @return \josn|void
*/
public
function
add
()
{
$data
=
array
();
// 数据接收
$data
[
'product_id'
]
=
input
(
"param.product_id"
);
$data
[
'user_id'
]
=
input
(
"param.user_id"
);
$list
=
$data
[
'product_id'
];
$ProductAllocationModel
=
new
ProductAllocationModel
();
foreach
(
$list
as
$val
){
$info
=
[
'user_id'
=>
$data
[
'user_id'
],
'product_id'
=>
$val
,
'distribute_time'
=>
date
(
'Y-m-d H:i:s'
),
];
$result
=
$ProductAllocationModel
->
insert
(
$info
);
}
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),[]);
}
/**
* 查看信息
* @return \josn
*/
public
function
see
()
{
$id
=
input
(
"id"
);
if
(
empty
(
$id
)){
return
returnResult
(
config
(
"config.code.error"
),
'ID错误!'
);
}
$ProductAllocationModel
=
new
ProductAllocationModel
();
$ProductModel
=
new
ProductModel
();
$EnterpriseInfoModel
=
new
EnterpriseInfoModel
();
$AdminModel
=
new
AdminModel
();
$productAllocationInfo
=
$ProductAllocationModel
->
where
(
'id'
,
$id
)
->
find
();
if
(
empty
(
$productAllocationInfo
)){
return
returnResult
(
config
(
"config.code.error"
),
'未找到相关信息!'
);
}
$productInfo
=
$ProductModel
->
where
(
'id'
,
$productAllocationInfo
[
'product_id'
])
->
find
();
$enterpriseInfo
=
$EnterpriseInfoModel
->
where
(
'id'
,
$productInfo
[
'enterprise_id'
])
->
find
();
$adminInfo
=
$AdminModel
->
where
(
'id'
,
$productAllocationInfo
[
'user_id'
])
->
find
();
$result
=
[
'userInfo'
=>
$adminInfo
,
'enterpriseInfo'
=>
$enterpriseInfo
,
'productInfo'
=>
$productInfo
,
'productAllocationInfo'
=>
$productAllocationInfo
,
'number'
=>
''
,
];
if
(
$result
){
$info
=
$ProductAllocationModel
->
where
(
'user_id'
,
$productAllocationInfo
[
'user_id'
])
->
select
();
$num
=
[];
foreach
(
$info
as
$val
){
array_push
(
$num
,
$val
[
'id'
]);
}
$index
=
array_search
(
$id
,
$num
);
$front
=
$index
-
1
;
$after
=
$index
+
1
;
if
(
$front
<
0
)
{
$front
=
$index
;
}
if
(
$after
>=
count
(
$num
))
{
$after
=
$index
;
}
$result
[
'number'
]
=
[
'front'
=>
$num
[
$front
],
'after'
=>
$num
[
$after
]];
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
$result
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.null_data"
),[]);
}
}
/**
* 保存编辑信息
* @return \josn|void
*/
public
function
save
()
{
try
{
$id
=
input
(
"id"
);
$product_id
=
input
(
"product_id"
);
$product_name
=
input
(
"product_name"
);
$product_categ_name
=
input
(
"product_categ_name"
);
$page_url
=
input
(
"page_url"
);
$product_model
=
input
(
"product_model"
);
$describe
=
input
(
"describe"
);
$parameter
=
input
(
"parameter"
);
$inspect_remarks
=
input
(
"inspect_remarks"
);
$ProductAllocationModel
=
new
ProductAllocationModel
();
$ProductModel
=
new
ProductModel
();
$result
=
$ProductAllocationModel
->
where
(
'id'
,
$id
)
->
update
([
'inspect_time'
=>
date
(
'Y-m-d H:i:s'
),
'status'
=>
1
]);
if
(
$result
){
$ProductModel
->
where
(
'id'
,
$product_id
)
->
update
(
[
'product_name'
=>
$product_name
,
'product_categ_name'
=>
$product_categ_name
,
'page_url'
=>
$page_url
,
'product_model'
=>
$product_model
,
'describe'
=>
$describe
,
'parameter'
=>
$parameter
,
'inspect_remarks'
=>
$inspect_remarks
,
'inspect_status'
=>
1
]
);
}
if
(
$result
){
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
$result
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.null_data"
),[]);
}
}
catch
(
\Exception
$e
){
exception
(
$e
,
self
::
$name
.
'.edit'
);
}
}
/**
* 数据异常
* @return \josn
*/
public
function
abnormal
()
{
$id
=
input
(
"id"
);
$is
=
input
(
"is"
);
$product_id
=
input
(
"product_id"
);
$inspect_remarks
=
input
(
"inspect_remarks"
);
$ProductAllocationModel
=
new
ProductAllocationModel
();
$ProductModel
=
new
ProductModel
();
$result
=
$ProductAllocationModel
->
where
(
'id'
,
$id
)
->
update
([
'inspect_time'
=>
date
(
'Y-m-d H:i:s'
),
'status'
=>
1
]);
if
(
$result
){
$ProductModel
->
where
(
'id'
,
$product_id
)
->
update
(
[
'inspect_remarks'
=>
$inspect_remarks
,
'inspect_status'
=>
$is
]
);
}
if
(
$result
){
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
$result
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.null_data"
),[]);
}
}
public
function
importProduct
()
{
$spreadsheet
=
IOFactory
::
load
(
'DUE0930_2000.xlsx'
);
$objWorksheet
=
$spreadsheet
->
getSheet
(
0
);
// 只允许读取第一页,多页请分开文档
$data
=
$objWorksheet
->
toArray
();
$list
=
[];
foreach
(
$data
as
$index
=>
$value
){
if
(
$index
>
1
){
$timestamp
=
time
();
// 当前时间戳
$randomNumber
=
mt_rand
(
100000
,
999999
);
// 生成一个六位的随机数
$uniqueIdentifier
=
$timestamp
.
$randomNumber
;
// 时间戳和随机数拼接
$res
=
Db
::
name
(
'enterprise_info'
)
->
where
(
'enterprise_name'
,
$value
[
1
])
->
find
();
if
(
$res
){
$arr
=
[
'product_id'
=>
'RS'
.
$uniqueIdentifier
,
'enterprise_id'
=>
$res
[
'id'
],
'page_url'
=>
$value
[
4
],
'product_categ_name'
=>
$value
[
2
],
'product_name'
=>
$value
[
3
],
'product_model'
=>
$value
[
5
],
'describe'
=>
$value
[
6
],
'parameter'
=>
$value
[
7
],
];
$product
=
Db
::
name
(
'product'
)
->
where
(
'product_name'
,
$value
[
3
])
->
where
(
'page_url'
,
$value
[
4
])
->
where
(
'product_categ_name'
,
$value
[
2
])
->
where
(
'product_model'
,
$value
[
5
])
->
where
(
'describe'
,
$value
[
6
])
->
where
(
'parameter'
,
$value
[
7
])
->
find
();
if
(
empty
(
$product
)){
$product
=
Db
::
name
(
'product'
)
->
insert
(
$arr
);
}
}
else
{
var_dump
(
$value
[
1
]);
}
}
}
}
public
function
importEnterpriseInfo
()
{
$spreadsheet
=
IOFactory
::
load
(
'33.xlsx'
);
$objWorksheet
=
$spreadsheet
->
getSheet
(
0
);
// 只允许读取第一页,多页请分开文档
$data
=
$objWorksheet
->
toArray
();
$list
=
[];
foreach
(
$data
as
$index
=>
$value
){
if
(
$index
>
1
){
//enterprise_name
//enterprise_id
//enterprise_website_official
//unavailable
$timestamp
=
time
();
// 当前时间戳
$randomNumber
=
mt_rand
(
100000
,
999999
);
// 生成一个六位的随机数
$uniqueIdentifier
=
$timestamp
.
$randomNumber
;
// 时间戳和随机数拼接
$arr
=
[
'enterprise_name'
=>
$value
[
1
],
'enterprise_id'
=>
$uniqueIdentifier
,
'enterprise_website_official'
=>
$value
[
2
],
'unavailable'
=>
$value
[
3
],
];
$res
=
Db
::
name
(
'enterprise_info'
)
->
where
(
'enterprise_name'
,
$value
[
1
])
->
find
();
if
(
empty
(
$res
)){
Db
::
name
(
'enterprise_info'
)
->
insert
(
$arr
);
}
else
{
if
(
$res
[
'unavailable'
]
!=
$value
[
3
]){
Db
::
name
(
'enterprise_info'
)
->
where
(
'id'
,
$res
[
'id'
])
->
update
([
'unavailable'
=>
$value
[
3
]]);
}
}
}
}
}
}
\ No newline at end of file
app/api/controller/ProductAllocation.php
View file @
b3bc53fa
...
@@ -56,7 +56,7 @@ class ProductAllocation extends AuthBase
...
@@ -56,7 +56,7 @@ class ProductAllocation extends AuthBase
->
alias
(
't1'
)
->
alias
(
't1'
)
->
join
(
'product t2'
,
't1.product_id=t2.id'
)
->
join
(
'product t2'
,
't1.product_id=t2.id'
)
->
join
(
'admin t3'
,
't1.user_id=t3.id'
)
->
join
(
'admin t3'
,
't1.user_id=t3.id'
)
->
field
(
't1.status as product_allocation_status,t1.*'
)
->
field
(
't1.status as product_allocation_status,t1.
id as allocation_id,t1.
*'
)
->
field
(
't2.status as product_status,t2.*'
)
->
field
(
't2.status as product_status,t2.*'
)
->
field
(
't3.status as admin_status,t3.*'
)
->
field
(
't3.status as admin_status,t3.*'
)
->
where
(
$where
)
->
where
(
$where
)
...
@@ -126,6 +126,9 @@ class ProductAllocation extends AuthBase
...
@@ -126,6 +126,9 @@ class ProductAllocation extends AuthBase
$EnterpriseInfoModel
=
new
EnterpriseInfoModel
();
$EnterpriseInfoModel
=
new
EnterpriseInfoModel
();
$AdminModel
=
new
AdminModel
();
$AdminModel
=
new
AdminModel
();
$productAllocationInfo
=
$ProductAllocationModel
->
where
(
'id'
,
$id
)
->
find
();
$productAllocationInfo
=
$ProductAllocationModel
->
where
(
'id'
,
$id
)
->
find
();
if
(
empty
(
$productAllocationInfo
)){
return
returnResult
(
config
(
"config.code.error"
),
'未找到相关信息!'
);
}
$productInfo
=
$ProductModel
->
where
(
'id'
,
$productAllocationInfo
[
'product_id'
])
->
find
();
$productInfo
=
$ProductModel
->
where
(
'id'
,
$productAllocationInfo
[
'product_id'
])
->
find
();
$enterpriseInfo
=
$EnterpriseInfoModel
->
where
(
'id'
,
$productInfo
[
'enterprise_id'
])
->
find
();
$enterpriseInfo
=
$EnterpriseInfoModel
->
where
(
'id'
,
$productInfo
[
'enterprise_id'
])
->
find
();
$adminInfo
=
$AdminModel
->
where
(
'id'
,
$productAllocationInfo
[
'user_id'
])
->
find
();
$adminInfo
=
$AdminModel
->
where
(
'id'
,
$productAllocationInfo
[
'user_id'
])
->
find
();
...
...
app/api/controller/Test.php
View file @
b3bc53fa
...
@@ -162,5 +162,121 @@ class Test
...
@@ -162,5 +162,121 @@ class Test
$res
=
Db
::
name
(
'enterprise_info'
)
->
where
(
'enterprise_name'
,
'亿嘉和科技股份有限公司'
)
->
select
();
$res
=
Db
::
name
(
'enterprise_info'
)
->
where
(
'enterprise_name'
,
'亿嘉和科技股份有限公司'
)
->
select
();
dump
(
$res
);
dump
(
$res
);
}
}
public
function
exportData
()
{
$result
=
Db
::
name
(
'product'
)
->
where
(
'status'
,
1
)
->
select
();
$spreadsheet
=
new
Spreadsheet
();
$writer
=
new
Xlsx
(
$spreadsheet
);
$spreadsheet
->
createSheet
();
$spreadsheet
->
setActiveSheetIndex
(
0
);
$spreadsheet
->
getActiveSheet
(
0
)
->
setTitle
(
'产品库'
);
$sheet
=
$spreadsheet
->
getActiveSheet
(
0
);
$num
=
0
;
$row
=
2
;
foreach
(
$result
as
$index
=>
$value
){
$info
=
Db
::
name
(
'enterprise_info'
)
->
where
(
'id'
,
$value
[
'enterprise_id'
])
->
find
();
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setVertical
(
\PhpOffice\PhpSpreadsheet\Style\Alignment
::
VERTICAL_CENTER
);
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setHorizontal
(
\PhpOffice\PhpSpreadsheet\Style\Alignment
::
HORIZONTAL_CENTER
);
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setWrapText
(
true
);
$sheet
->
getDefaultRowDimension
()
->
setRowHeight
(
50
);
// 默认行高
$sheet
->
getDefaultColumnDimension
()
->
setWidth
(
50
);
// 默认单元格宽度
$sheet
->
getStyle
(
'A1:J1'
)
->
getFill
()
->
setFillType
(
\PhpOffice\PhpSpreadsheet\Style\Fill
::
FILL_SOLID
)
->
getStartColor
()
->
setARGB
(
'C5D9F1'
);
// FF后面的六位数是颜色的RGB值
$title
=
[
'产品ID'
,
'企业名称'
,
'产品分类'
,
'产品名称'
,
'产品链接'
,
'产品型号'
,
'产品功能描述'
,
'产品规格参数'
,
'检查备注'
,
'检查状态'
,
];
$col
=
'A'
;
$column
=
[
'A'
];
for
(
$coli
=
0
;
$coli
<
count
(
$title
);
$coli
++
)
{
$col
=
\app\api\business\ExcelBus
::
excelColPlus
(
$col
);
array_push
(
$column
,
$col
);
}
// 遍历标题数组,设置每个单元格的值
foreach
(
$title
as
$columns
=>
$val
)
{
// 'A1', 'B1', 'C1', ...
$cell
=
$column
[
$columns
]
.
'1'
;
// 设置单元格的值
$sheet
->
setCellValue
(
$cell
,
$val
);
// 设置单元格A1的对齐方式为居中
}
$position
=
0
;
$sheet
=
$spreadsheet
->
getActiveSheet
();
// 名称
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'product_id'
]);
$position
++
;
// 名称
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$info
[
'enterprise_name'
]);
$position
++
;
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'product_categ_name'
]);
$position
++
;
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'product_name'
]);
$position
++
;
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'page_url'
]);
$position
++
;
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'product_model'
]);
$position
++
;
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'describe'
]);
$position
++
;
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'parameter'
]);
$position
++
;
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'inspect_remarks'
]);
$position
++
;
$inspect_status
=
$value
[
'inspect_status'
];
if
(
$inspect_status
==
0
){
$inspect_status
=
'待检查'
;
}
if
(
$inspect_status
==
1
){
$inspect_status
=
'检查完成'
;
}
if
(
$inspect_status
==
2
){
$inspect_status
=
'检查中'
;
}
if
(
$inspect_status
==
3
){
$inspect_status
=
'数据异常'
;
}
if
(
$inspect_status
==
4
){
$inspect_status
=
'检查异常'
;
}
if
(
$inspect_status
==
5
){
$inspect_status
=
'数据废弃'
;
}
// 位置
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$inspect_status
);
$position
++
;
$row
++
;
}
$name
=
'./product_'
.
date
(
'Y-m-d H:i:s'
)
.
'.csv'
;
$writer
->
save
(
$name
);
}
}
}
\ No newline at end of file
app/api/route/api.php
View file @
b3bc53fa
...
@@ -112,3 +112,5 @@ Route::rule("service/enterpriseName","Service/enterpriseName");
...
@@ -112,3 +112,5 @@ Route::rule("service/enterpriseName","Service/enterpriseName");
Route
::
rule
(
"test"
,
"test/product"
);
Route
::
rule
(
"test"
,
"test/product"
);
Route
::
rule
(
"cee"
,
"test/cee"
);
Route
::
rule
(
"cee"
,
"test/cee"
);
Route
::
rule
(
"exportData"
,
"test/exportData"
);
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