Commit cb995417 by 汪伟伟

add

parent a6d377b3
......@@ -4,6 +4,7 @@ namespace App\Admin\Controllers;
use App\Admin\Metrics\Examples;
use App\Http\Controllers\Controller;
use Dcat\Admin\Admin;
use Dcat\Admin\Http\Controllers\Dashboard;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
......@@ -13,12 +14,15 @@ class HomeController extends Controller
{
public function index(Content $content)
{
// if ((Admin::user())->is_admin == 0){
// return response()->redirectTo('/receive');
// }
return $content
->header('Dashboard')
->description('Description...')
->body(function (Row $row) {
$row->column(6, function (Column $column) {
$column->row(Dashboard::title());
// $column->row(Dashboard::title());
$column->row(new Examples\Tickets());
});
......
......@@ -3,6 +3,7 @@
namespace App\Admin\Controllers;
use App\Admin\Extensions\Tools\BatchReceiveAction;
use App\Admin\Extensions\Tools\CreateSettlementOrder;
use App\Admin\Extensions\Tools\ReceiveAction;
use App\Admin\Repositories\Task;
use App\Models\TasksReceive;
......@@ -35,9 +36,14 @@ class TaskController extends AdminController
protected function getData()
{
return Grid::make(new Task(), function (Grid $grid) {
$user = Admin::user();
$user = Admin::user();
$exists = TasksReceive::query()->where('user_id',$user->id)->pluck('task_id')->toArray();
// $model = \App\Models\Task::query()->whereNotIn('id',$exists)
return Grid::make(new Task(), function (Grid $grid)use ($user,$exists) {
$grid->model()->whereNotIn('id',$exists);
// dd(Admin::user()->is_admin);
// dd(trans('admin.view'));//查看
......@@ -74,12 +80,11 @@ class TaskController extends AdminController
$grid->disableEditButton()->disableDeleteButton()->disableCreateButton();
$grid->disableBatchDelete();
$grid->tools(function (Grid\Tools $tools) use ($user) {
if ($user->is_admin == 0) {
$tools->append(new BatchReceiveAction());//新增批量领取按钮
}
});
if ($user->is_admin == 0) {
$grid->tools(new BatchReceiveAction('<button data-action="refresh" class="btn btn-primary grid-refresh btn-mini btn-outline" style="margin-right:3px">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline">&nbsp; 批量领取</span></button>'));
}
});
}
......@@ -214,7 +219,9 @@ class TaskController extends AdminController
$form->select('level')->options([1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5])->required();
// $form->select('province_id', '省')->options($arr)->loads('city_id', '/getCity');
$form->multipleSelect('city_id', '选择地区')->options('/getCity')->required();
$form->multipleSelect('city_id', '选择地区')->options('/getCity')->required()->saving(function ($v){
return $v[0];
});
// $form->distpicker([
// 'province_id' => '省',
......
<?php
namespace App\Admin\Extensions\Tools;
use Dcat\Admin\Grid\RowAction;
use App\Admin\Services\CityAreaService;
use App\Models\Task;
use App\Models\TasksApprove;
use App\Models\TasksCollect;
use App\Models\TasksOrder;
use App\Models\TasksReceive;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\BatchAction;
use Illuminate\Http\Request;
class BatchReceiveAction extends RowAction
class BatchReceiveAction extends BatchAction
{
protected $action;
/**
* 返回字段标题
*
*
* * @return string
*/
public function title()
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
{
return '<button data-action="refresh" class="btn btn-primary grid-refresh btn-mini btn-outline" style="margin-right:3px">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline">&nbsp; 批量领取</span></button>';
$this->title = $title;
$this->action = $action;
}
/**
* 添加JS
*
*
* * @return string
*/
// 确认弹窗信息
public function confirm()
{
return '您确定要领取吗?';
}
/**
* 处理请求,如果不需要接口处理,请直接删除这个方法
*
* @param Request $request
*
* @return \Dcat\Admin\Actions\Response
*/
// 处理请求
public function handle(Request $request)
{
// 获取主键
$key = $this->getKey();
// dd($key);
return $this->response()
->success('Processed successfully.')
->redirect('/');
// 获取选中的ID数组
$keys = $this->getKey();
$user = \Admin::user();
$counts = TasksReceive::query()->where('user_id',$user->id)->where('status',0)->count();
if (count($keys) + $counts > 10){
return $this->response()->error('最多只能领取十个任务');
}
// 获取请求参数
foreach ($keys as $id){
$exists= TasksReceive::query()->where('task_id',$id)->where('user_id',$user->id)->exists();
// dd()
$task = Task::query()->find($id);
if (!$exists && $task->num > 0){
$receive = TasksReceive::query()->create([
'task_id'=>$id,
'user_id'=>$user->id,
'area'=> CityAreaService::getAreaName($task->city_id),
]);
$task->num -= 1;
$task->save();
TasksCollect::query()->updateOrCreate([//默认新增一条收集数据的记录
'task_id'=>$id,
'user_id'=>$user->id,
'receive_id'=>$receive->id,
],[
'task_id'=>$id,
'user_id'=>$user->id,
'receive_id'=>$receive->id,
]);
}
}
return $this->response()->success('领取成功')->refresh();
}
public function html()
// 设置请求参数
public function parameters()
{
// $this->setHtmlAttribute(['data-excel' => $this->row->excel_url, 'class' => 'download-btn fa fa-download']);
return parent::html();
return [
'action' => $this->action,
];
}
}
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 to comment