game2006admin_be/app/Http/Controllers/ApplyController.php

127 lines
4.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\ApplyModel;
use App\Models\User;
use App\Models\UserNodeLine;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Validator;
class ApplyController extends Controller
{
//
public function index($type,Request $request){
$size = $request->get('size', 10);
// $node_id = UserNodeLine::where('user_id',auth()->id())->pluck('node_group_id')->toArray();
//// dump($node_id);die;
//当用户是申请组
if ($type==1){
$data = ApplyModel::withTrashed()->where('creator_account',auth()->user()->account)->orderBy('id','desc')->paginate($size)->toArray();
return $this->success($data);
}
//当用户是审核组
if ($type==2){
$data = ApplyModel::orderBy('id','desc')->paginate($size)->toArray();
return $this->success($data);
}
//当用户是执行组
if ($type==3){
$data = ApplyModel::where('state',1)->orderBy('id','desc')->paginate($size)->toArray();
return $this->success($data);
}
}
public function create(Request $request){
$validator = Validator::make($request->all(),[
'item_id' => 'required',
'send_account' => 'required',
'reason' => 'required',
], [
'item_id.required' => '道具id不能为空',
'send_account.required' => '接收账号不能为空',
'reason.required' => '申请原因不能为空',
]);
if ($validator->fails()){
return $this->error(ERROR_CODE_PARAM_INVALID,$validator->errors()->first());
}
$data = $request->all();
$data['creator_account'] = auth()->user()->account;
if (Cache::has('unikey_id')){
$unikey_id = Cache::get("unikey_id");
}else{
$unikey_id = 1;
Cache::add("unikey_id",$unikey_id);
}
$data['unikey'] = date('ymd_his',time()).'_'.$unikey_id;
$data['create_time'] = time();
$res = ApplyModel::insert($data);
if(! $res){
return $this->error(ERROR_CODE_NO,'系统繁忙,稍后再试');
};
Cache::increment('unikey_id');
return $this->success([]);
}
public function show($id){
if (! is_numeric($id)){
return $this->error(ERROR_CODE_PARAM_INVALID,'参数格式不对');
}
$data = ApplyModel::withTrashed()->find($id);
return $this->success($data);
}
public function destroy($id){
if (! is_numeric($id)){
return $this->error(ERROR_CODE_PARAM_INVALID,'参数格式不对');
}
$model = ApplyModel::find($id);
if (!$model || $model->state){
return $this->error(ERROR_CODE_PARAM_INVALID,'无法撤销');
}
$res = $model->delete();
if(! $res){
return $this->error(ERROR_CODE_NO,'系统繁忙,稍后再试');
};
return $this->success([]);
}
public function pass($id){
if (! is_numeric($id)){
return $this->error(ERROR_CODE_PARAM_INVALID,'参数格式不对');
}
$model = ApplyModel::find($id);
if (!$model || $model->state){
return $this->error(ERROR_CODE_PARAM_INVALID,'无需审核');
}
$model->audit_account = auth()->user()->account;
$model->audit_time = time();
$model->state = 1;
$res = $model->save();
if(! $res){
return $this->error(ERROR_CODE_NO,'系统繁忙,稍后再试');
};
return $this->success([]);
}
public function noPass($id){
if (! is_numeric($id)){
return $this->error(ERROR_CODE_PARAM_INVALID,'参数格式不对');
}
$model = ApplyModel::find($id);
if (!$model || $model->state){
return $this->error(ERROR_CODE_PARAM_INVALID,'无需审核');
}
$model->audit_account = auth()->user()->account;
$model->audit_time = time();
$model->state = 2;
$res = $model->save();
if(! $res){
return $this->error(ERROR_CODE_NO,'系统繁忙,稍后再试');
};
return $this->success([]);
}
}