示例#1
0
 public function get_list($lat, $long, $page, $pagesize, $activity_type)
 {
     $where = array("status" => 0, "invite_time" => array("gt", time()));
     if ($activity_type !== false) {
         $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.status=0 AND i.activity_type=" . $activity_type . " AND i.invite_time>" . time() . " ORDER BY i.pigcms_id DESC, u.sex DESC";
         $where["activity_type"] = intval($activity_type);
     } else {
         $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.status=0 AND i.invite_time>" . time() . " ORDER BY i.pigcms_id DESC, u.sex DESC";
     }
     $start = ($page - 1) * $pagesize;
     $count = $this->where($where)->count();
     $sql .= " limit {$start}, {$pagesize}";
     $mode = new Model();
     $res = $mode->query($sql);
     $today = strtotime(date("Y-m-d")) + 86400;
     $tomorrow = $today + 86400;
     $lastday = $tomorrow + 86400;
     foreach ($res as &$v) {
         $v["_time"] = date("Y-m-d H:i", $v["invite_time"]);
         $v["juli"] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat * PI() / 180 - $v["lat"] * PI() / 180) / 2), 2) + COS($lat * PI() / 180) * COS($v["lat"] * PI() / 180) * POW(SIN(($long * PI() / 180 - $v["long"] * PI() / 180) / 2), 2))) * 1000);
         $v["juli"] = 1000 < $v["juli"] ? number_format($v["juli"] / 1000, 1) . "km" : ($v["juli"] < 100 ? "<100m" : $v["juli"] . "m");
         $v["invite_time"] = $v["invite_time"] < $today ? "今天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $tomorrow ? "明天  " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $lastday ? "后天  " . date("H:i", $v["invite_time"]) : date("m-d H:i", $v["invite_time"])));
         $v["birthday"] && ($v["age"] = date("Y") - date("Y", strtotime($v["birthday"])));
         $v["age"] = 100 < $v["age"] || $v["age"] < 0 ? "保密" : $v["age"] . "岁";
     }
     return array("data" => $res, "total" => $count);
 }
