Commit 574822a0 by 杨树贤

新增IQC检测

parent d7e89d0a
......@@ -3,7 +3,9 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\SupplierExaminationService;
use App\Http\Transformers\SupplierLogTransformer;
use App\Http\Validators\SupplierExaminationValidator;
use App\Model\LogModel;
use App\Model\SupplierLogModel;
use Illuminate\Http\Request;
......@@ -19,45 +21,36 @@ class SupplierExaminationApiController extends Controller
//获取供应商信息变更记录
public function GetSupplierExaminationList($request)
{
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new SupplierLogModel();
$list = $model->where('supplier_id', $supplierId)->orderBy('id', 'desc')->paginate($limit)->toArray();
$transformer = new SupplierLogTransformer();
$list['data'] = $transformer->transformList($list['data']);
$model = new SupplierExaminationService();
$list = $model->getSupplierExaminationList($request);
$this->response(0, 'ok', $list['data'], $list['total']);
}
//添加
public function AddSupplierIQC($request)
public function AddSupplierExamination($request)
{
$data = $request->only([
'supplier_id',
'type',
'desc'
$params = $request->only([
'supplier_name',
'examine_time',
'purchase_name',
'sku_name',
'brand_name',
'amount',
'examine_amount',
'unhealthy_amount',
'unhealthy_content',
'examine_result',
'abnormal_level',
'handle_way',
'remark',
]);
if (empty($data['type']) || empty($data['desc'])) {
$this->response(-1, '类型或者描述都不能为空');
}
if (strlen($data['desc']) > 500) {
$this->response(-1, '描述不能超过500个字');
$validator = new SupplierExaminationValidator();
$validateResult = $validator->checkSave($params);
if ($validateResult) {
$this->response(-1, $validateResult);
}
$data['admin_id'] = $request->user->userId;
$data['admin_name'] = $request->user->name;
$data['add_time'] = time();
$model = new SupplierLogModel();
$result = $model->insert($data);
$result = (new SupplierExaminationService())->saveSupplierExamination($params);
if ($result) {
//还要添加操作记录
$logModel = new LogModel();
$data = [
'action' => '添加信息记录',
'content' => $data['desc'],
'add_time' => time(),
'admin_name' => $request->user->name,
'admin_id' => $request->user->userId,
];
$logModel->insert($data);
$this->response(0, '添加成功');
}
$this->response(-1, '添加失败', $result);
......
......@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Filter;
use App\Model\SupplierAccountModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierExaminationModel;
class SupplierExaminationFilter
{
......@@ -12,44 +13,26 @@ class SupplierExaminationFilter
public function listFilter($request)
{
$map = $request->all();
$model = new SupplierAccountModel();
$model = new SupplierExaminationModel();
$query = $model->orderBy('id', 'desc');
if (!empty($map['supplier_name'])) {
//先去供应商主表找出id
$supplierChannelModel = new SupplierChannelModel();
$supplierIds = $supplierChannelModel->where('supplier_name', 'like',
"%${map['supplier_name']}%")->pluck('supplier_id');
$query->whereIn('supplier_id', $supplierIds);
$query->where('supplier_name', 'like', "%${map['supplier_name']}%");
}
if (!empty($map['supplier_code'])) {
$query->where('supplier_code', 'like', "%${map['supplier_code']}%");
}
if ((isset($map['a_status']) && $map['a_status'] === '0') || !empty($map['a_status'])) {
$query->where('a_status', $map['a_status']);
}
if (!empty($map['mobile'])) {
$query->where('mobile', 'like', "%${map['mobile']}%");
if (!empty($map['purchase_name'])) {
$query->where('purchase_name', $map['purchase_name']);
}
if ((isset($map['a_type']) && $map['a_type'] === '0') || !empty($map['a_type'])) {
$query->where('a_type', $map['a_type']);
}
if (!empty($map['create_time'])) {
$times = explode('~', $map['create_time']);
$startTime = strtotime($times[0]);
$endTime = strtotime($times[1]);
$query->whereBetween('create_time', [$startTime, $endTime]);
if (!empty($map['abnormal_level'])) {
$query->where('abnormal_level', $map['abnormal_level']);
}
if (!empty($map['update_time'])) {
$times = explode('~', $map['update_time']);
if (!empty($map['examine_time'])) {
$times = explode('~', $map['examine_time']);
$startTime = strtotime($times[0]);
$endTime = strtotime($times[1]);
$query->whereBetween('update_time', [$startTime, $endTime]);
$query->whereBetween('examine_time', [$startTime, $endTime]);
}
return $query;
......
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Http\Services\AdminUserService;
use App\Http\Services\RoleService;
use App\Http\Services\SupplierContactService;
use App\Http\Services\SupplierService;
......@@ -42,24 +43,20 @@ class SupplierExaminationController extends Controller
//操作日志列表
public function SupplierExaminationList($request)
{
//获取所有采购员提供选择
$purchaseUsers = (new IntracodeModel())->getAllEncode();
$purchaseUserNames = collect($purchaseUsers)->pluck('name','name')->toArray();
$this->data['purchaseUserNames'] = $purchaseUserNames;
$this->data['title'] = 'IQC检测列表';
return $this->view('IQC检测列表');
}
public function AddSupplierExamination($request)
{
//获取所有启用的供应商编码,而且类型是包括云芯
$model = new SupplierChannelModel();
$suppliers = $model->where('is_type', 0)
->whereRaw('stockup_type like "%5%"')
->where('status', SupplierChannelModel::STATUS_PASSED)
->select(['supplier_name', 'supplier_code'])->get();
$supplierCodes = [];
foreach ($suppliers as $supplier) {
$supplier = $supplier->toArray();
$supplierCodes[$supplier['supplier_code']] = $supplier['supplier_name'] . '(' . $supplier['supplier_code'] . ')';
}
$this->data['supplierCodes'] = $supplierCodes;
//获取所有采购员提供选择
$purchaseUsers = (new IntracodeModel())->getAllEncode();
$purchaseUserNames = collect($purchaseUsers)->pluck('name','name')->toArray();
$this->data['purchaseUserNames'] = $purchaseUserNames;
$this->data['title'] = '添加供应商账号';
return $this->view('添加供应商账号');
}
......
......@@ -5,47 +5,40 @@ namespace App\Http\Services;
use App\Http\Controllers\Filter\SupplierAccountFilter;
use App\Http\Controllers\Filter\SupplierExaminationFilter;
use App\Http\Transformers\SupplierAccountTransformer;
use App\Http\Transformers\SupplierExaminationTransformer;
use App\Model\LogModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierExaminationModel;
use Carbon\Carbon;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
class SupplierExaminationService
{
public function getSupplierAccountList($request)
public function getSupplierExaminationList($request)
{
$limit = $request->get('limit', 10);
$filter = new SupplierAccountFilter();
$filter = new SupplierExaminationFilter();
$query = $filter->listFilter($request);
$list = $query->paginate($limit)->toArray();
$transformer = new SupplierAccountTransformer();
$transformer = new SupplierExaminationTransformer();
$list['data'] = $transformer->transformList($list['data']);
return $list;
}
//推送队列告诉搜索要去初始化数据
public function pushToInitData($supplierCode)
//保存
public function saveSupplierExamination($data)
{
return true;
//还要去推送给搜索做品牌初始化任务
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
$channel = $conn->channel();
$channel->queue_declare('yunxin_supplier_add', false, true, false, false);
$time = strtotime("2021-01-01 00:00:00");
$body = json_encode([
'canal' => $supplierCode,
'update_time' => $time
]);
$msg = new AMQPMessage($body,
['content_type' => 'text/plain', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT]);
$result = $channel->basic_publish($msg, '', 'yunxin_supplier_add');
$channel->close();
$conn->close();
$data['examine_time'] = strtotime($data['examine_time']);
if (!empty($data['id'])) {
$data['update_time'] = time();
return SupplierExaminationModel::where($data['id'])->update($data);
} else {
$data['create_time'] = time();
return SupplierExaminationModel::insert($data);
}
}
}
\ No newline at end of file
......@@ -10,18 +10,11 @@ class SupplierExaminationTransformer
{
public function transformList($list)
{
//获取供应商名称
$supplierIds = array_column($list, 'supplier_id');
$supplierModel = new SupplierChannelModel();
$suppliers = $supplierModel->whereIn('supplier_id', $supplierIds)->pluck('supplier_name', 'supplier_id');
foreach ($list as &$item) {
$item['supplier_name'] = array_get($suppliers, $item['supplier_id']);
$item['type_name'] = array_get(config('field.SupplierAccountType'), $item['a_type']);
$item['create_time'] = $item['create_time'] ? date('Y-m-d H:i:s', $item['create_time']) : '';
$item['update_time'] = $item['update_time'] ? date('Y-m-d H:i:s', $item['update_time']) : '';
}
unset($item);
return $list;
}
......
......@@ -11,54 +11,58 @@ class SupplierExaminationValidator
{
//保存相关的验证,别问我为什么不用laravel自带的form-request类
//因为控制器那边已经被之前的人魔改的难用的一比,而且控制器那边还接收了一大堆统一变量
public function checkSave($request)
public function checkSave($params)
{
//整理下请求数据
$account = $request->all();
$rules = [
"supplier_code" => "required",
"mobile" => "required|regex:/^1[0-9][0-9]{9}$/",
"password_raw" => "required",
"a_type" => "required",
"supplier_name" => "required|max:100",
"examine_time" => "required",
"purchase_name" => "required",
"sku_name" => "required",
"brand_name" => "required",
"amount" => "required|numeric",
"examine_amount" => "required",
"unhealthy_amount" => "required",
"unhealthy_content" => "required",
"examine_result" => "required",
"abnormal_level" => "required",
"handle_way" => "required",
"remark" => "required",
];
$messages = $this->messages();
$validator = Validator::make($account, $rules, $messages);
$validator = Validator::make($params, $rules, $messages, $this->attributes());
//判断联系方式的表单验证
if ($validator->fails()) {
return $validator->errors()->first();
}
if (empty($account['id'])) {
$supplierModel = new SupplierChannelModel();
$yunxinChannelUid = $supplierModel->where('supplier_code',
$account['supplier_code'])->value('yunxin_channel_uid');
if (empty($yunxinChannelUid)) {
return '该供应商没有绑定云芯采购,请完善相关信息';
}
$model = new SupplierAccountModel();
$supplierCount = $model->where('supplier_code', $account['supplier_code'])
->count();
if ($supplierCount > 0) {
return '该供应商已经存在账号';
}
$mobileCount = $model->where('mobile', $account['mobile'])
->count();
if ($mobileCount > 0) {
return '该手机号已经被注册';
}
}
return true;
return null;
}
private function messages()
{
return [
'supplier_code.required' => '请选择一个供应商',
'a_type.required' => '类型必须勾选为云芯商家',
'mobile.required' => '登录账号不能为空',
'mobile.regex' => '账号格式必须为手机号',
'password_raw.required' => '账号密码不能为空',
'required' => ':attribute 不能为空',
'numeric' => ':attribute 必须为数字',
];
}
public function attributes()
{
return [
'supplier_name' => '供应商名称',
'examine_time' => '检测时间',
'purchase_name' => '采购员',
'sku_name' => '型号',
'brand_name' => '品牌',
'amount' => '数量',
'examine_amount' => '检测数量',
'unhealthy_amount' => '不良数量',
'unhealthy_content' => '不良现象',
'examine_result' => '检验结果',
'abnormal_level' => '异常等级',
'handle_way' => '处理方式',
'remark' => '备注',
];
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
namespace App\Presenters;
class DateTimePresenter
class DatePresenter
{
public function render($name, $text, $value)
{
......@@ -23,8 +23,8 @@ class DateTimePresenter
let laydate = layui.laydate;
laydate.render({
elem: 'input[name=$name]'
,type: 'datetime'
,format: 'yyyy-MM-dd H:i:s'
,type: 'date'
,format: 'yyyy-MM-dd'
});
});
}
......
<script>
layui.use(['table', 'form', 'element', 'table', 'layer', 'admin','xmSelect'], function () {
let admin = layui.admin;
let form = layui.form;
let element = layui.element;
let xmSelect = layui.xmSelect;
form.on('submit(addSupplierExamination)', function (data) {
let url = '/api/supplier_examination/AddSupplierExamination';
let res = ajax(url, data.field);
if (!res) {
layer.msg('网络错误,请重试', {icon: 6});
} else {
if (res.err_code === 0) {
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
parent.layer.msg(res.err_msg, {icon: 5});
}
}
return false;
});
form.on('submit(cancel)', function (data) {
admin.closeThisDialog();
});
});
</script>
\ No newline at end of file
......@@ -74,11 +74,11 @@
});
//根据供应商编码已经品牌等去基石调用接口下架
$("#add_supplier_account").click(function () {
$("#add_supplier_examination").click(function () {
layer.open({
type: 2,
content: '/supplier_examination/AddSupplierExamination?view=iframe',
area: ['800px', '600px'],
area: ['80%', '70%'],
title: '添加IQC检测记录',
end: function () {
table.reload('supplierExaminationList');
......
<style>
.layui-form-item {
margin-bottom: 5px;
}
</style>
<div class="layui-card">
<div class="layui-card-body">
<blockquote class="layui-elem-quote layui-text">
<b>IQC基本信息</b>
</blockquote>
<form class="layui-form" action="">
<div class="layui-form-item">
<div class="layui-col-md6">
@inject('datePresenter','App\Presenters\DatePresenter')
{!! $datePresenter->render('examine_time','检货时间 : ','') !!}
</div>
<div class="layui-col-md6">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('purchase_name','采购员 : ','',
$purchaseUserNames,['required'=>true]) !!}
</div>
</div>
<div class="layui-form-item">
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>供应商 : </label>
<div class="layui-input-block">
<input type="text" name="supplier_name" id="supplier_name"
placeholder="请输入供应商名称" class="layui-input"
value="{{$account['mobile'] or ''}}">
</div>
</div>
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>数量 : </label>
<div class="layui-input-block">
<input type="text" name="amount" id="amount"
placeholder="请填写数量(个)" class="layui-input"
value="{{$account['amount'] or ''}}">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>品牌 : </label>
<div class="layui-input-block">
<input type="text" name="brand_name" id="brand_name"
placeholder="请填写品牌" class="layui-input"
value="{{$account['brand_name'] or ''}}">
</div>
</div>
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>型号 : </label>
<div class="layui-input-block">
<input type="text" name="sku_name" id="sku_name"
placeholder="请输入登录账号" class="layui-input"
value="{{$account['sku_name'] or ''}}">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>检测数量 : </label>
<div class="layui-input-block">
<input type="text" name="examine_amount" id="examine_amount"
placeholder="请填写检测数量(个)" class="layui-input"
value="{{$account['examine_amount'] or ''}}">
</div>
</div>
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>不良数 : </label>
<div class="layui-input-block">
<input type="text" name="unhealthy_amount" id="unhealthy_amount"
placeholder="请填写不良数(个)" class="layui-input"
value="{{$account['unhealthy_amount'] or ''}}">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>不良现象 : </label>
<div class="layui-input-block">
<input type="text" name="unhealthy_content" id="unhealthy_content"
placeholder="请填写不良现象" class="layui-input"
value="{{$account['unhealthy_content'] or ''}}">
</div>
</div>
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>检验结果 : </label>
<div class="layui-input-block">
<input type="text" name="examine_result" id="examine_result"
placeholder="请填写检验结果" class="layui-input"
value="{{$account['examine_result'] or ''}}">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-col-md6">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('abnormal_level','异常等级 : ','',
[1=>1,2=>2,3=>3],['required'=>true]) !!}
</div>
<div class="layui-col-md6">
<label class="layui-form-label"><span class="require">*</span>处理方式 : </label>
<div class="layui-input-block">
<input type="text" name="handle_way" id="handle_way"
placeholder="请填写处理方式" class="layui-input"
value="{{$account['handle_way'] or ''}}">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">备注说明 : </label>
<div class="layui-input-block">
<input type="text" name="remark" id="remark"
placeholder="备注说明" class="layui-input"
value="{{$account['remark'] or ''}}">
</div>
</div>
<div class="layui-form-item">
<div align="center" style="margin-top: 20px;text-align: right">
<button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
lay-filter="addSupplierExamination">确认
</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit
lay-filter="cancel">取消
</button>
</div>
</div>
</form>
</div>
</div>
......@@ -12,29 +12,16 @@
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">供应商编码</label>
<div class="layui-input-inline">
<input type="text" value="" name="supplier_code" placeholder="支持模糊匹配" autocomplete="off"
class="layui-input">
</div>
</div>
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('a_status','账号状态',request()->get('status'),[0=>'禁用',1=>'启用']) !!}
{!! $statusPresenter->render('purchase_name','采购员',request()->get('status'),$purchaseUserNames) !!}
</div>
</div>
<div class="layui-row">
<div class="layui-inline">
<label class="layui-form-label">账号</label>
<div class="layui-input-inline">
<input type="text" value="" name="mobile" placeholder="支持模糊匹配" autocomplete="off"
class="layui-input">
</div>
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('abnormal_level','异常等级',request()->get('abnormal_level'),[1=>1,2=>2,3=>3]) !!}
</div>
<div class="layui-inline" style="width: 600px">
@inject('transformableTimeIntervalPresenter','App\Presenters\Filter\TransformableTimeIntervalPresenter')
{!! $transformableTimeIntervalPresenter->render(['create_time'=>'创建时间','update_time'=>'更新时间']) !!}
{!! $transformableTimeIntervalPresenter->render(['examine_time'=>'检货时间']) !!}
</div>
</div>
<div class="layui-row" style="margin-top:10px;margin-bottom: 10px;margin-left: 20px;">
......@@ -48,9 +35,12 @@
</div>
<div style="margin-left: 20px;margin-right: 20px">
<div class="layui-btn-group demoTable" style="margin-top: 15px">
<button type="button" class="layui-btn layui-btn-sm" id="add_supplier_examination">新增账号</button>
<button type="button" class="layui-btn layui-btn-sm" id="update_supplier_examination">修改</button>
<button type="button" class="layui-btn layui-btn-sm" id="delete_supplier_examination">启用</button>
<button type="button" class="layui-btn layui-btn-sm" id="add_supplier_examination">新增</button>
<button type="button" class="layui-btn layui-btn-sm" id="update_supplier_examination">编辑</button>
<button type="button" class="layui-btn layui-btn-sm" id="import_supplier_examination">导入</button>
<a href="/data/import_supplier_examination_template.xlsx" target="_blank" class="layui-btn layui-btn-sm"
id="download_supplier_examination_import_template">下载模板</a>
<button type="button" class="layui-btn layui-btn-sm" id="delete_supplier_examination">删除</button>
</div>
<table class="layui-table" id="supplierExaminationList" lay-filter="supplierExaminationList"></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