| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Services;
- use App\Traits\ServiceAppAop;
- use App\WorkOrderProcessLog;
- use Illuminate\Support\Facades\Auth;
- class WorkOrderProcessLogService
- {
- use ServiceAppAop;
- protected $modelClass = WorkOrderProcessLog::class;
- public function hasLogisticProcessLog($workOrderId): bool
- {
- return WorkOrderProcessLog::query()
- ->where('work_order_id', $workOrderId)
- ->where('type', '2')->exists();
- }
- public function hasBaoShiProcessLog($workOrderId): bool
- {
- return WorkOrderProcessLog::query()
- ->where('work_order_id', $workOrderId)
- ->where('type', '1')->exists();
- }
- public function createLogisticProcessLog($params)
- {
- // 赔偿方 是否赔偿
- if ($params['is_indemnity'] == 1) { // 赔偿
- $params = [
- 'work_order_id' => $params['work_order_id'],
- 'is_indemnity' => $params['is_indemnity'],
- 'indemnity' => $params['indemnity'],
- 'indemnitor' => 1,
- 'remark' => $params['remark'],
- 'type' => 2,
- ];
- } else if ($params['is_indemnity'] == 2){ // 不赔偿
- $params = [
- 'work_order_id' => $params['work_order_id'],
- 'is_indemnity' => $params['is_indemnity'],
- 'remark' => $params['remark'],
- 'indemnitor' => 0,
- ];
- }
- $params['creator_id'] = Auth::user()['id'];
- $params['type'] = '2';
- $log = WorkOrderProcessLog::query()->create($params);
- $log->workOrder()->update(['work_order_status' => '3']);
- $this->syncOrderIssueIndemnity($log);
- $log->loadMissing('creator');
- return $log;
- }
- public function createBaoShiProcessLog($params)
- {
- if ($params['is_indemnity'] == 1){ // 赔偿
- $params = [
- 'work_order_id' => $params['work_order_id'],
- 'is_indemnity' => $params['is_indemnity'],
- 'indemnitor' => $params['indemnitor'],
- 'indemnity' => $params['indemnity'],
- ];
- } else if ($params['is_indemnity'] == 2){ // 不赔偿
- $params = [
- 'work_order_id' => $params['work_order_id'],
- 'is_indemnity' => $params['is_indemnity'],
- 'remark' => $params['remark'],
- 'indemnity' => $params['indemnity'],
- ];
- }
- $params['creator_id'] = Auth::user()['id'];
- $params['type'] = 1;
- if ($params['is_indemnity'] == 2) $params['indemnity'] = 0;
- $log = WorkOrderProcessLog::query()->create($params);
- $this->syncOrderIssueIndemnity($log);
- $log->loadMissing('creator');
- return $log;
- }
- public function syncOrderIssueIndemnity($log)
- {
- if ($log->is_indemnity == '否') return;
- $orderIssue = $log->workOrder->orderIssue;
- if ($log->isBaoShiLog()) {
- if ($log->indemnitor == '宝时'){
- if ($orderIssue->baoshi_indemnity_money) return ;
- $orderIssue->update(['baoshi_indemnity_money'=>$log->indemnity]);
- } else if ($log->indemnitor == '承运商'){
- if ($orderIssue->logistic_indemnity_money) return ;
- $orderIssue->update(['logistic_indemnity_money'=>$log->indemnity]);
- }
- } else if ($log->isLogisticLog()){
- if ($orderIssue->logistic_indemnity_money) return ;
- $orderIssue->update(['logistic_indemnity_money'=>$log->indemnity]);
- }
- }
- }
|