function sync_event_users() { $current_users = OutboundUsers::GetPartnerUsers(1); $current_users_by_mobile = Utility::AssColumn($current_users, 'mobile'); $users = Users::GetUsers(NULL, 0, 50000); global $g_user_type; global $g_active_status; foreach ($users as $i => $eu) { if (!$current_users_by_mobile[$eu['mobile']]) { $new_id = OutboundUsers::AddCommonUser(1, $eu); $new_ids[] = $new_id; //添加默认标签 if ($eu['user_type'] && $eu['user_type'] !== 'other') { $gid = OutboundUserGroups::AddGroup(1, $g_user_type[$eu['user_type']]); OutboundUserGroups::AddMap($new_id, $gid); } if ($eu['active_status']) { $gid = OutboundUserGroups::AddGroup(1, $g_active_status[$eu['active_status']]); OutboundUserGroups::AddMap($new_id, $gid); } $current_users_by_mobile[$eu['mobile']] = 1; } } return $new_ids; }
protected function UpdateById($args) { $object_id = $args[0]; $metas = $args[1]; $old_data = Utility::AssColumn($this->GetById(array($object_id)), 'meta_key'); foreach ($metas as $k => $v) { if ($v && $v !== $old_data[$k]['meta_value']) { $m = array(); if ($old_data[$k]) { $m['id'] = $old_data[$k]['id']; } $m[$this->_fetch_id_name] = $object_id; $m['meta_key'] = $k; $m['meta_value'] = $v; $new_data[] = $m; } } if (!$new_data) { return; } $mm = D($this->_table_name); foreach ($new_data as $d) { $mm->create($d); $mm->saveOrUpdate(); } return; }
public function getTagsWeight($tag_type) { $sql = 'SELECT tag_id tag_id, name, COUNT(*) count FROM jxdrcms_tag t, jxdrcms_tag_mapping tm WHERE t.id = tm.tag_id and t.type_name = "' . $tag_type . '" GROUP BY tag_id'; $rs = Utility::AssColumn($this->query($sql, true), 'tag_id'); return $rs; }
function _after_select(&$resultSet, $options) { if ($resultSet) { $creator_ids = Utility::GetColumn($resultSet, "create_user_id"); $users = M("Users")->where(array("id" => array("in", $creator_ids)))->select(); $users = Utility::AssColumn($users); foreach ($resultSet as $index => $result) { $resultSet[$index]['create_user_name'] = $users[$result['create_user_id']]['username']; } } return $resultSet; }
public function getQuestionAnswers($cms_user_id = 0, $type_id) { if ($type_id == 1) { $f['recommend_id'] = $cms_user_id; } else { $f['cms_user_id'] = $cms_user_id; } $raw = Utility::AssColumn($this->where($f)->select(), 'question_id'); $questions = D("UserTypeQuestions")->gets($type_id, true); foreach ($questions as $q) { // 如果问题已经被删除,并且没有对应的填写过的答案,忽略之 if ($q['is_deleted'] && !$raw[$q['id']]['answer']) { continue; } $res[$q['question']] = $raw[$q['id']]['answer']; } return $res; }
function render_dialog_edit() { $partner_id = $this->_param("id"); if (!$partner_id) { return; } $partner = D('Partners')->getPartnerById($partner_id, 0); $data['partner'] = $partner; $data['all_tags'] = D('PartnerTags')->getTags($this->login_user['team_id']); $data['tags'] = Utility::AssColumn($partner['tags'], 'partner_tag_id'); $data['title'] = $partner['title']; // var_dump($data); $data['modal_style'] = 'style="width:780px"'; $this->assign($data); $html = $this->fetch('Partner:tag_editor_dialog'); $data = array(array("data" => $html, "type" => "dialog"), array("data" => "dialog_validator()", "type" => "eval")); json($data, "mix"); }
static function GetTag($tagname = 'dochead', $ass = null) { $xml = Config::Instance('xml'); $r = array(); if (!$xml->{$tagname}->item) { return $r; } foreach ($xml->{$tagname}->item as $one) { $attr = $one->attributes(); $pa = array(); foreach ($attr as $k => $v) { $pa[strval($k)] = strval($v); } $r[] = $pa; } if ($ass) { return Utility::AssColumn($r, 'id'); } return $r; }
} Table::Delete('category', $id); option_category($category['zone']); Session::Set('notice', '删除分类成功'); json(null, 'refresh'); } else { if ('teamcoupon' == $action) { need_auth('team'); $team = Table::Fetch('team', $id); team_state($team); if ($team['now_number'] < $team['min_number']) { json('团购未结束或未达到最低成团人数', 'alert'); } /* all orders */ $all_orders = DB::LimitQuery('order', array('condition' => array('team_id' => $id, 'state' => 'pay'))); $all_orders = Utility::AssColumn($all_orders, 'id'); $all_order_ids = Utility::GetColumn($all_orders, 'id'); $all_order_ids = array_unique($all_order_ids); /* all coupon id */ $coupon_sql = "SELECT order_id, count(1) AS count FROM coupon WHERE team_id = '{$id}' GROUP BY order_id"; $coupon_res = DB::GetQueryResult($coupon_sql, false); $coupon_order_ids = Utility::GetColumn($coupon_res, 'order_id'); $coupon_order_ids = array_unique($coupon_order_ids); /* miss id */ $miss_ids = array_diff($all_order_ids, $coupon_order_ids); foreach ($coupon_res as $one) { if ($one['count'] < $all_orders[$one['order_id']]['quantity']) { $miss_ids[] = $one['order_id']; } } $orders = Table::Fetch('order', $miss_ids);
static public function GetDbRowById($table, $ids=array()) { $one = is_array($ids) ? false : true; settype($ids, 'array'); $idstring = join('\',\'', $ids); if(preg_match('/[\s]/', $idstring)) return array(); $q = "SELECT * FROM `{$table}` WHERE id IN ('{$idstring}')"; $r = self::GetQueryResult($q, $one); if ($one) return $r; return Utility::AssColumn($r, 'id'); }
public function getSchoolProjectsBySchoolId($school_id) { $map = D("SchoolProjectMapping")->order('id desc')->getsBySchoolId(intval($school_id)); $f['id'] = array('in', Utility::GetColumn($map, 'project_id')); $projects = Utility::AssColumn(D("Projects")->where($f)->select()); foreach ($map as $k => $v) { $map[$k]['project'] = $projects[$v['project_id']]; } return $map; }
public static function DBFetch($n = null, $ids = array(), $k = 'id', $db = null) { if (empty($ids)) { return array(); } settype($ids, 'array'); $ids = array_values($ids); $ids = array_diff($ids, array(NULL)); if (is_object($db)) { $result = $db->LimitQuery($n, array('condition' => array($k => $ids))); } else { $result = DB::LimitQuery($n, array('condition' => array($k => $ids))); } $result = Utility::AssColumn($result, $k); /* if ( 'id' === $k ) { $key = Memcache::GetObjectKey($n, $ids, $k); $memcache = Memcache::Instance(); foreach( $key AS $id => $c_key ) { if ( isset($result[$id]) ) $memcache->Set($c_key, $result[$id]); } } */ return $result; }
static function GetObject($tablename, $id) { $single = !is_array($id); settype($id, 'array'); $k = array(); foreach ($id as $oid) { $k[] = self::GetObjectKey($tablename, $oid); } $r = Utility::AssColumn(self::Get($k), 'id'); return $single ? array_pop($r) : $r; }
function option_p_category($zone = 'city', $force = false, $all = false) { $cache = $force ? 0 : 86400 * 30; $cates = DB::LimitQuery('category', array('condition' => array('zone' => $zone, 'parent_id is null'), 'order' => 'ORDER BY sort_order DESC, id DESC', 'cache' => $cache)); $cates = Utility::AssColumn($cates, 'id'); return $all ? $cates : Utility::OptionArray($cates, 'id', 'name'); }
private function _handle_upload() { $attachments = $this->_param("attachments"); if ($attachments) { $exists = Utility::AssColumn(D("UserAttachments")->where('user_id=' . intval($this->login_user['id']))->field('path')->select(), 'path'); $attachments = explode('||', $attachments); foreach ($attachments as $attachment) { $attach_info = explode(",", $attachment); if ($exists[$attach_info[0]]) { continue; } $attachment_infos[] = $attach_info; $file = array("path" => $attach_info[0], "title" => $attach_info[1], "size" => $attach_info[2], "create_user_id" => $this->login_user['id'], "user_id" => $this->userinfo['recommend_info']['id'], "create_time" => date('Y-m-d H:i:s'), "type" => 'user', "dir_id" => intval($this->_param('dir_id' . $attach_info[3]))); D("UserAttachments")->add($file); } } return $attachment_infos; }
public static function GetDbRowById($table, $ids = array()) { $one = is_array($ids) ? false : true; settype($ids, 'array'); if (preg_match('/[^\\w\\-\\_]/', implode('', $ids))) { return array(); } $idstring = implode("','", $ids); $q = "SELECT * FROM `{$table}` WHERE id IN ('{$idstring}')"; $r = self::GetQueryResult($q, $one); if ($one) { return $r; } return Utility::AssColumn($r, 'id'); }
function display_tag_filter($tagid_str = NULL) { if (!$tagid_str) { return; } $ids = array_unique(explode('-', $tagid_str)); $tags = Utility::AssColumn(D('PartnerTags')->select(implode(',', $ids))); foreach ($ids as $tid) { $others = array_diff($ids, array($tid)); $map[$tags[$tid]['name']]['other_ids'] = implode('-', $others); $map[$tags[$tid]['name']]['rgb'] = $tags[$tid]['rgb']; } if (!$map) { return; } $str = '<p class="tag-filter">'; foreach ($map as $name => $tag) { $str .= '<a href="/partner?tagid=' . $tag['other_ids'] . '" ><span style="background-color:' . $tag['rgb'] . '" class="label label-info"><span>' . $name . ' | X</span></span></a> '; } $str .= '</p>'; return $str; }
</div> <br /><?php } } ?> </div> </div> <!-- 审核信息 --> <a name="audits"></a> <?php $display_status = D("UserStatuses")->getAuditStatusIdNameMap(); $isAdmin = auditEditable($login_user['role']); $max_audit_status = max(array_keys($display_status)); $tmps = Utility::AssColumn(D("UserAudits")->where('user_id=%d', $user['id'])->order('id desc')->select()); foreach ($tmps as $k => $v) { $audits[$v['status']][] = $v; if ($v['status'] > $max_audit_status) { $max_audit_status = $v['status']; } } $auditing_status = 0; foreach ($display_status as $status => $name) { if ($status > $max_audit_status) { unset($display_status[$status]); } if ($status == $user['status']) { $auditing_status = $active_status = $status; } }
public function GetTagsWeight($team_id) { $sql = 'SELECT partner_tag_id tag_id, name, COUNT(*) count FROM partner_tags t, partner_tag_mapping tm WHERE t.id = tm.partner_tag_id and t.team_id = ' . $team_id . ' GROUP BY partner_tag_id'; $rs = Utility::AssColumn($this->query($sql, true), 'tag_id'); return $rs; }
} if (preg_match('#/city#', $_SERVER['HTTP_REFERER'])) { redirect( 'index.php'); } redirect($_SERVER['HTTP_REFERER']); } redirect('index.php'); } } $cities = DB::LimitQuery('category', array( 'condition' => array( 'zone' => 'city') , )); foreach($cities as &$c){ $daytime = time(); $condition = array( 'city_id' => array(0, abs(intval($c['id']))), "begin_time < {$daytime}", "end_time > {$daytime}", ); $c['team_num'] = Table::Count('team',$condition); } $cities = Utility::AssColumn($cities, 'letter', 'ename'); ksort($cities); $pagetitle = '城市选择'; include template('m_city');
public function getRichInfo($projects, $rich = false) { if (!$projects) { return NULL; } $one = 0; if (!$projects[0]) { $one = $projects['id']; $ps[0] = $projects; $projects = $ps; } $projects = Utility::AssColumn($projects); $ids = array_keys($projects); // $types = M('CommonTypes')->where("`key`='project_type'")->getField('id, name'); // $service_objects = M('CommonTypes')->where("`key`='project_service_object'")->getField('id, name'); // $action_types = M('CommonTypes')->where("`key`='project_action_type'")->getField('id, name'); $statuses = M('ProjectStatuses')->getField('id, name'); foreach ($projects as $k => $v) { $v['link'] = '/project/detail/' . $v['id']; // if($v['address_province']) { // $v['address'] = '【'.$v['address_province'] .'】'. $v['address']; // } // $v['batch'] = D('ProjectBatches')->getById($v['batch_id']); // $v['batch_short_title'] = $v['batch']['short_title']; // if($v['judge1_id']) { // $v['judge_names'] = M('Users')->getFieldById($v['judge1_id'], 'realname'); // } // if($v['judge2_id']) { // $v['judge_names'] .= ',' . M('Users')->getFieldById($v['judge2_id'], 'realname'); // } $v['status_name'] = $statuses[$v['status']]; // $v['manager'] = M('Users')->getById($v['manager_id']); $v['manager_name'] = $v['manager']['realname']; // // $v['partner'] = D('Partners')->getPartnerById($v['partner_id']); // $v['partner_title'] = $v['partner']['title']; //已累计资助额 $f['project_id'] = $v['id']; $f['is_planed'] = 0; $v['had_grant_amount'] = M('ProjectGrantRecords')->where($f)->sum('amount'); $v['grant_amount_ratio'] = '0%'; if ($v['contract_budget']) { $v['grant_amount_ratio'] = moneyit($v['had_grant_amount']) . '(' . intval($v['had_grant_amount'] * 100 / $v['contract_budget']) . '%' . ')'; } //进度 $tmpend = strtotime($v['actual_end_time'] > '1' ? $v['actual_end_time'] : $v['end_time']); $tmpstart = strtotime($v['start_time']); $total = $tmpend - $tmpstart; $already = time() - $tmpstart; if (intval($already) <= 0) { $v['progress'] = 0; } else { $v['progress'] = intval($already * 100 / $total); if ($v['progress'] > 100) { $v['progress'] = 100; } } $v['period_month'] = intval($total / (30 * 24 * 3600)); $tmpend = $v['actual_end_time'] > '1' ? $v['actual_end_time'] : $v['end_time']; $v['period_string'] = str_replace('-', '.', $v['start_time'] . '~' . $tmpend) . '(' . $v['period_month'] . '个月)'; if ($v['actual_end_time'] && $v['actual_end_time'] > $v['end_time']) { $postpone_days = (strtotime($v['actual_end_time']) - strtotime($v['end_time'])) / 3600 / 24; $v['period_string'] .= '<a data-toggle="tooltip" title="项目延期' . $postpone_days . '天,合同结束时间为' . $v['end_time'] . '" class="mytooltip"><i class="icon-exclamation-sign"></i></a>'; } $v['grant_records'] = D('ProjectGrantRecords')->getGrantRecords($v['id']); //detail $v = array_merge($v, D('ProjectDetails')->getById($v['id'])); $v['pm_display_toggle'] = unserialize($v['pm_display_toggle']); $projects[$k] = $v; } if ($one) { return $projects[$one]; } return $projects; }