pluck('id'); } else if($order['is_change' == 2]) { $project_role_ids = ProjectRole::whereIn('key', ['machine', 'admin'])->pluck('id'); } else { $project_role_ids = ProjectRole::whereIn('key', ['machine'])->pluck('id'); } } else if($order['status'] == $back_id) { $project_role_ids = ProjectRole::whereIn('key', ['admin'])->pluck('id'); } if(count($project_role_ids) > 0) { $user_ids = ProjectUser::where([ ['project_id', $order['project_id']] ])->whereIn('project_role_id', $project_role_ids)->pluck('user_id'); } // 外部租赁 if($order['type'] == 1) { // 审批成功 if($order['status'] == $checked_id && $last_role && $last_role['key'] == 'manager') { $status = 1; } else if($role && in_array($role['key'], ['machine', 'assist', 'manager'])) { // 审批待处理 $status = 2; } else if($order['status'] == $reject_id) { // 审批被驳回 $status = 3; } else if($order['status'] == $pass_id) { // 租赁已完成 $status = 5; } } else { // 调用 // 调用成功 if($order['status'] == $checked_id && $role && $last_role && $last_role['key'] == 'admin') { $status = $order['is_change'] == 1 ? 7 : 1; } else if($role && in_array($role['key'], ['assist', 'manager', 'admin'])) { // 调用待处理 $status = 2; } else if($order['status'] == $reject_id) { // 调用被驳回 $status = 3; } else if($order['status'] == $pass_id) { // 调用已完成 $status = 5; } else if($order['status'] == $back_id) { // 调用已归还 $status = 6; } else if($order['is_change'] == 1) { // 调用修改通知 $status = 7; } } // 调用时间到期 status = 4 if($overdue) { $status = 4; } foreach($user_ids as $user_id) { Notification::create([ 'user_id' => $user_id, 'order_id' => $order['id'], 'status' => $status, 'type' => $order['type'], 'is_read' => 2 ]); } return true; } /** * 租赁时间到期 status = 4 * @param $id * @return bool */ public static function sendOverdue($id) { $order = self::find($id); if(!$order) return false; $role = $order->type == 1 ? $role = ProjectRole::getByKey('work') : ProjectRole::getByKey('machine'); $user_ids = ProjectUser::where([ ['project_id', $order['project_id']], ['project_role_id', $role['id']] ])->pluck('user_id'); foreach($user_ids as $user_id) { Notification::create([ 'user_id' => $user_id, 'order_id' => $order['id'], 'status' => 4, 'type' => $order['type'], 'is_read' => 2 ]); } return false; } public function getNameContent() { if($this['type'] == 1) { if($this['status'] == 1) { return [ 'name' => '租赁审批成功通知', 'content' => '你的设备租赁申请已通过,请确认相关信息:' ]; } else if($this['status'] == 2) { return [ 'name' => '租赁审批待处理通知', 'content' => '你有一条设备租赁申请待审批,请确认相关信息:' ]; } else if($this['status'] == 3) { return [ 'name' => '租赁审批驳回通知', 'content' => '你有一条设备租赁申请被驳回,请确认相关信息:' ]; } else if($this['status'] == 4) { return [ 'name' => '租赁时间到期通知', 'content' => '你有一条设备租赁已到期消息,请确认相关信息:' ]; } else if($this['status'] == 5) { return [ 'name' => '租赁完成通知', 'content' => '你有一条设备租赁已完成消息,请确认相关信息:' ]; } } else { if($this['status'] == 1) { return [ 'name' => '调用审批成功通知', 'content' => '你的设备调用申请已通过,请确认相关信息:' ]; } else if($this['status'] == 2) { return [ 'name' => '调用审批待处理通知', 'content' => '你有一条设备调用申请待审批,请确认相关信息:' ]; } else if($this['status'] == 3) { return [ 'name' => '调用审批驳回通知', 'content' => '你有一条设备调用申请被驳回,请确认相关信息:' ]; } else if($this['status'] == 4) { return [ 'name' => '调用时间到期通知', 'content' => '你有一条设备调用已到期消息,请确认相关信息:' ]; } else if($this['status'] == 5) { return [ 'name' => '调用完成通知', 'content' => '你有一条设备调用已完成消息,请确认相关信息:' ]; } else if($this['status'] == 6) { return [ 'name' => '调用退回通知', 'content' => '你有一条设备调用已归还消息,请确认相关信息:' ]; } else if($this['status'] == 7) { return [ 'name' => '调用修改通知', 'content' => '你有一条设备调用被修改消息,请确认相关信息:' ]; } } return ['name' => '', 'content' => '']; } }