Commit e1a7110f by 孙龙
parents fc74d7d6 d0e61bd1
......@@ -7,6 +7,7 @@ use App\Admin\Renderable\BarChart;
use App\Admin\Renderable\InquiryDetail;
use App\Admin\Renderable\PostTable;
use App\Admin\Repositories\Inquiry;
use App\Admin\Service\InquiryService;
use App\Models\Cms\CmsUser;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
......
......@@ -34,7 +34,7 @@ class UserController extends AdminController
$grid->disableRefreshButton();
$grid->disableBatchDelete();
// $grid->disableCreateButton();
$grid->model()->orderBy("id", "desc");
$grid->model()->orderBy("id", "desc")->rule(\App\Models\User::$ruleViewList, 'sale_id');
UserService::userListListField($grid);
UserService::userListTool($grid);
UserService::userListActions($grid);
......@@ -79,14 +79,14 @@ class UserController extends AdminController
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'],
'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'] ?? [],
];
......@@ -116,8 +116,8 @@ class UserController extends AdminController
} catch (\Throwable $throwable) {
// var_dump((string)$throwable);
return Form::make()->response()
->error(trans('admin.save_failed'))
->withExceptionIf($throwable->getMessage(), $throwable);
->error(trans('admin.save_failed'))
->withExceptionIf($throwable->getMessage(), $throwable);
}
$url = admin_url("/users");
return Form::make()->response()->success(admin_trans("succeeded"))->redirect($url);
......
......@@ -27,7 +27,7 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
$form->disableCreatingCheck();
$form->row(function (Form\Row $form) {
$form->width(4)->text('company_name')->required();
$form->width(4)->text('user_sn');
$form->width(4)->text('user_sn')->disable();
});
$form->row(function (Form\Row $form) {
$form->width(4)->text('first_name')->required();
......
......@@ -15,4 +15,19 @@ class InquiryService
{
return Inquiry::batchUpdateSalesId($salesId, $userIds);
}
//根据用户id列表获取待处理和所有询价单的数量
public static function getInquiryCountByUserIds($userIds = [])
{
$result = [];
foreach ($userIds as $userId) {
$pendingCount = Inquiry::getInquiryCountByStatus($userId,Inquiry::STATUS_PENDING);
$allCount = Inquiry::where('user_id',$userId)->count();
$result[$userId] = [
'pending' => $pendingCount,
'all' => $allCount,
];
}
return $result;
}
}
<?php
/**
* Created by PhpStorm.
* User: duwenjun
* Date: 2021/8/25
* Time: 5:33 PM
*/
namespace App\Admin\Service;
use App\Http\Caches\PermCache;
use App\Http\Models\Cms\UserInfoModel;
use App\Models\Cms\CmsUser;
use App\Models\Cms\CmsUserDepartmentModel;
use Illuminate\Support\Facades\Log;
class PermService
{
const SELF_SYSTEM_NAME = "深贸后台";
// 获取指定用户下级所有人员
public static function getSubUserId($userId)
{
$sub_user_ids = [];
array_unshift($sub_user_ids, $userId); // 将当前用户添加到数组
$user_info = CmsUser::getInfoByUserId($userId);
if (empty($user_info) || !$user_info['department_id']) {
return $sub_user_ids;
}
// 获取所有下级部门
$department_ids = self::_getDepartmentIds($user_info['department_id']);
// 获取下级部门的人员
$sub_user_ids = CmsUser::getUserIdsByDepartmentIds($department_ids);
return array_unique($sub_user_ids);
}
// 获取查询的部门id,查询销售和采购部门下所有子部门的ids
// 这里要使用循环的查询方法,如果改部门下面还有子部门,那么一并查询,最终合并用户子部门id集
public static function _getDepartmentIds($top_department_id)
{
$all_department_ids = $next_department_ids = [$top_department_id];
while ($next_department_ids) {
$next_department_ids = CmsUserDepartmentModel::getDepartmentIdsParrentIds($next_department_ids);
$all_department_ids = array_merge($all_department_ids, $next_department_ids);
}
return $all_department_ids;
}
}
......@@ -50,6 +50,20 @@ class UserService
$grid->column('email');
$grid->column('remark');
$grid->column('sale_name');
$grid->column('order_num_data')->display(function ($order_num_data) {
$data = InquiryService::getInquiryCountByUserIds([$this->id])[$this->id] ?? [
"pending" => 0,
"all" => 0
];
return "{$data['pending']}/{$data['all']}";
});
$grid->column('inquiry_num_data')->display(function ($order_num_data) {
$data = InquiryService::getInquiryCountByUserIds([$this->id])[$this->id] ?? [
"pending" => 0,
"all" => 0
];
return "{$data['pending']}/{$data['all']}";
});
$grid->column('created_time')->display(function ($time) {
return $time ? date('Y-m-d H:i:s', $time) : '';
})->sortable();;
......@@ -58,10 +72,11 @@ class UserService
public static function userListTool(Grid $grid)
{
$grid->tools([
new UserTransferAction(),
new UserAssignAction(),
]);
$action = [new UserTransferAction()];
if (getAdminUserId() == 1000 || checkPerm(User::SEM_USER_VIEW_SUB) || checkPerm(User::SEM_USER_VIEW_ALL)) {
$action[] = new UserAssignAction();
}
$grid->tools($action);
}
public static function userListActions(Grid $grid)
......@@ -114,6 +129,8 @@ class UserService
"update_time" => time(),
];
$userId = User::insertData($userData);
$userSn = self::generateSn($userId);
User::updateById($userId, ["user_sn" => $userSn]);
foreach ($params['user_address_list'] as $address) {
if ($address['_remove_']) {
......@@ -162,6 +179,12 @@ class UserService
}
}
public static function generateSn($userId)
{
$id = str_pad($userId, 6, 0, STR_PAD_LEFT);
return 'SU' . $id;
}
public static function transferUser($ids, $saleId)
{
try {
......@@ -178,6 +201,8 @@ class UserService
"sale_name" => $saleInfo["name"],
];
User::updateByIdArr($userIds, $update);
InquiryService::batchUpdateSalesId($saleId, $userIds);
OrderService::changeOrderSales($userIds, $saleId, $saleInfo["name"]);
DB::commit();
} catch (\Throwable $throwable) {
......
<?php
namespace App\Models;
use App\Admin\Service\PermService;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{ /*
* 权限
*/
public function scopeRule($query, $viewList, $adminUser = "sale_id")
{
$nowSaleId = getAdminUserId();
if ($nowSaleId == 1000) {
return $query;
}
//查看所有
if (checkPerm($viewList[0])) {
return $query;
}
//查看下级
if (checkPerm($viewList[1])) { //查看下级的权限//获取用户部门下的所有用户
$userIds = PermService::getSubUserId($nowSaleId);
if (!empty($userIds)) {
return $query->whereIn($adminUser, $userIds);
}
}
$query = $query->where($adminUser, $nowSaleId);
return $query;
}
}
......@@ -16,10 +16,34 @@ class CmsUser extends Model
return ($res) ? $res->toArray() : [];
}
public static function getUserList()
{
return CmsUser::where([])->rule(\App\Models\User::$ruleViewList, 'userId')->pluck('name', 'userId')->toArray();
}
//根据部门id获取列表
public static function getUserListByDepartmentId($departmentIds)
{
$res = self::whereIn('department_id', $departmentIds)->get();
return ($res) ? $res->toArray() : [];
}
// 根据部门ID获取用户
public static function getUserIdsByDepartmentIds($department_ids = [], $field = [], $status = '')
{
$res = self::whereIn('department_id', $department_ids);
if ($status !== '') {
$res = $res->where('status', $status);
}
if (!$field) {
$res = $res->pluck('userId');
} else {
$res = $res->select($field)->get();
}
return ($res) ? $res->toArray() : [];
}
}
......@@ -32,6 +32,11 @@ class Inquiry extends Model
return $this->hasOne(CmsUser::class, 'userId', 'sales_id');
}
public static function getInquiryCountByStatus($userId,$status)
{
return self::where('user_id',$userId)->where('status', $status)->count();
}
public static function batchUpdateSalesId($salesId, $userIds = [])
{
......
......@@ -26,7 +26,7 @@ use Illuminate\Database\Eloquent\Model;
* @property $created_time 创建时间
* @property $update_time 更新时间
*/
class User extends Model
class User extends BaseModel
{
use HasDateTimeFormatter;
protected $table = 'users';
......@@ -39,6 +39,13 @@ class User extends Model
const ACCOUNT_PROPERTIES_PERSONAL = 1;
const ACCOUNT_PROPERTIES_ENTERPRISE = 2;
//查看权限
public static $ruleViewList = [
self::SEM_USER_VIEW_ALL, //查看所有
self::SEM_USER_VIEW_SUB,//查看下级
];
const SEM_USER_VIEW_ALL = "sem_user_viewAllList";//查看所有
const SEM_USER_VIEW_SUB = "sem_user_viewSubList";//查看下级
public static function insertData($data)
{
......
......@@ -329,7 +329,7 @@ function getAdminUser()
*/
function getAdminUserId()
{
$admin = request()->get("user");
$admin = request()->user;
if (!$admin) {
throw new \App\Exceptions\InvalidRequestException("没找到登录相关信息,请先登录~_~");
}
......
......@@ -28,6 +28,8 @@ return [
'created_time' => '创建时间',
'update_time' => '更新时间',
'reg_source' => '注册来源',
'order_num_data' => '进行中 / 总计 订单数',
'inquiry_num_data' => '待处理 / 总计 询价数',
'user_address' => [
'consignee' => 'Sales Name',
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment