[ 'template' => '{from_user} 将 {title} 任务分配给您,请及时查看。', ], 2 => [ 'template' => '{from_user} 邀请您参与 {title} 任务,请及时查看。', ], 3 => [ 'template' => '{from_user} 将 {title} 任务标记结束。', ], 4 => [ 'template' => '{from_user} 回复了您的 {title} 日志:“今天工作状态不错,继续加油!”,请及时查看', ], 5 => [ 'template' => '{from_user} 将日志 {title} 发送给您,请及时查看。', ], 6 => [ 'template' => '{from_user} 提交 {title} 审批,请及时处理。', ], 7 => [ 'template' => '{from_user} 拒绝您的 {title} 审批,拒绝理由:“日期填写错误”,请及时处理。', ], 8 => [ 'template' => '{from_user} 已经审核通过您的 {title} ,请及时查看。', ], 9 => [ 'template' => '您有一个新公告 {title} ,请及时查看。', ], 10 => [ 'template' => '{from_user} 邀请您参与 {title} 日程,将于**分钟后开始,请及时查看。', ], 11 => [ 'template' => '{from_user} 提交 {title} 合同审批待您处理,请及时查看。', ], 12 => [ 'template' => '{from_user} 拒绝您的 {title} 合同审批,拒绝理由:“日期填写错误”,请及时处理。', ], 13 => [ 'template' => '{from_user} 已经审核通过您的 {title} 合同,请及时查看', ], 14 => [ 'template' => '{from_user} 提交 {title} 回款审批待您处理,请及时查看。', ], 15 => [ 'template' => '{from_user} 拒绝您的 {title} 回款审批,拒绝理由:“日期填写错误”,请及时处理。', ], 16 => [ 'template' => '{from_user} 已经审核通过您的 {title} 回款,请及时查看。', ], 17 => [ // 'template' => '{from_user} 导入客户数据,共 {total} 条,已导入 {done} 条 , 成功 {success} 条, 覆盖 {cover} 条, 失败 {error} 条。', 'template' => '{total},{cover},{success},{error}', ], 18 => [ // 'template' => '{from_user} 导入联系人数据,共 {total} 条,已导入 {done} 条 , 成功 {success} 条, 覆盖 {cover} 条, 失败 {error} 条。', 'template' => '{total},{cover},{success},{error}', ], 19 => [ // 'template' => '{from_user} 导入线索数据,共 {total} 条,已导入 {done} 条 , 成功 {success} 条, 覆盖 {cover} 条, 失败 {error} 条。', 'template' => '{total},{cover},{success},{error}', ], 20 => [ // 'template' => '{from_user} 导入产品数据,共 {total} 条,已导入 {done} 条 , 成功 {success} 条, 覆盖 {cover} 条, 失败 {error} 条。', 'template' => '{total},{cover},{success},{error}', ], 21 => [ 'template' => '{from_user} 将您添加为客户 {title} 的成员。', ], 22 => [ 'template' => '{from_user} 将您添加为商机 {title} 的成员。', ], 23 => [ 'template' => '{from_user} 将您添加为合同 {title} 的成员。', ], 24 => [ 'template' => '{from_user} 提交 {title} 发票审批待您处理,请及时查看。', ], 25 => [ 'template' => '{from_user} 拒绝您的 {title} 发票审批,请及时处理。', ], 26 => [ 'template' => '您的 {title} 发票已经审批通过,请及时查看。', ], 27 => [ // 'template' => '{date},{from_user} 导入任务,共 {total} 条,已导入 {done} 条 , 成功 {success} 条, 覆盖 {cover} 条, 失败 {error} 条。{title}', 'template' => '{total},{cover},{success},{error}', ], 28 => [ 'template' => '{from_user} 退出了您商机 {title} 的团队。', ], 29 => [ 'template' => '{from_user} 退出了您客户 {title} 的团队。', ], 30 => [ 'template' => '{from_user} 退出了您合同 {title} 的团队。', ], 31 => [ 'template' => '将{from_user} 移除了您 {title} 的团队。', ], 32 => [ 'template' => '{from_user} 将您添加为线索 {title} 的成员。', ], ]; /** * 消息类型分组 */ public static $typeGroup = [ 'announcement' => [ self::NOTICE_MESSAGE, ], 'examine' => [ self::EXAMINE_TO_DO, self::EXAMINE_REJECT, self::EXAMINE_PASS, ], 'task' => [ self::TASK_ALLOCATION, self::TASK_INVITE, self::TASK_OVER, self::IMPORT_TASK, ], 'log' => [ self::LOG_REPLAY, self::LOG_SEND, ], 'event' => [ self::EVENT_MESSAGE, ], 'crm' => [ self::CONTRACT_TO_DO, self::CONTRACT_REJECT, self::CONTRACT_PASS, self::RECEIVABLES_TO_DO, self::RECEIVABLES_REJECT, self::RECEIVABLES_PASS, self::IMPORT_CUSTOMER, self::IMPORT_CONTACTS, self::IMPORT_LEADS, self::IMPORT_PRODUCT, self::TEAM_CUSTOMER, self::TEAM_BUSINESS, self::TEAM_CONTRACT, self::INVOICE_TO_DO, self::INVOICE_REJECT, self::INVOICE_PASS, self::BUSINESS_PASS, self::CUSTOMER_PASS, self::CONTRACT_END, ], 'jxc' => [ self::PURCHASE_TO_DO, self::PURCHASE_REJECT, self::PURCHASE_PASS, self::RETREAT_TO_DO, self::RETREAT_REJECT, self::RETREAT_PASS, self::SALE_TO_DO, self::SALE_REJECT, self::SALE_PASS, self::SALERETURN_TO_DO, self::SALERETURN_REJECT, self::SALERETURN_PASS, self::COLLECTION_TO_DO, self::COLLECTION_REJECT, self::COLLECTION_PASS, self::PAYMENT_TO_DO, self::PAYMENT_REJECT, self::PAYMENT_PASS, self::ALLOCATION_TO_DO, self::ALLOCATION_REJECT, self::ALLOCATION_PASS, self::INVENTORY_TO_DO, self::INVENTORY_REJECT, self::INVENTORY_PASS, ] ]; /** * 发送系统通知 * * @param int $type 消息类型 * @param array $data 关联信息 * @param array|int $user_id 接收消息员工ID * @param boolean $system 是否系统消息 * @return bool * @author Ymob * @datetime 2019-10-17 17:23:05 */ public function send($type, $data, $user_id_list, $system = false) { if (!isset($this->typeList[$type])) { $this->error = '消息类型错误'; return false; } $user_id_list = (array)$user_id_list; $user_id_list = array_unique(array_filter($user_id_list)); if (empty($user_id_list)) { $this->error = '接收人不能为空'; return false; } $action_id = $data['action_id']; $title = $data['title']; $content = $this->typeList[$type]['template']; foreach ($data as $key => $val) { $content = str_replace('{' . $key . '}', $val, $content); } $advance_time= $data['advance_time']; $content = str_replace('{from_user}', User::userInfo('realname'), $content); $content = str_replace('{date}', date('Y-m-d'), $content); $data = []; $data['type'] = $type; $data['content'] = $content; $data['action_id'] = $action_id; $data['read_time'] = 0; $data['from_user_id'] = $system ? 0 : User::userInfo('id'); $data['title'] = $title; $data['advance_time'] = $advance_time ?: 0; $request = request(); $data['controller_name'] = strtolower($request->controller()); $data['module_name'] = strtolower($request->module()); $data['action_name'] = strtolower($request->action()); $from_user_id = $data['from_user_id']; if (!in_array($type,[9,17,18,19,20,27])) { $user_id_list = array_filter($user_id_list, function ($val) use ($from_user_id) { return $val !== $from_user_id; }); } $all_data = []; foreach ($user_id_list as $user_id) { $temp = $data; $temp['to_user_id'] = $user_id; $all_data[] = $temp; } if (!empty($from_user_id) && class_exists('DingTalk')) { (new Dingtalk())->message($user_id_list, $content); } $this->saveAll($all_data); } /** * 获取关联模块数据 * * @author Ymob * @datetime 2019-10-22 15:34:35 */ public function getRelationTitleAttr($val, $data) { switch ($data['type']) { // 任务 case self::TASK_ALLOCATION: case self::TASK_INVITE: case self::TASK_OVER: return TaskModel::where(['task_id' => $data['action_id']])->value('name') ?: ''; // 日志 case self::LOG_REPLAY: case self::LOG_SEND: return LogModel::where(['log_id' => $data['action_id']])->value('title') ?: ''; // 审批 case self::EXAMINE_TO_DO: case self::EXAMINE_REJECT: case self::EXAMINE_PASS: $category_id = ExamineModel::where(['examine_id' => $data['action_id']])->value('category_id') ?: 0; $categoryInfo = (new ExamineCategory())->getDataById($category_id); return $categoryInfo['title']; // 公告 case self::NOTICE_MESSAGE: return AnnouncementModel::where(['announcement_id' => $data['action_id']])->value('title') ?: ''; // 日程 case self::EVENT_MESSAGE: return EventModel::where(['event_id' => $data['action_id']])->value('title') ?: ''; // 合同 case self::CONTRACT_TO_DO: case self::CONTRACT_REJECT: case self::CONTRACT_PASS: case self::TEAM_CONTRACT: return ContractModel::where(['contract_id' => $data['action_id']])->value('name') ?: ''; // 回款 case self::RECEIVABLES_TO_DO: case self::RECEIVABLES_REJECT: case self::RECEIVABLES_PASS: return ReceivablesModel::where(['receivables_id' => $data['action_id']])->value('number') ?: ''; // 发票 case self::INVOICE_TO_DO: case self::INVOICE_REJECT: case self::INVOICE_PASS: return Invoice::where(['invoice_id' => $data['action_id']])->value('invoice_apple_number') ?: ''; // 导入数据 case self::IMPORT_CUSTOMER: case self::IMPORT_CONTACTS: case self::IMPORT_LEADS: case self::IMPORT_PRODUCT: case self::IMPORT_TASK: $error = ImportRecordModel::where(['id' => $data['action_id']])->value('error'); return $error ? '点击下载错误数据' : ''; // 客户 case self::TEAM_CUSTOMER: case self::CUSTOMER_PASS: return CustomerModel::where(['customer_id' => $data['action_id']])->value('name') ?: ''; // 商机 case self::TEAM_BUSINESS: case self::BUSINESS_PASS: return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: ''; // 采购单 case self::PURCHASE_TO_DO: case self::PURCHASE_REJECT: case self::PURCHASE_PASS: return PurchaseModel::where(['purchase_id' => $data['action_id']])->value('order_number') ?: ''; // 采购退货单 case self::RETREAT_TO_DO: case self::RETREAT_REJECT: case self::RETREAT_PASS: return RetreatModel::where(['retreat_id' => $data['action_id']])->value('order_number') ?: ''; // 销售订单 case self::SALE_TO_DO: case self::SALE_REJECT: case self::SALE_PASS: return SaleModel::where(['sale_id' => $data['action_id']])->value('order_number') ?: ''; // 销售退货单订单 case self::SALERETURN_TO_DO: case self::SALERETURN_REJECT: case self::SALERETURN_PASS: return SalereturnModel::where(['salereturn_id' => $data['action_id']])->value('order_number') ?: ''; // 回款单 case self::COLLECTION_TO_DO: case self::COLLECTION_REJECT: case self::COLLECTION_PASS: return CollectionModel::where(['collection_note_id' => $data['action_id']])->value('collection_no') ?: ''; // 付款单 case self::PAYMENT_TO_DO: case self::PAYMENT_REJECT: case self::PAYMENT_PASS: return PaymentModel::where(['payment_note_id' => $data['action_id']])->value('payment_no') ?: ''; // 调拨 case self::ALLOCATION_TO_DO: case self::ALLOCATION_REJECT: case self::ALLOCATION_PASS: return PaymentModel::where(['allocation_id' => $data['action_id']])->value('allocation_code') ?: ''; // 盘点 case self::INVENTORY_TO_DO: case self::INVENTORY_REJECT: case self::INVENTORY_PASS: return PaymentModel::where(['inventory_id' => $data['action_id']])->value('inventory_number') ?: ''; } return ''; } /** * 发送人 */ public function getFromUserIdInfoAttr($val, $data) { return $data['from_user_id'] ? UserModel::getUserById($data['from_user_id']) : []; } }