WorkOrderProcessLogService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Services;
  3. use App\Traits\ServiceAppAop;
  4. use App\WorkOrderProcessLog;
  5. use Illuminate\Support\Facades\Auth;
  6. class WorkOrderProcessLogService
  7. {
  8. use ServiceAppAop;
  9. protected $modelClass = WorkOrderProcessLog::class;
  10. public function hasLogisticProcessLog($workOrderId): bool
  11. {
  12. return WorkOrderProcessLog::query()
  13. ->where('work_order_id', $workOrderId)
  14. ->where('type', '2')->exists();
  15. }
  16. public function hasBaoShiProcessLog($workOrderId): bool
  17. {
  18. return WorkOrderProcessLog::query()
  19. ->where('work_order_id', $workOrderId)
  20. ->where('type', '1')->exists();
  21. }
  22. public function createLogisticProcessLog($params)
  23. {
  24. // 赔偿方 是否赔偿
  25. if ($params['is_indemnity'] == 1) { // 赔偿
  26. $params = [
  27. 'work_order_id' => $params['work_order_id'],
  28. 'is_indemnity' => $params['is_indemnity'],
  29. 'indemnity' => $params['indemnity'],
  30. 'indemnitor' => 1,
  31. 'remark' => $params['remark'],
  32. 'type' => 2,
  33. ];
  34. } else if ($params['is_indemnity'] == 2){ // 不赔偿
  35. $params = [
  36. 'work_order_id' => $params['work_order_id'],
  37. 'is_indemnity' => $params['is_indemnity'],
  38. 'remark' => $params['remark'],
  39. 'indemnitor' => 0,
  40. ];
  41. }
  42. $params['creator_id'] = Auth::user()['id'];
  43. $params['type'] = '2';
  44. $log = WorkOrderProcessLog::query()->create($params);
  45. $log->workOrder()->update(['work_order_status' => '3']);
  46. $this->syncOrderIssueIndemnity($log);
  47. $log->loadMissing('creator');
  48. return $log;
  49. }
  50. public function createBaoShiProcessLog($params)
  51. {
  52. if ($params['is_indemnity'] == 1){ // 赔偿
  53. $params = [
  54. 'work_order_id' => $params['work_order_id'],
  55. 'is_indemnity' => $params['is_indemnity'],
  56. 'indemnitor' => $params['indemnitor'],
  57. 'indemnity' => $params['indemnity'],
  58. ];
  59. } else if ($params['is_indemnity'] == 2){ // 不赔偿
  60. $params = [
  61. 'work_order_id' => $params['work_order_id'],
  62. 'is_indemnity' => $params['is_indemnity'],
  63. 'remark' => $params['remark'],
  64. 'indemnity' => $params['indemnity'],
  65. ];
  66. }
  67. $params['creator_id'] = Auth::user()['id'];
  68. $params['type'] = 1;
  69. if ($params['is_indemnity'] == 2) $params['indemnity'] = 0;
  70. $log = WorkOrderProcessLog::query()->create($params);
  71. $this->syncOrderIssueIndemnity($log);
  72. $log->loadMissing('creator');
  73. return $log;
  74. }
  75. public function syncOrderIssueIndemnity($log)
  76. {
  77. if ($log->is_indemnity == '否') return;
  78. $orderIssue = $log->workOrder->orderIssue;
  79. if ($log->isBaoShiLog()) {
  80. if ($log->indemnitor == '宝时'){
  81. if ($orderIssue->baoshi_indemnity_money) return ;
  82. $orderIssue->update(['baoshi_indemnity_money'=>$log->indemnity]);
  83. } else if ($log->indemnitor == '承运商'){
  84. if ($orderIssue->logistic_indemnity_money) return ;
  85. $orderIssue->update(['logistic_indemnity_money'=>$log->indemnity]);
  86. }
  87. } else if ($log->isLogisticLog()){
  88. if ($orderIssue->logistic_indemnity_money) return ;
  89. $orderIssue->update(['logistic_indemnity_money'=>$log->indemnity]);
  90. }
  91. }
  92. }