isAjax()){ $user_type = get_login_admin('user_type'); $where = array(); if($user_type == -1 || $user_type == -2){ $where = [ 'user_type' => -1, ]; } $list = Db::name('PushMessage')->where($where)->select(); // dump($list); return to_assign(0, '', $list); } else { return view(); } } // 添加通知设置 public function add(){ $param = get_params(); if(request()->isAjax()){ $data = [ 'title' => $param['title'], 'is_who' => implode(',', $param['is_who']), 'is_wechat' => $param['is_wechat'], 'is_wechat_company' => $param['is_wechat_company'], 'is_wechat_proprietor' => $param['is_wechat_proprietor'], 'content' => $param['content'], 'is_project_name' => $param['is_project_name'], 'is_people' => $param['is_people'], 'content_company' => $param['content_company'], 'is_project_name_company' => $param['is_project_name_company'], 'is_people_company' => $param['is_people_company'], 'content_proprietor' => $param['content_proprietor'], 'is_project_name_proprietor' => $param['is_project_name_proprietor'], 'is_people_proprietor' => $param['is_people_proprietor'], // 'rule_id' => $param['rule_id'], // 'rule_url' => Db::name('AdminRule')->where('id', $param['rule_id'])->value('src'), 'rule_url' => $param['rule_url'], 'user_type' => -1, 'unit_name' => get_login_admin('unit_name'), 'pid' => $param['pid'], ]; if(isset( $param['title_company'])){ $data['title_company'] = $param['title_company']; } if(isset( $param['title_proprietor'])){ $data['title_proprietor'] = $param['title_proprietor']; } // halt($data); if($data['rule_url'] != NULL){ $rule_url = Db::name('PushMessage')->where('rule_url', $data['rule_url'])->find(); if($rule_url != NULL){ return to_assgin(1, "已存在该通知阶段"); } } Db::startTrans(); try { $uid = Db::name('PushMessage')->strict(false)->field(true)->insertGetId($data); add_log('add', $uid, $data); // 提交事务 Db::commit(); }catch(\Exception $e){ // 回滚事务 Db::rollback(); return to_assign(1, '提交失败:' . $e->getMessage()); } return to_assign(0,"操作成功"); }else{ $pid = isset($param['pid']) ? $param['pid'] : 0; $user_type = get_login_admin('user_type'); $push_message = Db::name('PushMessage')->where('user_type', -1)->select()->toArray(); $push_message = set_recursion($push_message); $rule = Db::name('adminRule')->order('sort asc,id asc')->select(); $rule = set_recursion($rule); View::assign('push_message', $push_message); View::assign('rule', $rule); View::assign('pid', $pid); return view(); } } //编辑通知设置 public function edit(){ $param = get_params(); // halt($param); if(request()->isAjax()){ $arr = array(); if(isset($param['is_cost'])){ $arr[0] = 0; } if(isset($param['is_owner'])){ $arr[1] = 1; } if(isset($param['is_company'])){ $arr[2] = 2; } $param['is_who'] = implode(',', $arr); // halt($param); $data = [ 'id' => $param['id'], 'title' => $param['title'], 'title_company' => $param['title_company'], 'title_proprietor' => $param['title_proprietor'], 'is_who' => $param['is_who'], 'is_wechat' => $param['is_wechat'], 'is_wechat_company' => $param['is_wechat_company'], 'is_wechat_proprietor' => $param['is_wechat_proprietor'], 'content' => $param['content'], 'is_project_name' => $param['is_project_name'], 'is_people' => $param['is_people'], 'content_company' => $param['content_company'], 'is_project_name_company' => $param['is_project_name_company'], 'is_people_company' => $param['is_people_company'], 'content_proprietor' => $param['content_proprietor'], 'is_project_name_proprietor' => $param['is_project_name_proprietor'], 'is_people_proprietor' => $param['is_people_proprietor'], 'rule_url' => $param['rule_url'], 'user_type' => -1, 'unit_name' => get_login_admin('unit_name'), 'pid' => $param['pid'], ]; if($data['rule_url'] != NULL){ if($data['rule_url'] != Db::name('PushMessage')->where('id', $data['id'])->value('rule_url')){ $rule_url = Db::name('PushMessage')->where('rule_url', $data['rule_url'])->find(); if($rule_url != NULL){ return to_assign(1, "已存在该通知阶段"); } } } // halt($data); Db::startTrans(); try { Db::name('PushMessage')->strict(false)->field(true)->update($data); add_log('add', $param['id'], $data); // 提交事务 Db::commit(); }catch(\Exception $e){ // 回滚事务 Db::rollback(); return to_assign(1, '提交失败:' . $e->getMessage()); } return to_assign(0,"操作成功"); }else{ $id = $param['id']; $data = Db::name('PushMessage')->where('id', $id)->find(); $data['is_who'] = explode(',', $data['is_who']); // dump($data); if(in_array(0, $data['is_who'])){ // 财政局 $data['is_cost'] = 1; }else{ $data['is_cost'] = 0; } if(in_array(1, $data['is_who'])){ // 业主 $data['is_owner'] = 1; }else{ $data['is_owner'] = 0; } if(in_array(2, $data['is_who'])){ // 公司 $data['is_company'] = 1; }else{ $data['is_company'] = 0; } $push_message = Db::name('PushMessage')->where('user_type', -1)->select()->toArray(); $push_message = set_recursion($push_message); $rule = Db::name('AdminRule')->order('sort asc,id asc')->select(); $rule = set_recursion($rule); View::assign('data', $data); View::assign('push_message', $push_message); View::assign('rule', $rule); return view(); } } // 删除通知设置 public function delete(){ $id = get_params('id'); $count = Db::name('PushMessage')->where('pid', '=', $id)->count(); if ($count > 0) { return to_assign(1, "该通知设置下还有子设置,无法删除"); } if (Db::name('PushMessage')->delete($id) !== false) { add_log('delete', $id); return to_assign(0, "删除通知设置成功"); } else { return to_assign(1, "删除失败"); } // $is_who = [ // 'cai','gongi',' yezhu' // ]; // $is_who = [ // 'cai','gongi' // ]; // $is_who = [ // 'cai'=> 0, // 'gongi'=> 1, // ]; } /** * $url: 方法URL * $project_id:项目ID int * $financial:财政局人员 array * [1,2,3] * [ * 0 => 1, * 1 => 2, * ]; * $company:公司人员 [1,2,3] array * $proprietor:业主人员 [1,2,3] array * $new_url:用于新的内容设置 */ public function pushMessage($project_id, $financial = NULL, $company = NULL, $proprietor = NULL, $new_url = NULL){ if($new_url == NULL){ $url = (string) \think\facade\Route::buildUrl(); $url = self::handleUrl($url); }else{ $url = $new_url; } $push = Db::name('PushMessage')->where('rule_url', $url)->find(); // 通知成员 // $project_id $message_id = $push['id']; // 抄送成员 $member = Db::name('PushMember')->where('message_id', $message_id)->where('unit_name', get_login_admin('unit_name'))->value('member_id'); if(get_login_admin('user_type') == 0){ if(!empty($financial)){ // $financial = array_unique(array_merge(explode(',', $member), $financial)); $member = self::inform_send($financial, $member); } }else if(get_login_admin('user_type') == 2){ if(!empty($company)){ // $company = array_unique(array_merge(explode(',', $member), $company)); $member = self::inform_send($company, $member); } }else if(get_login_admin('user_type') == 1){ $member = self::inform_send($proprietor, $member); }else{ return 0; } if($financial != NULL){ // halt($financial); if($push['content'] != NULL){ // 财政局 $content = self::handleContent($push, $project_id); self::webPush($content, $project_id, $financial); // dump($financial, $content); if($push['is_wechat'] == 1){ self::initialize()->sendText($financial, $content); } if($member != NULL){ $str = ''; for($i = 0; $i where('id', $financial[$i])->value('nickname') . ','; }else{ $str = $str . Db::name('Admin')->where('id', $financial[$i])->value('nickname'); } } $content = str_replace('您', $str, $content); self::webPush($content, $project_id, $member); // dump($financial, $content); if($push['is_wechat'] == 1){ self::initialize()->sendText($member, $content); } } } } if($proprietor != NULL){ if($push['content_proprietor'] != NULL){ //公司 $content_proprietor = self::handleContent_proprietor($push, $project_id); self::webPush($content_proprietor, $project_id, $proprietor); if($push['is_wechat_proprietor'] == 1){ self::initialize()->sendText($proprietor, $content_proprietor); } if($member != NULL){ $str = ''; for($i = 0; $i where('id', $proprietor[$i])->value('nickname') . ','; }else{ $str = $str . Db::name('Admin')->where('id', $proprietor[$i])->value('nickname'); } } $content = str_replace('您', $str, $content); self::webPush($content, $project_id, $member); // dump($financial, $content); if($push['is_wechat'] == 1){ self::initialize()->sendText($member, $content); } } } } if($company != NULL){ if($push['content_company'] != NULL){ //公司 $content_company = self::handleContent_company($push, $project_id); self::webPush($content_company, $project_id, $company); if($push['is_wechat_company'] == 1){ self::initialize()->sendText($company, $content_company); } if($member != NULL){ $str = ''; for($i = 0; $i where('id', $company[$i])->value('nickname') . ','; }else{ $str = $str . Db::name('Admin')->where('id', $company[$i])->value('nickname'); } } $content = str_replace('您', $str, $content); self::webPush($content, $project_id, $member); // dump($financial, $content); if($push['is_wechat'] == 1){ self::initialize()->sendText($member, $content); } } } } } // 网页通知 public function webPush($content, $project_id, $uid){ $uid = (array)$uid; for($i = 0; $i < count($uid); $i++){ $data = [ 'content' => $content, 'project_id' => $project_id, 'uid' => $uid[$i], 'create_time' => time(), ]; $newId = Db::name('ProjectMsg')->strict(false)->field(true)->insertGetId($data); $unread = (string) Db::name('Admin')->where('id', $uid[$i])->value('unread'); $unread = $unread . ',' . $newId; Db::name('Admin')->where('id', $uid[$i])->update(['unread' => $unread]); } } public function handleContent($push, $project_id){ if(!is_array ($project_id)){ $project_id = (array)$project_id; } $content = $push['content']; if($push['is_project_name'] == 0 && $push['is_people'] == NULL){ $is_project_name = ''; $people = ''; }else if($push['is_project_name'] == 1 && $push['is_people'] == NULL){ $is_project_name = '项目名称' . ':'; for($i = 0; $i < count($project_id); $i++){ if($i < count($project_id) - 1){ $is_project_name = $is_project_name . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . ','; continue; } $is_project_name = $is_project_name . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . '。'; } $people = ''; }else if($push['is_project_name'] == 0 && $push['is_people'] != NULL){ $is_project_name = ''; $people = $push['is_people'] . ':' . get_login_admin('nickname') . '。'; }else{ $is_project_name = '项目名称' . ':'; for($i = 0; $i < count($project_id); $i++){ if($i < count($project_id) - 1){ $is_project_name = $is_project_name . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . ','; continue; } $is_project_name = $is_project_name . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . '。'; } $people = $push['is_people'] . ':' . get_login_admin('nickname') . '。'; } if($push['is_people'] != NULL){ $str = '“' . $push['is_people'] . '”'; if(mb_strpos($content, $str) !== false){ $content = str_replace($str, get_login_admin('nickname'), $content); } } $str = "“公司”"; if(mb_strpos($content, $str) !== false){ $company_name = Db::name('Department')->where('id', get_login_admin('unit_name'))->value('title'); $content = str_replace($str, $company_name, $content); } $content = $content . "\n". $is_project_name . "\n". $people; return $content; } public function handleContent_proprietor($push, $project_id){ if(!is_array ($project_id)){ $project_id = (array)$project_id; } $content_proprietor = $push['content_proprietor']; if($push['is_project_name_proprietor'] == 0 && $push['is_people_proprietor'] == NULL){ $is_project_name_proprietor = ''; $people_proprietor = ''; }else if($push['is_project_name_proprietor'] == 1 && $push['is_people_proprietor'] == NULL){ $is_project_name_proprietor = '项目名称' . ':'; for($i = 0; $i < count($project_id); $i++){ if($i < count($project_id) - 1){ $is_project_name_proprietor = $is_project_name_proprietor . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . ','; continue; } $is_project_name_proprietor = $is_project_name_proprietor . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . '。'; } // $is_project_name_company = '项目名称' . ':' . Db::name('CostProject')->where('id', $project_id)->value('project_name') . '。'; $people_proprietor = ''; }else if($push['is_project_name_proprietor'] == 0 && $push['is_people_proprietor'] != NULL){ $is_project_name_proprietor = ''; $people_proprietor = $push['is_people_proprietor'] . ':' . get_login_admin('nickname') . '。'; }else{ $is_project_name_proprietor = '项目名称' . ':'; for($i = 0; $i < count($project_id); $i++){ if($i < count($project_id) - 1){ $is_project_name_proprietor = $is_project_name_proprietor . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . ','; continue; } $is_project_name_proprietor = $is_project_name_proprietor . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . '。'; } // $is_project_name_company = '项目名称' . ':' . Db::name('CostProject')->where('id', $project_id)->value('project_name') . '。'; $people_proprietor = $push['is_people_proprietor'] . ':' . get_login_admin('nickname') . '。'; } if($push['is_people_proprietor'] != NULL){ $str = '“' . $push['is_people_proprietor'] . '”'; if(mb_strpos($content_proprietor, $str) !== false){ $content_proprietor = str_replace($str, get_login_admin('nickname'), $content_proprietor); } } $str = "“公司”"; if(mb_strpos($content_proprietor, $str) !== false){ $company_name = Db::name('Department')->where('id', get_login_admin('unit_name'))->value('title'); $content_proprietor = str_replace($str, $company_name, $content_proprietor); } $content_proprietor = $content_proprietor . "\n". $is_project_name_proprietor . "\n". $people_proprietor; return $content_proprietor; } public function handleContent_company($push, $project_id){ if(!is_array ($project_id)){ $project_id = (array)$project_id; } $content_company = $push['content_company']; if($push['is_project_name_company'] == 0 && $push['is_people_company'] == NULL){ $is_project_name_company = ''; $people_company = ''; }else if($push['is_project_name_company'] == 1 && $push['is_people_company'] == NULL){ $is_project_name_company = '项目名称' . ':'; for($i = 0; $i < count($project_id); $i++){ if($i < count($project_id) - 1){ $is_project_name_company = $is_project_name_company . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . ','; continue; } $is_project_name_company = $is_project_name_company . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . '。'; } // $is_project_name_company = '项目名称' . ':' . Db::name('CostProject')->where('id', $project_id)->value('project_name') . '。'; $people_company = ''; }else if($push['is_project_name_company'] == 0 && $push['is_people_company'] != NULL){ $is_project_name_company = ''; $people_company = $push['is_people_company'] . ':' . get_login_admin('nickname') . '。'; }else{ $is_project_name_company = '项目名称' . ':'; for($i = 0; $i < count($project_id); $i++){ if($i < count($project_id) - 1){ $is_project_name_company = $is_project_name_company . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . ','; continue; } $is_project_name_company = $is_project_name_company . Db::name('CostProject')->where('id', $project_id[$i])->value('project_name') . '。'; } // $is_project_name_company = '项目名称' . ':' . Db::name('CostProject')->where('id', $project_id)->value('project_name') . '。'; $people_company = $push['is_people_company'] . ':' . get_login_admin('nickname') . '。'; } if($push['is_people_company'] != NULL){ $str = '“' . $push['is_people_company'] . '”'; if(mb_strpos($content_company, $str) !== false){ $content_company = str_replace($str, get_login_admin('nickname'), $content_company); } } $str = "“公司”"; if(mb_strpos($content_company, $str) !== false){ $company_name = Db::name('Department')->where('id', get_login_admin('unit_name'))->value('title'); $content_company = str_replace($str, $company_name, $content_company); } $content_company = $content_company . "\n". $is_project_name_company . "\n". $people_company; return $content_company; } public function handleUrl($url){ $url = substr($url, 1); $url = strtolower($url); return $url; } public function handleId($notify){ $idList = []; foreach($notify as $key => $value){ $idList[$key] = $notify[$key]['id']; } // $idList = explode(',', $idList); return $idList; } public function handleParam($param){ if (isset($param["financial"])) { $financial = $param['financial']; unset($param['financial']); $financial = self::handleId($financial); }else{ $financial = NULL; } if(isset($param["company"])){ $company = $param['company']; unset($param['company']); $company = self::handleId($company); }else{ $company = NULL; } $data = [ 'param' => $param, 'financial' => $financial, 'company' => $company, ]; return $data; } // 抄送成员去除通知成员 // $inform 通知成员 // $member 抄送成员 public function inform_send($inform, $member){ // public function inform_send(){ // $inform = [ // 0 => 1, // 1 => 2, // ]; // $member = [ // // 0 => 3, // // 1 => 2, // // 2 => 6, // ]; $a = 0; $b = 0; if(!empty($inform)){ $a = count((array)$inform); $inform = (array)$inform; } if(!empty($member)){ $b = count((array)$member); $member = (array)$member; } for($i = 0; $i < $a; $i++){ for($j = 0; $j < $b; $j++){ if($inform[$i] == $member[$j]){ unset($member[$j]); } } } if(!empty($member)){ $member = array_values($member); } // if($member ==null){ // dump('111'); // }else{ // dump('222'); // } // halt($member); return $member; } public function test(){ dump(self::test1([])); } public function test1($a = NULL){ if($a == NULL){ return NULL; }else{ return "!!!"; } } }