Commit af9389db by 汪伟伟

事务

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