public function getRoleList() { $idArray = getSubRoleId(); $roleList = array(); foreach ($idArray as $roleId) { $roleList[$roleId] = getUserByRoleId($roleId); } $this->ajaxReturn($roleList, '', 1); }
public function changeDialog() { if ($this->isAjax()) { $m_contacts = M('contacts'); $m_customer = M('customer'); $p = !$_REQUEST['p'] || $_REQUEST['p'] <= 0 ? 1 : intval($_REQUEST['p']); $where = array(); $params = array(); $where['owner_role_id'] = array('in', implode(',', getSubRoleId(true))); $where['is_deleted'] = array('neq', 1); if ($_REQUEST['customer_id'] != 0) { $contacts_id = M('RContactsCustomer')->where('customer_id = %d', $_REQUEST['customer_id'])->getField('contacts_id', true); $where['contacts_id'] = array('in', implode(',', $contacts_id)); } elseif ($_REQUEST['is_check']) { $list = M($_REQUEST['r'])->getField('contacts_id', true); $list[] = 0; $where['contacts_id'] = array('not in', implode(',', $list)); } if ($_REQUEST["field"]) { $field = trim($_REQUEST['field']) == 'all' ? 'name|telephone|email|address|post|department|description' : $_REQUEST['field']; $search = empty($_REQUEST['search']) ? '' : trim($_REQUEST['search']); $condition = empty($_REQUEST['condition']) ? 'is' : trim($_REQUEST['condition']); if ('create_time' == $field || 'update_time' == $field) { $search = is_numeric($search) ? $search : strtotime($search); } switch ($condition) { case "is": $where[$field] = array('eq', $search); break; case "isnot": $where[$field] = array('neq', $search); break; case "contains": $where[$field] = array('like', '%' . $search . '%'); break; case "not_contain": $where[$field] = array('notlike', '%' . $search . '%'); break; case "start_with": $where[$field] = array('like', $search . '%'); break; case "end_with": $where[$field] = array('like', '%' . $search); break; case "is_empty": $where[$field] = array('eq', ''); break; case "is_not_empty": $where[$field] = array('neq', ''); break; case "gt": $where[$field] = array('gt', $search); break; case "egt": $where[$field] = array('egt', $search); break; case "lt": $where[$field] = array('lt', $search); break; case "elt": $where[$field] = array('elt', $search); break; case "eq": $where[$field] = array('eq', $search); break; case "neq": $where[$field] = array('neq', $search); break; case "between": $where[$field] = array('between', array($search - 1, $search + 86400)); break; case "nbetween": $where[$field] = array('not between', array($search, $search + 86399)); break; case "tgt": $where[$field] = array('gt', $search + 86400); break; default: $where[$field] = array('eq', $search); } } $contactsList = $m_contacts->where($where)->order('create_time desc')->page($p . ',10')->select(); $count = $m_contacts->where($where)->count(); if (!$_REQUEST['is_check']) { foreach ($contactsList as $k => $v) { if ($customer_id = M('rContactsCustomer')->where('contacts_id = %d', $v['contacts_id'])->getField('customer_id')) { $contactsList[$k]['customer'] = $m_customer->where('customer_id = %d', $customer_id)->find(); } } } $data['list'] = $contactsList; $data['p'] = $p; $data['count'] = $count; $data['total'] = $count % 10 > 0 ? ceil($count / 10) : $count / 10; //echo '<pre>';print_r($data);echo '</pre>'; die(); $this->ajaxReturn($data, "", 1); } }
public function analytics() { $m_leads = M('leads'); if ($_GET['role']) { $role_id = intval($_GET['role']); } else { $role_id = 'all'; } if ($_GET['department'] && $_GET['department'] != 'all') { $department_id = intval($_GET['department']); } else { $department_id = D('RoleView')->where('role.role_id = %d', session('role_id'))->getField('department_id'); } if ($_GET['start_time']) { $start_time = strtotime(date('Y-m-d', strtotime($_GET['start_time']))); } $end_time = $_GET['end_time'] ? strtotime(date('Y-m-d 23:59:59', strtotime($_GET['end_time']))) : strtotime(date('Y-m-d 23:59:59', time())); if ($role_id == "all") { $roleList = getRoleByDepartmentId($department_id); $role_id_array = array(); foreach ($roleList as $v2) { $role_id_array[] = $v2['role_id']; } $where_source['creator_role_id'] = array('in', implode(',', $role_id_array)); $where_status['owner_role_id'] = array('in', implode(',', $role_id_array)); } else { $where_source['creator_role_id'] = $role_id; $where_status['owner_role_id'] = $role_id; } if ($start_time) { $where_source['create_time'] = array(array('elt', $end_time), array('egt', $start_time), 'and'); $where_status['create_time'] = array(array('elt', $end_time), array('egt', $start_time), 'and'); } else { $where_source['create_time'] = array('elt', $end_time); $where_status['create_time'] = array('elt', $end_time); } //线索来源统计 $setting = M('Fields')->where("model = 'leads' and field = 'source'")->getField('setting'); $setting_str = '$revenueList=' . $setting . ';'; //eval($setting_str); $source_count_array = array(); $sourceList = M('leads')->field('count(1) as num , source')->group('source')->where($where_source)->select(); foreach ($sourceList as $v) { $source = $v['source'] ? $v['source'] : L('OTHER'); $source_count[$source] = $v['num']; } foreach ($revenueList['data'] as $v) { if ($source_count[$v]) { $source_count_array[] = '["' . $v . '",' . $source_count[$v] . ']'; } else { $source_count_array[] = '["' . $v . '",0]'; } } $this->source_count = implode(',', $source_count_array); //Statistics Content $role_id_array = array(); if ($role_id == "all") { if ($department_id != "all") { if (session('?admin')) { $roleList = M('role')->where('user_id <> 0')->getField('role_id', true); } else { $roleList = getRoleByDepartmentId($department_id); } //$roleList = getRoleByDepartmentId($department_id); foreach ($roleList as $v) { $role_id_array[] = $v; } } else { $role_id_array = getSubRoleId(); } } else { $role_id_array[] = $role_id; } if ($start_time) { $create_time = array(array('elt', $end_time), array('egt', $start_time), 'and'); } else { $create_time = array('elt', $end_time); } $add_count_total = 0; $own_count_total = 0; $success_count_total = 0; $deal_count_total = 0; foreach ($role_id_array as $v) { $user = getUserByRoleId($v); $add_count = $m_leads->where(array('is_deleted' => 0, 'creator_role_id' => $v, 'create_time' => $create_time))->count(); $own_count = $m_leads->where(array('is_deleted' => 0, 'owner_role_id' => $v, 'create_time' => $create_time))->count(); $success_count = $m_leads->where(array('is_deleted' => 0, 'is_transformed' => 1, 'owner_role_id' => $v, 'create_time' => $create_time))->count(); $deal_count = $m_leads->where('is_deleted = 0 and owner_role_id = %d and is_transformed != 1 and update_time>create_time', $v)->count(); $reportList[] = array("user" => $user, "add_count" => $add_count, "own_count" => $own_count, "success_count" => $success_count, "deal_count" => $deal_count); $add_count_total += $add_count; $own_count_total += $own_count; $success_count_total += $success_count; $deal_count_total += $deal_count; } $this->total_report = array("add_count" => $add_count_total, "own_count" => $own_count_total, "success_count" => $success_count_total, "deal_count" => $deal_count_total); $this->reportList = $reportList; if (session('?admin')) { $idArray = M('role')->where('user_id <> 0')->getField('role_id', true); } else { $idArray = getSubRoleId(); } $roleList = array(); foreach ($idArray as $roleId) { $roleList[$roleId] = getUserByRoleId($roleId); } $this->roleList = $roleList; $departments = M('roleDepartment')->select(); $departmentList[] = M('roleDepartment')->where('department_id = %d', session('department_id'))->find(); $departmentList = array_merge($departmentList, getSubDepartment(session('department_id'), $departments, '')); $this->assign('departmentList', $departmentList); $this->alert = parseAlert(); $this->display(); }
public function listDialog() { $below_ids = getSubRoleId(true); $contract = D('ContractView'); $business_id = intval($_GET['bid']); if (!empty($business_id)) { $where['business_id'] = array('eq', $business_id); } $where['contract.owner_role_id'] = array('in', implode(',', $below_ids)); $where['contract.is_deleted'] = 0; $list = $contract->where($where)->page('0,10')->order('create_time desc')->select(); $count = $contract->where($where)->count(); $this->total = $count % 10 > 0 ? ceil($count / 10) : $count / 10; $this->count_num = $count; $this->assign('contractList', $list); $this->display(); }
public function index() { $m_log = M('ActionLog'); $by = isset($_GET['by']) ? trim($_GET['by']) : ''; $where = array(); $params = array(); $order = "create_time desc"; if ($_GET['desc_order']) { $order = trim($_GET['desc_order']) . ' desc'; } elseif ($_GET['asc_order']) { $order = trim($_GET['asc_order']) . ' asc'; } $all_ids = getSubRoleId(); switch ($by) { case 'today': $where['create_time'] = array('gt', strtotime(date('Y-m-d', time()))); break; case 'week': $where['create_time'] = array('gt', strtotime(date('Y-m-d', time())) - (date('N', time()) - 1) * 86400); break; case 'month': $where['create_time'] = array('gt', strtotime(date('Y-m-01', time()))); break; case 'me': $where['role_id'] = session('role_id'); break; case 'add': $order = 'create_time desc'; break; } if (!isset($where['role_id'])) { $where['role_id'] = array('in', implode(',', getSubRoleId())); } if (trim($_GET['module'])) { $where['module_name'] = trim($_GET['module']); } if (trim($_GET['act'])) { $where['action_name'] = trim($_GET['act']); } if ($_REQUEST["field"]) { $field = trim($_REQUEST['field']) == 'all' ? 'subject|content' : $_REQUEST['field']; $search = empty($_REQUEST['search']) ? '' : trim($_REQUEST['search']); $condition = empty($_REQUEST['condition']) ? 'eq' : trim($_REQUEST['condition']); if ('create_time' == $field) { $search = strtotime($search); } $params = array('field=' . $_REQUEST['field'], 'condition=' . $condition, 'search=' . trim($_REQUEST["search"])); switch ($_REQUEST['condition']) { case "is": $where[$field] = array('eq', $search); break; case "isnot": $where[$field] = array('neq', $search); break; case "contains": $where[$field] = array('like', '%' . $search . '%'); break; case "not_contain": $where[$field] = array('notlike', '%' . $search . '%'); break; case "start_with": $where[$field] = array('like', $search . '%'); break; case "end_with": $where[$field] = array('like', '%' . $search); break; case "is_empty": $where[$field] = array('eq', ''); break; case "is_not_empty": $where[$field] = array('neq', ''); break; case "gt": $where[$field] = array('gt', $search); break; case "egt": $where[$field] = array('egt', $search); break; case "lt": $where[$field] = array('lt', $search); break; case "elt": $where[$field] = array('elt', $search); break; case "eq": $where[$field] = array('eq', $search); break; case "neq": $where[$field] = array('neq', $search); break; case "between": $where[$field] = array('between', array($search - 1, $search + 86400)); break; case "nbetween": $where[$field] = array('not between', array($search, $search + 86399)); break; case "tgt": $where[$field] = array('gt', $search + 86400); break; default: $where[$field] = array('eq', $search); } } $p = isset($_GET['p']) ? intval($_GET['p']) : 1; $list = $m_log->where($where)->page($p . ',10')->order($order)->select(); $count = $m_log->where($where)->count(); foreach ($list as $k => $v) { $param_name = ''; if (!empty($v['param_name'])) { $param_name = $v['param_name']; } if ($v['module_name'] == 'finance') { $module_name = substr($v['param_name'], 2); } else { $module_name = $v['module_name']; } $m_module_name = M($module_name); $id = $m_module_name->getPk(); $name = $m_module_name->where("{$id} = %d", $v['action_id'])->getField('name'); if (empty($name)) { $name = $m_module_name->where("{$id} = %d", $v['action_id'])->getField('subject'); } $list[$k]['content'] = $v['content'] . '---<a href="./index.php?m=' . $v[module_name] . '&a=view&' . $param_name . '&id=' . $v[action_id] . '">' . $name . '</a>'; } import("@.ORG.Page"); $Page = new Page($count, 10); if (!empty($_REQUEST['by'])) { $params['by'] = 'by=' . trim($_REQUEST['by']); } if (!empty($_REQUEST['module'])) { $params['module'] = 'module=' . trim($_REQUEST['module']); } if (!empty($_REQUEST['act'])) { $params['act'] = 'act=' . trim($_REQUEST['act']); } $this->parameter = implode('&', $params); if ($_GET['desc_order']) { $params[] = "desc_order=" . trim($_GET['desc_order']); } elseif ($_GET['asc_order']) { $params[] = "asc_order=" . trim($_GET['asc_order']); } $Page->parameter = implode('&', $params); $show = $Page->show(); $this->assign('page', $show); foreach ($list as $k => $v) { $list[$k]['creator'] = getUserByRoleId($v['role_id']); } $d_role_view = D('RoleView'); $this->role_list = $d_role_view->where('role.role_id in (%s)', implode(',', $below_ids))->select(); $this->assign('list', $list); $this->alert = parseAlert(); $this->display(); }
/** * 首页销售漏斗统计 **/ public function getSalesFunnel() { $dashboard = M('user')->where('user_id = %d', session('user_id'))->getField('dashboard'); $widget = unserialize($dashboard); $where['owner_role_id'] = array('in', getSubRoleId()); $m_business = M('Business'); $status_count_array = array(); $status = M('BusinessStatus')->order('order_id desc')->where('status_id <> 99')->order('order_id asc')->getField('status_id,name', true); $statusList = array(); $where['is_deleted'] = array('eq', 0); foreach ($status as $k => $v) { $where['status_id'] = array('eq', $k); $status_count = $m_business->where($where)->count(); $statusList[] = array($v, intval($status_count)); } $this->ajaxReturn($statusList, 'success', 1); }
/** * 首页应收款年度对比统计 * @ level 0:自己的数据 1:自己和下属的数据 **/ public function getYearReceiveComparison() { $m_receivables = M('receivables'); $dashboard = M('user')->where('user_id = %d', session('user_id'))->getField('dashboard'); $widget = unserialize($dashboard); $where['creator_role_id'] = array('in', getSubRoleId()); $year = date('Y'); $prev_year = $year - 1; $moon = 1; $receive_this_year_money = array(); $receive_prev_year_money = array(); $where['is_deleted'] = array('eq', 0); $where_this_year = $where; $where_prev_year = $where; while ($moon <= 12) { if ($moon == 12) { $where_this_year['pay_time'] = array(array('egt', strtotime($year . '-' . $moon . '-1')), array('lt', strtotime($year + 1 . '-1-1')), 'and'); $where_prev_year['pay_time'] = array(array('egt', strtotime($prev_year . '-' . $moon . '-1')), array('lt', strtotime($year . '-1-1')), 'and'); } else { $where_this_year['pay_time'] = array(array('egt', strtotime($year . '-' . $moon . '-1')), array('lt', strtotime($year . '-' . ($moon + 1) . '-1')), 'and'); $where_prev_year['pay_time'] = array(array('egt', strtotime($prev_year . '-' . $moon . '-1')), array('lt', strtotime($prev_year . '-' . ($moon + 1) . '-1')), 'and'); } $receive_this_year_price = $m_receivables->where($where_this_year)->sum('price'); //今年月度收款金额总和 $receive_prev_year_price = $m_receivables->where($where_prev_year)->sum('price'); //去年月度收款金额总和 $receive_this_year_money[] = empty($receive_this_year_price) ? 0 : round($receive_this_year_price, 2); $receive_prev_year_money[] = empty($receive_prev_year_price) ? 0 : round($receive_prev_year_price, 2); $moon++; } $total_money = array('this_year' => $receive_this_year_money, 'prev_year' => $receive_prev_year_money); $this->ajaxReturn($total_money, 'success', 1); }
/** * 首页客户来源统计 * @ level 0:自己的数据 1:自己和下属的数据 **/ public function getCustomerOriginal() { $dashboard = M('user')->where('user_id = %d', session('user_id'))->getField('dashboard'); $widget = unserialize($dashboard); $where['owner_role_id'] = array('in', getSubRoleId()); $m_customer = M('customer'); $original = $m_customer->Distinct(true)->field('origin')->getField('origin', true); $originalArr = array_filter($original); $customerArr = array(); $where['is_deleted'] = array('eq', 0); foreach ($originalArr as $v) { $where['origin'] = array('eq', $v); $origin_count = $m_customer->where($where)->count(); $customerArr['series'][] = array('value' => intval($origin_count), 'name' => $v); $customerArr['legend'][] = $v; } $this->ajaxReturn($customerArr, 'success', 1); }
public function analytics() { $m_task = M('Task'); if ($_GET['role']) { $role_id = intval($_GET['role']); } else { $role_id = 'all'; } if ($_GET['department'] && $_GET['department'] != 'all') { $department_id = intval($_GET['department']); } else { $department_id = D('RoleView')->where('role.role_id = %d', session('role_id'))->getField('department_id'); } if ($_GET['start_time']) { $start_time = strtotime($_GET['start_time']); } $end_time = $_GET['end_time'] ? strtotime($_GET['end_time']) : time(); if ($role_id == "all") { if (session('?admin')) { $roleList = M('role')->where('user_id <> 0')->getField('role_id', true); } else { $roleList = getRoleByDepartmentId($department_id); } //$roleList = getRoleByDepartmentId($department_id); $role_id_array = array(); foreach ($roleList as $v) { $role_id_array[] = '%,' . $v['role_id'] . ',%'; } $where_completion['owner_role_id'] = array('like', $role_id_array, 'or'); } else { $where_completion['owner_role_id'] = array('like', '%,' . $role_id . ',%'); } if ($start_time) { $where_create_time = array(array('lt', $end_time), array('gt', $start_time), 'and'); $where_completion['create_time'] = $where_create_time; } else { $where_completion['create_time'] = array('lt', $end_time); } $completion_count_array = array(); $statusList = array(L('NOT_START'), L('DELAY'), L('ONGOING'), L('COMPLETE')); $where_completion['is_deleted'] = 0; $where_completion['isclose'] = 0; foreach ($statusList as $v) { $where_completion['status'] = $v; $target_count = $m_task->where($where_completion)->count(); $completion_count_array[] = '[' . '"' . $v . '",' . $target_count . ']'; } $this->completion_count = implode(',', $completion_count_array); $role_id_array = array(); if ($role_id == "all") { if ($department_id != "all") { if (session('?admin')) { $roleList = M('role')->where('user_id <> 0')->getField('role_id', true); } else { $roleList = getRoleByDepartmentId($department_id); } //$roleList = getRoleByDepartmentId($department_id); foreach ($roleList as $v) { $role_id_array[] = $v; } } else { $role_id_array = getSubRoleId(); } } else { $role_id_array[] = $role_id; } if ($start_time) { $create_time = array(array('lt', $end_time), array('gt', $start_time), 'and'); } else { $create_time = array('lt', $end_time); } $own_count_total = 0; $new_count_total = 0; $late_count_total = 0; $deal_count_total = 0; $success_count_total = 0; $busi_customer_array = M('Business')->getField('customer_id', true); $busi_customer_id = implode(',', $busi_customer_array); foreach ($role_id_array as $v) { $user = getUserByRoleId($v); $owner_role_id = array('like', '%,' . $v . ',%'); $own_count = $m_task->where(array('is_deleted' => 0, 'isclose' => 0, 'owner_role_id' => $owner_role_id, 'create_date' => $create_time))->count(); $new_count = $m_task->where(array('is_deleted' => 0, 'isclose' => 0, 'status' => L('NOT_START'), 'owner_role_id' => $owner_role_id, 'create_date' => $create_time))->count(); $late_count = $m_task->where(array('is_deleted' => 0, 'isclose' => 0, 'status' => L('DELAY'), 'owner_role_id' => $owner_role_id, 'create_date' => $create_time))->count(); $deal_count = $m_task->where(array('is_deleted' => 0, 'isclose' => 0, 'status' => L('ONGOING'), 'owner_role_id' => $owner_role_id, 'create_date' => $create_time))->count(); $success_count = $m_task->where(array('is_deleted' => 0, 'isclose' => 0, 'status' => L('COMPLETE'), 'owner_role_id' => $owner_role_id, 'create_date' => $create_time))->count(); $reportList[] = array("user" => $user, "new_count" => $new_count, "late_count" => $late_count, "own_count" => $own_count, "success_count" => $success_count, "deal_count" => $deal_count); $late_count_total += $late_count; $own_count_total += $own_count; $success_count_total += $success_count; $deal_count_total += $deal_count; $new_count_total += $new_count; } $this->total_report = array("new_count" => $new_count_total, "late_count" => $late_count_total, "own_count" => $own_count_total, "success_count" => $success_count_total, "deal_count" => $deal_count_total); $this->reportList = $reportList; if (session('?admin')) { $idArray = M('role')->where('user_id <> 0')->getField('role_id', true); } else { $idArray = getSubRoleId(); } //$idArray = getSubRoleId(); $roleList = array(); foreach ($idArray as $roleId) { $roleList[$roleId] = getUserByRoleId($roleId); } $this->roleList = $roleList; $departments = M('roleDepartment')->select(); $department_id = D('RoleView')->where('role.role_id = %d', session('role_id'))->getField('department_id'); $departmentList[] = M('roleDepartment')->where('department_id = %d', $department_id)->find(); $departmentList = array_merge($departmentList, getSubDepartment($department_id, $departments, '')); $this->assign('departmentList', $departmentList); $this->display(); }
public function mylog_edit() { if ($_GET['id']) { $log_id = $_GET['id']; $m_log = M('Log'); $log = $m_log->where('log_id = %d', $_GET['id'])->find(); //Log related Module $m_customer = M('Customer'); $m_r_customer_log = M('RCustomerLog'); $m_contacts = M('Contacts'); $m_r_contacts_log = M('RContactsLog'); $m_business = M('Business'); $m_r_business_log = M('RBusinessLog'); $m_task = M('Task'); $m_r_task_log = M('RLogTask'); $m_event = M('Event'); $m_r_event_log = M('REventLog'); $m_leads = M('Leads'); $m_r_leads_log = M('RLeadsLog'); $r_customer_log = $m_r_customer_log->where('log_id = %d', $log_id)->find(); if (!empty($r_customer_log)) { $customer = $m_customer->where('customer_id = %d', $r_customer_log['customer_id'])->find(); $log['customer_id'] = $customer['customer_id']; $log['customer_name'] = $customer['name']; } $r_contacts_log = $m_r_contacts_log->where('log_id = %d', $log_id)->find(); if (!empty($r_contacts_log)) { $contacts = $m_contacts->where('contacts_id = %d', $r_contacts_log['contacts_id'])->find(); $log['contacts_id'] = $contacts['contacts_id']; $log['contacts_name'] = $contacts['name']; } $r_business_log = $m_r_business_log->where('log_id = %d', $log_id)->find(); if (!empty($r_business_log)) { $business = $m_business->where('business_id = %d', $r_business_log['business_id'])->find(); $log['business_id'] = $business['business_id']; $log['business_name'] = $business['name']; } $r_task_log = $m_r_task_log->where('log_id = %d', $log_id)->find(); if (!empty($r_task_log)) { $task = $m_task->where('task_id = %d', $r_task_log['task_id'])->find(); $log['task_id'] = $task['task_id']; $log['task_name'] = $task['subject']; } $r_event_log = $m_r_event_log->where('log_id = %d', $log_id)->find(); if (!empty($r_event_log)) { $event = $m_event->where('event_id = %d', $r_event_log['event_id'])->find(); $log['event_id'] = $event['event_id']; $log['event_name'] = $event['subject']; } $r_leads_log = $m_r_leads_log->where('log_id = %d', $log_id)->find(); if (!empty($r_leads_log)) { $leads = $m_leads->where('leads_id = %d', $r_leads_log['leads_id'])->find(); $log['leads_id'] = $leads['leads_id']; $log['leads_name'] = $leads['name']; } if (in_array($log['role_id'], getSubRoleId(false))) { if (!($log['comment_role_id'] > 0)) { $this->comment_role_id = session('role_id'); } } $this->log = $log; $this->alert = parseAlert(); $this->display(); } elseif ($_POST['submit']) { $log = M('Log'); $log->create(); $log->update_date = time(); if ($log->save()) { alert('success', L('EDIT_LOG_SUCCESS'), U('log/mylog_view', 'id=' . $_POST['log_id'])); } else { alert('error', L('EDIT_LOG_FAILED'), $_SERVER['HTTP_REFERER']); } } }
/** * 动态首页 * **/ public function index() { $m_action_log = M('actionLog'); $m_comment = M('comment'); $where = array(); //查询条件 $where['action_delete'] = 0; $opeartion = 'view'; //默认都跳转到view界面 $p = isset($_GET['p']) ? intval($_GET['p']) : 1; $by = isset($_GET['by']) ? trim($_GET['by']) : ''; $reply = isset($_GET['reply']) ? trim($_GET['reply']) : ''; //module=log时,module_id为log表的log_id; module为dynamic时,module_id为action_log表的log_id //查询我的任务 $what['_string'] = 'about_roles like "%,' . session('role_id') . ',%" OR owner_role_id like "%,' . session('role_id') . ',%"'; $what['is_deleted'] = 0; $what['isclose'] = 0; $task_count = M('task')->where($what)->count(); //查看我的日程 $event_count = M('event')->where('owner_role_id = "%s" and isclose = 0 and is_deleted = 0', session('role_id'))->count(); switch ($by) { case 'log': $where['module_name'] = array('eq', 'log'); break; case 'crm': $where['module_name'] = array('neq', 'log'); break; } switch ($reply) { case 'tome': //回复我的 if ($by == 'log') { //如果是日志,查action_id $module_idArr = $m_comment->group('module_id')->where('to_role_id = %d and module = "%s"', session('role_id'), 'log')->order('create_time desc')->getField('module_id', true); $where['action_id'] = array('in', $module_idArr); } elseif ($by == '') { //如果为空,先查log,根据comment表的molule_id查到action_log表的action_id对应的log_id,再查动态,根据comment表的module_id,查到action_log表的log_id $log_idArr = $m_comment->group('module_id')->where('to_role_id = %d and module = "%s"', session('role_id'), 'log')->order('create_time desc')->getField('module_id', true); //comment 表的 module_id $module_idArrA = $m_action_log->group('action_id')->where(array('action_id' => array('in', $log_idArr), 'module_name' => 'log', 'action_delete' => 0))->getField('log_id', true); //module=log时,根据module_id对应action_log表的action_id查到的action_log表的log_id $module_idArrB = $m_comment->where('to_role_id = %d and module <> "%s"', session('role_id'), 'log')->group('module_id')->order('create_time desc')->getField('module_id', true); //module!=log时,根据module_id对应action_log表的log_id获取到action_log表的log_id empty($module_idArrA) ? $module_idArrA = array() : ($module_idArrA = $module_idArrA); empty($module_idArrB) ? $module_idArrB = array() : ($module_idArrB = $module_idArrB); $log_id = array_merge($module_idArrA, $module_idArrB); $where['log_id'] = array('in', $log_id); } else { $module_idArr = $m_comment->group('module_id')->where('to_role_id = %d and module <> "%s"', session('role_id'), 'log')->order('create_time desc')->getField('module_id', true); $where['log_id'] = array('in', $module_idArr); } break; case 'toother': //我回复的 if ($by == 'log') { //如果是日志,查action_id $module_idArr = $m_comment->group('module_id')->where('creator_role_id = %d and module = "%s"', session('role_id'), 'log')->order('create_time desc')->getField('module_id', true); $where['action_id'] = array('in', $module_idArr); } elseif ($by == '') { //如果为空,先查log,根据comment表的molule_id查到action_log表的action_id对应的log_id,再查动态,根据comment表的module_id,查到action_log表的log_id $log_idArr = $m_comment->group('module_id')->where('creator_role_id = %d and module = "%s"', session('role_id'), 'log')->order('create_time desc')->getField('module_id', true); //comment 表的 module_id $module_idArrA = $m_action_log->group('action_id')->where(array('action_id' => array('in', $log_idArr), 'module_name' => 'log', 'action_delete' => 0))->getField('log_id', true); //module=log时,根据module_id对应action_log表的action_id查到的action_log表的log_id $module_idArrB = $m_comment->where('creator_role_id = %d and module <> "%s"', session('role_id'), 'log')->group('module_id')->order('create_time desc')->getField('module_id', true); //module!=log时,根据module_id对应action_log表的log_id查到的action_log表的log_id empty($module_idArrA) ? $module_idArrA = array() : ($module_idArrA = $module_idArrA); empty($module_idArrB) ? $module_idArrB = array() : ($module_idArrB = $module_idArrB); $log_id = array_merge($module_idArrA, $module_idArrB); $where['log_id'] = array('in', $log_id); } else { $module_idArr = $m_comment->group('module_id')->where('creator_role_id = %d and module <> "%s"', session('role_id'), 'log')->order('create_time desc')->getField('module_id', true); $where['log_id'] = array('in', $module_idArr); } break; } if (!empty($reply)) { $params[] = "reply=" . trim($_GET['reply']); } if ($_GET['department_id']) { $department_id = intval($_GET['department_id']); //选中部门下的所有员工 $subPositionIdArr = M('position')->where('department_id = %d', $department_id)->order('position_id asc')->getField('position_id', true); $subRoleIdArr = M('role')->where(array('position_id' => array('in', $subPositionIdArr)))->getField('role_id', true); //部门下role_id if (!session('admin')) { //条件为选中部门下,我的下属员工的role_id $mySubRoleIdArr = getSubRoleId(); //我的下属role_id $where['role_id'] = array('in', array_intersect($subRoleIdArr, $mySubRoleIdArr)); } else { $where['role_id'] = array('in', $subRoleIdArr); } } else { //条件为选中部门下,我的下属员工的role_id if (!session('?admin')) { $where['role_id'] = array('in', getSubRoleId()); } } if ($_REQUEST["field"]) { $field = trim($_REQUEST['field']); $search = empty($_REQUEST['search']) ? '' : trim($_REQUEST['search']); if ($field == 'role') { if (!empty($search)) { $same_role_id_array = M('user')->where('name like "%s"', "%{$search}%")->getField('role_id', true); $role_id_array = getSubRoleId(true, 1); //下属role_id $role_idArr = array_intersect($same_role_id_array, $role_id_array); //交集 $where['role_id'] = array('in', $role_idArr); } } elseif ($field == 'content') { $where['content'] = array('like', "%{$search}%"); } $params = array('field=' . trim($_REQUEST['field']), 'search=' . $search); } $action_log = $m_action_log->where($where)->page($p . ',5')->order('create_time desc')->select(); $count = $m_action_log->where($where)->count(); import("@.ORG.Page"); $Page = new Page($count, 5); if (!empty($_GET['by'])) { $params[] = "by=" . trim($_GET['by']); } foreach ($action_log as $k => $v) { if ($v['module_name'] == 'finance') { $module_name = substr($v['param_name'], 2); } else { $module_name = $v['module_name']; } $m_module_name = M($module_name); $pk_id = $m_module_name->getPk(); $object_module = $m_module_name->where("{$pk_id} = %d", $v['action_id'])->find(); $name = $object_module['name']; if (empty($name)) { $name = $object_module['subject']; } //如果是日志,则追加日志内容 if ($v['action_name'] == 'mylog_add') { $apContent = $object_module['content']; $appHtml = '<p>' . $apContent . '</p>'; //如果是日志,则跳转到mylog_view $action_name = 'mylog_view'; } else { $appHtml = ''; $action_name = strtolower($v['action_name']); } $action_log[$k]['creator'] = getUserByRoleId($v['role_id']); $username = $action_log[$k]['creator']['user_name']; $operation = L(strtolower($v['action_name'])) . L('THE_IS'); $module = L(strtolower($v['module_name'])); $action_log[$k]['dynamic'] = $username . ' ' . $operation . $module . ' - <a href="./index.php?m=' . $v[module_name] . '&a=' . $action_name . '&' . $param_name . '&id=' . $v[action_id] . '">' . $name . '</a>' . $appHtml; //查评论 //如果是评论日志,则从操作日志表中根据action_id查找,否则根据操作日志表的log_id查找 if ($v['module_name'] == 'log') { $comment = $m_comment->where('module = "%s" and module_id = %d', 'log', $v['action_id'])->order('create_time desc')->limit(0, 5)->select(); $comment_count = $m_comment->where('module = "%s" and module_id = %d', 'log', $v['action_id'])->order('create_time desc')->count(); } else { $comment = $m_comment->where('module = "%s" and module_id = %d', 'dynamic', $v['log_id'])->order('create_time desc')->limit(0, 5)->select(); $comment_count = $m_comment->where('module = "%s" and module_id = %d', 'dynamic', $v['log_id'])->order('create_time desc')->count(); } //$comment = $m_comment->where('(module = "%s" or module = "%s") and module_id = %d','log', 'dynamic', $v['log_id'])->order('create_time desc')->select(); foreach ($comment as $key => $val) { $comment[$key]['comment_role'] = getUserByRoleId($val['creator_role_id']); } $action_log[$k]['comment'] = $comment; $action_log[$k]['comment_count'] = $comment_count; $action_log[$k]['comment_left_count'] = intval($comment_count) - 5; } $this->parameter = implode('&', $params); $this->actionLog = $action_log; $this->event_count = $event_count; $this->task_count = $task_count; $this->userInfo = getUserByRoleId(session('role_id')); $this->department = getSubDepartment2(0, M('roleDepartment')->select()); $show = $Page->show(); $this->page = $show; $this->alert = parseAlert(); $this->display(); }
public function excelExport($eventList = false) { import("ORG.PHPExcel.PHPExcel"); $objPHPExcel = new PHPExcel(); $objProps = $objPHPExcel->getProperties(); $objProps->setCreator("5kcrm"); $objProps->setLastModifiedBy("5kcrm"); $objProps->setTitle("5kcrm Event Data"); $objProps->setSubject("5kcrm Event Data"); $objProps->setDescription("5kcrm Event Data"); $objProps->setKeywords("5kcrm Event Data"); $objProps->setCategory("Event"); $objPHPExcel->setActiveSheetIndex(0); $objActSheet = $objPHPExcel->getActiveSheet(); $objActSheet->setTitle('Sheet1'); $objActSheet->setCellValue('A1', L('THEME')); $objActSheet->setCellValue('B1', L('PLACE')); $objActSheet->setCellValue('C1', L('OWNER_ROLE')); $objActSheet->setCellValue('D1', L('START_TIME')); $objActSheet->setCellValue('E1', L('END_TIME')); $objActSheet->setCellValue('F1', L('WHETHER_TO_SEND_A_NOTIFICATION_EMAIL')); $objActSheet->setCellValue('G1', L('CONTENT')); $objActSheet->setCellValue('H1', L('CREATOR_ROLE')); $objActSheet->setCellValue('I1', L('CREATE_TIME')); if (is_array($eventList)) { $list = $eventList; } else { $where['owner_role_id'] = array('in', implode(',', getSubRoleId())); $where['is_deleted'] = 0; $list = M('event')->where($where)->select(); } $i = 1; foreach ($list as $k => $v) { $i++; $creator = D('RoleView')->where('role.role_id = %d', $v['creator_role_id'])->find(); $owner = D('RoleView')->where('role.role_id = %d', $v['owner_role_id'])->find(); $objActSheet->setCellValue('A' . $i, $v['subject']); $objActSheet->setCellValue('B' . $i, $v['venue']); $objActSheet->setCellValue('C' . $i, $owner['user_name'] . '[' . $owner['department_name'] . '-' . $owner['role_name'] . ']'); $v['start_date'] == 0 || strlen($v['start_date']) != 10 ? '' : $objActSheet->setCellValue('D' . $i, date("Y-m-d", $v['start_date'])); $v['end_date'] == 0 || strlen($v['end_date']) != 10 ? '' : $objActSheet->setCellValue('E' . $i, date("Y-m-d", $v['end_date'])); $v['send_email'] == 0 ? $objActSheet->setCellValue('F' . $i, L('NO')) : $objActSheet->setCellValue('F' . $i, L('YES')); $objActSheet->setCellValue('G' . $i, $v['description']); $objActSheet->setCellValue('H' . $i, $creator['user_name'] . '[' . $creator['department_name'] . '-' . $creator['role_name'] . ']'); $objActSheet->setCellValue('I' . $i, date("Y-m-d H:i:s", $v['create_date'])); } $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); ob_end_clean(); header("Content-Type: application/vnd.ms-excel;"); header("Content-Disposition:attachment;filename=5kcrm_event_" . date('Y-m-d', mktime()) . ".xls"); header("Pragma:no-cache"); header("Expires:0"); $objWriter->save('php://output'); }
public function sendemail() { if ($this->isPost()) { if (!($smtp = M('UserSmtp')->where('smtp_id = %d', intval($_POST['smtp']))->find())) { alert('error', L('NEED_SET_SMTP'), $_SERVER['HTTP_REFERER']); } import('@.ORG.Mail'); $emails = trim($_POST['emails']); $title = trim($_POST['title']); $content = trim($_POST['content']); $url = $this->_server('HTTP_HOST'); preg_match_all('/<a(.*?)href="(\\/Uploads.+?)">(.*?)<\\/a>/i', $content, $str_array); foreach ($str_array as $v) { $content = str_replace($str_array[0], '', $content); } $fail_array = array(); $success_array = array(); $emails = str_replace(" ", "", $emails); $emails_array = explode(chr(10), $emails); if ($emails && $content && $title) { foreach ($emails_array as $k => $v) { $email = ''; $str_content = ''; $email_array = array(); if ($v) { if (strpos($v, ',') !== false || strpos($v, ',') !== false) { $email_array = strpos($v, ',') ? explode(',', $v) : explode(',', $v); $email = trim($email_array[0]); $str_content = str_replace('{name}', $email_array[1], $content); } else { $email = trim($v); $str_content = $content; } $str_content = strpos($content, '{name}') !== false ? str_replace('{name}', $email_array[1], $content) : $content; if (is_email($email)) { $old_array[$email] = $v; $success_array[] = array('email' => $email, 'content' => $str_content); } else { $fail_array[] = $v; } } } if (!empty($fail_array)) { $fail_message = L('INVALIDATE_EMAIL') . implode(',', $fail_array); } $i = 0; foreach ($success_array as $value) { $result = bsendemail($value['email'], $title, $value['content'], $str_array[3], true, intval($_POST['smtp'])); if ($result) { $i++; } else { $fail_result .= L('SEND_FAILED_UNKNOWN_REASON', array($old_array[$value['email']])); } } if ($i > 0) { alert('success', L('SEND_SUCCESS_MAY_DELAY_BY_BAD_NETWORK') . $fail_message . '<br>' . $fail_result, $_SERVER['HTTP_REFERER']); } else { alert('error', L('SEND_FAILED_CONTACTS_ADMIN') . $fail_message . '<br>' . $fail_result, $_SERVER['HTTP_REFERER']); } } else { alert('error', L('INCOMPLETE_INFO'), $_SERVER['HTTP_REFERER']); } } else { $model = trim($_GET['model']); if ($model == 'customer') { $customer_ids = trim($_GET['customer_ids']); if ($customer_ids) { if ($customer_ids == 'all') { $all_ids = getSubRoleId(); $where['is_deleted'] = array('neq', 1); $where['owner_role_id'] = array('in', $all_ids); $customer_ids = D('CustomerView')->where($where)->getField('customer_id', true); $contacts_ids = M('RContactsCustomer')->where('customer_id in (%s)', implode(',', $customer_ids))->getField('contacts_id', true); $contacts_ids = implode(',', $contacts_ids); $contacts = D('ContactsView')->where('contacts.contacts_id in (%s)', $contacts_ids)->select(); } else { $contacts_ids = M('RContactsCustomer')->where('customer_id in (%s)', $customer_ids)->getField('contacts_id', true); $contacts_ids = implode(',', $contacts_ids); $contacts = D('ContactsView')->where('contacts.contacts_id in (%s)', $contacts_ids)->select(); } $this->contacts = $contacts; } else { alert('error', L('SELECT_CUSTOMER_TO_SEND_EMAIL'), $_SERVER['HTTP_REFERER']); } } elseif ($model == 'contacts') { $contacts_ids = trim($_GET['contacts_ids']); if (!$contacts_ids) { alert('error', L('SELECT_CONTACTS_TO_SEND_EMAIL'), $_SERVER['HTTP_REFERER']); } $contacts = D('ContactsView')->where('contacts.contacts_id in (%s)', $contacts_ids)->select(); $this->contacts = $contacts; } elseif ($model == 'leads') { $d_v_leads = D('LeadsView'); $leads_ids = trim($_GET['leads_ids']); if ('all' != $leads_ids) { $where['leads_id'] = array('in', $leads_ids); } $customer_list = $d_v_leads->where($where)->select(); $contacts = array(); foreach ($customer_list as $k => $v) { $contacts[] = array('name' => $v['contacts_name'], 'customer_name' => $v['name'], 'email' => trim($v['email'])); } $this->contacts = $contacts; } $this->templateList = M('EmailTemplate')->order('order_id')->select(); $this->smtpList = M('UserSmtp')->select(); $this->alert = parseAlert(); $this->display(); } }