Files
liche/common/models/biz/Biz_model.php
T
2022-02-09 10:16:17 +08:00

93 lines
2.3 KiB
PHP
Executable File

<?php
/**
* Created by PhpStorm.
* User: linfan
* Date: 2018/11/5
* Time: 13:47
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Biz_model extends HD_Model
{
private $table_name = 'lc_biz';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* 根据id获取数据
* @param array() $ids
*/
public function get_map_by_ids($ids,$fileds=''){
$rows = [];
$ids = array_filter($ids);
if($ids){
$cf_ids = implode(',',$ids);
$where = [
"id in ($cf_ids)" => null
];
$rows = $this->map('id','',$where,'','','',$fileds);
}
return $rows;
}
/**
* id数组获取门店
* @param array() $ids
* @param string $fileds
* @return array()
*/
public function get_by_id_arr($ids_arr,$o_where,$fileds='id,biz_name'){
$bizs = [];
$ids = implode(',',$ids_arr);
if($ids){
$where = [
"id in ($ids)" => null,
"status" => 1
];
is_array($o_where) && $where = array_merge($where,$o_where);
$bizs = $this->biz_model->select($where,'',0,0,$fileds);
}
return $bizs;
}
/**
* 获取类型
* @param null $key
* @return mixed
*/
function type_ary($key = null){
$map = array('1' => '品牌店', '2' => '合伙店', '3' => '代理店', '4' => '合作店' , '5' => '联营店');
if(!is_null($key)){
return $map[$key];
}
return $map;
}
/**
* 根据经纬度获取附近门店
* @param $lat float 纬度
* @param $lng float 经度
* @param $page int 页码
* @param $size int 分页大小
*/
public function nearby($lat,$lng,$page=1,$size=20,$filed='*' ){
$lat = (float)$lat;
$lng = (float)$lng;
$where = "status=1 and lat>0 and lng>0";
if($page){
$offset = ($page - 1) * $size;
$limit = $size;
}
$sql = "select {$filed},round(sqrt(pow(lat-{$lat},2)+pow(lng-{$lng},2)),5)*80000 as dis from lc_biz where {$where} order by dis asc limit {$offset},{$limit}";
$rows = $this->db->query($sql)->result_array();
return $rows;
}
}