You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
4.9 KiB
166 lines
4.9 KiB
4 years ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Api;
|
||
|
|
||
|
use App\Http\Resources\EmployeeBankCollection;
|
||
|
use App\Http\Resources\EmployeeBank;
|
||
|
use App\Models\EmployeeBankT;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
/**
|
||
|
* @title 银行卡管理
|
||
|
* @description 员工银行卡管理
|
||
|
* @package App\Http\Controllers\Api
|
||
|
* @author zcstatham
|
||
|
* @time 2021/2/3
|
||
|
*/
|
||
|
class EmployeeBankController extends BaseController
|
||
|
{
|
||
|
|
||
|
protected $rules = [
|
||
|
'store' => [
|
||
|
'rules' => [
|
||
|
'employee_id' => 'required',
|
||
|
'super_bank_name' => 'required',
|
||
|
'bank_name' => 'required',
|
||
|
'bank_code' => 'required',
|
||
|
'bank_num' => 'required',
|
||
|
'bank_man' => 'required',
|
||
|
'maximum' => 'max:10000000',
|
||
|
],
|
||
|
'custom' => 'unique,App\Models\EmployeeBankT,bank_num'
|
||
|
],
|
||
|
'show' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
],
|
||
|
'custom' => 'exists,App\Models\EmployeeBankT,id'
|
||
|
],
|
||
|
'update' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
'employee_id' => 'required',
|
||
|
'super_bank_name' => 'required',
|
||
|
'bank_name' => 'required',
|
||
|
'bank_code' => 'required',
|
||
|
'bank_num' => 'required',
|
||
|
'bank_man' => 'required',
|
||
|
'maximum' => 'max:10000000',
|
||
|
],
|
||
|
'custom' => [
|
||
|
'exists,App\Models\EmployeeBankT,id',
|
||
|
'unique,App\Models\EmployeeBankT,bank_num,id'
|
||
|
]
|
||
|
],
|
||
|
'destroy' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
],
|
||
|
'custom' => [
|
||
|
'exists,App\Models\EmployeeBankT,id',
|
||
|
]
|
||
|
]
|
||
|
];
|
||
|
|
||
|
public function __construct(Request $request)
|
||
|
{
|
||
|
$this->model = new EmployeeBankT();
|
||
|
parent::__construct($request);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 银行卡列表
|
||
|
* @description 银行卡列表
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function index()
|
||
|
{
|
||
|
$query = $this->model->query();
|
||
|
|
||
|
if(isset($this->params['name']) && $this->params['name'] != ''){
|
||
|
$query->where('name', $this->params['name']);
|
||
|
}
|
||
|
|
||
|
$data = $query->paginate();
|
||
|
|
||
|
return $this->success(new EmployeeBankCollection($data));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 银行卡保存
|
||
|
* @description 银行卡保存
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function store()
|
||
|
{
|
||
|
$this->model->employee_id = $this->params['employee_id'];
|
||
|
$this->model->super_bank_name = $this->params['super_bank_name'];
|
||
|
$this->model->bank_name = $this->params['bank_name'];
|
||
|
$this->model->bank_code = $this->params['bank_code'];
|
||
|
$this->model->bank_num = $this->params['bank_num'];
|
||
|
$this->model->bank_man = $this->params['bank_man'];
|
||
|
$this->model->maximum = $this->params['maximum'];
|
||
|
$this->model->priority = $this->params['priority'];
|
||
|
if($this->model->save()){
|
||
|
return $this->success(new EmployeeBank($this->model));
|
||
|
} else {
|
||
|
return $this->error(500, '银行卡信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 银行卡详情
|
||
|
* @description 银行卡详情
|
||
|
* @param $id
|
||
|
* @return mixed
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function show($id)
|
||
|
{
|
||
|
return $this->success(new EmployeeBank($this->model->where('id', $id)->first()));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 银行卡更新
|
||
|
* @description 银行卡更新
|
||
|
* @param $id
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function update($id)
|
||
|
{
|
||
|
$this->model = $this->model->where('id', $id)->first();
|
||
|
$this->model->employee_id = $this->params['employee_id'];
|
||
|
$this->model->super_bank_name = $this->params['super_bank_name'];
|
||
|
$this->model->bank_name = $this->params['bank_name'];
|
||
|
$this->model->bank_code = $this->params['bank_code'];
|
||
|
$this->model->bank_num = $this->params['bank_num'];
|
||
|
$this->model->bank_man = $this->params['bank_man'];
|
||
|
$this->model->maximum = $this->params['maximum'];
|
||
|
$this->model->priority = $this->params['priority'];
|
||
|
if($this->model->save()){
|
||
|
return $this->success(new EmployeeBank($this->model));
|
||
|
} else {
|
||
|
return $this->error(500, '银行卡信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 银行卡删除
|
||
|
* @description 银行卡删除
|
||
|
* @param $id
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function destroy($id)
|
||
|
{
|
||
|
if($this->model->destroy($id)){
|
||
|
return $this->success();
|
||
|
} else {
|
||
|
return $this->error(500, '银行卡信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
}
|