示例#2
0
function run_008()
{
    // Ugly but haven't found a better way
    global $setting, $config, $statistics, $block, $mysqli;
    // Version information
    $db_version_old = '0.0.7';
    // What version do we expect
    $db_version_new = '0.0.8';
    // What is the new version we wish to upgrade to
    $db_version_now = $setting->getValue('DB_VERSION');
    // Our actual version installed
    // Upgrade specific variables
    $dDifficulty = POW(2, $config['difficulty'] - 16);
    $aSql[] = "UPDATE " . $statistics->getTableName() . " SET valid = valid * {$dDifficulty}, invalid = invalid * {$dDifficulty}, pplns_valid = pplns_valid * {$dDifficulty}, pplns_invalid = pplns_invalid * {$dDifficulty}";
    $aSql[] = "UPDATE " . $block->getTableName() . "      SET shares = shares * {$dDifficulty}";
    $aSql[] = "UPDATE " . $setting->getTableName() . "    SET value = '0.0.8' WHERE name = 'DB_VERSION'";
    if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
        // Run the upgrade
        echo '- Starting database migration to version ' . $db_version_new . PHP_EOL;
        foreach ($aSql as $sql) {
            echo '-  Preparing: ' . $sql . PHP_EOL;
            $stmt = $mysqli->prepare($sql);
            if ($stmt && $stmt->execute()) {
                echo '-    success' . PHP_EOL;
            } else {
                echo '-    failed: ' . $mysqli->error . PHP_EOL;
                exit(1);
            }
        }
    }
}
示例#3
0
function procDistanceTime2($coor, $thiscoor, $ref, $mode)
{
    $xdistance = ABS($thiscoor['x'] - $coor['x']);
    if ($xdistance > WORLD_MAX) {
        $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
    }
    $ydistance = ABS($thiscoor['y'] - $coor['y']);
    if ($ydistance > WORLD_MAX) {
        $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
    }
    $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
    if (!$mode) {
        if ($ref == 1) {
            $speed = 16;
        } else {
            if ($ref == 2) {
                $speed = 12;
            } else {
                if ($ref == 3) {
                    $speed = 24;
                } else {
                    if ($ref == 300) {
                        $speed = 5;
                    } else {
                        $speed = 1;
                    }
                }
            }
        }
    } else {
        $speed = $ref;
    }
    return round($distance / $speed * 3600 / INCREASE_SPEED);
}
示例#4
0
 public function procDistanceTime($coor, $thiscoor, $ref, $mode)
 {
     global $bid28, $bid14, $building;
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     if (!$mode) {
         if ($ref == 1) {
             $speed = 16;
         } else {
             if ($ref == 2) {
                 $speed = 12;
             } else {
                 if ($ref == 3) {
                     $speed = 24;
                 } else {
                     if ($ref == 300) {
                         $speed = 5;
                     } else {
                         $speed = 1;
                     }
                 }
             }
         }
     } else {
         $speed = $ref;
         if ($building->getTypeLevel(14) != 0 && $distance >= TS_THRESHOLD) {
             $speed = $speed * ($bid14[$building->gettypeLevel(14)]['attri'] / 100);
         }
     }
     if ($speed != 0) {
         return round($distance / $speed * 3600 / INCREASE_SPEED);
     } else {
         return round($distance * 3600 / INCREASE_SPEED);
     }
 }
 function prep()
 {
     ### CHART MATH
     //find Y grid
     if ($this->settings['ymode'] == 'fit') {
         //adjust ymax so that the grid is a nice multiple of 1,2 or 5
         $this->settings['ymin'] = 0;
         $rawygrid = ($this->settings['ymax'] - $this->settings['ymin']) / $this->settings['yqtymajorgrids'];
         //raw
         $yexp = log10(abs($rawygrid));
         //ie.how many zeros
         $osig = $sig = $rawygrid / POW(10, floor($yexp));
         //the sigfigs
         if ($sig < 1.5) {
             $sig = 1;
         } elseif ($sig < 3.5) {
             $sig = 2;
         } elseif ($sig < 7.5) {
             $sig = 5;
         } else {
             $sig = 10;
         }
         $this->settings['ygrid'] = $ygrid = $sig * POW(10, floor($yexp));
         //adjusted now
         $this->debug("YSig:{$osig}");
         $this->debug("YExp:{$yexp}");
         $this->debug("YGrd:{$ygrid}");
     } else {
         $this->settings['ygrid'] = $ygrid = ($this->settings['ymax'] - $this->settings['ymin']) / $this->settings['yqtymajorgrids'];
     }
     //calc y scale factor
     $numygrids = ceil(($this->settings['ymax'] - $this->settings['ymin']) / $this->settings['ygrid']);
     //now adjusted
     $this->settings['ymax'] = $this->settings['ymin'] + $this->settings['ygrid'] * $numygrids;
     //now adjusted
     $this->settings['ysf'] = ($this->settings['canvas_height'] - $this->settings['bottommargin'] - $this->settings['topmargin']) / ($this->settings['ymax'] - $this->settings['ymin']);
     //calc X scale factor
     $divisor = $this->settings['xmode'] == 'adj' ? $this->settings['npoints'] - 1 : $this->settings['npoints'];
     $this->xsf = ($this->settings['canvas_width'] - $this->settings['leftmargin'] - $this->settings['rightmargin']) / $divisor;
     #### DRAW BG AND LABELS
     $scale = $this->settings['scale'];
     //canvas border
     if ($this->settings['showborder']) {
         $x1 = 0;
         $y1 = 0;
         $x2 = $this->settings['canvas_width'] - 1;
         //starts at 0 therefore 1 less
         $y2 = $this->settings['canvas_height'] - 1;
         $opts = array('color' => $this->settings['border_color'], 'alpha' => 100);
         $this->draw->rectangle($x1, $y1, $x2, $y2, $opts);
     }
     //margin background color
     $bsize = round(1 * $scale);
     //1px
     $x1 = $bsize;
     $y1 = $bsize;
     $x2 = round($this->settings['canvas_width'] - $bsize - 1);
     $y2 = round($this->settings['canvas_height'] - $bsize - 1);
     $opts = array('color' => $this->settings['margin_color'], 'alpha' => 100);
     $this->draw->rectangle($x1, $y1, $x2, $y2, $opts);
     //graph background color
     $x1 = $this->settings['leftmargin'];
     $y1 = $this->settings['topmargin'];
     $x2 = $this->settings['canvas_width'] - $this->settings['rightmargin'];
     $y2 = $this->settings['canvas_height'] - $this->settings['bottommargin'];
     $opts = array('color' => $this->settings['background_color'], 'alpha' => 100);
     $this->draw->rectangle($x1, $y1, $x2, $y2, $opts);
     //draw threshold bands
     if ($this->settings['ybands']) {
         foreach ($this->settings['ybands'] as $b) {
             $y1 = $this->settings['canvas_height'] - $this->settings['bottommargin'] - ($b['y1band'] - $this->settings['ymin']) * $this->settings['ysf'];
             $y2 = $this->settings['canvas_height'] - $this->settings['bottommargin'] - ($b['y2band'] - $this->settings['ymin']) * $this->settings['ysf'];
             $x1 = $this->settings['leftmargin'];
             $x2 = $this->settings['canvas_width'] - $this->settings['rightmargin'];
             $opts = array('color' => $b['bandcolor'], 'alpha' => 90);
             $this->draw->rectangle($x1, $y1, $x2, $y2, $opts);
         }
     }
     ### Draw the 3 main titles
     //draw chart title
     if ($this->settings['title']) {
         $opts = array('text' => $this->settings['title'], 'x' => $this->settings['canvas_width'] / 2, 'y' => $this->settings['topmargin'] / 2, 'align' => 'middlemiddle', 'fontname' => $this->settings['fontbold'], 'fontsize' => $this->settings['fontsize'] * 1.35, 'color' => $this->settings['fontcolor'], 'angle' => 0);
         $this->draw->text($opts);
     }
     //draw X axis title
     if ($this->settings['xaxistitle']) {
         $opts = array('text' => $this->settings['xaxistitle'], 'x' => $this->settings['canvas_width'] / 2, 'y' => $this->settings['canvas_height'] - $this->settings['bottommargin'] * 0.33, 'align' => 'middlemiddle', 'fontname' => $this->settings['fontbold'], 'fontsize' => $this->settings['fontsize'] * 1.44, 'color' => $this->settings['fontcolor'], 'angle' => 0);
         $this->draw->text($opts);
     }
     //draw Y title
     if ($this->settings['yaxistitle']) {
         $opts = array('text' => $this->settings['yaxistitle'], 'x' => $this->settings['leftmargin'] * 0.33, 'y' => $this->settings['canvas_height'] / 2, 'align' => 'middlemiddle', 'fontname' => $this->settings['fontbold'], 'fontsize' => $this->settings['fontsize'] * 1.3, 'color' => $this->settings['fontcolor'], 'angle' => 90);
         $this->draw->text($opts);
     }
     $ticksize = round(5 * $scale);
     $tickwidth = round(1 * $scale);
     ### X axis
     //draw x axis line
     $x1 = $this->settings['leftmargin'];
     $y1 = $this->settings['canvas_height'] - $this->settings['bottommargin'];
     $x2 = $this->settings['canvas_width'] - $this->settings['rightmargin'];
     $y2 = $y1;
     $color = $this->settings['grid_color_major'];
     $opts = array('color' => $color, 'linewidth' => $tickwidth, 'smooth' => false);
     $this->draw->line($x1, $y1, $x2, $y2, $opts);
     //draw x ticks
     $max = $this->settings['xmode'] == 'adj' ? $this->settings['npoints'] : $this->settings['npoints'] + 1;
     for ($i = 0; $i < $max; $i++) {
         $x1 = $this->settings['leftmargin'] + $i * $this->xsf;
         $y1 = $this->settings['canvas_height'] - $this->settings['bottommargin'] + 0.5 * $scale;
         //1px below the axis
         $x2 = $x1;
         $y2 = $y1 + $ticksize;
         if ($i % $this->settings['xintervalmajor'] == 0) {
             $opts = array('color' => $this->settings['grid_color_major'], 'linewidth' => $tickwidth, 'smooth' => false);
             $this->draw->line($x1, $y1, $x2, $y2, $opts);
         } elseif ($this->settings['xuseminorgrid']) {
             $mi = round($this->settings['xintervalmajor'] / $this->settings['xqtyminorgrids']);
             if ($i % $mi == 0) {
                 $opts = array('color' => $this->settings['grid_color_minor'], 'linewidth' => $tickwidth, 'smooth' => false);
                 $this->draw->line($x1, $y1, $x2, $y2, $opts);
             }
         }
     }
     //draw x axis labels
     $offset = $this->settings['xmode'] == 'adj' ? 0 : $this->xsf / 2;
     for ($i = 0; $i < $this->settings['npoints']; $i++) {
         if ($i % $this->settings['xintervalmajor'] == 0) {
             $opts = array('text' => $this->xdata[$i], 'x' => $this->settings['leftmargin'] + $i * $this->xsf + $offset, 'y' => $this->settings['canvas_height'] - $this->settings['bottommargin'] + 8 * $scale, 'align' => 'topmiddle', 'fontname' => $this->settings['font'], 'fontsize' => $this->settings['fontsize'] * 1.0, 'color' => $this->settings['fontcolor'], 'angle' => 0);
             $this->draw->text($opts);
         }
     }
     //draw x grids (vertical)
     if ($this->settings['xusemajorgrid']) {
         for ($i = 1; $i < $this->settings['npoints']; $i++) {
             $x1 = $this->settings['leftmargin'] + $i * $this->xsf;
             $y1 = $this->settings['topmargin'];
             $x2 = $x1;
             $y2 = $this->settings['canvas_height'] - $this->settings['bottommargin'];
             if ($i % $this->settings['xintervalmajor'] == 0) {
                 $opts = array('color' => $this->settings['grid_color_major'], 'linewidth' => $tickwidth, 'smooth' => false);
                 $this->draw->line($x1, $y1, $x2, $y2, $opts);
             } elseif ($this->settings['xuseminorgrid']) {
                 $mi = round($this->settings['xintervalmajor'] / $this->settings['xqtyminorgrids']);
                 if ($i % $mi == 0) {
                     $opts = array('color' => $this->settings['grid_color_minor'], 'linewidth' => $tickwidth, 'smooth' => false);
                     $this->draw->line($x1, $y1, $x2, $y2, $opts);
                 }
             }
         }
     }
     ### Y AXIS
     //draw y axis
     $x1 = $this->settings['leftmargin'];
     $y1 = $this->settings['topmargin'];
     $x2 = $x1;
     $y2 = $this->settings['canvas_height'] - $this->settings['bottommargin'];
     $color = $this->settings['grid_color_major'];
     $opts = array('color' => $color, 'linewidth' => $tickwidth, 'smooth' => false);
     $this->draw->line($x1, $y1, $x2, $y2, $opts);
     //draw y ticks
     $vdivision = ($this->settings['canvas_height'] - $this->settings['topmargin'] - $this->settings['bottommargin']) / $numygrids;
     //ysf?
     for ($i = 0; $i < $numygrids + 1; $i++) {
         $x1 = $this->settings['leftmargin'] - $ticksize;
         $y1 = $this->settings['canvas_height'] - $this->settings['bottommargin'] - $vdivision * $i;
         $x2 = $this->settings['leftmargin'] - 0.5 * $scale;
         $y2 = $y1;
         if ($i % $this->settings['yaxislabelfreq'] == 0) {
             $color = $this->settings['grid_color_major'];
         } else {
             $color = $this->settings['grid_color_minor'];
         }
         $opts = array('color' => $color, 'linewidth' => $tickwidth, 'smooth' => false);
         $this->draw->line($x1, $y1, $x2, $y2, $opts);
     }
     //draw y axis labels
     for ($i = 0; $i < $numygrids + 1; $i++) {
         if ($i % $this->settings['yaxislabelfreq'] == 0) {
             $label = $i * $this->settings['ygrid'] + $this->settings['ymin'];
             $opts = array('text' => $this->convertlabel($label, $this->settings['yaxislabelspec']), 'x' => $this->settings['leftmargin'] - 8 * $scale, 'y' => $this->settings['canvas_height'] - $this->settings['bottommargin'] - $vdivision * $i, 'align' => 'middleright', 'fontname' => $this->settings['font'], 'fontsize' => $this->settings['fontsize'] * 1.0, 'color' => $this->settings['fontcolor'], 'angle' => 0);
             $this->draw->text($opts);
         }
     }
     //draw y grid lines (horizontal)
     if ($this->settings['yusemajorgrid']) {
         for ($i = 1; $i < $numygrids + 1; $i++) {
             $x1 = $this->settings['leftmargin'];
             $y1 = $this->settings['canvas_height'] - $this->settings['bottommargin'] - $vdivision * $i;
             $x2 = $this->settings['canvas_width'] - $this->settings['rightmargin'];
             $y2 = $y1;
             if ($i % $this->settings['yaxislabelfreq'] == 0) {
                 $color = $this->settings['grid_color_major'];
                 $opts = array('color' => $color, 'linewidth' => $tickwidth, 'smooth' => false);
                 $this->draw->line($x1, $y1, $x2, $y2, $opts);
             } elseif ($this->settings['yuseminorgrid']) {
                 $color = $settings['grid_color_minor'];
                 $opts = array('color' => $color, 'linewidth' => $tickwidth, 'smooth' => false);
                 $this->draw->line($x1, $y1, $x2, $y2, $opts);
             }
         }
     }
     //method ends
     return 1;
 }
