Example #1
0
 /**
  * 活动列表
  */
 function action_list()
 {
     $table = self::$table;
     $table_alias = 'a';
     $join = ' inner join et_user as u on u.id = a.uid ';
     if (empty($table_alias)) {
         throw new ErrorException("table is not defined");
     }
     //$request = http_request("rows","page","sidx","sord");
     $request = PtLib\http_request("verify", "production_status", "ship_status", "uid", "rows", "page", "sidx", "sord", "activity_id", "activity_name", "username", "mobile", 'startDate', 'endDate', 'pass', 'status', 'success');
     $limit = $request['rows'];
     $page = $request['page'];
     $sort = $request['sidx'];
     $sort_type = $request['sord'];
     $username = $request['username'];
     //fields
     $select_fields = " a.production_status,a.ship_status,a.status,a.verify,a.id,a.name,a.uid,a.sale_count,a.sale_target,a.sale_total,a.start_time,a.sale_profit,a.end_time,a.period,a.thumb_svg_url,a.thumb_img_url";
     //where
     $args = array();
     if (empty($limit)) {
         $limit = 20;
     }
     if (empty($page)) {
         $page = 1;
     }
     if (empty($sort)) {
         $sort = "id";
         $sort_type = "desc";
     } else {
         if (empty($sort_type)) {
             $sort_type = "desc";
         }
     }
     $where = " where 1=1 ";
     $args = array();
     if ($request['uid']) {
         $where .= 'and a.uid = ? ';
         $args[] = $request['uid'];
     }
     if ($request['verify'] === "0" || $request['verify'] > 0) {
         $where .= 'and a.verify = ? ';
         $args[] = $request['verify'];
     }
     if ($request['status'] === "0" || $request['status'] > 0) {
         if ($request['status'] == 1) {
             //进行中
             $where .= 'and a.start_time < now() and now() < a.end_time and a.status = 1';
         }
         if ($request['status'] == 10) {
             //结束
             $where .= 'and now() > a.end_time and a.status > 0';
         }
         if ($request['status'] == 0) {
             //草稿
             $where = 'and a.status = 0 ';
         }
         if ($request['status'] == 2) {
             //失败的
             $where = 'and a.status = 2 ';
         }
         if ($request['status'] == 3) {
             //成功的
             $where = 'and a.status = 3 ';
         }
     }
     if ($request['activity_id']) {
         $where .= " and a.id = ? ";
         $args[] = $request['activity_id'];
     }
     if ($request['activity_name']) {
         $where .= " and a.name like '%" . mysql_escape($request['activity_name']) . "%' ";
     }
     //order
     $order = "";
     if ($sort) {
         $order = "order by a." . addslashes($sort) . " " . $sort_type;
     }
     $sql = "select count(a.id) as total from {$table} as a {$join} {$where} ";
     //$count_res = db()->select_row($sql,$args);
     $count_res = PtLib\db()->select_row($sql, $args);
     $records = $count_res['total'];
     $response = new stdClass();
     $response->page = $page;
     //cur page
     if ($records > 0) {
         $total_pages = ceil($records / $limit);
     } else {
         $total_pages = 1;
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $response->total = $total_pages;
     //total pages
     $response->records = $records;
     //count
     $skip = ($page - 1) * $limit;
     $sql = "select {$select_fields} from {$table} as a {$join} {$where} {$order} limit {$skip},{$limit} ";
     //$rows = db()->select_rows($sql,$args);
     $rows = PtLib\db()->select_rows($sql, $args);
     foreach ($rows as $row) {
         $response->rows[] = array('id' => $row['id'], "cell" => $row);
     }
     return $response;
 }
Example #2
0
function get_table_list($table, $table_alias, $join = '')
{
    #$join = '';
    //fields
    $select_fields = " {$table_alias}.* ";
    if (empty($table_alias)) {
        throw new ErrorException("table is not defined");
    }
    //    $request = http_request("rows","page","sidx","sord");
    $request = PtLib\http_request("rows", "page", "sidx", "sord");
    $limit = $request['rows'];
    $page = $request['page'];
    $sort = $request['sidx'];
    $sort_type = $request['sord'];
    if (empty($limit)) {
        $limit = 20;
    }
    if (empty($page)) {
        $page = 1;
    }
    if (empty($sort)) {
        $sort = "id";
        $sort_type = "desc";
    } else {
        if (empty($sort_type)) {
            $sort_type = "desc";
        }
    }
    //where
    $args = array();
    $where = " where 1=1 ";
    //order
    $order = "";
    if ($sort) {
        $order = "order by {$table_alias}." . addslashes($sort) . " " . $sort_type;
    }
    $sql = "select count({$table_alias}.id) as total from {$table} as {$table_alias} {$join} {$where} ";
    $count_res = db()->select_row($sql, $args);
    #$count_res = PtLib\db()->select_row($sql,$args);
    $records = $count_res['total'];
    $response = new stdClass();
    $response->page = $page;
    //cur page
    if ($records > 0) {
        $total_pages = ceil($records / $limit);
    } else {
        $total_pages = 1;
    }
    if ($page > $total_pages) {
        $page = $total_pages;
    }
    $response->total = $total_pages;
    //total pages
    $response->records = $records;
    //count
    $skip = ($page - 1) * $limit;
    $sql = "select {$select_fields} from {$table} as {$table_alias} {$join} {$where} {$order} limit {$skip},{$limit} ";
    $rows = db()->select_rows($sql, $args);
    #$rows = PtLib\db()->select_rows($sql,$args);
    foreach ($rows as $row) {
        $response->rows[] = array('id' => $row['id'], "cell" => $row);
    }
    return $response;
}