Files
liche/api/controllers/wxapp/liche/Aptinfo.php
T
2021-07-22 10:01:41 +08:00

150 lines
5.1 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by Vim
* User: lcc
* Desc: 预约信息
* Date: 2021.06.23
* Time: 14:08
*/
require_once APPPATH.'controllers/wxapp/Wxapp.php';
class Aptinfo extends Wxapp{
function __construct($inputs, $app_key){
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg =array();//授权微信信息
}
protected function get(){
$this->load->model('area_model');
$city_code = $this->input_param('c_code');
!$city_code && $city_code = 350206;
//获取城市
$citys = ['350200','350800'];
$city_ids = implode(',',$citys);
$where["city_id in ({$city_ids})"] = null;
$fileds = 'id,city_id,city_name,county_id,county_name';
$county_rows = $this->area_model->map('city_id','',$where,'','','',$fileds);
$city_list = $county_list = [];
foreach($citys as $val){
$city_list[] = [
'id' => $val,
'parid' => 1,
'name' => $county_rows[$val][0]['city_name'],
'regtype' => 1
];
if($county_rows){
foreach($county_rows[$val] as $val2){
$county_list[] = [
'id' => $val2['county_id'],
'parid' => $val2['city_id'],
'name' => $val2['county_name'],
'regtype' => 2
];
}
}
}
//获取默认选中地区
$city_row = $this->area_model->get(['county_id'=>$city_code]);
if(!$city_row){
$city_row = $this->area_model->get(['county_id'=>350206]);
}
$default = $city_row['city_name'].'/'.$city_row['county_name'];
$c_list = array_merge($city_list,$county_list);
$data = [
'city_list' => $c_list,
'def_city' => $default,
'img' => 'https://qs.haodian.cn/wechat_app/liche/buyCar/ex-default.jpg',
];
return $data;
}
protected function get_bizs(){
$data['data'] = [];
return $data; //展示隐藏没有门店
$city_id = $this->input_param('city_id');
if(!$city_id){
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
}
$lat = $this->input_param('lat'); //纬度
$lng = $this->input_param('lng'); //经度
$this->load->model('biz/biz_model');
$filed = 'id,biz_name';
$lat = $this->db->escape($lat);
$lng = $this->db->escape($lng);
$city_id = $this->db->escape($city_id);
$where = " status=1 ";
$city_id && $where .= " and (city_id={$city_id} or county_id={$city_id}) ";
if($lat && $lng){
$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 20";
}else{
$sql = "select {$filed} from lc_biz where {$where} order by id desc limit 20";
}
$rows = $this->biz_model->db->query($sql)->result_array();
$list = [];
if($rows){
foreach($rows as $key=>$val){
$list[] = [
'id' => $val['id'],
'biz_name' => $val['biz_name']
];
}
}
return $list;
}
//预约
protected function post(){
$cf_id = 1;
$this->load->model('receiver/receiver_clues_model','clues_model');
$this->load->model('auto/auto_series_model');
$biz_id = $this->input_param('biz_id');
$series_id = $this->input_param('car_id');//车系id
$city_code = $this->input_param('city_id');
$series_row = $this->auto_series_model->get(['id'=>$series_id]);
$jsondata['info'] = [
'biz_id' => $biz_id ? $biz_id : '',
'city_code' => $city_code
];
$cf_platform = 'wxapp';
$where = [
'cf_id' => $cf_id,
'cf_uid' => $this->session['uid'],
'app_id' => $this->app_id,
'cf_platform' => $cf_platform,
];
$row = $this->clues_model->get($where);
if(!$row){
$add_data = [
'name' => $this->session['nickname'],
'mobile' => $this->session['mobile'],
'cf_uid' => $this->session['uid'],
'cf_id' => $cf_id,
'app_id' => $this->app_id,
'if_driver' => 1,
'cf_platform' => $cf_platform,
'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE),
'c_time' => time()
];
$series_row['brand_id'] && $add_data['brand_id'] = $series_row['brand_id'];
$series_row['id'] && $add_data['s_id'] = $series_row['id'];
$this->clues_model->add($add_data);
}
throw new Exception('预约成功', API_CODE_SUCCESS);
}
}