Skip to content

Commit ced9384

Browse files
authored
Merge pull request #11 from liaodeity/8.x
8.2.5
2 parents 29689f4 + f817260 commit ced9384

File tree

17 files changed

+1119
-439
lines changed

17 files changed

+1119
-439
lines changed

CHANGELOG.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.1...8.x)
3+
## [Unreleased](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.4...8.x)
44

5-
## [v8.2.1(2021-06-09)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.0...8.2.1)
5+
## [v8.2.4(2021-06-23)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.3...v8.2.4)
6+
7+
### Added
8+
- 添加附件管理列表([#10](https://github.com/liaodeity/laravel-admin-cms/pull/10)
9+
- 添加支持图片附件上传
10+
11+
### Changed
12+
- 变更route目录,添加admin.php路由([47411f0](https://github.com/liaodeity/laravel-admin-cms/pull/10/commits/47411f0eea800ef0cfc9551090bccc84fcb05cd1)
13+
- 更新菜单和权限,添加基础表配置
14+
15+
## [v8.2.3(2021-06-10)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.2...v8.2.3)
16+
17+
### Fixed
18+
- 修复发现问题
19+
20+
## [v8.2.2(2021-06-09)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.1...v8.2.2)
21+
22+
### Fixed
23+
- 修复发现问题
24+
25+
## [v8.2.1(2021-06-09)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.0...v8.2.1)
626

727
### Added
828
- 添加单页面管理,添加富文本编辑器,修改图片上传
929
- 更新wangEditor到最新4.7.2、修改富文本图片上传
1030
- 添加开发进度,修改说明
1131

12-
## [v8.2.0(2021-06-03)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.1.14...8.2.0)
32+
## [v8.2.0(2021-06-03)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.1.14...v8.2.0)
1333

1434
### Added
1535
- 更新用户表结构,将登录次数及登录时间字段加入主表users([#5](https://github.com/liaodeity/laravel-admin-cms/pull/5)

app/Exports/UserMemberExport.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/*
3+
|-----------------------------------------------------------------------------------------------------------
4+
| laravel-admin-cms [ 简单高效的开发插件系统 ]
5+
|-----------------------------------------------------------------------------------------------------------
6+
| Licensed ( MIT )
7+
| ----------------------------------------------------------------------------------------------------------
8+
| Copyright (c) 2020-2021 https://gitee.com/liaodeiy/laravel-admin-cms All rights reserved.
9+
| ----------------------------------------------------------------------------------------------------------
10+
| Author: 廖春贵 < liaodeity@gmail.com >
11+
|-----------------------------------------------------------------------------------------------------------
12+
*/
13+
namespace App\Exports;
14+
15+
use App\Models\Log;
16+
use App\Models\User\UserMember;
17+
use Illuminate\Contracts\View\View;
18+
use Maatwebsite\Excel\Concerns\FromView;
19+
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
20+
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
21+
use Maatwebsite\Excel\Concerns\WithColumnWidths;
22+
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
23+
use PhpOffice\PhpSpreadsheet\Cell\Cell;
24+
use PhpOffice\PhpSpreadsheet\Cell\DataType;
25+
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
26+
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
27+
28+
class UserMemberExport extends DefaultValueBinder implements FromView, ShouldAutoSize, WithColumnWidths, WithColumnFormatting, WithCustomValueBinder
29+
{
30+
private $resultData;
31+
32+
public function __construct ($result)
33+
{
34+
$this->resultData = $result;
35+
}
36+
37+
public function bindValue (Cell $cell, $value)
38+
{
39+
if (is_numeric ($value) && strlen ($value) >= 10) {
40+
$cell->setValueExplicit ($value, DataType::TYPE_STRING);
41+
42+
return true;
43+
}
44+
45+
return parent::bindValue ($cell, $value);
46+
}
47+
48+
public function columnWidths (): array
49+
{
50+
return [
51+
'A' => 25,
52+
'B' => 25,
53+
'C' => 25,
54+
'D' => 25,
55+
'E' => 25,
56+
'F' => 25,
57+
'G' => 25,
58+
'H' => 25,
59+
'I' => 25,
60+
'J' => 25,
61+
];
62+
}
63+
64+
public function columnFormats (): array
65+
{
66+
return [
67+
'A' => NumberFormat::FORMAT_TEXT,
68+
'B' => NumberFormat::FORMAT_TEXT,
69+
];
70+
}
71+
72+
/**
73+
* @return View
74+
*/
75+
public function view (): View
76+
{
77+
$details = $this->resultData;
78+
foreach ($details as $key => $item) {
79+
//
80+
}
81+
82+
Log::createLog (Log::INFO_TYPE, '进行会员记录', '', 0, UserMember::class);
83+
84+
return view ('admin.user_member.list_export', compact ('details'));
85+
}
86+
}

app/Http/Controllers/Admin/UserMemberController.php

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace App\Http\Controllers\Admin;
1515

1616
use App\Exceptions\BusinessException;
17+
use App\Exports\UserMemberExport;
1718
use App\Http\Controllers\Controller;
1819
use App\Libs\Parameter;
1920
use App\Libs\QueryWhere;
@@ -25,6 +26,7 @@
2526
use Illuminate\Support\Facades\DB;
2627
use Illuminate\Support\Facades\Hash;
2728
use Illuminate\Support\Facades\View;
29+
use Maatwebsite\Excel\Facades\Excel;
2830
use Spatie\Permission\Models\Role;
2931

3032
class UserMemberController extends Controller
@@ -52,31 +54,7 @@ public function index (Request $request)
5254
return auth_error_return ();
5355
}
5456
if (request ()->wantsJson ()) {
55-
$limit = $request->input ('limit', 15);
56-
QueryWhere::defaultOrderBy ('users.id', 'DESC')->setRequest ($request->all ());
57-
$M = $this->repository->makeModel ()->select ('user_members.*', 'users.name','users.login_count','users.last_login_at',
58-
'user_infos.real_name', 'user_infos.gender', 'user_infos.telephone', 'user_infos.address');
59-
$M->join ('user_members', 'users.id', '=', 'user_members.user_id');
60-
$M->leftJoin ('user_infos', 'user_infos.user_id', '=', 'users.id');
61-
QueryWhere::eq ($M, 'user_members.status');
62-
QueryWhere::like ($M, 'users.name');
63-
QueryWhere::like ($M, 'user_infos.real_name');
64-
QueryWhere::orderBy ($M);
65-
66-
$roleId = QueryWhere::input ('role_id');
67-
if ($roleId) {
68-
$role = Role::find ($roleId);
69-
$usersid = $role->users ()->pluck ('model_id');
70-
QueryWhere::in ($M, 'users.id', $usersid);
71-
}
72-
73-
$M = $M->paginate ($limit);
74-
$count = $M->total ();
75-
$data = $M->items ();
76-
foreach ($data as $key => $item) {
77-
$data[ $key ]['gender'] = Parameter::genderItem ($item->gender);
78-
$data[ $key ]['status'] = Parameter::userStatusItem ($item->status);
79-
}
57+
list($data, $count) = $this->getData ($request, false);
8058
$result = [
8159
'count' => $count,
8260
'data' => $data
@@ -93,6 +71,42 @@ public function index (Request $request)
9371
}
9472
}
9573

74+
private function getData (Request $request, bool $export = false)
75+
{
76+
$limit = $request->input ('limit', 15);
77+
QueryWhere::defaultOrderBy ('users.id', 'DESC')->setRequest ($request->all ());
78+
$M = $this->repository->makeModel ()->select ('user_members.*', 'users.name','users.email', 'users.login_count', 'users.last_login_at',
79+
'user_infos.real_name', 'user_infos.gender', 'user_infos.telephone', 'user_infos.address');
80+
$M->join ('user_members', 'users.id', '=', 'user_members.user_id');
81+
$M->leftJoin ('user_infos', 'user_infos.user_id', '=', 'users.id');
82+
QueryWhere::eq ($M, 'user_members.status');
83+
QueryWhere::like ($M, 'users.name');
84+
QueryWhere::like ($M, 'user_infos.real_name');
85+
QueryWhere::orderBy ($M);
86+
87+
$roleId = QueryWhere::input ('role_id');
88+
if ($roleId) {
89+
$role = Role::find ($roleId);
90+
$usersid = $role->users ()->pluck ('model_id');
91+
QueryWhere::in ($M, 'users.id', $usersid);
92+
}
93+
if ($export) {
94+
$data = $M->get ();
95+
$count = count ($data);
96+
} else {
97+
$M = $M->paginate ($limit);
98+
$count = $M->total ();
99+
$data = $M->items ();
100+
}
101+
102+
foreach ($data as $key => $item) {
103+
$data[ $key ]['gender'] = Parameter::genderItem ($item->gender);
104+
$data[ $key ]['status'] = Parameter::userStatusItem ($item->status);
105+
}
106+
107+
return [$data, $count];
108+
}
109+
96110
/**
97111
* Show the form for creating a new resource.
98112
*
@@ -272,4 +286,14 @@ public function destroy (UserMember $userMember)
272286
{
273287
//
274288
}
289+
290+
public function export (Request $request)
291+
{
292+
if (!check_admin_auth ($this->module_name . '_export')) {
293+
return auth_error_return ();
294+
}
295+
list($data, $count) = $this->getData ($request, true);
296+
297+
return Excel::download (new UserMemberExport($data), date ('Y-m-d') . '会员账号记录.xlsx');
298+
}
275299
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"laravel/framework": "^8.12",
1616
"laravel/helpers": "^1.4",
1717
"laravel/tinker": "^2.5",
18+
"maatwebsite/excel": "^3.1",
1819
"mews/captcha": "^3.2",
1920
"spatie/laravel-permission": "^4.0",
2021
"zanysoft/laravel-zip": "^1.0"

0 commit comments

Comments
 (0)