79 lines
3.0 KiB
PHP
79 lines
3.0 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Common extends HD_Controller
|
|
{
|
|
private $smsSign = '理车宝';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('area_model');
|
|
$this->load->model('app/paic/app_paic_users_model');
|
|
}
|
|
|
|
public function getAreaList()
|
|
{
|
|
$redis = load_cache();
|
|
$cache_key = "area_list_h5";
|
|
$data = $redis->get($cache_key);
|
|
if (!$data) {
|
|
$county_list = $city_list = $province_list = [];
|
|
$where = [];
|
|
$province_rows = $this->area_model->select($where, null, null, null, 'distinct(province_id), province_name');
|
|
foreach ($province_rows as $province_row) {
|
|
$province_list[$province_row['province_id']] = $province_row['province_name'];
|
|
}
|
|
$city_rows = $this->area_model->select($where, null, null, null, 'distinct(city_id), city_name');
|
|
foreach ($city_rows as $city_row) {
|
|
$city_list[$city_row['city_id']] = $city_row['city_name'];
|
|
}
|
|
$county_rows = $this->area_model->select($where, null, null, null, 'distinct(city_id), city_name');
|
|
foreach ($county_rows as $county_row) {
|
|
$county_list[$county_row['city_id']] = $county_row['city_name'];
|
|
}
|
|
$data = [
|
|
'province_list' => $province_list,
|
|
'city_list' => $city_list,
|
|
'county_list' => $county_list
|
|
];
|
|
$redis->save($cache_key, $data, 24 * 60 * 60);
|
|
}
|
|
$this->success($data, '');
|
|
}
|
|
|
|
public function Sms()
|
|
{
|
|
try {
|
|
$mc = &load_cache();
|
|
$mobile = $this->input->post('mobile');
|
|
$type = $this->input->post('type');
|
|
if (!mobile_valid($mobile)) {
|
|
throw new Exception('请输入正确的手机号码');
|
|
}
|
|
$user = $this->app_paic_users_model->get(['mobile' => $mobile, 'status' => App_paic_users_model::STATUS_NORMAL]);
|
|
if ($type == 'login') {
|
|
if (!$user) {
|
|
throw new Exception('手机号未注册');
|
|
}
|
|
$key = "paic_login_code_" . $mobile;
|
|
} else {
|
|
if ($user) {
|
|
throw new Exception('手机号已注册');
|
|
}
|
|
$key = "paic_reg_code_" . $mobile;
|
|
}
|
|
if (!$code = $mc->get($key)) {
|
|
$this->load->helper('string');
|
|
$code = random_string('numeric', 4);
|
|
$mc->save($key, $code, 600);
|
|
}
|
|
$content = "【{$this->smsSign}】" . "您的验证码为:{$code},请勿泄露于他人!";
|
|
b2m_send_sms($mobile, $content);
|
|
$this->success('', '发送成功');
|
|
} catch (Exception $e) {
|
|
$this->fail('', $e->getMessage());
|
|
}
|
|
}
|
|
}
|