Commit af9389db by 汪伟伟

事务

parent 0b0afaa0
......@@ -14,11 +14,12 @@ use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class NoDoneTaskController extends AdminController
{
public $title='未完成任务';
public $title = '未完成任务';
/**
* Make a grid builder.
......@@ -35,7 +36,7 @@ class NoDoneTaskController extends AdminController
$grid->model()->where('status', 0);
// dd(trans('admin.view'));//查看
$grid->model()->orderBy('created_at','desc');
$grid->model()->orderBy('created_at', 'desc');
// 在 display 回调中使用
$grid->column('序号')->display(function () {
return $this->_index + 1;
......@@ -48,14 +49,14 @@ class NoDoneTaskController extends AdminController
// $grid->column('id')->sortable();
$grid->column('task.name', '指标名称');
$grid->column('task.city_id', '地区')->display(function ($v){
$grid->column('task.city_id', '地区')->display(function ($v) {
return CityAreaService::getAreaName($v);
});
$grid->column('task.year', '时间');
$grid->column('task.refer', '参考信源')->display(function ($val) {
if (filter_var($val, FILTER_VALIDATE_URL) !== false) {//是链接
return "<a href={$val} target='_blank' style='color: #00b44e'>点击查看</a>";
}else{
} else {
return $val;
}
});
......@@ -135,14 +136,16 @@ class NoDoneTaskController extends AdminController
}
public function notFind($id,Request $request)
public function notFind($id, Request $request)
{
DB::beginTransaction();
try {
$remark = $request->get('remark');
$receive = \App\Models\TasksReceive::query()->find($id);
if ($receive){
$receive->status =1;
$receive->time =date('Y-m-d H:i:s');
TasksCollect::query()->where('receive_id',$id)->update(['is_find'=>0,'remark'=>$remark]);
if ($receive) {
$receive->status = 1;
$receive->time = date('Y-m-d H:i:s');
TasksCollect::query()->where('receive_id', $id)->update(['is_find' => 0, 'remark' => $remark]);
$receive->save();
TasksApprove::query()->updateOrCreate([//审核表里新增一条记录
'task_id' => $receive->task_id,
......@@ -156,19 +159,23 @@ class NoDoneTaskController extends AdminController
}
$no = \App\Models\TasksReceive::query()
->where('id','!=',$id)
->where('user_id',(Admin::user())->id)
->where('status',0)
->where('id', '!=', $id)
->where('user_id', (Admin::user())->id)
->where('status', 0)
->orderBy('created_at')
->first();
if ($no){
$url = '/noDone/'.$no->id.'/edit';
}else{
if ($no) {
$url = '/noDone/' . $no->id . '/edit';
} else {
$url = '/noDone';
}
DB::commit();
return response()->redirectTo($url);//自动跳转下一个
} catch (\Exception $exception) {
DB::rollBack();
$form = Form::make();
return $form->response()->error('操作失败,请重试');
}
}
......@@ -177,13 +184,13 @@ class NoDoneTaskController extends AdminController
*
* @return Form
*/
protected function form($id='')
protected function form($id = '')
{
// $model = \App\Models\TasksReceive::query()
// ->leftJoin('tasks as a','task_id','=','a.id')
// ->select(['a.name','a.city_id','a.year','a.refer','tasks_receives.*'])
// ->with(['collects']);
return Form::make(\App\Models\TasksReceive::with(['task','collects']), function (Form $form) use ($id) {
return Form::make(\App\Models\TasksReceive::with(['task', 'collects']), function (Form $form) use ($id) {
$form->display('id');
$form->display('task.name', '指标名称');
$form->display('area', '地区');
......@@ -191,18 +198,18 @@ class NoDoneTaskController extends AdminController
$form->display('task.year', '时间');
$form->display('task.refer', '参考信源');
$form->text('collects.value', '指标值')->rules('required',['required'=>'指标值不能为空']);
$form->text('collects.reality_refer', '实际信源')->rules('required',['required'=>'实际信源不能为空']);
$form->select('collects.refer_level', '信源等级')->options([1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5])->rules('required',['required'=>'信源等级不能为空']);
$form->editor('collects.net_img', '网页截图')->rules('required',['required'=>'网页截图不能为空']);
$form->text('collects.remark', '备注信息')->placeholder('如果找不到请填写备注信息')->attribute(['id'=>'remark-zbd']);
$form->text('collects.value', '指标值')->rules('required', ['required' => '指标值不能为空']);
$form->text('collects.reality_refer', '实际信源')->rules('required', ['required' => '实际信源不能为空']);
$form->select('collects.refer_level', '信源等级')->options([1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5])->rules('required', ['required' => '信源等级不能为空']);
$form->editor('collects.net_img', '网页截图')->rules('required', ['required' => '网页截图不能为空']);
$form->text('collects.remark', '备注信息')->placeholder('如果找不到请填写备注信息')->attribute(['id' => 'remark-zbd']);
// $form->button('<a style="color: white;" href=/notFind/' . $id . '?remark='.'>找不到<a>');
$form->footer(function ($footer)use ($id) {
$form->footer(function ($footer) use ($id) {
$receive = \App\Models\TasksReceive::query()->find($id);
if ($receive && $receive->status == 0){
$footer->view('admin.button', ['id'=>$id]);
if ($receive && $receive->status == 0) {
$footer->view('admin.button', ['id' => $id]);
}
});
......@@ -245,7 +252,7 @@ class NoDoneTaskController extends AdminController
if ($this->status == 0) {
// dd($this->id);
\App\Models\TasksReceive::query()->where('id', $this->id)->update(['status' => 1,'time'=>date('Y-m-d H:i:s')]);//状态更新成已完成
\App\Models\TasksReceive::query()->where('id', $this->id)->update(['status' => 1, 'time' => date('Y-m-d H:i:s')]);//状态更新成已完成
TasksCollect::query()->where('receive_id', $this->id)->update(['is_find' => 1]);//可以找到
TasksApprove::query()->updateOrCreate([//审核表里新增一条记录
'task_id' => $this->task_id,
......@@ -258,14 +265,14 @@ class NoDoneTaskController extends AdminController
]);
$no = \App\Models\TasksReceive::query()
->where('id','!=',$this->id)
->where('user_id',(Admin::user())->id)
->where('status',0)
->orderBy('created_at','desc')
->where('id', '!=', $this->id)
->where('user_id', (Admin::user())->id)
->where('status', 0)
->orderBy('created_at', 'desc')
->first();
if ($no){
$url = '/noDone/'.$no->id.'/edit';
}else{
if ($no) {
$url = '/noDone/' . $no->id . '/edit';
} else {
$url = '/noDone';
}
// var_dump($url);
......
......@@ -19,6 +19,7 @@ use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Widgets\Table;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class TasksApproveController extends AdminController
{
......@@ -44,11 +45,11 @@ class TasksApproveController extends AdminController
}
$query->where('status', 1);
})
->with(['receives'=>function($qq){
$qq->orderBy('time','desc');
->with(['receives' => function ($qq) {
$qq->orderBy('time', 'desc');
}
,'receives.collects', 'receives.user', 'receives.approve'])
->orderBy('created_at','desc')
, 'receives.collects', 'receives.user', 'receives.approve'])
->orderBy('created_at', 'desc')
->paginate($pageSize, '*', 'page', $page)
->toArray();
......@@ -253,6 +254,7 @@ class TasksApproveController extends AdminController
public function pass($receiveId)
{
DB::transaction(function () use ($receiveId) {
$approve = \App\Models\TasksApprove::query()->where('receive_id', $receiveId)->first();
TasksReceive::query()->where('id', $receiveId)->update(['status' => 3]);//3:审核通过但未结算的任务
$approve->status = 2;//审核通过
......@@ -260,12 +262,15 @@ class TasksApproveController extends AdminController
$approve->save();
// dd($id,$user->id);
});
return true;
}
public function noPass($receiveId)
{
DB::transaction(function () use ($receiveId) {
$msg = \request()->input('msg');
// dd($receiveId,$msg);
......@@ -275,11 +280,15 @@ class TasksApproveController extends AdminController
$approve->msg = $msg;
$approve->time = date('Y-m-d H:i:s');
$approve->save();
});
return true;
}
public function allPass($taskId)
{
DB::transaction(function () use ($taskId) {
$task = Task::query()->find($taskId);
foreach ($task->receives->toArray() as $receive) {
if ($receive['status'] == 1) {
......@@ -290,11 +299,15 @@ class TasksApproveController extends AdminController
$approve->save();
}
}
});
return true;
}
public function allNoPass($taskId)
{
DB::transaction(function () use ($taskId) {
$msg = \request()->input('msg');
$task = Task::query()->find($taskId);
......@@ -310,6 +323,7 @@ class TasksApproveController extends AdminController
}
}
// dd($taskId,$msg,$task->receives->toArray());
});
return true;
}
......
......@@ -8,6 +8,7 @@ use App\Models\TasksReceive;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class BackAction extends RowAction
......@@ -45,7 +46,8 @@ class BackAction extends RowAction
*/
public function handle(Request $request)
{
DB::beginTransaction();
try {
// 获取主键
$id = $this->getKey();
// $user = Admin::user();
......@@ -60,15 +62,21 @@ class BackAction extends RowAction
$task->num += 1;
$task->save();
if (in_array($type,[1,2])){
if (in_array($type, [1, 2])) {
$url = 'already';
}
if ($type == 0){
if ($type == 0) {
$url = 'noDone';
}
DB::commit();
return $this->response()->success('退回成功')
->redirect($url);
} catch (\Exception $exception) {
DB::rollBack();
}
}
public function html()
......
......@@ -11,6 +11,7 @@ use App\Models\TasksReceive;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\BatchAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class BatchReceiveAction extends BatchAction
{
......@@ -32,44 +33,48 @@ class BatchReceiveAction extends BatchAction
// 处理请求
public function handle(Request $request)
{
DB::beginTransaction();
try {
// 获取选中的ID数组
$keys = $this->getKey();
$user = \Admin::user();
$counts = TasksReceive::query()->where('user_id',$user->id)->whereIn('status',[0,2])->count();
if (count($keys) + $counts > 10){
$counts = TasksReceive::query()->where('user_id', $user->id)->whereIn('status', [0, 2])->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();
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){
if (!$exists && $task->num > 0) {
$receive = TasksReceive::query()->create([
'task_id'=>$id,
'user_id'=>$user->id,
'area'=> CityAreaService::getAreaName($task->city_id),
'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,
'task_id' => $id,
'user_id' => $user->id,
'receive_id' => $receive->id,
], [
'task_id' => $id,
'user_id' => $user->id,
'receive_id' => $receive->id,
]);
}
}
DB::commit();
return $this->response()->success('领取成功')->refresh();
} catch (\Exception $exception) {
DB::rollBack();
return $this->response()->error('领取失败啊');
}
}
// 设置请求参数
......
......@@ -8,6 +8,7 @@ use App\Models\TasksOrder;
use App\Models\TasksReceive;
use Dcat\Admin\Grid\BatchAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CreateSettlementOrder extends BatchAction
{
......@@ -29,6 +30,8 @@ class CreateSettlementOrder extends BatchAction
// 处理请求
public function handle(Request $request)
{
DB::beginTransaction();
try {
// 获取选中的ID数组
$keys = $this->getKey();
......@@ -56,8 +59,12 @@ class CreateSettlementOrder extends BatchAction
TasksReceive::query()->whereIn('id', $keys)->update(['order_id' => $orderId, 'status' => 4]);
// dd($orderId);
DB::commit();
return $this->response()->success('生成结算单成功')->refresh();
} catch (\Exception $exception) {
DB::rollBack();
return $this->response()->error('生成结算单失败,请重试');
}
}
// 设置请求参数
......
......@@ -10,6 +10,7 @@ use App\Models\TasksReceive;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PassAction extends RowAction
......@@ -47,6 +48,8 @@ class PassAction extends RowAction
*/
public function handle(Request $request)
{
DB::beginTransaction();
try {
// 获取主键
$id = $this->getKey();
// $user = Admin::user();
......@@ -58,8 +61,13 @@ class PassAction extends RowAction
// dd($id,$user->id);
DB::commit();
return $this->response()->success('Processed successfully')
->refresh();
} catch (\Exception $exception) {
DB::rollBack();
return $this->response()->error('操作失败,请重试');
}
}
public function html()
......
......@@ -10,6 +10,7 @@ use App\Models\TasksReceive;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use SuperEggs\DcatDistpicker\DcatDistpickerHelper;
class ReceiveAction extends RowAction
......@@ -48,41 +49,49 @@ class ReceiveAction extends RowAction
*/
public function handle(Request $request)
{
DB::beginTransaction();
try {
// 获取主键
$id = $this->getKey();
$user = Admin::user();
$exists= TasksReceive::query()->where('task_id',$id)->where('user_id',$user->id)->exists();
$exists = TasksReceive::query()->where('task_id', $id)->where('user_id', $user->id)->exists();
$task = Task::query()->find($id);
$counts = TasksReceive::query()->where('user_id',$user->id)->whereIn('status',[0,2])->count();
if ($counts > 9){
$counts = TasksReceive::query()->where('user_id', $user->id)->whereIn('status', [0, 2])->count();
if ($counts > 9) {
return $this->response()->error('最多只能领取十个任务');
}
if (!$exists && $task->num > 0){
if (!$exists && $task->num > 0) {
$receive = TasksReceive::query()->create([
'task_id'=>$id,
'user_id'=>$user->id,
'area'=> CityAreaService::getAreaName($task->city_id),
'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,
'task_id' => $id,
'user_id' => $user->id,
'receive_id' => $receive->id,
], [
'task_id' => $id,
'user_id' => $user->id,
'receive_id' => $receive->id,
]);
}
// dd($id,$user->id);
DB::commit();
return $this->response()->success('领取成功')
->redirect('receive');
} catch (\Exception $exception) {
DB::rollBack();
return $this->response()->error('操作失败,请重试');
}
}
public function html()
......
......@@ -9,6 +9,7 @@ use App\Models\TasksReceive;
use Dcat\Admin\Actions\Action;
use Dcat\Admin\Grid\BatchAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class UserConfirmOrder extends Action
{
......@@ -16,7 +17,7 @@ class UserConfirmOrder extends Action
protected $orderId;
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null,$orderId = 0, $status = 1)
public function __construct($title = null, $orderId = 0, $status = 1)
{
$this->title = $title;
$this->orderId = $orderId;
......@@ -26,31 +27,37 @@ class UserConfirmOrder extends Action
// 确认弹窗信息
public function confirm()
{
return $this->status == 1 ?'您确定结账吗?':'您确定收款吗?';
return $this->status == 1 ? '您确定结账吗?' : '您确定收款吗?';
}
// 处理请求
public function handle(Request $request)
{
DB::beginTransaction();
try {
// 获取请求参数
$status = $request->get('status');
$orderId = $request->get('order_id');
$order = TasksOrder::query()->find($orderId);
if ($order){
if ($order->status == 0 && $status == 1){
if ($order) {
if ($order->status == 0 && $status == 1) {
$order->status = $status;
$order->save();
}
if ($order->status == 1 && $status == 2){
if ($order->status == 1 && $status == 2) {
$order->status = $status;
$order->save();
}
}
DB::commit();
return $this->response()->success('操作成功')->refresh();
} catch (\Exception $exception) {
DB::rollBack();
return $this->response()->error('操作失败,请重试');
}
}
// 设置请求参数
......
......@@ -7,10 +7,14 @@ use App\Models\TasksReceive;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
class MsgSetting extends Form implements LazyRenderable
{
use LazyWidget; // 使用异步加载功能
use LazyWidget;
// 使用异步加载功能
/**
* Handle the form request.
*
......@@ -20,6 +24,8 @@ class MsgSetting extends Form implements LazyRenderable
*/
public function handle(array $input)
{
DB::beginTransaction();
try {
// 获取外部传递参数
$id = $this->payload['id'] ?? null;
// 表单参数
......@@ -32,10 +38,17 @@ class MsgSetting extends Form implements LazyRenderable
$approve->time = date('Y-m-d H:i:s');
$approve->save();
DB::commit();
return $this
->response()
->success('Processed successfully')
->refresh();
} catch (\Exception $exception) {
DB::rollBack();
return $this
->response()
->error('操作失败,请重试');
}
}
/**
......@@ -46,7 +59,7 @@ class MsgSetting extends Form implements LazyRenderable
// Since v1.6.5 弹出确认弹窗
// $this->confirm('您确定要提交表单吗', 'content');
$this->text('msg','原因')->required();
$this->text('msg', '原因')->required();
}
/**
......
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