WorkOrderProcessLogService.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. 'indemnitor' => 1,
  30. 'remark' => $params['remark'],
  31. 'type' => 2,
  32. ];
  33. } else if ($params['is_indemnity'] == 2){ // 不赔偿
  34. $params = [
  35. 'work_order_id' => $params['work_order_id'],
  36. 'is_indemnity' => $params['is_indemnity'],
  37. 'remark' => $params['remark'],
  38. 'indemnitor' => 0,
  39. ];
  40. }
  41. $params['creator_id'] = Auth::user()['id'];
  42. $params['type'] = '2';
  43. $log = WorkOrderProcessLog::query()->create($params);
  44. $log->workOrder()->update(['work_order_status' => '3']);
  45. $log->loadMissing('creator');
  46. return $log;
  47. }
  48. public function createBaoShiProcessLog($params)
  49. {
  50. if ($params['is_indemnity'] == 1){ // 赔偿
  51. $params = [
  52. 'work_order_id' => $params['work_order_id'],
  53. 'is_indemnity' => $params['is_indemnity'],
  54. 'indemnitor' => $params['indemnitor'],
  55. 'indemnity' => $params['indemnity'],
  56. ];
  57. } else if ($params['is_indemnity'] == 2){ // 不赔偿
  58. $params = [
  59. 'work_order_id' => $params['work_order_id'],
  60. 'is_indemnity' => $params['is_indemnity'],
  61. 'remark' => $params['remark'],
  62. 'indemnity' => $params['indemnity'],
  63. ];
  64. }
  65. $params['creator_id'] = Auth::user()['id'];
  66. $params['type'] = 1;
  67. if ($params['is_indemnity'] == 2) $params['indemnity'] = 0;
  68. $log = WorkOrderProcessLog::query()->create($params);
  69. $log->loadMissing('creator');
  70. return $log;
  71. }
  72. }