示例#1
0
function calculations($desc, $asc)
{
    $result = 0;
    $iterations = 0;
    do {
        $iterations++;
        $desc = join_number($desc);
        $asc = join_number($asc);
        $result = $desc - $asc;
        $result_split = split_number($result);
        $desc = sort_desc($result_split);
        $asc = sort_asc($result_split);
    } while ($result != 6174);
    return $iterations;
}
 public function detail()
 {
     //	dump($_GET);
     $id = isset($_GET['id']) ? htmlspecialchars($_GET['id']) : '';
     if (empty($id)) {
         $this->error('id为空');
     }
     $furlen = isset($_GET['furl']) ? $_GET['furl'] : '';
     $furl = urldecode(base64_decode($furlen));
     //已报价商家
     $dis = M('')->table(C('DB_PREFIX') . "member_demand as a")->field('a.*,b.nick_name,b.mobile,b.header')->join(C('DB_PREFIX') . "member as b on a.member_id = b.id")->where("a.id={$id}")->find();
     $dis['header'] = imgUrl($dis['header']);
     $dis['pics'] = imgUrl(json_decode($dis['pics'], true));
     $db = M('');
     //分开显示报价情况
     // 		$bidding = $db ->table(C('DB_PREFIX')."merchant_bidding as a ")->field('b.name,a.price,a.out_time,c.merchant_name,c.header,c.mobile,c.tel,a.merchant_id')
     // 		->join(C('DB_PREFIX')."category as b on a.sub_id = b.id",'LEFT')
     // 		->join(C('DB_PREFIX')."merchant as c on a.merchant_id = c.id",'LEFT')
     // 		->where(array('a.demand_id'=>$id))->order('a.addtime asc')->select();
     // 		$biddingMerchant = array();
     // 		foreach($bidding as $k =>$r){
     // 			$bidding_data [$r['merchant_id']]['child'][] = $r;
     // 			$bidding_data [$r['merchant_id']]['total_price'] += $r['price'];
     // 			$bidding_data [$r['merchant_id']]['out_time'] += $r['price'];
     // 			if(!array($r['merchant_id'],$biddingMerchant)){
     // 				$biddingMerchant[] = $r['merchant_id'];
     // 			}
     // 		}
     // 		dump($bidding_data);dump($biddingMerchant);die();
     $bidding = $db->query("select sum(a.price) as total_price,sum(a.out_time) as total_time,b.merchant_name,b.header,b.mobile,b.tel ,b.id as merchant_id,b.latitude,b.longitude from " . C('DB_PREFIX') . "merchant_bidding as a left join " . C('DB_PREFIX') . "merchant as b on a.merchant_id = b.id where demand_id = " . $id . "  group by merchant_id order by a.addtime asc");
     $count = count($bidding);
     foreach ($bidding as $ke => $ro) {
         $bidding[$ke]['header'] = imgUrl($ro['header']);
         $distance = getDistance($dis['latitude'], $dis['longitude'], $ro['latitude'], $ro['longitude']);
         $bidding[$ke]['distance'] = $distance;
         $bidding[$ke]['remark'] = $this->getMerRemark($id, $ro['merchant_id']);
         unset($bidding[$ke]['latitude']);
         unset($bidding[$ke]['longitude']);
         $biddingMerchant[] = $ro['merchant_id'];
     }
     $db = M('DemandMerchantEnable');
     $enable = $db->table(C('DB_PREFIX') . "demand_merchant_enable as f ")->join(C('DB_PREFIX') . "merchant as a on f.merchant_id = a.id", 'LEFT')->field('a.merchant_name,a.tel,a.id,a.mobile,a.header,a.longitude,a.latitude,a.address,b.name as province,c.name as city,d.name as area')->join(C('DB_PREFIX') . "city as b on a.province_id = b.id", 'LEFT')->join(C('DB_PREFIX') . "city as c on a.city_id = c.id", 'LEFT')->join(C('DB_PREFIX') . "city as d on a.area_id = d.id", 'LEFT')->where(array('f.demand_id' => $id))->select();
     if ($enable === false) {
         $this->error('商户未收到需求');
     } else {
         if (count($biddingMerchant) > 0) {
             foreach ($enable as $key => $row) {
                 if (in_array($row['id'], $biddingMerchant)) {
                     unset($enable[$key]);
                 }
             }
             sort($enable);
         }
     }
     foreach ($enable as $key => $row) {
         $enable[$key]['header'] = imgUrl($row['header']);
         $enable[$key]['distance'] = getDistance($dis['latitude'], $dis['longitude'], $row['latitude'], $row['longitude']);
     }
     $enable = sort_asc($enable);
     $this->assign('merchant', $enable);
     $this->assign('furlen', $furlen);
     $this->assign('furl', $furl);
     $this->assign('data', $dis);
     $this->assign('bidding', $bidding);
     $this->display();
 }
 /**
  * 附近商家(未启用)
  */
 public function around_merchant()
 {
     $longitude = $_POST['longitude'];
     $latitude = $_POST['latitude'];
     $classid = isset($_POST['cat_id']) ? htmlspecialchars($_POST['cat_id']) : '';
     $sort = isset($_POST['sort']) ? htmlspecialchars($_POST['sort']) : '1';
     $page = isset($_POST['page']) ? htmlspecialchars($_POST['page']) : '1';
     $num = isset($_POST['num']) ? htmlspecialchars($_POST['num']) : '6';
     // $km=isset($_POST['km'])?htmlspecialchars($_POST['km']):'3';
     if (empty($longitude) || empty($latitude)) {
         $this->jsonUtils->echo_json_msg(4, '经纬度参数为空...');
         exit;
     }
     // $ll_arr=rangekm($km, $longitude,$latitude);//获取最大最小经纬度
     // $maxLng=$ll_arr['maxLng'];
     // $minLng=$ll_arr['minLng'];
     // $maxLat=$ll_arr['maxLat'];
     // $minLat=$ll_arr['minLat'];
     $where = " 1=1 and is_salesman =0 ";
     // $where .= "and b.longitude <$maxLng and b.longitude>$minLng and
     // b.latitude <$maxLat and b.latitude>$minLat";
     // $sql="select
     // a.id,a.longitude,a.latitude,a.intro,a.pics,a.header,a.merchant_name
     // ,a.pcat_id ,b.name as area_name from ". C('DB_PREFIX')."merchant as a
     // left join ".C('DB_PREFIX')."city as b on a.area_id=b.id where
     // a.collecter=0 and a.longitude <$maxLng and a.longitude>$minLng and
     // a.latitude <$maxLat and a.latitude>$minLat ";
     if (!empty($classid)) {
         $sql = $where . " and a.pcat_id ={$classid} ";
         $arr = $this->dao->table(C('DB_PREFIX') . "service as a")->join(C('DB_PREFIX') . 'merchant as b on a.merchant_id = b.id')->field('b.id,b.merchant_name,b.header,b.intro,b.tel,b.address,b.mobile,b.longitude,b.latitude,b.area_id')->where($where)->group('a.merchant_id')->page($page)->limit($num)->select();
     } else {
         $arr = $this->dao->table(C('DB_PREFIX') . "merchant as b")->field('b.id,b.merchant_name,b.header,b.intro,b.tel,b.address,b.mobile,b.longitude,b.latitude,b.area_id')->where($where)->page($page)->limit($num)->select();
     }
     // $sql=$sql." limit $pagenum,20";
     // $arr=$this->dao->query($sql);
     if ($arr) {
         foreach ($arr as $key => $value) {
             if ($arr[$key]['pics']) {
                 // 取json数组图片第一张作为图片
                 $json_arr = json_decode($arr[$key]['pics']);
                 $arr[$key]['pics'] = imgUrl($json_arr[0]);
             }
             $arr[$key]['header'] = imgUrl($value['header']);
             $arr[$key]['area_name'] = CityController::getName($value['area_id']);
             $arr[$key]['service_name'] = CommonController::getMerchantServerListName($value['id']);
             $arr[$key]['distance'] = getDistance($latitude, $longitude, $arr[$key]['latitude'], $arr[$key]['longitude']);
             // 计算两点距离
         }
         if ($sort == 1) {
             // 按距离升序和降序
             $arr1 = sort_asc($arr);
         }
         if ($sort == 2) {
             $arr1 = sort_desc($arr);
         }
         $data['list'] = $arr1;
         $this->jsonUtils->echo_json_data(0, 'ok', $data);
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '该附近没有商家信息...');
     }
 }
示例#4
0
<?php

set_time_limit(0);
$iterations = array();
$iterations_map = array();
for ($i = 1000; $i <= 9998; $i++) {
    $digits[$i]["number"] = split_number($i);
    $digits[$i]["valid"] = validity_check($digits[$i]["number"]);
    $digits[$i]["desc"] = sort_desc($digits[$i]["number"]);
    $digits[$i]["asc"] = sort_asc($digits[$i]["number"]);
    $digits[$i]["iterations"] = "";
    if ($digits[$i]["valid"] == true) {
        $digits[$i]["iterations"] = calculations($digits[$i]["desc"], $digits[$i]["asc"]);
    }
    if (in_array($digits[$i]["iterations"], $iterations) == true && $digits[$i]["valid"] == true) {
        $iterations_map[array_search($digits[$i]["iterations"], $iterations)]++;
    } else {
        if ($digits[$i]["valid"] == true) {
            array_push($iterations, $digits[$i]["iterations"]);
            $iterations_map[array_search($digits[$i]["iterations"], $iterations)] = 1;
        }
    }
}