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 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, '该附近没有商家信息...'); } }
<?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; } } }