示例#6
0
 public function procDistanceTime($coor, $thiscoor, $ref, $mode)
 {
     global $bid14, $database, $generator;
     $resarray = $database->getResourceLevel($generator->getBaseID($coor['x'], $coor['y']));
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     if (!$mode) {
         if ($ref == 1) {
             $speed = 16;
         } else {
             if ($ref == 2) {
                 $speed = 12;
             } else {
                 if ($ref == 3) {
                     $speed = 24;
                 } else {
                     if ($ref == 300) {
                         $speed = 5;
                     } else {
                         $speed = 1;
                     }
                 }
             }
         }
     } else {
         $speed = $ref;
         if ($this->getsort_typeLevel(14, $resarray) != 0 && $distance >= TS_THRESHOLD) {
             $speed = $speed * ($bid14[$this->getsort_typeLevel(14, $resarray)]['attri'] / 100);
         }
     }
     if ($speed != 0) {
         return round($distance / $speed * 3600 / INCREASE_SPEED);
     } else {
         return round($distance * 3600 / INCREASE_SPEED);
     }
 }
 public function mysign()
 {
     $invitation_signs = D("Invitation_sign")->field("invid")->where(array("uid" => $this->user_session["uid"]))->order("invid DESC")->select();
     $invids = $pre = "";
     foreach ($invitation_signs as $is) {
         $invids .= $pre . $is["invid"];
         $pre = ",";
     }
     $today = strtotime(date("Y-m-d")) + 86400;
     $tomorrow = $today + 86400;
     $lastday = $tomorrow + 86400;
     if ($invids) {
         $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.pigcms_id IN ({$invids}) ORDER BY i.pigcms_id DESC, u.sex DESC";
         $mode = new Model();
         $res = $mode->query($sql);
         foreach ($res as &$v) {
             $v["_time"] = date("Y-m-d H:i", $v["invite_time"]);
             $v["juli"] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($this->_lat * PI() / 180 - $v["lat"] * PI() / 180) / 2), 2) + COS($this->_lat * PI() / 180) * COS($v["lat"] * PI() / 180) * POW(SIN(($this->_long * PI() / 180 - $v["long"] * PI() / 180) / 2), 2))) * 1000);
             $v["juli"] = 1000 < $v["juli"] ? number_format($v["juli"] / 1000, 1) . "km" : ($v["juli"] < 100 ? "<100m" : $v["juli"] . "m");
             $v["invite_time"] = $v["invite_time"] < $today ? "今天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $tomorrow ? "明天  " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $lastday ? "后天  " . date("H:i", $v["invite_time"]) : date("m-d H:i", $v["invite_time"])));
             $v["birthday"] && ($v["age"] = date("Y") - date("Y", strtotime($v["birthday"])));
         }
         $this->assign("date_list", $res);
     }
     $this->display();
 }
