/** * * @param array $args * project * message * @return array */ function getList($args = array()) { if (isset($args['project'])) { $this->db->join('project_document', "project_document.document = document.id AND project_document.project = {$args['project']}", 'inner'); } if (isset($args['message'])) { $this->db->join('message_document', "message_document.document = document.id AND message_document.message = {$args['message']}", 'inner'); } return parent::getList($args); }
function getList(array $args = array()) { $args['company'] = $args['display'] = false; return parent::getList($args); }
/** * 继承自SS_Model::getList(),具有基本的type,label,orderby和limit配置功能 * @param array $args: * name string 匹配部分people.name, people.abbreviation, people.name_en * * is_team=>bool * * in_project int 只获得指定事务中的人员列表 * project_people_type 指定事务,特定关联类型 * project_people_role 指定事务,特定角色 * * in_same_project_with, int or array, people.id 有相同的相关案件的人员 * * is_staff * * 人员 - 人员关系查找 * 直接关系 * is_relative_of =>user_id people_relationship 人员关联,根据本人获得相关人 * has_relative_like => user_id people_relationship 人员关联,根据相关人获得本人 * 间接关系 * is_secondary_relative_of 右侧相关人的右侧相关人 * ~_team bool 中间相关人是团队,下同 * is_both_relative_with 右侧相关人的左侧相关人 * ~_team * has_common_relative_with 左侧相关人的右侧相关人 * ~_team * has_secondary_relative_like 左侧相关人的左侧相关人 * ~_team * * 团队 - 人员关系查找 * in_team => array or int, is_relative_of的别名 * team_leader_of => array or int team(s) * */ function getList($args = array()) { $this->db->select(' people.id,people.type,people.name,people.phone,people.email, IF(people.abbreviation IS NULL,people.name,people.abbreviation) AS abbreviation, people.uid,people.time,people.time_insert ', false); if (isset($args['name'])) { $args['name'] = $this->db->escape_like_str($args['name']); $this->db->where("(people.name LIKE '%{$args['name']}%' \tOR people.abbreviation LIKE '%{$args['name']}%' OR people.name_en LIKE '%{$args['name']}%')", NULL, false); unset($args['name']); } if (isset($args['is_team'])) { if ($args['is_team']) { $this->db->where("people.id IN (SELECT id FROM people INNER JOIN team USING (id) WHERE people.company = {$this->company->id})", NULL, false); } else { $this->db->where("people.id NOT IN (SELECT id FROM people INNER JOIN team USING (id) WHERE people.company = {$this->company->id})", NULL, false); } } if (isset($args['in_project'])) { $this->db->select('project_people.id AS relationship_id,GROUP_CONCAT(project_people.role) AS role, project_people.weight', false)->join('project_people', "project_people.people = people.id AND project_people.project{$this->db->escape_int_array($args['in_project'])}", 'inner')->group_by('project_people.people'); if (isset($args['project_people_type'])) { $this->db->where('project_people.type', $args['project_people_type']); } if (isset($args['project_people_role'])) { $this->db->where('project_people.role', $args['project_people_role']); } } if (isset($args['in_same_project_with'])) { $this->db->where("\n\t\t\t\tpeople.id IN (\n\t\t\t\t\tSELECT people FROM project_people WHERE `project` IN (\n\t\t\t\t\t\tSELECT `project` FROM project_people WHERE people{$this->db->escape_int_array($args['in_same_project_with'])}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t", NULL, false); } if (isset($args['in_team'])) { $args['is_relative_of'] = $args['in_team']; unset($args['in_team']); } if (isset($args['is_staff'])) { if ($args['is_staff']) { $this->db->join('staff', 'staff.id = people.id', 'inner'); } else { $this->db->where('people.id NOT IN (SELECT id FROM staff)'); } } if (isset($args['team_leader_of'])) { $this->db->where("people.id IN (SELECT leader FROM team WHERE id " . $this->db->escape_int_array($args['team_leader_of']) . ")", NULL, false); } if (isset($args['is_relative_of'])) { $this->db->join("people_relationship", "people.id = people_relationship.relative AND people_relationship.people{$this->db->escape_int_array($args['is_relative_of'])}", 'inner')->select('people_relationship.relation, people_relationship.accepted, people_relationship.time relationship_time'); if (isset($args['accepted'])) { $this->db->where('people_relationship.accepted', $args['accepted']); } if (isset($args['is_on'])) { $this->db->where('people_relationship.is_on', $args['is_on']); } } if (isset($args['has_relative_like'])) { $this->db->join('people_relationship', "people.id = people_relationship.people AND people_relationship.relative{$this->db->escape_int_array($args['has_relative_like'])}", 'inner')->select('people_relationship.relation, people_relationship.accepted, people_relationship.time relationship_time'); if (isset($args['accepted'])) { $this->db->where('people_relationship.accepted', $args['accepted']); } if (isset($args['is_on'])) { $this->db->where('people_relationship.is_on', $args['is_on']); } } if (isset($args['is_secondary_relative_of'])) { $this->db->where("people.id IN (SELECT relative FROM people_relationship WHERE people IN (SELECT relative FROM people_relationship" . (empty($args['is_secondary_relative_of_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.relative') . " WHERE people{$this->db->escape_int_array($args['is_secondary_relative_of'])}))"); } if (isset($args['is_both_relative_with'])) { $this->db->where("people.id IN (SELECT relative FROM people_relationship WHERE people IN (SELECT people FROM people_relationship" . (empty($args['is_both_relative_with_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.people') . " WHERE relative{$this->db->escape_int_array($args['is_both_relative_with'])}))"); } if (isset($args['has_common_relative_with'])) { $this->db->where("people.id IN (SELECT people FROM people_relationship WHERE relative IN (SELECT relative FROM people_relationship" . (empty($args['has_common_relative_with_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.relative') . " WHERE people{$this->db->escape_int_array($args['has_common_relative_with'])}))"); } if (isset($args['has_secondary_relative_like'])) { $this->db->where("people.id IN (SELECT people FROM people_relationship WHERE relative IN (SELECT people FROM people_relationship" . (empty($args['has_secondary_relative_like_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.people') . " WHERE relative{$this->db->escape_int_array($args['has_secondary_relative_like'])}))"); } return parent::getList($args); }
/** * @param array $args * name: 帐目摘要 * received: 是否到帐 * reviewed: 已审核 * count: 计入创收 * project: 指定项目id * project_labels * project_without_labels * project_is_active * show_payer: 获得付款人信息payer, payer_name * date: (预估)到账日期 * array( * from=>日期字符串 * to=>日期字符串 * ) * contract_date: 签约日期 * array( * from=>日期字符串 * to=>日期字符串 * ) * group_by: * account: 根据帐目编号分组并获得帐目中创收金额received, 总额total, receive_date, receivable_date, comment * team: 根据团组分组并获得team_name, team * people: 根据项目人员分组并获得people_name, people,role,type * month: 根据收款月份分组并获得month * month_contract: 根据签约月份分组并获得month * team: 团队 * people: 指定项目人员 * role: 指定项目人员角色(需配合group:people或people) * account: 指定帐目编号 * sum: 获得amount求和,此操作将使除group获得的其他值失去意义 * @return array */ function getList(array $args = array()) { $this->db->select('account.*')->join('project', 'project.id = account.project', 'LEFT'); if (isset($args['received'])) { $this->db->where('account.received', (bool) intval($args['received'])); } if (isset($args['project'])) { $this->db->where('project', $args['project']); } if (isset($args['project_labels'])) { foreach ($args['project_labels'] as $id => $label_name) { $this->db->join("project_label t_{$id}", "account.project = t_{$id}.project AND t_{$id}.label_name = '{$label_name}'", 'inner'); } } if (isset($args['project_without_labels'])) { foreach ($args['project_without_labels'] as $id => $label_name) { $this->db->where("account.project NOT IN (SELECT project FROM project_label WHERE label_name = '{$label_name}')"); } } if (isset($args['project_is_active'])) { $this->db->where('project.active', (bool) $args['project_is_active']); } if (isset($args['show_project'])) { $this->db->select('project.id project, project.type project_type, project.name project_name'); if (isset($args['project_name'])) { $this->db->like('project.name', $args['project_name']); } } if (isset($args['show_payer'])) { $this->db->join('people payer', "payer.id = account.people", 'left')->select('IF(payer.abbreviation IS NULL, payer.name, payer.abbreviation) AS payer_name,payer.id AS payer', false); if (isset($args['payer_name'])) { $this->db->like('payer.name', $args['payer_name']); } } if (isset($args['show_account'])) { $this->db->join('account a', 'a.id = account.account', 'inner')->select('a.name AS name, a.type AS type'); } foreach (array('date', 'contract_date') as $date_args) { if (!isset($args[$date_args])) { $args[$date_args] = array_prefix($args, $date_args); } } if (isset($args['date']['from']) && $args['date']['from']) { $this->db->where("TO_DAYS(account.date) >= TO_DAYS('{$args['date']['from']}')", NULL, FALSE); } if (isset($args['date']['to']) && $args['date']['to']) { $this->db->where("TO_DAYS(account.date) <= TO_DAYS('{$args['date']['to']}')", NULL, FALSE); } if (isset($args['contract_date']['from']) && $args['contract_date']['from']) { $this->db->where("TO_DAYS(project.time_contract) >= TO_DAYS('{$args['contract_date']['from']}')", NULL, FALSE); } if (isset($args['contract_date']['to']) && $args['contract_date']['to']) { $this->db->where("TO_DAYS(project.time_contract) <= TO_DAYS('{$args['contract_date']['to']}')", NULL, FALSE); } if (isset($args['team'])) { $team = intval($args['team']); $this->db->where('account.team', $team); } if (isset($args['people'])) { $people = intval($args['people']); $this->db->join('project_people', "project_people.project = project.id AND project_people.people = {$people}", 'inner'); if (isset($args['role'])) { $this->db->select('weight', false); if (is_array($args['role'])) { $this->db->where_in('project_people.role', $args['role']); } else { $this->db->where('project_people.role', $args['role']); } } } if (isset($args['account'])) { $account = intval($args['account']); $this->db->where('account.account', $account); } if (isset($args['amount'])) { $this->db->where('account.amount', $args['amount']); } if (isset($args['reviewed'])) { $this->db->where('account.received', (bool) intval($args['reviewed'])); } if (isset($args['count'])) { $this->db->where('account.count', (bool) intval($args['count'])); unset($args['count']); } if (isset($args['group_by'])) { if ($args['group_by'] === 'account') { $this->db->group_by('account.account')->select(' MAX(account.type) AS type, SUM(IF(account.received,account.amount,0)) AS received_amount, SUM(IF(account.received,0,account.amount)) AS total_amount, SUM(IF(account.received,0,account.amount)) - SUM(IF(account.received,account.amount,0)) AS receivable_amount, MAX(IF(account.received,account.date,NULL)) AS received_date, MAX(IF(account.received,NULL,account.date)) AS receivable_date, GROUP_CONCAT(account.comment) AS comment ', false); } elseif ($args['group_by'] === 'team') { $this->db->group_by('account.team')->join('team', 'team.id = account.team', 'inner')->select('team.name AS team_name, team.id AS team'); } elseif ($args['group_by'] === 'people') { if ($args['role']) { $this->db->join('project_people', 'project_people.project = account.project', 'inner')->select('project_people.role, project_people.weight, account.amount * project_people.weight `amount`', false); if (is_array($args['role'])) { $this->db->where_in('project_people.role', $args['role']); } else { $this->db->where('project_people.role', $args['role']); } } else { $this->db->join('project_people', 'project_people.project = account.project', 'inner'); } $this->db->join('people', 'people.id = project_people.people', 'inner')->group_by('project_people.people')->select('people.name AS people_name, people.id AS people'); } elseif ($args['group_by'] === 'month') { $this->db->group_by('LEFT(account.date,7)', false)->order_by('month')->select('LEFT(account.date,7) AS month', false); } elseif ($args['group_by'] === 'month_contract') { $this->db->group_by('LEFT(project.time_contract,7)', false)->order_by('month')->select('LEFT(project.time_contract,7) AS month', false); } elseif ($args['group_by'] === 'project') { $this->db->group_by('account.project')->select('account.project'); } if (isset($args['having'])) { $this->db->having($args['having']); } } if (isset($args['sum']) && $args['sum'] === true) { array_remove_value($this->db->ar_select, 'account.*'); array_remove_value($this->db->ar_select, '`amount`', true); if (isset($args['role'])) { if (isset($args['ten_thousand_unit']) && $args['ten_thousand_unit']) { $this->db->select('ROUND(SUM(account.amount * weight)/1E4,1) `sum`', false); } else { $this->db->select('ROUND(SUM(account.amount * weight)) `sum`', false); } } else { if (isset($args['ten_thousand_unit']) && $args['ten_thousand_unit']) { $this->db->select('ROUND(SUM(account.amount)/1E4,1) `sum`', false); } else { $this->db->select('ROUND(SUM(account.amount)) `sum`', false); } } //$this->db->having('sum >',0); } else { if (isset($args['ten_thousand_unit']) && $args['ten_thousand_unit']) { $this->db->select('ROUND(account.amount/1E4,1) `amount`', false); } } return parent::getList($args); }
/** * @param array $args * people * role * num * active * is_relative_of * before * time_contract * from * to * first_contact * from * to * count * group * team * people * role * */ function getList(array $args = array()) { if (isset($args['people'])) { $where = "project.id IN (SELECT project FROM project_people WHERE people{$this->db->escape_int_array($args['people'])}"; if (isset($args['role'])) { $where .= " AND role = '{$args['role']}'"; } $where .= ')'; $this->db->where($where, NULL, FALSE); } if (isset($args['people_is_relative_of'])) { $where = "project.id IN (SELECT project FROM project_people WHERE people IN (SELECT relative FROM people_relationship WHERE people{$this->db->escape_int_array($args['people_is_relative_of'])})"; if (isset($args['role'])) { $where .= " AND role = '{$args['role']}'"; } $where .= ')'; $this->db->where($where, NULL, FALSE); } if (isset($args['people_has_relative_like'])) { $where = "project.id IN (SELECT project FROM project_people WHERE people IN (SELECT people FROM people_relationship WHERE relative{$this->db->escape_int_array($args['people_has_relative_like'])})"; if (isset($args['role'])) { $where .= " AND role = '{$args['role']}'"; } $where .= ')'; $this->db->where($where, NULL, FALSE); } if (isset($args['num'])) { $this->db->like('project.num', $args['num']); } if (isset($args['active'])) { $this->db->where('project.active', (bool) $args['active']); } if (isset($args['is_relative_of'])) { $this->db->select('project.*')->select('relationship.relation')->join('project_relationship relationship', "relationship.relative = project.id", 'inner')->where('relationship.project', intval($args['is_relative_of'])); } if (isset($args['before'])) { $this->db->where('project.id <', $args['before']); } foreach (array('first_contact', 'time_contract', 'end') as $date_field) { if (isset($args[$date_field]['from']) && $args[$date_field]['from']) { $this->db->where("TO_DAYS(project.{$date_field}) >= TO_DAYS('{$args[$date_field]['from']}')", NULL, FALSE); } if (isset($args[$date_field . '/from']) && $args[$date_field . '/from']) { $this->db->where("TO_DAYS(project.{$date_field}) >= TO_DAYS('{$args[$date_field . '/from']}')", NULL, FALSE); } if (isset($args[$date_field]['to']) && $args[$date_field]['to']) { $this->db->where("TO_DAYS(project.{$date_field}) <= TO_DAYS('{$args[$date_field]['to']}')", NULL, FALSE); } if (isset($args[$date_field . '/to']) && $args[$date_field . '/to']) { $this->db->where("TO_DAYS(project.{$date_field}) <= TO_DAYS('{$args[$date_field . '/to']}')", NULL, FALSE); } } if (isset($args['group_by'])) { if ($args['group_by'] === 'team') { $this->db->join('team', 'team.id = project.team', 'inner')->group_by('project.team')->select('team.id `team`, team.name `team_name`'); } if ($args['group_by'] === 'people') { $this->db->join('project_people', 'project_people.project = project.id', 'inner')->join('people', 'people.id = project_people.people', 'inner')->group_by('project_people.people')->select('people.name AS people_name, people.id AS people'); if (isset($args['role'])) { $this->db->where('project_people.role', $args['role']); } } } return parent::getList($args); }
/** * * @param array $args * project: get schedule only under this project * project_type * project_labels: 仅获取带有给定标签的事务的日程 * people: * people_type: * people_labels: 仅获取带有给定标签的人员的相关日程 * group_by * people * in_todo_list 仅在指定people或group_by people的时候有效 * enrolled 仅在指定people或group_by people的时候有效 * completed 仅在指定people或group_by people的时候有效 * time array or boolean 时间段的范围 * false * array( * from=>timestamp/date string/datetime string * to=>timestamp/date string/datetime string * input_format=>timestamp, date(default) * date_form=>mysql date form string, or false (default: '%Y-%m-%d') * ) * in_project_of_people bool * show_creater * show_project * id_in_set * @return array */ function getList(array $args = array()) { $this->db->select('schedule.*'); if (isset($args['project']) && $args['project']) { $this->db->where('schedule.project', $args['project']); } if (isset($args['project_type']) && $args['project_type']) { $this->db->where("schedule.project IN (SELECT id FROM project WHERE type ={$this->db->escape($args['project_type'])} AND company = {$this->company->id} )"); } if (isset($args['project_labels']) && $args['project_labels']) { foreach ($args['project_labels'] as $id => $label_name) { $this->db->join("project_label t_{$id}", "schedule.project = t_{$id}.project AND t_{$id}.label_name = {$this->db->escape($label_name)}", 'inner'); } } //判断需要内联schedule_people表的参数 if (isset($args['people']) || isset($args['people_labels']) || isset($args['group_by']) && $args['group_by'] === 'people') { $this->db->join('schedule_people', 'schedule_people.schedule = schedule.id', 'inner'); } //依赖schedule_people表 //TODO 判断多个人同时属于一个日程,并区分对待人员状态(如统计一个律师对一个客户的时间) if (isset($args['people']) && $args['people']) { $this->db->where('schedule_people.people' . $this->db->escape_int_array($args['people']), NULL, FALSE); } //依赖schedule_people表 if (isset($args['people_type']) && $args['people_type']) { $this->db->where("schedule.id IN (\n\t\t\t\tSELECT schedule FROM schedule_people WHERE people IN (\n\t\t\t\t\tSELECT id FROM people WHERE type = {$this->db->escape($args['people_type'])}\n\t\t\t\t)\n\t\t\t)"); } //依赖schedule_people表 if (isset($args['people_labels']) && $args['people_labels']) { foreach ($args['people_labels'] as $id => $label_name) { $this->db->join("people_label t_{$id}", "schedule_people.people = t_{$id}.people AND t_{$id}.label_name = {$label_name}", 'inner'); } } if (isset($args['group_by'])) { //依赖schedule_people表 //TODO 判断多个人同时属于一个日程,并区分对待人员状态(如统计一个律师对一个客户的时间) if ($args['group_by'] === 'people') { if (isset($args['people_is_staff']) && $args['people_is_staff']) { $this->db->where('schedule_people.people IN (SELECT id FROM staff)', NULL, false); } $this->db->group_by('schedule_people.people')->join('people', 'people.id = schedule_people.people', 'inner')->select('people.id people, people.name people_name'); } } if ((isset($args['people']) || isset($args['group_by']) && $args['group_by'] === 'people') && isset($args['in_todo_list'])) { //依赖人员参数 $this->db->where('schedule_people.in_todo_list', $args['in_todo_list']); } if ((isset($args['people']) || isset($args['group_by']) && $args['group_by'] === 'people') && isset($args['enrolled'])) { //依赖人员参数 $this->db->where('schedule_people.enrolled', $args['enrolled']); } if (isset($args['people']) || isset($args['group_by']) && $args['group_by'] === 'people') { //依赖人员参数 !isset($args['deleted']) && ($args['deleted'] = false); $this->db->where('schedule_people.deleted', $args['deleted']); } if (isset($args['completed'])) { $this->db->where('schedule.completed', $args['completed']); } if (!isset($args['time'])) { $args['time'] = array_prefix($args, 'time'); } if ($args['time']) { if ($args['time'] === false) { $this->db->where(array('schedule.start' => NULL, 'schedule.end' => NULL)); } if (isset($args['time']['from']) && $args['time']['from']) { if (isset($args['time']['input_format']) && $args['time']['input_format'] !== 'timestamp') { $args['time']['from'] = strtotime($args['time']['from']); } $this->db->where('schedule.start >=', $args['time']['from']); } if (isset($args['time']['to']) && $args['time']['to']) { if (isset($args['time']['input_format']) && $args['time']['input_format'] !== 'timestamp') { $args['time']['to'] = strtotime($args['time']['to']); } if (isset($args['time']['input_format']) && $args['time']['input_format'] === 'date') { $args['time']['to'] += 86400; } $this->db->where('schedule.end <', $args['time']['to']); } if (!isset($args['date_form'])) { $args['date_form'] = '%Y-%m-%d'; } if ($args['date_form'] !== false) { $this->db->select(array("FROM_UNIXTIME(schedule.start, '{$args['date_form']}') `start`", "FROM_UNIXTIME(schedule.end, '{$args['date_form']}') `end`", "FROM_UNIXTIME(schedule.deadline, '{$args['date_form']}') `deadline`"), false); } unset($args['time']); } if (isset($args['in_project_of_people']) && $args['in_project_of_people']) { $this->db->where("\n\t\t\t\tschedule.project IN (\n\t\t\t\t\tSELECT project FROM project_people WHERE people{$this->db->escape_int_array($args['in_project_of_people'])}\n\t\t\t\t)", NULL, FALSE); } if (isset($args['show_project']) && $args['show_project']) { $this->db->join('project', 'project.id = schedule.project', 'left')->select('project.name project_name'); } if (isset($args['show_creater']) && $args['show_creater']) { $this->db->join('people creater', 'creater.id = schedule.uid', 'inner')->select('creater.id creater, creater.name creater_name'); } if (isset($args['id_in_set'])) { $args['id_in'] = $args['id_in_set']; if ($args['id_in_set']) { $this->db->order_by("FIELD(schedule.id, " . implode(', ', $args['id_in_set']) . ")", '', false); $args['order_by'] = false; } } if (isset($args['sum']) && $args['sum']) { array_remove_value($this->db->ar_select, 'schedule.*'); array_remove_value($this->db->ar_select, '`deadline`', true); array_remove_value($this->db->ar_select, '`start`', true); array_remove_value($this->db->ar_select, '`end`', true); $this->db->select('SUM(IF(hours_checked IS NULL, hours_own, hours_checked)) sum', false); } $schedules = parent::getList($args); !isset($args['sum']) && array_walk($schedules, function (&$schedule, $index) { if ($schedule['completed']) { $schedule['color'] = '#36C'; } else { if ($schedule['start'] < $this->date->now) { $schedule['color'] = '#555'; } else { $schedule['color'] = '#E35B00'; } } $schedule['all_day'] = (bool) $schedule['all_day']; $schedule['completed'] = (bool) $schedule['completed']; }, $this); return $schedules; }