Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_admin
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
30085249
authored
Nov 14, 2022
by
宁成龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善新增客户页面
parent
90333144
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
16 deletions
app/Admin/Controllers/UserController.php
app/Admin/Renderable/CreateUser.php
app/Admin/Service/UserService.php
app/Models/User.php
app/Models/UserAddress.php
resources/lang/en/user.php
app/Admin/Controllers/UserController.php
View file @
30085249
...
@@ -16,6 +16,8 @@ use Dcat\Admin\Layout\Content;
...
@@ -16,6 +16,8 @@ use Dcat\Admin\Layout\Content;
use
Dcat\Admin\Layout\Row
;
use
Dcat\Admin\Layout\Row
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Illuminate\Support\Facades\Validator
;
use
Symfony\Component\HttpFoundation\Response
;
class
UserController
extends
AdminController
class
UserController
extends
AdminController
{
{
...
@@ -32,6 +34,7 @@ class UserController extends AdminController
...
@@ -32,6 +34,7 @@ class UserController extends AdminController
$grid
->
disableRefreshButton
();
$grid
->
disableRefreshButton
();
$grid
->
disableBatchDelete
();
$grid
->
disableBatchDelete
();
// $grid->disableCreateButton();
// $grid->disableCreateButton();
$grid
->
model
()
->
orderBy
(
"id"
,
"desc"
);
UserService
::
userListListField
(
$grid
);
UserService
::
userListListField
(
$grid
);
UserService
::
userListTool
(
$grid
);
UserService
::
userListTool
(
$grid
);
UserService
::
userListActions
(
$grid
);
UserService
::
userListActions
(
$grid
);
...
@@ -62,12 +65,64 @@ class UserController extends AdminController
...
@@ -62,12 +65,64 @@ class UserController extends AdminController
*/
*/
public
function
create
(
Content
$content
)
public
function
create
(
Content
$content
)
{
{
return
$content
return
$content
->
body
(
CreateUser
::
make
()
->
render
());
->
header
(
'Dashboard'
)
->
description
(
'Description...'
)
->
body
(
CreateUser
::
make
()
->
render
());
}
}
/**
* Store a newly created resource in storage.
*
* @return mixed
*/
public
function
store
()
{
try
{
$data
=
request
()
->
all
();
$params
=
[
'company_name'
=>
$data
[
'company_name'
],
'user_sn'
=>
$data
[
'user_sn'
],
'first_name'
=>
$data
[
'first_name'
],
'last_name'
=>
$data
[
'last_name'
],
'phone'
=>
$data
[
'phone'
],
'email'
=>
$data
[
'email'
],
'account_properties'
=>
$data
[
'account_properties'
],
'remark'
=>
$data
[
'remark'
],
'user_address_list'
=>
$data
[
'user_address_list'
]
??
[],
];
$validator
=
Validator
::
make
(
$params
,
[
'company_name'
=>
'required'
,
'first_name'
=>
'required'
,
'last_name'
=>
'required'
,
'phone'
=>
'required'
,
'email'
=>
'required'
,
'account_properties'
=>
'required'
,
// 'user_address_list' => 'required',
// 'user_address_list.first_name' => 'required',
// 'user_address_list.last_name' => 'required',
// 'user_address_list.email' => 'required',
// 'user_address_list.phone' => 'required',
// 'user_address_list.country' => 'required',
// 'user_address_list.city' => 'required',
// 'user_address_list.post_code' => 'required',
// 'user_address_list.detail_address' => 'required',
// 'user_address_list.is_default' => 'required',
]);
if
(
$validator
->
fails
())
{
$error
=
$validator
->
errors
()
->
first
();
throw
new
\Exception
(
$error
);
}
UserService
::
createUserAndAddress
(
$params
);
}
catch
(
\Throwable
$throwable
)
{
return
$this
->
form
()
->
response
()
->
error
(
trans
(
'admin.save_failed'
))
->
withExceptionIf
(
$throwable
->
getMessage
(),
$throwable
);
}
$url
=
admin_url
(
"/users/list"
);
return
$this
->
form
()
->
response
()
->
success
(
'操作成功'
)
->
redirect
(
$url
)
->
refresh
();
}
/**
/**
* Make a form builder.
* Make a form builder.
*
*
...
...
app/Admin/Renderable/CreateUser.php
View file @
30085249
...
@@ -27,7 +27,7 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
...
@@ -27,7 +27,7 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
$form
->
disableCreatingCheck
();
$form
->
disableCreatingCheck
();
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
width
(
4
)
->
text
(
'company_name'
)
->
required
();
$form
->
width
(
4
)
->
text
(
'company_name'
)
->
required
();
$form
->
width
(
4
)
->
text
(
'user_sn'
)
->
required
()
;
$form
->
width
(
4
)
->
text
(
'user_sn'
);
});
});
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
width
(
4
)
->
text
(
'first_name'
)
->
required
();
$form
->
width
(
4
)
->
text
(
'first_name'
)
->
required
();
...
@@ -35,15 +35,15 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
...
@@ -35,15 +35,15 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
});
});
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
width
(
4
)
->
text
(
'phone'
)
->
required
();
$form
->
width
(
4
)
->
text
(
'phone'
)
->
required
();
$form
->
width
(
4
)
->
text
(
'email'
)
->
required
();
$form
->
width
(
4
)
->
email
(
'email'
)
->
required
();
});
});
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
width
(
4
)
->
select
(
"
reg_source"
)
->
options
(
admin_trans
(
'user.options.reg_source
'
))
->
required
();
$form
->
width
(
4
)
->
select
(
"
account_properties"
)
->
options
(
admin_trans
(
'user.options.account_properties
'
))
->
required
();
$form
->
width
(
4
)
->
text
(
'remark'
)
->
required
()
;
$form
->
width
(
4
)
->
text
(
'remark'
);
});
});
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
row
(
function
(
Form\Row
$form
)
{
$form
->
array
(
'
column_name
'
,
function
(
$table
)
{
$form
->
array
(
'
user_address_list
'
,
function
(
$table
)
{
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
width
(
3
)
->
text
(
'first_name'
)
->
required
();
$table
->
width
(
3
)
->
text
(
'first_name'
)
->
required
();
$table
->
width
(
3
)
->
text
(
'last_name'
)
->
required
();
$table
->
width
(
3
)
->
text
(
'last_name'
)
->
required
();
...
@@ -51,15 +51,15 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
...
@@ -51,15 +51,15 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
width
(
3
)
->
select
(
'address_type'
)
->
options
(
admin_trans
(
'user-address.options.address_type'
))
$table
->
width
(
3
)
->
select
(
'address_type'
)
->
options
(
admin_trans
(
'user-address.options.address_type'
))
->
required
();
->
required
();
$table
->
width
(
3
)
->
text
(
'company_name'
)
->
required
()
;
$table
->
width
(
3
)
->
text
(
'company_name'
);
});
});
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
width
(
3
)
->
text
(
'email'
)
->
required
();
$table
->
width
(
3
)
->
email
(
'email'
)
->
required
();
$table
->
width
(
3
)
->
text
(
'phone'
)
->
required
();
$table
->
width
(
3
)
->
text
(
'phone'
)
->
required
();
});
});
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
row
(
function
(
Form\Row
$table
)
{
$table
->
width
(
3
)
->
select
(
'country'
)
->
options
(
Country
::
getCountryMap
())
->
required
();
$table
->
width
(
3
)
->
select
(
'country'
)
->
options
(
Country
::
getCountryMap
())
->
required
();
$table
->
width
(
3
)
->
text
(
'province'
)
->
required
()
;
$table
->
width
(
3
)
->
text
(
'province'
);
$table
->
width
(
3
)
->
text
(
'city'
)
->
required
();
$table
->
width
(
3
)
->
text
(
'city'
)
->
required
();
$table
->
width
(
2
)
->
text
(
'post_code'
)
->
required
();
$table
->
width
(
2
)
->
text
(
'post_code'
)
->
required
();
});
});
...
...
app/Admin/Service/UserService.php
View file @
30085249
...
@@ -9,10 +9,16 @@ use App\Admin\Actions\User\UserStatusAction;
...
@@ -9,10 +9,16 @@ use App\Admin\Actions\User\UserStatusAction;
use
App\Admin\Actions\User\UserTransferAction
;
use
App\Admin\Actions\User\UserTransferAction
;
use
App\Models\Cms\CmsUser
;
use
App\Models\Cms\CmsUser
;
use
App\Models\User
;
use
App\Models\User
;
use
App\Models\UserAddress
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Http\JsonResponse
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Validator
;
use
Symfony\Component\HttpFoundation\Response
;
class
UserService
class
UserService
{
{
public
static
function
userListFilter
(
Grid
$grid
)
public
static
function
userListFilter
(
Grid
$grid
)
{
{
$grid
->
filter
(
function
(
$filter
)
{
$grid
->
filter
(
function
(
$filter
)
{
...
@@ -36,7 +42,7 @@ class UserService
...
@@ -36,7 +42,7 @@ class UserService
public
static
function
userListListField
(
Grid
$grid
)
public
static
function
userListListField
(
Grid
$grid
)
{
{
$grid
->
column
(
'company_name'
);
$grid
->
column
(
'company_name'
);
$grid
->
column
(
'user_sn'
)
->
link
(
function
(
$user_sn
)
use
(
$grid
)
{
$grid
->
column
(
'user_sn'
)
->
link
(
function
(
$user_sn
)
use
(
$grid
)
{
return
admin_url
(
"/users/
{
$this
->
id
}
"
);
return
admin_url
(
"/users/
{
$this
->
id
}
"
);
});
});
$grid
->
column
(
'name'
);
$grid
->
column
(
'name'
);
...
@@ -50,8 +56,6 @@ class UserService
...
@@ -50,8 +56,6 @@ class UserService
$grid
->
column
(
'status'
)
->
using
(
admin_trans
(
'user.options.status'
));
$grid
->
column
(
'status'
)
->
using
(
admin_trans
(
'user.options.status'
));
}
}
public
static
function
userListTool
(
Grid
$grid
)
public
static
function
userListTool
(
Grid
$grid
)
{
{
$grid
->
tools
([
$grid
->
tools
([
...
@@ -73,7 +77,7 @@ class UserService
...
@@ -73,7 +77,7 @@ class UserService
// $rowArray = $actions->row->toArray();
// $rowArray = $actions->row->toArray();
// 获取当前行主键值
// 获取当前行主键值
$id
=
$actions
->
getKey
();
$id
=
$actions
->
getKey
();
$actions
->
append
(
'<a href="'
.
admin_url
(
"/users/
{
$id
}
"
)
.
'" class="btn btn-primary btn-sm
$actions
->
append
(
'<a href="'
.
admin_url
(
"/users/
{
$id
}
"
)
.
'" class="btn btn-primary btn-sm
btn-mini">detail</a> '
);
btn-mini">detail</a> '
);
//状态按钮
//状态按钮
$actions
->
append
(
new
UserStatusAction
());
$actions
->
append
(
new
UserStatusAction
());
...
@@ -87,4 +91,70 @@ class UserService
...
@@ -87,4 +91,70 @@ class UserService
];
];
User
::
updateById
(
$id
,
$update
);
User
::
updateById
(
$id
,
$update
);
}
}
public
static
function
createUserAndAddress
(
$params
)
{
try
{
DB
::
beginTransaction
();
$userData
=
[
"company_name"
=>
$params
[
"company_name"
],
"user_sn"
=>
$params
[
"user_sn"
],
"first_name"
=>
$params
[
"first_name"
],
"last_name"
=>
$params
[
"last_name"
],
"phone"
=>
$params
[
"phone"
],
"email"
=>
$params
[
"email"
],
"reg_source"
=>
User
::
REG_SOURCE_MANUAL
,
"remark"
=>
$params
[
"remark"
],
"password"
=>
"1234567"
,
"status"
=>
User
::
STATUS_NORMAL
,
"sale_id"
=>
request
()
->
user
[
'userId'
]
??
"1000"
,
"sale_name"
=>
request
()
->
user
[
'name'
]
??
"admin"
,
"created_time"
=>
time
(),
"update_time"
=>
time
(),
];
$userId
=
User
::
insertData
(
$userData
);
foreach
(
$params
[
'user_address_list'
]
as
$address
)
{
$validator
=
Validator
::
make
(
$address
,
[
'first_name'
=>
'required'
,
'last_name'
=>
'required'
,
'email'
=>
'required'
,
'phone'
=>
'required'
,
'country'
=>
'required'
,
'city'
=>
'required'
,
'post_code'
=>
'required'
,
'detail_address'
=>
'required'
,
'is_default'
=>
'required'
,
]);
if
(
$validator
->
fails
())
{
$error
=
$validator
->
errors
()
->
first
();
throw
new
\Exception
(
"客户地址错误:"
.
$error
);
}
$addressData
=
[
"user_id"
=>
$userId
,
"first_name"
=>
$address
[
"first_name"
]
??
""
,
"last_name"
=>
$address
[
"last_name"
]
??
""
,
"address_type"
=>
$address
[
"address_type"
]
??
""
,
"company_name"
=>
$address
[
"company_name"
]
??
""
,
"email"
=>
$address
[
"email"
]
??
""
,
"phone"
=>
$address
[
"phone"
]
??
""
,
"country"
=>
$address
[
"country"
]
??
""
,
"province"
=>
$address
[
"province"
]
??
""
,
"city"
=>
$address
[
"city"
]
??
""
,
"post_code"
=>
$address
[
"post_code"
]
??
""
,
"detail_address"
=>
$address
[
"detail_address"
]
??
""
,
"is_default"
=>
$address
[
"is_default"
]
??
""
,
"create_time"
=>
time
(),
"update_time"
=>
time
(),
];
UserAddress
::
insertData
(
$addressData
);
}
DB
::
commit
();
}
catch
(
\Throwable
$throwable
)
{
DB
::
rollBack
();
throw
$throwable
;
}
}
}
}
app/Models/User.php
View file @
30085249
...
@@ -34,6 +34,12 @@ class User extends Model
...
@@ -34,6 +34,12 @@ class User extends Model
const
STATUS_NORMAL
=
1
;
const
STATUS_NORMAL
=
1
;
const
STATUS_DISABLE
=
-
1
;
const
STATUS_DISABLE
=
-
1
;
const
REG_SOURCE_WEB
=
1
;
const
REG_SOURCE_MANUAL
=
2
;
const
ACCOUNT_PROPERTIES_PERSONAL
=
1
;
const
ACCOUNT_PROPERTIES_ENTERPRISE
=
2
;
public
static
function
insertData
(
$data
)
public
static
function
insertData
(
$data
)
{
{
return
self
::
insertGetId
(
$data
);
return
self
::
insertGetId
(
$data
);
...
...
app/Models/UserAddress.php
View file @
30085249
...
@@ -31,6 +31,11 @@ class UserAddress extends Model
...
@@ -31,6 +31,11 @@ class UserAddress extends Model
protected
$table
=
'user_address'
;
protected
$table
=
'user_address'
;
public
static
function
insertData
(
$data
)
{
return
self
::
insertGetId
(
$data
);
}
public
static
function
getListByUserId
(
$userId
)
public
static
function
getListByUserId
(
$userId
)
{
{
$res
=
self
::
where
(
'user_id'
,
$userId
)
->
get
();
$res
=
self
::
where
(
'user_id'
,
$userId
)
->
get
();
...
...
resources/lang/en/user.php
View file @
30085249
...
@@ -36,5 +36,9 @@ return [
...
@@ -36,5 +36,9 @@ return [
"1"
=>
"网站"
,
"1"
=>
"网站"
,
"2"
=>
"人工新增"
"2"
=>
"人工新增"
],
],
"account_properties"
=>
[
"1"
=>
"个人"
,
"2"
=>
"企业"
],
],
],
];
];
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