示例#8
0
 /**
  * Caclulate estimated shares based on network difficulty and pool difficulty
  * @param dDiff double Network difficulty
  * @return shares integer Share count
  **/
 public function getEstimatedShares($dDiff)
 {
     return round(POW(2, 32 - $this->config['target_bits']) * $dDiff / pow(2, $this->config['difficulty'] - 16));
 }
示例#9
0
 /**
  * Calculate the memory needed by an image in B.
  * This function is used when we want to calculate the memory need by gd to create an image
  *
  * @return unknown
  */
 function _getImageMemorySize()
 {
     if (!is_file($this->path)) {
         return 0;
     }
     $iK64 = POW(2, 16);
     //number of bytes in 64K
     $iTweakFactor = 2;
     $imageInfo = getimagesize($this->path);
     $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + $iK64) * $iTweakFactor);
     return $memoryNeeded;
 }
示例#10
0
<?php

namespace {
    $x = pow(1, 2);
    $y = \Pow(POW(3, 4), 5);
}
namespace a {
    // no redefinition
    $xa = pOw(6, 7);
    $ya = \POw(pOW(8, 9), 10);
}
namespace b {
    // with redefinition
    function pow($a, $b)
    {
        print __FUNCTION__ . " {$a} \n";
    }
    $xa = pow(11, 12);
    $ya = \POW(pOw(13, 14), 15);
}
示例#11
0
 public function procDistanceTime($coor, $thiscoor, $ref, $vid)
 {
     global $bid28, $bid14;
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     $speed = $ref;
     if ($this->getTypeLevel(14, $vid) != 0 && $distance >= TS_THRESHOLD) {
         $speed = $speed * ($bid14[$this->getTypeLevel(14, $vid)]['attri'] / 100);
     }
     if ($speed != 0) {
         return round($distance / $speed * 3600 / INCREASE_SPEED);
     } else {
         return round($distance * 3600 / INCREASE_SPEED);
     }
 }
 public function wap_get_store_list_by_catid($cat_id, $area_id, $order, $lat, $long, $cat_url)
 {
     $stores = D('Store_category')->field('store_id')->where("cat_id='{$cat_id}'")->select();
     foreach ($stores as $s) {
         $store_ids[] = $s['store_id'];
     }
     $store_ids && ($where['store_id'] = array('in', $store_ids));
     if ($cat_url == 'dianying' && empty($store_ids)) {
         return false;
     }
     // 		$where['have_meal'] = 1;
     $where['status'] = 1;
     $area_id && ($where['area_id'] = $area_id);
     $count = D('Merchant_store')->where($where)->count();
     //排序
     switch ($order) {
         case 'distance':
             $order = "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat} * PI() / 180- `lat` * PI()/180)/2),2)+COS({$lat} *PI()/180)*COS(`lat`*PI()/180)*POW(SIN(({$long} *PI()/180- `long`*PI()/180)/2),2)))*1000) ASC";
             //'`g`.`price` ASC,`g`.`group_id` DESC';
             break;
             // 			case 'priceDesc':
             // 				$order = '`g`.`price` DESC,`g`.`group_id` DESC';
             // 				break;
             // 			case 'solds':
             // 				$order = '`g`.`sale_count` DESC,`g`.`group_id` DESC';
             // 				break;
             // 			case 'rating':
             // 				$order = '`g`.`score_mean` DESC,`g`.`group_id` DESC';
             // 				break;
             // 			case 'start':
             // 				$order = '`g`.`last_time` DESC,`g`.`group_id` DESC';
             // 				break;
         // 			case 'priceDesc':
         // 				$order = '`g`.`price` DESC,`g`.`group_id` DESC';
         // 				break;
         // 			case 'solds':
         // 				$order = '`g`.`sale_count` DESC,`g`.`group_id` DESC';
         // 				break;
         // 			case 'rating':
         // 				$order = '`g`.`score_mean` DESC,`g`.`group_id` DESC';
         // 				break;
         // 			case 'start':
         // 				$order = '`g`.`last_time` DESC,`g`.`group_id` DESC';
         // 				break;
         default:
             $order = '`store_id` DESC';
     }
     import('@.ORG.wap_group_page');
     $p = new Page($count, C('config.group_page_row'), C('config.group_page_val'));
     $list = D('Merchant_store')->field(true)->where($where)->order($order)->limit($p->firstRow . ',' . $p->listRows)->select();
     // 		echo D('Merchant_store')->_sql();
     $return['pagebar'] = $p->show();
     if ($list) {
         $store_image_class = new store_image();
         foreach ($list as &$v) {
             $images = $store_image_class->get_allImage_by_path($v['pic_info']);
             $v['image'] = $images ? array_shift($images) : '';
             $v['juli'] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat * PI() / 180 - $v['lat'] * PI() / 180) / 2), 2) + COS($lat * PI() / 180) * COS($v['lat'] * PI() / 180) * POW(SIN(($long * PI() / 180 - $v['long'] * PI() / 180) / 2), 2))) * 1000);
             $v['juli'] = $v['juli'] > 1000 ? number_format($v['juli'] / 1000, 1) . 'km' : ($v['juli'] < 100 ? '<100m' : $v['juli'] . 'm');
         }
     }
     $return['store_list'] = $list;
     return $return;
 }
示例#13
0
 private function procDistanceTime($coor, $thiscoor, $ref, $mode)
 {
     global $bid14, $database, $generator;
     $resarray = $database->getResourceLevel($generator->getBaseID($coor['x'], $coor['y']));
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     if (!$mode) {
         if ($ref == 1) {
             $speed = 16;
         } else {
             if ($ref == 2) {
                 $speed = 12;
             } else {
                 if ($ref == 3) {
                     $speed = 24;
                 } else {
                     if ($ref == 300) {
                         $speed = 5;
                     } else {
                         $speed = 1;
                     }
                 }
             }
         }
     } else {
         $speed = $ref;
         for ($i = 19; $i <= 40; $i++) {
             if ($resarray['f' . $i . 't'] == 14) {
                 $ts_level = $resarray['f' . $i];
                 $ts_attri = $bid14[$ts_level]['attri'];
             }
         }
         if ($ts_attri > 0) {
             $speed = $distance <= TS_THRESHOLD ? $speed : $speed * ((TS_THRESHOLD + ($distance - TS_THRESHOLD) * $ts_attri / 100) / $distance);
         }
     }
     return round($distance / $speed * 3600 / INCREASE_SPEED);
 }