Commit 7084aa32 by mushishixian

云芯采购员

parent 96c5013b
......@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\Filter\SupplierAccountFilter;
use App\Http\Services\SupplierAccountService;
use App\Http\Transformers\SupplierLogTransformer;
use App\Http\Validators\SupplierAccountValidator;
use App\Model\LogModel;
use App\Model\SupplierAccountModel;
use App\Model\SupplierChannelModel;
......@@ -38,6 +39,11 @@ class SupplierAccountApiController extends Controller
'password_raw',
'a_type',
]);
$validator = new SupplierAccountValidator();
$check = $validator->checkSave($request);
if ($check !== true) {
$this->response(-1, $check);
}
$supplierModel = new SupplierChannelModel();
$supplierId = $supplierModel->where('supplier_code', $data['supplier_code'])->value('supplier_id');
$data['supplier_id'] = $supplierId;
......@@ -63,6 +69,11 @@ class SupplierAccountApiController extends Controller
'password_raw',
'a_type',
]);
$validator = new SupplierAccountValidator();
$check = $validator->checkSave($request);
if (!$check) {
$this->response(-1, $check);
}
$supplierModel = new SupplierChannelModel();
$supplierId = $supplierModel->where('supplier_code', $data['supplier_code'])->value('supplier_id');
$data['supplier_id'] = $supplierId;
......
<?php
namespace App\Http\Validators;
use App\Model\SupplierAccountModel;
use App\Model\SupplierChannelModel;
use Validator;
class SupplierAccountValidator
{
//保存相关的验证,别问我为什么不用laravel自带的form-request类
//因为控制器那边已经被之前的人魔改的难用的一比,而且控制器那边还接收了一大堆统一变量
public function checkSave($request)
{
//整理下请求数据
$receipt = $request->all();
$rules = [
"supplier_code" => "required",
"mobile" => "required|regex:/^1[0-9][0-9]{9}$/",
"password_raw" => "required",
];
$messages = $this->messages();
$validator = Validator::make($receipt, $rules, $messages);
//判断联系方式的表单验证
if ($validator->fails()) {
return $validator->errors()->first();
}
if (empty($receipt['id'])) {
$model = new SupplierAccountModel();
$count = $model->where('supplier_code',$receipt['supplier_code'])
->where('mobile',$receipt['mobile'])->count();
if ($count > 0) {
return '该供应商以及对应的账号已经存在,请更换手机号';
}
}
return true;
}
private function messages()
{
return [
'supplier_code.required' => '请选择一个供应商',
'mobile.required' => '登陆账号不能为空',
'mobile.regex' => '账号格式必须为手机号',
'password_raw.required' => '账号密码不能为空',
];
}
}
\ No newline at end of file
......@@ -50,7 +50,7 @@
<div class="layui-btn-group demoTable" style="margin-top: 15px">
<button type="button" class="layui-btn layui-btn-sm" id="add_supplier_account">新增账号</button>
<button type="button" class="layui-btn layui-btn-sm" id="update_supplier_account">修改</button>
<button type="button" class="layui-btn layui-btn-sm" id="forbid_supplier_account">禁用</button>
<button type="button" class="layui-btn layui-btn-sm" id="disable_supplier_account">禁用</button>
</div>
<table class="layui-table" id="supplierAccountList" lay-filter="supplierAccountList"></table>
......
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 sign in to comment