Commit 734dceb1 by 杨树贤

新增逻辑文件

parent 15d5ee35
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Services\PurchaseRemarkService;
use App\Http\Services\SupplierAuditService;
use App\Http\Transformers\PurchaseRemarkTransformer;
use App\Http\Validators\PurchaseRemarkValidator;
use App\Model\LogModel;
use App\Model\PurchaseRemarksModel;
use App\Model\SupplierChannelModel;
use Illuminate\Http\Request;
class PurchaseRemarkApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
//获取供应商收款信息
public function GetPurchaseRemarkList($request)
{
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new PurchaseRemarksModel();
$model->where('supplier_id', $supplierId)->paginate();
$list = $model->where('supplier_id', $supplierId)->orderBy('attachment_id', 'desc')
->paginate($limit)->toArray();
$transformer = new PurchaseRemarkTransformer();
$list['data'] = $transformer->transformList($list['data']);
$this->response(0, 'ok', $list['data'], $list['total']);
}
//保存附件信息
public function SavePurchaseRemark($request)
{
//先去表单验证
$validator = new PurchaseRemarkValidator();
$validateResult = $validator->checkSave($request);
if ($validateResult) {
$this->response(-1, $validateResult);
}
$attachment = $request->only([
'field_name',
'validity_type',
'validity_period',
'description',
'file_name',
'file_url',
'supplier_id',
'attachment_id',
]);
$attachmentService = new PurchaseRemarkService();
$supplierId = $attachmentService->saveAttachment($attachment);
if (!$supplierId) {
$this->response(-1, '操作失败');
} else {
$canIgnoreAudit = (new SupplierAuditService())->checkCanIgnoreSupplierAudit($supplierId);
if (!$canIgnoreAudit) {
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'update_time' => time(),
'status' => SupplierChannelModel::STATUS_PENDING,
]);
}
$logService = new LogService();
$content = !empty($attachment['attachment_id']) ? '修改附件信息' : '添加附件信息';
$remark = json_encode($attachment);
$logService->AddLog($attachment['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
$this->response(0, '保存成功');
}
}
//判断是否要进入审核中状态,因为部分字段修改是不需要走审核的
private function checkNeedAudit($oldAttachment, $newAttachment)
{
$notNeedAuditField = [
'remark',
];
$diff = array_diff($oldAttachment, $newAttachment);
unset($diff['update_time']);
$changeField = array_keys($diff);
foreach ($changeField as $filed) {
//只要有一个不存在于不需要审核的字段,就返回需要审核
if (!in_array($filed, $notNeedAuditField)) {
return true;
}
}
return false;
}
//删除
public function DeletePurchaseRemark($request)
{
$attachmentId = $request->get('attachment_id');
$model = new PurchaseRemarksModel();
$attachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
$result = $model->where('attachment_id', $attachmentId)->delete();
if ($result) {
$logService = new LogService();
$content = "删除附件信息 : " . $attachment['type_name'];
$remark = json_encode($attachment);
$logService->AddLog($attachment['supplier_id'], LogModel::UPDATE_OPERATE, '删除附件信息', $content, $remark);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Services\RoleService;
use App\Http\Services\SupplierContactService;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierStatisticsService;
use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel;
use App\Model\PurchaseRemarkModel;
use App\Model\SupplierChannelModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PurchaseRemarkController extends Controller
{
public function info(Request $request, $id = '')
{
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'user_email' => $request->user->email,
'uri' => '/' . $path,
'id' => $id,
];
return $this->$id($request);
}
}
public function __call($name, $arr)
{
$data['errinfo'] = '访问路径错误';
return view('errors.error', $data);
}
//供应商详情
public function AddPurchaseRemark($request)
{
$this->data['title'] = '添加附件';
return $this->view('添加附件');
}
//供应商详情
public function UpdatePurchaseRemark($request)
{
$attachmentId = $request->get('attachment_id');
if (!empty($attachmentId)) {
$model = new PurchaseRemarksModel();
$attachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
$attachment['validity_period'] = $attachment['validity_start'] ? date('Y-m-d',
$attachment['validity_start']) . '~' . date('Y-m-d', $attachment['validity_start']) : '';
$this->data['attachment'] = $attachment;
}
$this->data['title'] = '修改附件';
$this->data['view'] = 'AddPurchaseRemark';
return $this->view('修改附件');
}
}
\ No newline at end of file
<?php
namespace App\Http\Services;
//后台用户相关信息服务
use App\Model\PurchaseRemarkModel;
//用于判断是否已经查看的服务
class PurchaseRemarkService
{
public function getPurchaseRemark($supplierId)
{
$remakeModel = new PurchaseRemarkModel();
return $remakeModel->where('supplier_id', $supplierId)->get()->toArray();
}
public function savePurchaseRemark($remake)
{
if ($remake['validity_period']) {
$validityPeriod = explode('~', $remake['validity_period']);
$remake['validity_start'] = strtotime(trim($validityPeriod[0]));
$remake['validity_end'] = strtotime(trim($validityPeriod[1]));
}
if ($remake['validity_type'] == 1) {
$remake['validity_start'] = $remake['validity_end'] = 0;
}
$remake['type_name'] = array_get(config('fixed.FileNameMapping'), $remake['field_name']);
unset($remake['validity_period']);
$remakeId = $remake['attachment_id'];
if (empty($remake['description'])) {
unset($remake['description']);
}
$remakeModel = new PurchaseRemarkModel();
if (empty($remakeId)) {
$remake['create_uid'] = request()->user->userId;
$remake['create_name'] = request()->user->name;
$remake['create_time'] = time();
return $remakeModel->insertGetId($remake);
} else {
$remake['update_time'] = time();
return $remakeModel->where('attachment_id', $remakeId)->update($remake)?$remake['supplier_id']:0;
}
}
}
\ No newline at end of file
<?php
namespace App\Http\Transformers;
class PurchaseRemarkTransformer
{
public function transformList($list)
{
if (empty($list)) {
return [];
}
foreach ($list as &$remark) {
if (!$remark) {
continue;
}
$remark['create_time'] = $remark['create_time'] ? date('Y-m-d H:i:s',
$remark['create_time']) : '';
$remark['update_time'] = $remark['update_time'] ? date('Y-m-d H:i:s',
$remark['update_time']) : '';
$remark['start_time'] = $remark['update_time'] ? date('Y-m-d',
$remark['end_time']) : ''; $remark['end_time'] = $remark['update_time'] ? date('Y-m-d',
$remark['end_time']) : '';
$remark['duration'] = $remark['start_time'] . ' ~ ' . $remark['end_time'];
}
unset($remark);
return $list;
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class PurchaseRemarkModel extends Model
{
protected $connection='web';
protected $table='purchase_remark';
protected $primaryKey = 'id';
public $timestamps = false;
}
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