Notification.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace App\Models;
  3. class Notification extends BaseModel
  4. {
  5. public static function send(Order $order)
  6. {
  7. if($order['is_draft'] == 1) return false;
  8. $checked_id = Option::get('orders', 'status', 'checked');
  9. $reject_id = Option::get('orders', 'status', 'reject');
  10. $pass_id = Option::get('orders', 'status', 'pass');
  11. $back_id = Option::get('orders', 'status', 'back');
  12. $last_role = ProjectRole::find($order['last_project_role_id']);
  13. $role = ProjectRole::find($order['project_role_id']);
  14. $status = 1;
  15. $user_ids = [];
  16. if($role) {
  17. $user_ids = ProjectUser::where([
  18. ['project_id', $order['project_id']],
  19. ['project_role_id', $role['id']]
  20. ])->pluck('user_id');
  21. }
  22. // 外部租赁
  23. if($order['type'] == 1) {
  24. // 审批成功
  25. if($order['status'] == $checked_id && $role && $last_role && $last_role['key'] == 'manager') {
  26. $status = 1;
  27. } else if($role && in_array($role['key'], ['machine', 'assist', 'manager'])) {
  28. // 审批待处理
  29. $status = 2;
  30. } else if($order['status'] == $reject_id) {
  31. // 审批被驳回
  32. $status = 3;
  33. } else if($order['status'] == $pass_id) {
  34. // 租赁时间到期 status = 4
  35. // 租赁已完成
  36. $status = 5;
  37. }
  38. } else {
  39. // 调用
  40. // 调用成功
  41. if($order['status'] == $checked_id && $role && $last_role && $last_role['key'] == 'admin') {
  42. $status = $order['is_change'] == 1 ? 7 : 1;
  43. } else if($role && in_array($role['key'], ['assist', 'manager', 'admin'])) {
  44. // 调用待处理
  45. $status = 2;
  46. } else if($order['status'] == $reject_id) {
  47. // 调用被驳回
  48. $status = 3;
  49. } else if($order['status'] == $pass_id) {
  50. // 调用时间到期 status = 4
  51. // 调用已完成
  52. $status = 5;
  53. } else if($order['status'] == $back_id) {
  54. // 调用已归还
  55. $status = 6;
  56. }
  57. }
  58. foreach($user_ids as $user_id) {
  59. Notification::create([
  60. 'user_id' => $user_id,
  61. 'order_id' => $order['id'],
  62. 'status' => $status,
  63. 'type' => $order['type'],
  64. 'is_read' => 2
  65. ]);
  66. }
  67. return true;
  68. }
  69. public function getNameContent()
  70. {
  71. if($this['type'] == 1) {
  72. if($this['status'] == 1) {
  73. return [
  74. 'name' => '设备租赁申请通过',
  75. 'content' => '你的设备租赁申请已通过,请确认相关信息:'
  76. ];
  77. } else if($this['status'] == 2) {
  78. return [
  79. 'name' => '设备租赁审批待处理',
  80. 'content' => '你有一条设备租赁申请待审批,请确认相关信息:'
  81. ];
  82. } else if($this['status'] == 3) {
  83. return [
  84. 'name' => '设备租赁审批被驳回',
  85. 'content' => '你有一条设备租赁申请被驳回,请确认相关信息:'
  86. ];
  87. } else if($this['status'] == 4) {
  88. return [
  89. 'name' => '设备租赁已到期',
  90. 'content' => '你有一条设备租赁已到期消息,请确认相关信息:'
  91. ];
  92. } else if($this['status'] == 5) {
  93. return [
  94. 'name' => '设备租赁已完成',
  95. 'content' => '你有一条设备租赁已完成消息,请确认相关信息:'
  96. ];
  97. }
  98. } else {
  99. if($this['status'] == 1) {
  100. return [
  101. 'name' => '设备调用申请通过',
  102. 'content' => '你的设备调用申请已通过,请确认相关信息:'
  103. ];
  104. } else if($this['status'] == 2) {
  105. return [
  106. 'name' => '设备调用审批待处理',
  107. 'content' => '你有一条设备调用申请待审批,请确认相关信息:'
  108. ];
  109. } else if($this['status'] == 3) {
  110. return [
  111. 'name' => '设备租赁调用被驳回',
  112. 'content' => '你有一条设备调用申请被驳回,请确认相关信息:'
  113. ];
  114. } else if($this['status'] == 4) {
  115. return [
  116. 'name' => '设备调用已到期',
  117. 'content' => '你有一条设备调用已到期消息,请确认相关信息:'
  118. ];
  119. } else if($this['status'] == 5) {
  120. return [
  121. 'name' => '设备调用已完成',
  122. 'content' => '你有一条设备调用已完成消息,请确认相关信息:'
  123. ];
  124. } else if($this['status'] == 6) {
  125. return [
  126. 'name' => '设备调用已归还',
  127. 'content' => '你有一条设备调用已归还消息,请确认相关信息:'
  128. ];
  129. } else if($this['status'] == 7) {
  130. return [
  131. 'name' => '设备调用被修改',
  132. 'content' => '你有一条设备调用被修改消息,请确认相关信息:'
  133. ];
  134. }
  135. }
  136. return ['name' => '', 'content' => ''];
  137. }
  138. }