Commit e298fda7 by 孙龙
parents 4f54ea7a 44ef292e
......@@ -53,3 +53,12 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
START_IFRAME_TAB=true
LOGIN_DOMAIN=user.semourdev.net
PERM_URL=http://perm.semourdev.net/api/check
PERM_ID=12
PERM_GOURL=http://perm.semourdev.net
ADMIN_GROUP=1000,20000
MENU_ID=2
MENU_URL=http://data.semourdev.net/api/config/
......@@ -18,7 +18,7 @@ use Dcat\Admin\Grid\RowAction;
class UserEditAction extends AbstractTool
{
protected $action;
protected $htmlClasses = ['btn btn-primary btn-sm btn-mini'];
protected $htmlClasses = ['btn btn-sm btn-primary'];
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
{
......@@ -26,19 +26,14 @@ class UserEditAction extends AbstractTool
$this->action = $action;
}
// // 确认弹窗信息
// public function confirm()
// {
// return '您确定要已选中的文章吗?';
// }
public function render()
{
$form = EditUserHandle::make(['key'=>$this->getKey()]);
$buttonName = trans('user.labels.handle');
return Modal::make()->lg()->title($this->title)->body($form->payload(['key'=>$this->getKey()]))->onLoad
($this->getModalScript())->button('<button class="btn btn-primary">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' . $buttonName . '</span>
($this->getModalScript())->button('<button style="margin-right: 5px" class="btn btn-sm btn-primary">
<i class="feather icon-check-circle"></i> <span class="d-none d-sm-inline" style="margin-left: 5px">' .
$buttonName . '</span>
</button>');
}
......
<?php
namespace App\Admin\Actions\UserAddress;
use App\Admin\Forms\User\AssignUserHandle;
use App\Admin\Forms\UserAddress\SaveUserAddressHandle;
use App\Admin\Forms\User\EditUserHandle;
use App\Models\Order as OrderModel;
use App\Models\User;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\BatchAction;
use Dcat\Admin\Grid\Tools\AbstractTool;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Http\Request;
use Dcat\Admin\Grid\RowAction;
class UserAddressCreateAction extends AbstractTool
{
protected $action;
protected $htmlClasses = ['btn btn-sm btn-primary'];
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
{
$this->title = $title;
$this->action = $action;
}
public function render()
{
$form = SaveUserAddressHandle::make(['user_id'=>$this->getKey()]);
$buttonName = trans('user.labels.handle');
return Modal::make()->lg()->title($this->title)->body($form->payload(['user_id'=>$this->getKey()]))->onLoad
($this->getModalScript())->button('<button style="margin-right: 5px" class="btn btn-sm btn-primary">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' .
$buttonName . '</span>
</button>');
}
protected function getModalScript()
{
return <<<JS
var key = {$this->getKey()}
$('#user_id').val(key);
JS;
}
public function html()
{
return parent::html(); // TODO: Change the autogenerated stub
}
// 设置请求参数
public function parameters()
{
return [
'action' => $this->action,
'user_id'=>$this->getKey()
];
}
}
<?php
namespace App\Admin\Actions\UserAddress;
use App\Admin\Service\UserService;
use App\Models\Order as OrderModel;
use App\Models\User;
use App\Models\UserAddress;
use Dcat\Admin\Grid\BatchAction;
use Dcat\Admin\Grid\Tools\AbstractTool;
use Illuminate\Http\Request;
use Dcat\Admin\Grid\RowAction;
class UserAddressDeleteAction extends RowAction
{
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn btn-white waves-effect';
/**
* 按钮文本
*
* @return string|void
*/
public function title()
{
$buttonName = "删除";
return $buttonName;
}
public function html()
{
$class = $this->getElementClass();
$color = "btn btn-danger btn-sm btn-mini";
// 获取当前行数据ID
$id = $this->getKey();
$this->setHtmlAttribute([
'data-id' => $id,
"class" => "{$class} {$color}",
]);
return parent::html();
}
/**
* 确认弹窗,如果不需要则返回空即可
*
* @return array|string|void
*/
public function confirm()
{
$buttonName = "删除";
return ["是否确认 {$buttonName} ?"];
}
/**
* 处理请求
* 如果你的类中包含了此方法,则点击按钮后会自动向后端发起ajax请求,并且会通过此方法处理请求逻辑
*
* @param Request $request
*/
public function handle(Request $request)
{
// 获取 parameters 方法传递的参数
$rowData = $request->get('rowData');
try {
UserAddress::deleteById($rowData['address_id']);
} catch (\Throwable $e) {
return $this->response()->error($e->getMessage());
}
return $this->response()->success('操作成功')->refresh();
}
/**
* 设置请求参数
*
* @return array|void
*/
public function parameters()
{
return [
'rowData' => $this->row,
];
}
}
<?php
namespace App\Admin\Actions\UserAddress;
use App\Admin\Forms\User\AssignUserHandle;
use App\Admin\Forms\UserAddress\SaveUserAddressHandle;
use App\Admin\Forms\User\EditUserHandle;
use App\Models\Order as OrderModel;
use App\Models\User;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\BatchAction;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Http\Request;
use Dcat\Admin\Grid\RowAction;
class UserAddressEditAction extends RowAction
{
protected $action;
protected $htmlClasses = ['btn btn-sm btn-primary'];
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
{
$this->title = $title;
$this->action = $action;
}
public function render()
{
$form = SaveUserAddressHandle::make(['address_id' => $this->getRow()['address_id']]);
$buttonName = trans('user.labels.handle');
return Modal::make()->lg()->title($this->title)->body($form->payload(['address_id' => $this->getRow()['address_id']]))
->onLoad
($this->getModalScript())->button('<button style="margin-right: 5px" class="btn btn-sm btn-primary">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' .
$buttonName . '</span>
</button>');
}
protected function getModalScript()
{
return <<<JS
var key = {$this->getRow()['address_id']}
$('#address_id').val(key);
JS;
}
public function html()
{
return parent::html(); // TODO: Change the autogenerated stub
}
// 设置请求参数
public function parameters()
{
return [
'action' => $this->action,
'address_id' => $this->getKey()
];
}
}
......@@ -26,10 +26,10 @@ class InquiryController extends AdminController
{
return Grid::make(new Inquiry(['user','sales_user']), function (Grid $grid) {
$grid->showFilter();
$grid->disableActions();
// $grid->disableActions();
$grid->disableFilterButton();
$grid->disableRefreshButton();
$grid->disableCreateButton();
// $grid->disableCreateButton();
$grid->filter(function ($filter) {
$filter->expand(true);
$filter->whereBetween('create_time', function ($q) {
......@@ -122,16 +122,29 @@ class InquiryController extends AdminController
protected function form()
{
return Form::make(new Inquiry(), function (Form $form) {
$form->display('inquiry_id');
$form->text('sales_id');
$form->text('inquiry_sn');
$form->text('status');
$form->text('remark');
$form->text('priority');
$form->text('user_types');
$form->text('processing_time');
$form->text('create_time');
$form->text('update_time');
$form->row(function (Form\Row $form) {
$form->text('sales_id');
$form->text('inquiry_sn');
});
$form->row(function (Form\Row $form) {
$form->text('status');
$form->text('remark');
$form->text('priority');
});
$form->row(function (Form\Row $form) {
$form->array('column_name', function ($table) {
$table->text('key')->width(3);
$table->text('value')->width(3);
$table->text('desc')->width(3);
$table->text('desc')->width(3);
$table->text('desc')->width(3);
$table->text('desc')->width(3);
$table->text('desc')->width(3);
$table->text('desc')->width(3);
$table->text('desc')->width(3);
});
});
});
}
......
......@@ -16,6 +16,8 @@ use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpFoundation\Response;
class UserController extends AdminController
{
......@@ -32,6 +34,7 @@ class UserController extends AdminController
$grid->disableRefreshButton();
$grid->disableBatchDelete();
// $grid->disableCreateButton();
$grid->model()->orderBy("id", "desc");
UserService::userListListField($grid);
UserService::userListTool($grid);
UserService::userListActions($grid);
......@@ -62,12 +65,64 @@ class UserController extends AdminController
*/
public function create(Content $content)
{
return $content
->header('Dashboard')
->description('Description...')
->body(CreateUser::make()->render());
return $content->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.
*
......@@ -75,27 +130,7 @@ class UserController extends AdminController
*/
protected function form()
{
return Form::make(new User(), function (Form $form) {
$form->display('id');
$form->text('user_sn');
$form->text('name');
$form->text('email');
$form->text('email_verified_at');
$form->text('password');
$form->text('phone');
$form->text('remember_token');
$form->text('account_properties');
$form->text('status');
$form->text('company_name');
$form->text('first_name');
$form->text('sale_id');
$form->text('sale_name');
$form->text('last_name');
$form->text('created_time');
$form->text('update_time');
$form->display('created_at');
$form->display('updated_at');
});
return Form::dialog("测试");
// return $form;
}
}
......@@ -61,7 +61,7 @@ class EditUserHandle extends Form implements LazyRenderable
$form->width(5)->text('email');
});
$this->row(function (Row $form) {
$form->width(5)->text('reg_source')->required();
$form->width(5)->select('reg_source')->options(admin_trans('user.options.reg_source'))->required();
$form->width(5)->text('remark');
});
}
......
<?php
namespace App\Admin\Forms\UserAddress;
use App\Models\Cms\CmsUser;
use App\Models\Country;
use App\Models\Inquiry;
use App\Models\User;
use App\Models\UserAddress;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Form\Row;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
class SaveUserAddressHandle extends Form implements LazyRenderable
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
try {
$addressId = $this->payload['address_id'] ?? 0;
if ($addressId) {
$address = UserAddress::getInfoByAddressId($addressId);
if (empty($address)) {
return $this->response()->error("地址不存在");
}
$input = array_filter($input, function ($value) {
return $value !== null;
});
if ($input['is_default'] == 1) {
UserAddress::updateByUserId($address['user_id'], ['is_default' => 0]);
}
UserAddress::updateById($addressId, $input);
} else {
$userId = $this->payload['user_id'] ?? 0;
if ($input['is_default'] == 1) {
UserAddress::updateByUserId($userId, ['is_default' => 0]);
}
$addressData = [
"user_id" => $userId,
"first_name" => $input["first_name"] ?? "",
"last_name" => $input["last_name"] ?? "",
"address_type" => $input["address_type"] ?? "",
"company_name" => $input["company_name"] ?? "",
"email" => $input["email"] ?? "",
"phone" => $input["phone"] ?? "",
"country" => $input["country"] ?? "",
"province" => $input["province"] ?? "",
"city" => $input["city"] ?? "",
"post_code" => $input["post_code"] ?? "",
"detail_address" => $input["detail_address"] ?? "",
"is_default" => $input["is_default"] ?? "",
"create_time" => time(),
"update_time" => time(),
];
UserAddress::insertData($addressData);
}
return $this
->response()
->success(trans('admin.update_succeeded'))
->refresh();
} catch (\Throwable $throwable) {
// var_dump((string)$throwable);
return $this->response()->error(trans('admin.update_failed'));
}
}
/**
* Build a form here.
*/
public function form()
{
$this->disableResetButton();
$this->row(function (Row $row) {
$row->width(3)->text('first_name')->required();
$row->width(3)->text('last_name')->required();
});
$this->row(function (Row $row) {
$row->width(3)->select('address_type')->options(admin_trans('user-address.options.address_type'))
->required();
$row->width(3)->text('company_name');
});
$this->row(function (Row $row) {
$row->width(3)->email('email')->required();
$row->width(3)->text('phone')->required();
});
$this->row(function (Row $row) {
$row->width(3)->select('country')->options(Country::getCountryMap())->required();
$row->width(3)->text('province')->default('');
$row->width(3)->text('city')->required();
$row->width(2)->text('post_code')->required();
});
$this->row(function (Row $row) {
$row->width(12)->textarea('detail_address')->required();
});
$this->row(function (Row $row) {
$row->width(3)->switch('is_default')->required();
});
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
$userInfo = UserAddress::getInfoByAddressId($this->payload['address_id'] ?? 0);
if (!$userInfo) {
return [];
}
return $userInfo;
}
}
......@@ -5,6 +5,7 @@ namespace App\Admin\Renderable;
use App\Admin\Actions\User\UserEditAction;
use App\Admin\Repositories\Inquiry;
use App\Admin\Repositories\User;
use App\Models\Country;
use App\Models\InquiryItems;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
......@@ -12,6 +13,7 @@ use Dcat\Admin\Grid\LazyRenderable;
use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Show;
use Dcat\Admin\Widgets\Table;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
class CreateUser extends \Dcat\Admin\Support\LazyRenderable
{
......@@ -19,13 +21,13 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
{
// 只填充内容,不需要标题
return Form::make(new User(), function (Form $form) {
$form->disableDeleteButton();
$form->disableCreatingCheck();
$form->disableViewCheck();
$form->disableEditingCheck();
$form->disableViewCheck();
$form->disableResetButton();
$form->disableCreatingCheck();
$form->row(function (Form\Row $form) {
$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->width(4)->text('first_name')->required();
......@@ -33,11 +35,41 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
});
$form->row(function (Form\Row $form) {
$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->width(4)->text('reg_source')->required();
$form->width(4)->text('remark')->required();
$form->width(4)->select("account_properties")->options(admin_trans('user.options.account_properties'))->required();
$form->width(4)->text('remark');
});
$form->row(function (Form\Row $form) {
$form->array('user_address_list', function ($table) {
$table->row(function (Form\Row $table) {
$table->width(3)->text('first_name')->required();
$table->width(3)->text('last_name')->required();
});
$table->row(function (Form\Row $table) {
$table->width(3)->select('address_type')->options(admin_trans('user-address.options.address_type'))
->required();
$table->width(3)->text('company_name');
});
$table->row(function (Form\Row $table) {
$table->width(3)->email('email')->required();
$table->width(3)->text('phone')->required();
});
$table->row(function (Form\Row $table) {
$table->width(3)->select('country')->options(Country::getCountryMap())->required();
$table->width(3)->text('province');
$table->width(3)->text('city')->required();
$table->width(2)->text('post_code')->required();
});
$table->row(function (Form\Row $table) {
$table->width(12)->textarea('detail_address')->required();
});
$table->row(function (Form\Row $table) {
$table->width(3)->switch('is_default')->required();
});
});
});
})->render();
}
......
......@@ -2,6 +2,12 @@
namespace App\Admin\Renderable;
use App\Admin\Actions\UserAddress\UserAddressDeleteAction;
use App\Admin\Actions\User\UserAssignAction;
use App\Admin\Actions\User\UserStatusAction;
use App\Admin\Actions\User\UserTransferAction;
use App\Admin\Actions\UserAddress\UserAddressCreateAction;
use App\Admin\Actions\UserAddress\UserAddressEditAction;
use App\Admin\Repositories\Inquiry;
use App\Admin\Repositories\User;
use App\Admin\Service\UserAddressService;
......@@ -22,11 +28,36 @@ class UserAddress extends \Dcat\Admin\Support\LazyRenderable
$grid->title("address");
$grid->disableFilterButton();
$grid->disableRefreshButton();
$grid->disableBatchDelete();
$grid->disableCreateButton();
$grid->disableBatchDelete();
$grid->disableEditButton();
UserAddressService::listField($grid);
});
// $addressList = \App\Models\UserAddress::getListByUserId($id);
$userAddressCreateAction = new UserAddressCreateAction("新增用户地址");
$userAddressCreateAction->setKey($this->key);
$grid->tools([
$userAddressCreateAction,
]);
$grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableDelete();
$actions->disableEdit();
$actions->disableQuickEdit();
$actions->disableView();
// 当前行的数据数组
// $rowArray = $actions->row->toArray();
$editAction = new UserAddressEditAction();
$editAction->setKey($actions->row);
$editAction->setRow($actions->row);
$actions->append($editAction);
// 获取当前行主键值
$deleteAction = new UserAddressDeleteAction();
$deleteAction->setRow($actions->row);
$deleteAction->setKey($actions->getKey());
$actions->append($deleteAction);
});
});
}
}
......@@ -23,9 +23,8 @@ class UserDetail extends \Dcat\Admin\Support\LazyRenderable
->tools(function (Show\Tools $tools) {
$userEditAction = new UserEditAction("用户编辑");
$userEditAction->setKey($this->key);
$tools->disableEdit();
$tools->disableList();
$tools->disableDelete();
$tools->disableEdit();
$tools->append($userEditAction);
});
$show->row(function (Show\Row $show) {
......
<?php
namespace App\Admin\Service;
use Illuminate\Support\Facades\DB;
class AutoAssignCustomer
{
public static function getNowAssignInfo()
{
try {
DB::beginTransaction();
$assignInfo = \App\Models\AutoAssignCustomer::getNowAssignInfo();
if (empty($res)) {
$assignInfo = \App\Models\AutoAssignCustomer::getInfoByOrderSort();
\App\Models\AutoAssignCustomer::updateAll(['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_NO]);
\App\Models\AutoAssignCustomer::updateById($assignInfo['id'],
['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_YES]);
}
DB::commit();
return $assignInfo;
} catch (\Throwable $throwable) {
DB::rollBack();
throw $throwable;
}
}
public static function incAssignNumByDepartmentId($departmentId, $num = 1)
{
$assignInfo = \App\Models\AutoAssignCustomer::getInfoByDepartmentId($departmentId);
if (empty($assignInfo)) {
return false;
}
$nowNum = $assignInfo['now_num'] + $num;
if ($nowNum > $assignInfo['max_num']) {
return false;
}
if ($nowNum == $assignInfo['max_num']) {
$nextAssignInfo = \App\Models\AutoAssignCustomer::getInfoByOrderSort($assignInfo['sort']);
if (empty($nextAssignInfo)) {
return false;
}
\App\Models\AutoAssignCustomer::updateAll(['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_NO]);
\App\Models\AutoAssignCustomer::updateById($nextAssignInfo['id'],
['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_YES]);
}
return \App\Models\AutoAssignCustomer::updateById($assignInfo['id'], ['now_num' => $nowNum]);
}
}
......@@ -9,10 +9,16 @@ use App\Admin\Actions\User\UserStatusAction;
use App\Admin\Actions\User\UserTransferAction;
use App\Models\Cms\CmsUser;
use App\Models\User;
use App\Models\UserAddress;
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
{
public static function userListFilter(Grid $grid)
{
$grid->filter(function ($filter) {
......@@ -36,7 +42,7 @@ class UserService
public static function userListListField(Grid $grid)
{
$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}");
});
$grid->column('name');
......@@ -50,8 +56,6 @@ class UserService
$grid->column('status')->using(admin_trans('user.options.status'));
}
public static function userListTool(Grid $grid)
{
$grid->tools([
......@@ -73,8 +77,8 @@ class UserService
// $rowArray = $actions->row->toArray();
// 获取当前行主键值
$id = $actions->getKey();
$actions->append('<a href="'.admin_url("/users/{$id}").'" class="btn btn-primary btn-sm
btn-mini">detail</a> ');
$actions->append('<a style="margin-right: 5px" href="' . admin_url("/users/{$id}") . '" class="btn btn-primary btn-sm
btn-mini">detail</a>');
//状态按钮
$actions->append(new UserStatusAction());
});
......@@ -87,4 +91,70 @@ class UserService
];
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;
}
}
}
......@@ -5,6 +5,7 @@ use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Form;
use Dcat\Admin\Grid\Filter;
use Dcat\Admin\Layout\Menu;
use Dcat\Admin\Layout\Navbar;
use Dcat\Admin\Show;
use Dcat\Admin\Show\Field;
......@@ -188,6 +189,35 @@ HTML
);
});
Admin::menu(function (Menu $menu) {
//权限系统的菜单
$permMenus = request()->menus;
$permMenus = (array) $permMenus;
$addMenus = [];
foreach ($permMenus as $key => &$permMenu) {
$permMenu = (array) $permMenu;
//为了区分本系统手动添加的菜单
$key = $key + 1000;
$permMenu['id'] = $key + 1;
$permMenu['icon'] = $permMenu['class'];
$permMenu['uri'] = $permMenu['href'];
$permMenu['parent_id'] = 0;
$addMenus[] = $permMenu;
if (!empty($permMenu['childs'])) {
foreach ($permMenu['childs'] as $k => &$child) {
$child = (array) $child;
//为了让字菜单的id不和父菜单的id冲突
$child['id'] = $k + ($key + 1) * 100;
$child['parent_id'] = $key + 1;
$child['icon'] = $child['class'];
$child['uri'] = $child['href'];
$addMenus[] = $child;
}
}
}
unset($permMenu, $child);
$menu->add($addMenus);
});
Grid::resolving(function (Grid $grid) {
$grid->tableCollapse(true);
......
......@@ -23,8 +23,8 @@ class Kernel extends HttpKernel
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
// CheckLogin::class,
// Permission::class,
CheckLogin::class,
Permission::class,
];
/**
......
......@@ -51,8 +51,7 @@ class CheckLogin
}
$user = $ret->data;
// $user->code = DB::connection()->table('lie_intracode')->where('admin_id',
// $user->userId)->select('code_id')->first();
$user->header = $request->cookie('oa_header');
$request->user = $user;
......
......@@ -13,5 +13,7 @@ class EncryptCookies extends Middleware
*/
protected $except = [
//
'oa_user_id',
'oa_skey'
];
}
......@@ -21,7 +21,7 @@ class Permission
//处理权限和菜单
$permData = config('perm.perm');
$action = $request->route('key');
empty($action) && $action = 'Dashboard';
empty($action) && $action = 'Index';
//获取菜单
if (!$isApi && empty($request->input('window'))) {
......
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
/**
* @property $id 主键id
* @property $department_id 部门id
* @property $department_name 部门名
* @property $assign_sale_name 分配业务员名
* @property $assign_sale_id 分配业务员id
* @property $sort 排序
* @property $now_num 当前数量
* @property $max_num 分配总数
* @property $is_now 是否为当前分配部门
*/
class AutoAssignCustomer extends Model
{
use HasDateTimeFormatter;
public $timestamps = false;
protected $table = 'auto_assign_customer';
const IS_NOW_YES = 1;
const IS_NOW_NO = 0;
public static function insertData($data)
{
return self::insertGetId($data);
}
public static function getNowAssignInfo()
{
$res = self::where('is_now', self::IS_NOW_YES)->get();
return ($res) ? $res->toArray() : [];
}
public static function getInfoByOrderSort($sort = 0)
{
$res = self::where('sort', ">=", $sort)->orderBy("sort", "ASC")->get();
return ($res) ? $res->toArray() : [];
}
public static function deleteById($addressId)
{
return self::where('address_id', $addressId)->delete();
}
public static function updateById($id, $update)
{
return self::where("address_id", $id)->update($update);
}
public static function updateAll( $update)
{
return self::update($update);
}
public static function updateByUserId($userId, $update)
{
return self::where("user_id", $userId)->update($update);
}
public static function getInfoById($id)
{
$res = self::where('id', $id)->first();
return ($res) ? $res->toArray() : [];
}
public static function getInfoByDepartmentId($id)
{
$res = self::where('department_id', $id)->first();
return ($res) ? $res->toArray() : [];
}
}
......@@ -2,6 +2,7 @@
namespace App\Models;
use App\Models\Cms\CmsUser;
use Illuminate\Database\Eloquent\Model;
class Country extends Model
......@@ -9,4 +10,12 @@ class Country extends Model
//
protected $table = 'country';
public $timestamps = false;
public static function getCountryMap()
{
$res = self::pluck('name', 'id')
->toArray();
return $res;
}
}
......@@ -34,6 +34,12 @@ class User extends Model
const STATUS_NORMAL = 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)
{
return self::insertGetId($data);
......@@ -70,4 +76,10 @@ class User extends Model
return self::whereIn("id", $idArr)->update($update);
}
public function user_address()
{
return $this->hasMany(UserAddress::class, 'user_id', 'id');
}
}
......@@ -28,13 +28,39 @@ use Illuminate\Database\Eloquent\Model;
class UserAddress extends Model
{
use HasDateTimeFormatter;
public $timestamps = false;
protected $table = 'user_address';
public static function insertData($data)
{
return self::insertGetId($data);
}
public static function getListByUserId($userId)
{
$res = self::where('user_id', $userId)->get();
return ($res) ? $res->toArray() : [];
}
public static function deleteById($addressId){
return self::where('address_id', $addressId)->delete();
}
public static function updateById($id, $update)
{
return self::where("address_id", $id)->update($update);
}
public static function updateByUserId($userId, $update)
{
return self::where("user_id", $userId)->update($update);
}
public static function getInfoByAddressId($id)
{
$res = self::where('address_id', $id)->first();
return ($res) ? $res->toArray() : [];
}
}
......@@ -128,7 +128,7 @@ return [
|
*/
'auth' => [
'enable' => true,
'enable' => false,
'controller' => App\Admin\Controllers\AuthController::class,
......@@ -200,7 +200,7 @@ return [
|--------------------------------------------------------------------------
*/
'helpers' => [
'enable' => true,
'enable' => false,
],
/*
......
<?php
return [
'perm' => [
'id' => env('PERM_ID'),
'url' => env('PERM_URL'),
'go_url' => env('PERM_GOURL'),
'admin_group' => explode(',', env('ADMIN_GROUP')),//管理员权限组,有所有权限
'menu_id' => env('MENU_ID'),
'menu_url' => env('MENU_URL'),
'not_auth' => []
]
];
<?php
return [
'login' => [
'login' => 'http://' . env('LOGIN_DOMAIN', '') . '/login',
'logout'=> 'http://' . env('LOGIN_DOMAIN', '') . '/logout',
'check' => 'http://' . env('LOGIN_DOMAIN', '') . '/api/checklogin',
'search'=> 'http://' . env('LOGIN_DOMAIN', '') . '/api/search',
'dashboard'=>'http://'.env('LOGIN_DOMAIN', '') . '/dashboard',
],
];
......@@ -5,5 +5,7 @@ return [
'userAddress' => 'UserAddress',
'inquiry' => 'Inquiry',
'country' => 'Country',
'task' => 'Task',
'use' => 'Task',
],
];
......@@ -22,5 +22,13 @@ return [
"update_time" => "修改时间",
],
'options' => [
"address_type"=> [
"0" => "个人",
"1" => "公司",
],
"is_default"=> [
"1" => "是",
"0" => "否",
],
],
];
......@@ -23,6 +23,9 @@ return [
'created_time' => '创建时间',
'update_time' => '更新时间',
'reg_source' => '注册来源',
'user_address' => [
'consignee' => 'Sales Name',
]
],
'options' => [
"status"=>[
......@@ -33,5 +36,9 @@ return [
"1"=>"网站",
"2"=>"人工新增"
],
"account_properties"=>[
"1"=>"个人",
"2"=>"企业"
],
],
];
<?php
return [
'labels' => [
'UserAddress' => 'UserAddress',
'user-address' => 'UserAddress',
],
'fields' => [
"address_id" => "用户用户地址ID",
"user_id" => "会员ID",
"address_type" => "地址类型;0:个人,1:公司",
"consignee" => "收货人/收货公司",
"email" => "邮箱",
"post_code" => "邮政编码",
"phone" => "手机/电话",
"country" => "国家",
"province" => "省份",
"city" => "城市",
"detail_address" => "详细地址",
"is_default" => "是否默认(1=是|0=否)",
"create_time" => "创建时间",
"update_time" => "修改时间",
],
'options' => [
"address_type"=> [
"0" => "个人",
"1" => "公司",
],
"is_default"=> [
"1" => "是",
"0" => "否",
],
],
];
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