Commit aef138ec by mushishixian

日志

parent c058592b
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Services\SupplierContactService;
use App\Http\Transformers\SupplierContactTransformer;
use App\Http\Validators\SupplierContactValidator;
......
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Transformers\LogTransformer;
use App\Http\Transformers\ReceiptTransformer;
use App\Http\Validators\ReceiptValidator;
......@@ -24,12 +25,12 @@ class SupplierReceiptApiController extends Controller
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new SupplierReceiptModel();
$model->where('supplier_id',$supplierId)->paginate();
$model->where('supplier_id', $supplierId)->paginate();
$list = $model->where('supplier_id', $supplierId)->orderBy('receipt_id', 'desc')
->paginate($limit)->toArray();
$transformer = new ReceiptTransformer();
$list['data'] = $transformer->transformList($list['data']);
$this->response(0, 'ok', $list['data'],$list['total']);
$this->response(0, 'ok', $list['data'], $list['total']);
}
//获取供应商信息变更记录
......@@ -65,6 +66,10 @@ class SupplierReceiptApiController extends Controller
$result = $model->insert($receipt);
}
if ($result) {
$logService = new LogService();
$content = !empty($receipt['receipt_id']) ? '修改银行信息' : '添加银行信息';
$remark = json_encode($receipt);
$logService->AddLog($receipt['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
......
......@@ -4,6 +4,7 @@
namespace App\Http\Services;
use App\Model\LogModel;
use App\Model\SupplierContactModel;
class SupplierContactService
......@@ -43,11 +44,16 @@ class SupplierContactService
//判断新增还是编辑
if (!empty($contact['contact_id'])) {
$contact['update_time'] = time();
return $model->where('contact_id', $contact['contact_id'])->update($contact);
$result = $model->where('contact_id', $contact['contact_id'])->update($contact);
} else {
$contact['add_time'] = time();
return $model->insert($contact);
$result = $model->insert($contact);
}
$logService = new LogService();
$content = !empty($contact['contact_id'])?'修改联系人':'添加联系人';
$remark = json_encode($contact);
$logService->AddLog($contact['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
return $result;
}
//批量保存联系方式,要区分新增还是修改还是删除
......@@ -57,8 +63,8 @@ class SupplierContactService
$model = new SupplierContactModel();
$originContactIds = $model->where('supplier_id', $supplierId)->pluck('contact_id')->toArray();
$newContactIds = array_column($contacts, 'contact_id');
$needDeleteContactIds = array_diff_assoc($originContactIds,$newContactIds);
$model->whereIn('contact_id',$needDeleteContactIds)->delete();
$needDeleteContactIds = array_diff_assoc($originContactIds, $newContactIds);
$model->whereIn('contact_id', $needDeleteContactIds)->delete();
foreach ($contacts as $key => $contact) {
//新增
if (empty($contact['contact_id'])) {
......
......@@ -92,17 +92,22 @@ class SupplierService
$this->saveSupplierCode($supplierId);
$logAction = "新增供应商";
$logContent = '新增供应商';
$logRemark = '';
$newSupplier = $model->where('supplier_id', $supplierId)->first();
$logRemark = json_encode($newSupplier);
} else {
$extraFaxService = new SupplierExtraFeeService();
$extraFaxService->saveSupplierExtraFee($extraFax);
$supplierId = $channel['supplier_id'];
$supplierData = $model->where('supplier_id', $supplierId)->first();
$oldSupplier = $model->where('supplier_id', $supplierId)->first();
$model->where('supplier_id', $supplierId)->update($channel);
$newSupplier = $model->where('supplier_id', $supplierId)->first();
$this->saveSupplierCode($supplierId);
$logAction = "更新供应商";
$logContent = "更新供应商";
$logRemark = json_encode($supplierData);
$logRemark = json_encode([
'old' => $oldSupplier,
'new' => $newSupplier
]);
}
//插入系数到redis
$this->saveRatioToRedis($supplierId);
......@@ -110,7 +115,8 @@ class SupplierService
$supplierSn = $this->generateSupplierSn($supplierId, $channel['supplier_group']);
//保存日志
$logService = new LogService();
$logService->AddLog($supplierId, 1, $logAction, $logContent, $logRemark);
$logType = !empty($channel['supplier_id']) ? LogModel::UPDATE_OPERATE : LogModel::ADD_OPERATE;
$logService->AddLog($supplierId, $logType, $logAction, $logContent, $logRemark);
//修改数据
$model->where('supplier_id', $supplierId)->update(['supplier_sn' => $supplierSn]);
// $messageService = new MessageService();
......@@ -232,7 +238,7 @@ class SupplierService
$purchaseUserName = array_get($purchaseUser, 'name', '');
$logService = new LogService();
$content = "将渠道开发员由 [${prePurchaseUserName}] 改为 [${purchaseUserName}]";
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '分配渠道开发员',$content);
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '分配渠道开发员', $content);
}
return $result;
......
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