static function list_rows($condition = array(), $pager = array(), $order = array()) { $sort_field = !in_array($order['sort_field'], array("id")) ? "id" : $order['sort_field']; $table = self::TABLE_REVISIT; $where = 'where 1= 1'; $args = array(); if (!empty($condition['client_id'])) { $where .= " and client_id = ?"; $args[] = $condition['client_id']; } // if(!empty($condition['name'])){ // $where .= " and name like ?"; // $args[] = "%".$condition['name']."%"; // } $sort_type_tpl = array("ascend" => "asc", "descend" => "desc"); $sort_type = !in_array($order['sort_type'], array_keys($sort_type_tpl)) ? "desc" : $sort_type_tpl[$order['sort_type']]; //_throw($sort_type); $count_res = self::_db()->select_row("SELECT COUNT(id) AS total FROM {$table} {$where}", $args); $records = $count_res['total']; $page = $pager['page']; $limit = $pager['limit']; if ($records > 0) { $total_pages = ceil($records / $limit); } else { $total_pages = 1; } $skip = ($page - 1) * $limit; $sql = "SELECT *,id as `key` FROM {$table} {$where} ORDER BY {$sort_field} {$sort_type} LIMIT {$skip},{$limit} "; //_throw($sql); //self::_debug(array($sql,$args,$condition,$pager,$order,$sort_field,$sort_type)); $rows = self::_db()->select_rows($sql, $args); foreach ($rows as &$row) { $op_uid = $row['op_uid']; $staff_info = Model_Admin_Staff::get_staff_info_by_uid_from_cache($op_uid); if ($staff_info) { $row['op_name'] = $staff_info['name']; $row['op_avatar'] = $staff_info['avatar']; } else { $row['op_name'] = ""; $row['op_avatar'] = ""; } } return array("total_pages" => $total_pages, "total" => $records, "rows" => $rows); }
static function list_rows($condition = array(), $pager = array(), $order = array()) { $sort_field = !in_array($order['sort_field'], array("id")) ? "id" : $order['sort_field']; $table = self::TABLE_ORDER; $where = 'where 1= 1'; $args = array(); if (!empty($condition['client_id'])) { $where .= " and client_id = ?"; $args[] = $condition['client_id']; } $sort_type_tpl = array("ascend" => "asc", "descend" => "desc"); $sort_type = !in_array($order['sort_type'], array_keys($sort_type_tpl)) ? "desc" : $sort_type_tpl[$order['sort_type']]; //_throw($sort_type); $count_res = self::_db()->select_row("SELECT COUNT(id) AS total FROM {$table} {$where}", $args); $records = $count_res['total']; $page = $pager['page']; $limit = $pager['limit']; if ($records > 0) { $total_pages = ceil($records / $limit); } else { $total_pages = 1; } $skip = ($page - 1) * $limit; $sql = "SELECT *,id as `key` FROM {$table} {$where} ORDER BY {$sort_field} {$sort_type} LIMIT {$skip},{$limit} "; //_throw($sql); //self::_debug(array($sql,$args,$condition,$pager,$order,$sort_field,$sort_type)); $rows = self::_db()->select_rows($sql, $args); foreach ($rows as &$row) { $op_uid = $row['op_uid']; $staff_info = Model_Admin_Staff::get_staff_info_by_uid_from_cache($op_uid); if ($staff_info) { $row['op_name'] = $staff_info['name']; $row['op_avatar'] = $staff_info['avatar']; } else { $row['op_name'] = ""; $row['op_avatar'] = ""; } $row['items'] = self::_db()->select_rows("select i.id as `key`,p.*,i.item_num as num,i.doct_uid,i.doct_name,i.appoint_time\n from crm_client_order_item as i\n left join crm_product as p on p.id = i.item_id\n where i.order_id = ?", $row['id']); } return array("total_pages" => $total_pages, "total" => $records, "rows" => $rows); }
static function row_advance($id) { $table = self::TABLE_ADVANCE; $row = self::_db()->select_row("select * from {$table} where client_id = ?", $id); if ($row) { $op_uid = $row['op_uid']; $staff_info = Model_Admin_Staff::get_staff_info_by_uid_from_cache($op_uid); if ($staff_info) { $row['op_name'] = $staff_info['name']; $row['op_avatar'] = $staff_info['avatar']; } else { $row['op_name'] = ""; $row['op_avatar'] = ""; } } return $row; }