384 lines
8.9 KiB
PHP
384 lines
8.9 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
use EasyWeChat\Foundation\Application as OfficialAccount;
|
|
class Active extends ApiController
|
|
{
|
|
private $_user_id = 0;
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->library('session');
|
|
$this->load->model('series_number_model');
|
|
$this->load->model('package_model');
|
|
$this->load->model('series_number_model');
|
|
$this->load->model('sample_model');
|
|
$this->load->model('customer_model');
|
|
|
|
//跨域
|
|
header("Access-Control-Allow-Origin: ".$this->config->config['allow-origin']['user']);
|
|
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
|
|
header('Access-Control-Allow-Headers:x-requested-with,content-type');
|
|
header('Access-Control-Allow-Credentials: true');
|
|
//未登录告警
|
|
if(empty($this->session->{Customer_model::SESSION_KEY})){
|
|
$this->error('您的授权信息不存在或已过期,请从微信公众号菜单进入');
|
|
}
|
|
$this->_user_id = $this->session->{Customer_model::SESSION_KEY};
|
|
}
|
|
|
|
public function ticket_get()
|
|
{
|
|
$config = [
|
|
'app_id' => WEIXIN_APPID,
|
|
'secret' => WEIXIN_APPSECERT,
|
|
'token' => WEIXIN_TOKEN,
|
|
'aes_key' => WEIXIN_EncodingAESKey,
|
|
'response_type' => 'array',
|
|
];
|
|
$app = new OfficialAccount($config);
|
|
$app->js->setUrl($_SERVER['HTTP_REFERER']);
|
|
$config = $app->js->config(array('updateAppMessageShareData', 'updateTimelineShareData', 'scanQRCode'), $debug = false, $beta = false, $json = true);
|
|
$this->success(['config'=>json_decode($config)]);
|
|
}
|
|
|
|
public function check_number_post()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'device_id',
|
|
'label' => '序列号',
|
|
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
|
),
|
|
);
|
|
$data = $this->json_validation($config);
|
|
$series = $this->series_number_model->get($data['device_id'],'device_id');
|
|
if(!$series){
|
|
$this->error('序列号不存在');
|
|
}
|
|
$sample = $this->sample_model->get($series['id'],'series_id');
|
|
if($sample){
|
|
$this->error('序列号已使用');
|
|
}
|
|
$package = $this->package_model->get($series['package_ori']);
|
|
if(!$package){
|
|
$this->error('套餐不存在');
|
|
}
|
|
$this->success(['package'=>$package]);
|
|
|
|
}
|
|
|
|
public function create_post()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'device_id',
|
|
'label' => '序列号',
|
|
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
|
),
|
|
array(
|
|
'field' => 'name',
|
|
'label' => '用户姓名',
|
|
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => 'You must provide a %s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'tel',
|
|
'label' => '手机',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'email',
|
|
'label' => '邮箱',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_name',
|
|
'label' => '宠物名称',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_age',
|
|
'label' => '宠物年龄',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_breed',
|
|
'label' => '宠物品系',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_sex',
|
|
'label' => '宠物性别',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_birthday',
|
|
'label' => '宠物生日',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_species',
|
|
'label' => '物种',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_img',
|
|
'label' => '宠物头像地址',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'package_id',
|
|
'label' => '检测套餐',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'note',
|
|
'label' => '其他需求',
|
|
'rules' => 'required'
|
|
)
|
|
);
|
|
$data = $this->json_validation($config);
|
|
$series = $this->series_number_model->get($data['device_id'],'device_id');
|
|
if(!$series){
|
|
$this->error('序列号不存在');
|
|
}
|
|
$sample = $this->sample_model->get($series['id'],'series_id');
|
|
if($sample){
|
|
$this->error('序列号已使用');
|
|
}
|
|
$package = $this->package_model->get($series['package_ori']);
|
|
if(!$package){
|
|
$this->error('套餐不存在');
|
|
}
|
|
$ret = $this->sample_model->add(
|
|
array_intersect_key(array_column($config,'field'),$data)
|
|
);
|
|
if($ret){
|
|
$this->success();
|
|
}else{
|
|
$this->error('提交失败');
|
|
}
|
|
}
|
|
|
|
//获取需回寄的样品
|
|
public function ship_get()
|
|
{
|
|
$ret = $this->sample_model->get($this->_user_id,'user_id',true);
|
|
//只展示需回寄样品
|
|
foreach ($ret as $key=>$item) {
|
|
if($item['step'] >= Sample_model::STEP_SENT){
|
|
unset($ret[$key]);
|
|
}
|
|
}
|
|
$this->success($ret);
|
|
}
|
|
|
|
//样品回寄
|
|
public function ship_post()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'device_id',
|
|
'label' => '序列号',
|
|
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
|
),
|
|
array(
|
|
'field' => 'name',
|
|
'label' => '用户姓名',
|
|
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => 'You must provide a %s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'tel',
|
|
'label' => '手机',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'email',
|
|
'label' => '邮箱',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_name',
|
|
'label' => '宠物名称',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_age',
|
|
'label' => '宠物年龄',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_breed',
|
|
'label' => '宠物品系',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_sex',
|
|
'label' => '宠物性别',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_birthday',
|
|
'label' => '宠物生日',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_species',
|
|
'label' => '物种',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_img',
|
|
'label' => '宠物头像地址',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'package_id',
|
|
'label' => '检测套餐',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'note',
|
|
'label' => '其他需求',
|
|
'rules' => 'required'
|
|
)
|
|
);
|
|
$data = $this->json_validation($config);
|
|
$series = $this->series_number_model->get($data['device_id'],'device_id');
|
|
|
|
}
|
|
|
|
//进度查询:样品列表
|
|
public function list_get()
|
|
{
|
|
$ret = $this->sample_model->get($this->_user_id,'user_id',true);
|
|
$this->success($ret);
|
|
}
|
|
|
|
//进度查询:样品进度详情
|
|
public function detail_get()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'id',
|
|
'label' => '样品ID',
|
|
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
|
)
|
|
);
|
|
$this->load->library('form_validation');
|
|
$data = $this->input->get();
|
|
$this->form_validation->set_data($data);
|
|
$this->form_validation->set_rules($config);
|
|
if ($this->form_validation->run() === FALSE)
|
|
{
|
|
$this->error('参数错误',$this->form_validation->error_array());
|
|
}
|
|
$row = $this->sample_model->get(trim($data['id']),'device_id');
|
|
if($row['user_id'] != $this->_user_id){
|
|
$this->error('您没有权限查看该样品');
|
|
}
|
|
$this->success($row);
|
|
}
|
|
|
|
//进度查询:快递详情
|
|
public function track_get()
|
|
{
|
|
$json_params = file_get_contents('php://input');
|
|
$data = json_decode($json_params, true);
|
|
|
|
$config = array(
|
|
array(
|
|
'field' => 'device_id',
|
|
'label' => '序列号',
|
|
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
|
),
|
|
array(
|
|
'field' => 'name',
|
|
'label' => '用户姓名',
|
|
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => 'You must provide a %s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'tel',
|
|
'label' => '手机',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'email',
|
|
'label' => '邮箱',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_name',
|
|
'label' => '宠物名称',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_age',
|
|
'label' => '宠物年龄',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_breed',
|
|
'label' => '宠物品系',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_sex',
|
|
'label' => '宠物性别',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_birthday',
|
|
'label' => '宠物生日',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_species',
|
|
'label' => '物种',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_img',
|
|
'label' => '宠物头像地址',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'package_id',
|
|
'label' => '检测套餐',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'note',
|
|
'label' => '其他需求',
|
|
'rules' => 'required'
|
|
)
|
|
);
|
|
$this->load->library('form_validation');
|
|
$this->load->model('package_model');
|
|
$this->form_validation->set_data($data);
|
|
$this->form_validation->set_rules($config);
|
|
|
|
if ($this->form_validation->run() == FALSE)
|
|
{
|
|
print_r($this->form_validation->error_array());
|
|
$this->error('错误');
|
|
}
|
|
else
|
|
{
|
|
echo '成功';
|
|
}
|
|
|
|
$this->success();
|
|
|
|
}
|
|
}
|