Commit 7c39b3a1 by mushishixian

共用审核

parent 6b7855a7
...@@ -3,12 +3,8 @@ ...@@ -3,12 +3,8 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Services\AdminUserService;
use App\Http\Services\SupplierShareApplyService; use App\Http\Services\SupplierShareApplyService;
use App\Http\Transformers\LogTransformer;
use App\Model\LogModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierShareApplyModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
//供应商共享申请 //供应商共享申请
...@@ -57,7 +53,7 @@ class SupplierShareApplyApiController extends Controller ...@@ -57,7 +53,7 @@ class SupplierShareApplyApiController extends Controller
if (empty($map['department_id']) || empty($map['supplier_id'])) { if (empty($map['department_id']) || empty($map['supplier_id'])) {
$this->response(-1, '缺少参数'); $this->response(-1, '缺少参数');
} }
$map['apply_user_id'] = $request->user->userId; $map['apply_code_id'] = $request->user->codeId;
$applyService = new SupplierShareApplyService(); $applyService = new SupplierShareApplyService();
$hasNoFinish = $applyService->checkHasNoFinishApply($map); $hasNoFinish = $applyService->checkHasNoFinishApply($map);
if ($hasNoFinish) { if ($hasNoFinish) {
...@@ -70,4 +66,29 @@ class SupplierShareApplyApiController extends Controller ...@@ -70,4 +66,29 @@ class SupplierShareApplyApiController extends Controller
return $this->response(0, '申请成功'); return $this->response(0, '申请成功');
} }
//获取共用审核列表
//1.审核分初审和复审
//2.有审核权限都可以看到这个列表
public function GetAuditSupplierShareApplyList($request)
{
$applyService = new SupplierShareApplyService();
$userId = $request->user->userId;
$list = $applyService->getAuditSupplierShareApplyList($userId);
$this->response(0, 'ok', $list['data'], $list['total']);
}
//审核
public function AuditSupplierShareApply($request)
{
$statusName = $request->get('status');
$applyService = new SupplierShareApplyService();
$userId = $request->user->userId;
$id = $request->get('id');
$result = $applyService->auditSupplierShareApply($id, $userId, $statusName);
if (!$result) {
$this->response(-1, '审核操作失败');
}
return $this->response(0, '审核操作成功');
}
} }
...@@ -41,4 +41,10 @@ class SupplierShareApplyController extends Controller ...@@ -41,4 +41,10 @@ class SupplierShareApplyController extends Controller
return $this->view('申请供应商共享'); return $this->view('申请供应商共享');
} }
//审核共用申请(列表)
public function AuditSupplierShareApply()
{
return $this->view('审核供应商共享');
}
} }
...@@ -67,5 +67,4 @@ class AdminUserService ...@@ -67,5 +67,4 @@ class AdminUserService
$users = $intracodeModel->getEncodeByUserIds($userIds); $users = $intracodeModel->getEncodeByUserIds($userIds);
return $users; return $users;
} }
} }
\ No newline at end of file
...@@ -79,4 +79,17 @@ class DepartmentService ...@@ -79,4 +79,17 @@ class DepartmentService
} }
return []; return [];
} }
public function getDepartmentByUserId($userId)
{
$userModel = new UserInfoModel();
$departmentId = $userModel->where('userId', $userId)->value('department_id');
if (empty($departmentId)) {
return [];
}
//去department表找到顶级id,也可能本身就是顶级id
$departmentModel = new DepartmentModel();
$department = $departmentModel->where('department_id', $departmentId)->first();
return !empty($department) ? $department->toArray() : [];
}
} }
\ No newline at end of file
...@@ -63,7 +63,7 @@ class SupplierContactService ...@@ -63,7 +63,7 @@ class SupplierContactService
$contact['update_time'] = time(); $contact['update_time'] = time();
$contact['admin_id'] = request()->user->userId; $contact['admin_id'] = request()->user->userId;
$result = $model->where('contact_id', $contactId)->update($contact); $result = $model->where('contact_id', $contactId)->update($contact);
}else{ } else {
$oldContact = []; $oldContact = [];
$contact['add_time'] = time(); $contact['add_time'] = time();
$contact['admin_id'] = request()->user->userId; $contact['admin_id'] = request()->user->userId;
...@@ -151,15 +151,31 @@ class SupplierContactService ...@@ -151,15 +151,31 @@ class SupplierContactService
$userId = request()->user->userId; $userId = request()->user->userId;
$codeId = request()->user->codeId; $codeId = request()->user->codeId;
$contactModel = new SupplierContactModel(); $contactModel = new SupplierContactModel();
$contact = $contactModel->where('can_check_uids',$codeId)->where('supplier_id',$supplierId) $contact = $contactModel->where('can_check_uids', $codeId)->where('supplier_id', $supplierId)
->first(); ->first();
$contact = !empty($contact) ? $contact->toArray() : []; $contact = !empty($contact) ? $contact->toArray() : [];
if (empty($contact)) { if (empty($contact)) {
$contact = $contactModel->where('admin_id',$userId)->where('supplier_id',$supplierId) $contact = $contactModel->where('admin_id', $userId)->where('supplier_id', $supplierId)
->first(); ->first();
$contact = !empty($contact) ? $contact->toArray() : []; $contact = !empty($contact) ? $contact->toArray() : [];
} }
return $contact; return $contact;
} }
//通过采购员编码直接创建空白的默认联系方式
public function createContactByChannelUid($supplierId, $channelUid)
{
//先去判断是否已经有对应的采购
$contactModel = new SupplierContactModel();
$count = $contactModel->where('supplier_id', $supplierId)->where('can_check_uids', $channelUid)->count();
if ($count) {
return true;
}
$contact['can_check_uids'] = $channelUid;
$contact['supplier_id'] = $supplierId;
$contact['add_time'] = time();
$contact['admin_id'] = request()->user->userId;
return $contactModel->insert($contact);
}
} }
\ No newline at end of file
...@@ -5,15 +5,9 @@ namespace App\Http\Services; ...@@ -5,15 +5,9 @@ namespace App\Http\Services;
//后台用户相关信息服务 //后台用户相关信息服务
use App\Http\Transformers\LogTransformer;
use App\Http\Transformers\SupplierShareApplyTransformer; use App\Http\Transformers\SupplierShareApplyTransformer;
use App\Model\DepartmentModel; use App\Model\DepartmentModel;
use App\Model\LogModel;
use App\Model\RedisModel;
use App\Model\RegionModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierShareApplyModel; use App\Model\SupplierShareApplyModel;
use Illuminate\Support\Facades\DB;
//用于判断是否已经查看的服务 //用于判断是否已经查看的服务
class SupplierShareApplyService class SupplierShareApplyService
...@@ -33,9 +27,13 @@ class SupplierShareApplyService ...@@ -33,9 +27,13 @@ class SupplierShareApplyService
{ {
$applyModel = new SupplierShareApplyModel(); $applyModel = new SupplierShareApplyModel();
$limit = request()->get('limit', 10); $limit = request()->get('limit', 10);
$query = $applyModel::with(['supplier'=>function ($q) { $query = $applyModel::with([
$q->select(['supplier_name','supplier_id']); 'supplier' => function ($q) {
}])->where('create_uid', $userId)->orderBy('id', 'desc'); $q->select(['supplier_name', 'supplier_id']);
},
'department',
'apply_department'
])->where('create_uid', $userId)->orderBy('id', 'desc');
$list = $query->paginate($limit)->toArray(); $list = $query->paginate($limit)->toArray();
$transformer = new SupplierShareApplyTransformer(); $transformer = new SupplierShareApplyTransformer();
$list['data'] = $transformer->transformList($list['data']); $list['data'] = $transformer->transformList($list['data']);
...@@ -77,13 +75,10 @@ class SupplierShareApplyService ...@@ -77,13 +75,10 @@ class SupplierShareApplyService
//保存申请 //保存申请
public function saveSupplierShareApply($map) public function saveSupplierShareApply($map)
{ {
$departmentModel = new DepartmentModel();
$departmentName = $departmentModel->where('department_id', $map['department_id'])->value('department_name');
$data = $map; $data = $map;
$data['department_name'] = $departmentName;
$data['status'] = 0; $data['status'] = 0;
$data['create_time'] = time(); $data['create_time'] = time();
$data['create_uid'] = $map['apply_user_id']; $data['create_uid'] = $map['apply_code_id'];
$applyModel = new SupplierShareApplyModel(); $applyModel = new SupplierShareApplyModel();
return $applyModel->insert($data); return $applyModel->insert($data);
} }
...@@ -92,9 +87,64 @@ class SupplierShareApplyService ...@@ -92,9 +87,64 @@ class SupplierShareApplyService
public function checkHasNoFinishApply($map) public function checkHasNoFinishApply($map)
{ {
$applyModel = new SupplierShareApplyModel(); $applyModel = new SupplierShareApplyModel();
$count=$applyModel->where('supplier_id', $map['supplier_id']) $count = $applyModel->where('supplier_id', $map['supplier_id'])
->where('apply_user_id', $map['apply_user_id'])->where('department_id', $map['department_id']) ->where('apply_code_id', $map['apply_code_id'])->where('department_id', $map['department_id'])
->whereNotIn('status', [$this::STATUS_AUDIT_REJECT, $this::STATUS_REVIEW_REJECT])->count(); ->whereNotIn('status', [$this::STATUS_AUDIT_REJECT, $this::STATUS_REVIEW_REJECT])->count();
return $count; return $count;
} }
public function getAuditSupplierShareApplyList($userId)
{
//1.先获取自己的部门ID
$departmentService = new DepartmentService();
$topDepartment = $departmentService->getTopDepartmentByUserId($userId);
$departmentId = $topDepartment['department_id'];
$applyModel = new SupplierShareApplyModel();
$query = $applyModel::with([
'supplier' => function ($q) {
$q->select(['supplier_name', 'supplier_id']);
},
'department',
'apply_department',
'apply_user'
])->where(function ($q) use ($departmentId) {
//当要判断申请者所在部门的时候,要审核人为空,因为审核这一步是所在部门的人审核的
$q->where('department_id', $departmentId)->where('audit_uid', 0);
})->orWhere(function ($q) use ($departmentId) {
//当要判断申请者申请的部门的时候,要复审人为空,因为复审这一步是被申请部门的人审核的
$q->where('apply_department_id', $departmentId)->where('review_uid', 0)->where('audit_uid', '!=', 0);
})->orderBy('id', 'desc');
$limit = request()->get('limit', 10);
$list = $query->paginate($limit)->toArray();
$transformer = new SupplierShareApplyTransformer();
$list['data'] = $transformer->transformList($list['data']);
return $list;
}
//审核供应商共用申请
public function auditSupplierShareApply($id, $userId, $statusName)
{
//先找出这个审核id对应的审核状态
//如果是初审(审核),就要处理初审,通过的话进入复审,而不是直接通过
$applyModel = new SupplierShareApplyModel();
$apply = $applyModel->where('id', $id)->first()->toArray();
//初审
if ($apply['status'] == self::STATUS_PENDING) {
$apply['status'] = $statusName == 'pass' ? self::STATUS_NEED_REVIEW : self::STATUS_AUDIT_REJECT;
$apply['audit_uid'] = $userId;
$apply['audit_time'] = time();
} else {
//复审
$apply['status'] = $statusName == 'pass' ? self::STATUS_PASS : self::STATUS_REVIEW_REJECT;
$apply['review_time'] = time();
$apply['review_uid'] = $userId;
//还要去将当前请求人的内部编码写到采购里面去
if ($statusName == 'pass') {
$contactService = new SupplierContactService();
$contactService->createContactByChannelUid($apply['supplier_id'], $apply['apply_code_id']);
}
}
return $applyModel->where('id', $id)->update($apply);
}
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace App\Http\Transformers; namespace App\Http\Transformers;
use App\Http\Services\AdminUserService;
use App\Http\Services\LogService; use App\Http\Services\LogService;
class SupplierShareApplyTransformer class SupplierShareApplyTransformer
......
...@@ -15,4 +15,20 @@ class SupplierShareApplyModel extends Model ...@@ -15,4 +15,20 @@ class SupplierShareApplyModel extends Model
return $this->hasOne(SupplierChannelModel::class, 'supplier_id', 'supplier_id'); return $this->hasOne(SupplierChannelModel::class, 'supplier_id', 'supplier_id');
} }
public function department()
{
return $this->hasOne(DepartmentModel::class, 'department_id', 'department_id');
}
//申请的部门信息
public function apply_department()
{
return $this->hasOne(DepartmentModel::class, 'department_id', 'apply_department_id');
}
public function apply_user()
{
return $this->hasOne(UserInfoModel::class, 'userId', 'apply_code_id');
}
} }
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
} }
}, },
{ {
field: 'department_name', title: '被申请部门', width: 150, align: 'center' field: 'department_name', title: '被申请部门', width: 150, align: 'center',templet: function (d) {
return d.apply_department ? d.apply_department.department_name : '';
}
}, },
{field: 'create_time', title: '申请时间', width: 150, align: 'center'}, {field: 'create_time', title: '申请时间', width: 150, align: 'center'},
{field: 'status_name', title: '状态', width: 150, align: 'center'}, {field: 'status_name', title: '状态', width: 150, align: 'center'},
......
<script>
layui.use(['table', 'form', 'element', 'table', 'layer', 'admin'], function () {
let table = layui.table
table.render({
elem: '#auditList'
, url: '/api/supplier_share_apply/GetAuditSupplierShareApplyList'
, method: 'post'
, size: 'sm'
, limit: 10
, cellMinWidth: 80 //全局定义常规单元格的最小宽度
, where: {}
, loading: true
, first: true //不显示首页
, last: false //不显示尾页
, cols: [[
{
field: 'supplier_name', title: '供应商名称', align: 'center', templet: function (d) {
return d.supplier ? d.supplier.supplier_name : '';
}
},
{
field: 'apply_department_name', title: '被申请部门', width: 150, align: 'center', templet: function (d) {
return d.apply_department ? d.apply_department.department_name : '';
}
},
{
field: 'apply_user_name', title: '申请人', width: 150, align: 'center', templet: function (d) {
return d.apply_user ? d.apply_user.name : '';
}
},
{
field: 'department_name', title: '被申请部门', width: 150, align: 'center', templet: function (d) {
return d.department ? d.department.department_name : '';
}
},
{field: 'create_time', title: '申请时间', width: 150, align: 'center'},
{field: 'status_name', title: '状态', width: 150, align: 'center'},
{field: 'operate', title: '操作', templet: '#operate', align: 'center'},
]]
, id: 'auditList'
, page: {}
});
$(document).on('click', '.audit_supplier_share_apply', function () {
let status = $(this).attr('status');
let id = $(this).val();
let statusName = status === 'pass' ? '通过' : '拒绝';
layer.confirm('确定要' + statusName + '该申请吗?', function () {
let url = '/api/supplier_share_apply/AuditSupplierShareApply';
let result = ajax(url, {
status: status,
id: id,
});
if (result.err_code === 0) {
layer.msg('审核成功', {icon: 6})
table.reload('auditList');
} else {
layer.msg(result.err_msg, {icon: 5})
}
});
});
});
</script>
\ No newline at end of file
...@@ -527,6 +527,17 @@ ...@@ -527,6 +527,17 @@
} }
}); });
}); });
//共用供应商审核
$("#audit_supplier_share_apply").click(function () {
layer.open({
type: 2,
content: '/supplier_share_apply/AuditSupplierShareApply?view=iframe',
area: ['70%', '80%'],
title: '共用申请审核',
end: function () {
}
});
});
//点击查询按钮 //点击查询按钮
form.on('submit(load)', function (data) { form.on('submit(load)', function (data) {
......
<blockquote class="layui-elem-quote layui-text">
<b>审核列表 : </b> (只要申请部门或者被申请部门和你是同一个部门的,具有审核权限的你都可以看到申请)
</blockquote>
<table class="layui-table" id="auditList" lay-filter="auditList"></table>
<script type="text/html" id="operate">
<div>
<button type="button" value="@{{ d.id}}" status="pass" class="layui-btn layui-btn-xs audit_supplier_share_apply">同意
</button>
<button type="button" value="@{{ d.id}}" status="reject" class="layui-btn layui-btn-xs layui-btn-danger audit_supplier_share_apply">拒绝
</button>
</div>
</script>
\ No newline at end of file
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</button> </button>
@endif @endif
@if(checkPerm('AuditSupplierShare')) @if(checkPerm('AuditSupplierShare'))
<button type="button" class="layui-btn layui-btn-sm" id="audit_supplier_share"> <button type="button" class="layui-btn layui-btn-sm" id="audit_supplier_share_apply">
共用审核 共用审核
</button> </button>
@endif @endif
......
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