Commit 32ecedd4 by LJM
parents edc939df 3350abd8
......@@ -3,10 +3,13 @@
namespace App\Admin\Actions\User;
use App\Admin\Forms\User\AssignUserHandle;
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;
......@@ -14,6 +17,7 @@ use Dcat\Admin\Grid\RowAction;
class UserAssignAction extends BatchAction
{
protected $action;
protected $htmlClasses = ['btn btn-primary btn-sm btn-mini'];
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
......@@ -25,15 +29,34 @@ class UserAssignAction extends BatchAction
// 确认弹窗信息
public function confirm()
{
return '您确定要发布已选中的文章吗?';
return '您确定要已选中的文章吗?';
}
public function render()
{
$form = AssignUserHandle::make();
$buttonName = trans('user.labels.handle');
return Modal::make()->lg()->title($this->title)->body($form->payload([]))->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>
</button>');
}
protected function getModalScript()
{
// 弹窗显示后往隐藏的id表单中写入批量选中的行ID
$warning = trans('global.labels.operate_must_select_data');
return <<<JS
var key = {$this->getSelectedKeysScript()}
if (!key.length){
Dcat.swal.error('$warning');
Dcat.reload();
}
$('#id').val(key);
JS;
}
public function html()
{
$class = $this->getElementClass();
$this->setHtmlAttribute([
"class" => "{$class} btn btn-primary btn-sm btn-mini",
]);
return parent::html(); // TODO: Change the autogenerated stub
}
......@@ -46,11 +69,6 @@ class UserAssignAction extends BatchAction
// 获取请求参数
$action = $request->get('action');
foreach (Post::find($keys) as $post) {
$post->released = $action;
$post->save();
}
$message = $action ? '文章发布成功' : '文章下线成功';
return $this->response()->success($message)->refresh();
......
......@@ -3,10 +3,12 @@
namespace App\Admin\Actions\User;
use App\Admin\Forms\User\AssignUserHandle;
use App\Models\Order as OrderModel;
use App\Models\User;
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;
......@@ -14,6 +16,7 @@ use Dcat\Admin\Grid\RowAction;
class UserTransferAction extends BatchAction
{
protected $action;
protected $htmlClasses = ['btn btn-primary btn-sm btn-mini'];
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
......@@ -25,18 +28,37 @@ class UserTransferAction extends BatchAction
// 确认弹窗信息
public function confirm()
{
return '您确定要发布已选中的文章吗?';
return '您确定要已选中的文章吗?';
}
public function render()
{
$form = AssignUserHandle::make();
$buttonName = trans('user.labels.handle');
return Modal::make()->lg()->title($this->title)->body($form->payload([]))->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>
</button>');
}
protected function getModalScript()
{
// 弹窗显示后往隐藏的id表单中写入批量选中的行ID
$warning = trans('global.labels.operate_must_select_data');
return <<<JS
var key = {$this->getSelectedKeysScript()}
if (!key.length){
Dcat.swal.error('$warning');
Dcat.reload();
}
$('#id').val(key);
JS;
}
public function html()
{
$class = $this->getElementClass();
$this->setHtmlAttribute([
"class" => "{$class} btn btn-primary btn-sm btn-mini",
]);
return parent::html(); // TODO: Change the autogenerated stub
}
// 处理请求
public function handle(Request $request)
{
......@@ -46,11 +68,6 @@ class UserTransferAction extends BatchAction
// 获取请求参数
$action = $request->get('action');
foreach (Post::find($keys) as $post) {
$post->released = $action;
$post->save();
}
$message = $action ? '文章发布成功' : '文章下线成功';
return $this->response()->success($message)->refresh();
......@@ -64,5 +81,3 @@ class UserTransferAction extends BatchAction
];
}
}
<?php
namespace App\Admin\Controllers;
use App\Admin\Repositories\Country;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
class CountryController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new Country(), function (Grid $grid) {
$grid->showFilter();
$grid->disableActions();
$grid->disableCreateButton();
$grid->filter(function ($filter) {
$filter->expand(true);
$filter->like('name')->width(3);
});
$grid->column('id')->sortable();
$grid->column('name')->editable();
$grid->column('capital');
$grid->column('currency');
$grid->column('currency_name');
$grid->column('currency_symbol');
$grid->column('region');
$grid->column('subregion');
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new Country(), function (Show $show) {
$show->field('id');
$show->field('name');
$show->field('capital');
$show->field('currency');
$show->field('currency_name');
$show->field('currency_symbol');
$show->field('region');
$show->field('subregion');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new Country(), function (Form $form) {
$form->display('id');
$form->text('name');
$form->text('capital');
$form->text('currency');
$form->text('currency_name');
$form->text('currency_symbol');
$form->text('region');
$form->text('subregion');
});
}
}
......@@ -20,6 +20,6 @@ JS
);
// 返回任意可被渲染的内容
return "<div class='box box-solid box-default no-margin box-show custom-textarea'><div class='box-body' style='min-height: 150px;'>$this->value</div></div>";
return "<div class='box box-solid box-default no-margin box-show custom-textarea'><div class='box-body' style='min-height: 120px;'>$this->value</div></div>";
}
}
<?php
namespace App\Admin\Forms\User;
use App\Models\Cms\CmsUser;
use App\Models\Inquiry;
use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
class AssignUserHandle extends Form implements LazyRenderable
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
try {
$ids = explode(",", $input['id']);
// $userList = User::getListByIdArr($ids);
$cmsUser = CmsUser::getInfoByUserId($input['sale_id']);
if (!$cmsUser) {
throw new \Exception('销售不存在');
}
User::updateByIdArr($ids, ['sale_id' => $input['sale_id'], "sale_name" => $cmsUser['name']]);
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->hidden('id')->attribute('id', 'id');
$this->select('sale_id')->options(CmsUser::pluck('name', 'userId')->toArray())->default(0)->required();
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return [
];
}
}
<?php
namespace App\Admin\Repositories;
use App\Models\Country as Model;
use Dcat\Admin\Repositories\EloquentRepository;
class Country extends EloquentRepository
{
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
}
......@@ -53,8 +53,8 @@ class UserService
public static function userListTool(Grid $grid)
{
$grid->tools([
new UserTransferAction("转让销售"),
new UserAssignAction("分配销售"),
new UserTransferAction("转移销售"),
]);
}
......
......@@ -20,6 +20,7 @@ Route::group([
$router->resource('order', 'OrderController');
$router->resource('test', 'TestController');
$router->resource('users', 'UserController');
$router->resource('country', 'CountryController');
//下载pdf
Route::get('/api/order_download', '\App\Admin\Controllers\Api\OrderApiController@orderDownload');
Route::get('/api/orderDownloadShow', '\App\Admin\Controllers\Api\OrderApiController@orderDownloadShow');
......
......@@ -9,4 +9,10 @@ class CmsUser extends Model
protected $connection = 'cms';
protected $table = 'user_info';
public $timestamps = false;
public static function getInfoByUserId($userId)
{
$res = self::where('userId', $userId)->first();
return ($res) ? $res->toArray() : [];
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Country extends Model
{
//
protected $table = 'country';
public $timestamps = false;
}
......@@ -48,21 +48,26 @@ class User extends Model
public static function getInfoByUserId($userId)
{
$res = self::where('user_id', $userId)->first();
$res = self::where('id', $userId)->first();
return ($res) ? $res->toArray() : [];
}
// 批量获取用户信息
public static function getInfoByUserIds($userId)
{
return self::whereIn('user_id', $userId)->get()->keyBy('user_id')->toArray();
return self::whereIn('id', $userId)->get()->keyBy('id')->toArray();
}
public static function getListByIdArr($userIdArr)
{
$res = self::wherein('user_id', $userIdArr)->get();
$res = self::wherein('id', $userIdArr)->get();
return ($res) ? $res->toArray() : [];
}
public static function updateByIdArr($idArr, $update)
{
return self::whereIn("id", $idArr)->update($update);
}
}
<?php
return [
'labels' => [
'Country' => 'Country',
'country' => 'Country',
],
'fields' => [
],
'options' => [
],
];
......@@ -4,5 +4,6 @@ return [
'titles' => [
'userAddress' => 'UserAddress',
'inquiry' => 'Inquiry',
'country' => 'Country',
],
];
<?php
return [
'labels' => [
'Country' => '国家/地区',
'country' => '国家/地区',
],
'fields' => [
'name' => '名称',
'capital' => '首都',
'currency' => '币种',
'currency_name' => '币种名称',
'currency_symbol' => '币种符号',
'region' => '区域',
'subregion' => '亚区域',
],
'options' => [
],
];
......@@ -15,6 +15,7 @@ return [
'icons' => '图标',
'userAddress' => '用户地址',
'inquiry' => '询价管理',
'task' => '任务管理'
'task' => '任务管理',
'country' => '地区管理',
],
];
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