Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
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
bc12fe2a
authored
Jul 15, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
供应商导出新需求
parent
d7914268
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
12 deletions
.gitignore
app/Http/Services/DataService.php
app/Http/routes.php
.gitignore
View file @
bc12fe2a
...
...
@@ -3,3 +3,5 @@
Homestead.yaml
Homestead.json
/.idea
/.vscode
/.history
app/Http/Services/DataService.php
View file @
bc12fe2a
<?php
namespace
App\Http\Services
;
//后台用户相关信息服务
use
App\Http\Transformers\SupplierContactTransformer
;
use
App\Http\Transformers\SupplierTransformer
;
use
App\Model\BrandModel
;
use
App\Model\IntracodeModel
;
use
App\Model\LogModel
;
use
App\Model\RedisModel
;
use
App\Model\SupplierChannelModel
;
use
App\Model\SupplierContactModel
;
use
App\Model\UserInfoModel
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Log
;
use
Maatwebsite\Excel\Facades\Excel
;
...
...
@@ -181,13 +178,13 @@ class DataService
//删除为空的联系人
$contactModel
=
new
SupplierContactModel
();
// $contactModel->where('supplier_id', $supplierId)
// ->where('supplier_consignee', '')->where('supplier_telephone', '')
// ->where('supplier_mobile', '')->where('add_time', '<', $startTime)->delete();
// //得到剩下的采购员
// ->where('supplier_consignee', '')->where('supplier_telephone', '')
// ->where('supplier_mobile', '')->where('add_time', '<', $startTime)->delete();
// //得到剩下的采购员
$remainChannelUids
=
$contactModel
->
where
(
'supplier_id'
,
$supplierId
)
->
pluck
(
'can_check_uids'
)
->
toArray
();
// $channelUidData = $remainChannelUids ? implode(',', $remainChannelUids) : '';
// $channelModel->where('supplier_id', $supplierId)->update(['channel_uid' => $channelUidData]);
// $channelModel->where('supplier_id', $supplierId)->update(['channel_uid' => $channelUidData]);
//把excel的新采购员写进去(先判断是否存在)
//没有联系方式的,要添加一个空的联系方式
$codeModel
=
new
IntracodeModel
();
...
...
@@ -251,7 +248,85 @@ class DataService
{
$model
=
new
SupplierChannelModel
();
$model
->
where
(
'status'
,
-
1
)
->
update
([
'status'
=>
1
'status'
=>
1
,
]);
}
}
\ No newline at end of file
//导出供应商(20210715)
public
function
exportSuppliersNew
()
{
set_time_limit
(
0
);
Excel
::
create
(
'供应商资料导出'
,
function
(
$excel
)
{
$excel
->
sheet
(
'sheet1'
,
function
(
$sheet
)
{
$redis
=
new
RedisModel
();
$sheet
->
setAutoSize
(
true
);
$model
=
new
SupplierChannelModel
();
// $suppliers = $model->where('is_type', 0)->limit(10)->get();
$suppliers
=
$model
->
where
(
'is_type'
,
0
)
->
get
();
if
(
empty
(
$suppliers
))
{
return
'供应商空'
;
}
$suppliers
=
$suppliers
->
toArray
();
$excelData
=
[];
$transformer
=
new
SupplierTransformer
();
$suppliers
=
$transformer
->
transformList
(
$suppliers
);
$adminService
=
new
AdminUserService
();
foreach
(
$suppliers
as
$supplier
)
{
$mainBrands
=
''
;
$mainBrandIds
=
$supplier
[
'main_brands'
]
?
explode
(
','
,
$supplier
[
'main_brands'
])
:
[];
if
(
!
empty
(
$mainBrandIds
))
{
$brandNames
=
$redis
->
hmget
(
'brand'
,
$mainBrandIds
);
$mainBrands
=
implode
(
','
,
$brandNames
);
}
$logModel
=
new
LogModel
();
$lastModifyTime
=
$logModel
->
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
where
(
'type'
,
1
)
->
orderBy
(
'id'
,
'desc'
)
->
limit
(
1
)
->
value
(
'add_time'
);
$lastModifyTime
=
$lastModifyTime
?
date
(
'Y-m-d H:i:s'
,
$lastModifyTime
)
:
''
;
//基础行信息
$lineData
=
[
'供应商ID'
=>
$supplier
[
'supplier_id'
],
'供应商编码'
=>
$supplier
[
'supplier_code'
],
'供应商名称'
=>
$supplier
[
'supplier_name'
],
'供应商性质'
=>
$supplier
[
'supplier_group'
],
'主营品牌'
=>
$mainBrands
,
'合作类型'
=>
$supplier
[
'stockup_type_name'
],
'联系人'
=>
'0'
,
'SKU上传'
=>
$supplier
[
'sku_num'
]
?
'是'
:
'否'
,
'状态'
=>
$supplier
[
'status_name'
],
'采购员'
=>
''
,
'渠道开发员'
=>
$supplier
[
'purchase_username'
]
?:
''
,
'创建人'
=>
$supplier
[
'create_name'
],
'最近修改时间'
=>
$lastModifyTime
,
'创建时间'
=>
$supplier
[
'create_time'
],
'正式供应商'
=>
$supplier
[
'is_type'
]
==
0
?
'是'
:
'否'
,
'联系人电话'
=>
''
,
'联系人姓名'
=>
''
,
'联系人邮箱'
=>
''
,
'联系人QQ'
=>
''
,
];
//获取联系人(有对应采购的)
//如果联系人有多个,则要生成多条excel行
$contactModel
=
new
SupplierContactModel
();
$contacts
=
$contactModel
->
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
where
(
'can_check_uids'
,
'!='
,
''
)
->
get
();
$contacts
=
$contacts
?
$contacts
->
toArray
()
:
[];
if
(
$contacts
)
{
$lineData
[
'联系人'
]
=
count
(
$contacts
);
foreach
(
$contacts
as
$contact
)
{
$channelUser
=
$adminService
->
getAdminUserInfoByCodeId
(
$contact
[
'can_check_uids'
]);
$lineData
[
'采购员'
]
=
$channelUser
[
'name'
];
$lineData
[
'联系人电话'
]
=
$contact
[
'supplier_mobile'
];
$lineData
[
'联系人姓名'
]
=
$contact
[
'supplier_consignee'
];
$lineData
[
'联系人邮箱'
]
=
$contact
[
'supplier_email'
];
$lineData
[
'联系人QQ'
]
=
$contact
[
'supplier_qq'
];
$excelData
[]
=
$lineData
;
}
}
else
{
$excelData
[]
=
$lineData
;
}
}
$sheet
->
fromArray
(
$excelData
);
});
})
->
export
(
'xlsx'
);
}
}
app/Http/routes.php
View file @
bc12fe2a
...
...
@@ -41,6 +41,6 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
$service
=
new
\App\Http\Services\DataService
();
$service
->
modifyStatus
();
$service
->
exportSuppliersNew
();
});
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