740 lines
23 KiB
PHP
740 lines
23 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
use EasyWeChat\Foundation\Application as OfficialAccount;
|
|
class Active extends ApiController
|
|
{
|
|
function __construct()
|
|
{
|
|
header('Access-Control-Allow-Credentials: true');
|
|
parent::__construct();
|
|
//跨域
|
|
$this->load->library('session');
|
|
$this->load->model('series_number_model');
|
|
$this->load->model('package_model');
|
|
$this->load->model('sample_model');
|
|
$this->load->model('customer_model');
|
|
$this->checkUser();
|
|
}
|
|
|
|
public function ticket_get()
|
|
{
|
|
$conf = $this->config->item('weixin_uah');
|
|
$config = [
|
|
'app_id' => $conf['AppId'],
|
|
'secret' => $conf['AppSecert'],
|
|
'token' => $conf['Token'],
|
|
'aes_key' => $conf['EncodingAESKey'],
|
|
'response_type' => 'array',
|
|
];
|
|
$app = new OfficialAccount($config);
|
|
$url = $this->input->get('url');
|
|
if(!empty($url)){
|
|
$app->js->setUrl($url);
|
|
}else
|
|
if(!empty($_SERVER['HTTP_REFERER'])){
|
|
$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[3]|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('序列号不可用,套餐信息不存在');
|
|
}
|
|
|
|
$content = empty($package['content'])?[]:json_decode($package['content'],true);
|
|
//获取所有疾病的名称
|
|
if(!empty($content)){
|
|
$disease_ids = [];
|
|
foreach ($content as $item) {
|
|
$disease_ids = array_merge($disease_ids,$item['disease_id']);
|
|
}
|
|
$this->load->model('disease_model');
|
|
$disease_list = $this->disease_model->get($disease_ids,'base.id',true);
|
|
$disease_map = [];
|
|
foreach ($disease_list as $val) {
|
|
$disease_map[$val['id']] = $val;
|
|
}
|
|
//疾病详情存到信息中
|
|
foreach ($content as $key=>$val) {
|
|
$val['disease_list'] = [];
|
|
foreach ($val['disease_id'] as $v) {
|
|
if(!isset($disease_map[$v])){
|
|
continue;
|
|
}
|
|
$val['disease_list'][] = $disease_map[$v];
|
|
}
|
|
$content[$key] = $val;
|
|
}
|
|
}
|
|
$package['content'] = $content;
|
|
$this->success(['package'=>$package]);
|
|
|
|
}
|
|
|
|
//新建样本
|
|
public function create_post()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'device_id',
|
|
'label' => '序列号',
|
|
'rules' => 'trim|required|min_length[4]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
'min_length' => '%s长度不足:%s.',
|
|
'max_length' => '%s长度不能超过:%s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'name',
|
|
'label' => '用户姓名',
|
|
'rules' => 'trim|required|min_length[1]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'tel',
|
|
'label' => '手机',
|
|
'rules' => 'required',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'pet_name',
|
|
'label' => '宠物名称',
|
|
'rules' => 'required',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'pet_sex',
|
|
'label' => '宠物性别',
|
|
'rules' => 'required',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'pet_birthday',
|
|
'label' => '宠物生日',
|
|
'rules' => 'required',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
//繁育:芯片号
|
|
array(
|
|
'field' => 'chip_number',
|
|
'label' => '芯片号',
|
|
'rules' => 'trim',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
//繁育:是否种猫
|
|
array(
|
|
'field' => 'is_breeding',
|
|
'label' => '是否种猫',
|
|
'rules' => 'trim',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
//繁育:血统认证机构
|
|
array(
|
|
'field' => 'lineage_cert_body',
|
|
'label' => '血统认证机构',
|
|
'rules' => 'trim',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
)
|
|
);
|
|
$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('套餐不存在');
|
|
}
|
|
|
|
//过滤字段
|
|
$fields = array_column($config,'field');
|
|
$entity = [];
|
|
foreach ($data as $key=>$val) {
|
|
if(in_array($key,$fields)){
|
|
$entity[$key] = $val;
|
|
}
|
|
}
|
|
unset($entity['device_id']);
|
|
|
|
//套餐是否要求选择疾病
|
|
$package['content'] = empty($package['content'])?[]:json_decode($package['content'],true);
|
|
//选择的疾病处理
|
|
if(!empty($package['content'])){
|
|
if(!isset($data['package_custom'])){
|
|
$this->error('请选择套餐选项');
|
|
}
|
|
//选择的选项是否允许选择
|
|
if(!isset($package['content'][$data['package_custom']])){
|
|
$this->error('您选择的套餐选项已失效');
|
|
}
|
|
|
|
$package_custom = $package['content'][$data['package_custom']];
|
|
//获取疾病的名称,保存起来,以免id变化
|
|
$this->load->model('disease_model');
|
|
$tmp = $this->disease_model->get($package_custom['disease_id'],'base.id',true);
|
|
$entity['package_custom'] = json_encode([
|
|
'id'=>$data['package_custom'],
|
|
'name'=>$package_custom['name'],
|
|
'disease_id'=>$package_custom['disease_id'],
|
|
'disease_name'=>array_column($tmp,'name')
|
|
],JSON_UNESCAPED_UNICODE);
|
|
}else{
|
|
$entity['package_custom'] = '';
|
|
}
|
|
//用户id
|
|
$entity['user_id'] = $this->_user_id;
|
|
//从device_id读取序列号ID
|
|
$entity['series_id'] = $series['id'];
|
|
//套餐
|
|
$entity['package_id'] = $series['package_ori'];
|
|
//套餐的猫狗写进样品,防止套餐变更造成影响
|
|
$entity['pet_species'] = $package['species'];
|
|
//头像处理
|
|
if(!empty($data['file']['content'])){
|
|
$imgBase64 = $data['file']['content'];
|
|
|
|
if(!empty($data['file']['ext'])){
|
|
//对于java接口,需要兼容前端的格式
|
|
$imgBase64 = 'data:image/'.trim($data['file']['ext']).';base64,'.$imgBase64;
|
|
}
|
|
|
|
$this->load->library('uploads');
|
|
//存原图
|
|
$pet_img = $this->uploads->save_pet_img_base64(
|
|
$imgBase64,
|
|
$data['device_id']
|
|
);
|
|
if($pet_img){
|
|
$entity['pet_img'] = $pet_img;
|
|
}
|
|
}
|
|
|
|
//绝育情况,如果没有传入则按“否”处理
|
|
if(empty($entity['is_sterilized'])){
|
|
$entity['is_sterilized'] = 0;
|
|
}
|
|
|
|
//处理宠物性别与绝育情况合并的情况(非繁育用户)
|
|
switch ($entity['pet_sex']){
|
|
case 1:
|
|
$entity['pet_sex'] = 1;
|
|
break;
|
|
case 2:
|
|
$entity['pet_sex'] = 2;
|
|
break;
|
|
case 3:
|
|
$entity['pet_sex'] = 1;
|
|
$entity['is_sterilized'] = 1;
|
|
break;
|
|
case 4:
|
|
$entity['pet_sex'] = 2;
|
|
$entity['is_sterilized'] = 1;
|
|
break;
|
|
default:
|
|
$entity['pet_sex'] = 1;
|
|
}
|
|
|
|
//步骤置为初始步骤
|
|
$entity['step'] = Sample_model::STEP_BIND;
|
|
//发送微信通知
|
|
$this->load->model('weixin_message_model');
|
|
$user = $this->customer_model->get($this->_user_id);
|
|
$conf = $this->config->item('allowed_cors_origins');
|
|
try{
|
|
//如果没关注,会抛出错误,忽略
|
|
$this->weixin_message_model->send(
|
|
$user['openid'],
|
|
Weixin_message_model::TEMPLATE_ACTIVE,
|
|
base_url().'weixin/?url='.urlencode($conf['user'].'/ship'),
|
|
[
|
|
'first'=>'激活成功,如您还没选择回寄,请点击回寄',
|
|
'keyword1'=>$data['device_id'],
|
|
'keyword2'=>$package['name'],
|
|
'remark'=>'',
|
|
]
|
|
);
|
|
}catch (Exception $e){
|
|
}
|
|
|
|
//如果证书有多个,用逗号组合
|
|
if(is_array($entity['lineage_cert_body'])){
|
|
$entity['lineage_cert_body'] = implode(',',$entity['lineage_cert_body']);
|
|
}
|
|
|
|
$ret = $this->sample_model->add($entity);
|
|
/*
|
|
//保存一条样品流程处理信息
|
|
$this->load->model('sample_processing_model');
|
|
$this->sample_processing_model->add([
|
|
'sample_id'=>$ret,
|
|
'step'=>$entity['step']
|
|
]);
|
|
//保存一条样品套餐升级信息
|
|
$this->load->model('sample_upgrade_model');
|
|
$this->sample_upgrade_model->add([
|
|
'sample_id'=>$ret,
|
|
'package_id'=>$entity['package_id'],
|
|
'package_custom'=>$entity['package_custom']
|
|
]);
|
|
*/
|
|
if($ret){
|
|
//激活了繁育套餐的客户,用户信息修改
|
|
//if(!empty($package['is_breed'])){}
|
|
$this->success();
|
|
}else{
|
|
$this->error('提交失败');
|
|
}
|
|
}
|
|
|
|
//获取需回寄的样品
|
|
public function ship_get()
|
|
{
|
|
$ret = $this->sample_model->get($this->_user_id,'user_id',true);
|
|
//只展示需回寄样品
|
|
$un_ship = [];
|
|
foreach ($ret as $key=>$item) {
|
|
if($item['step'] < Sample_model::STEP_SENT){
|
|
$un_ship[] = $ret[$key];
|
|
}
|
|
}
|
|
$first = [];
|
|
//取第一个样品的信息
|
|
if(!empty($un_ship)){
|
|
$first = $un_ship[0];
|
|
}elseif(!empty($ret)){
|
|
$first = $ret[0];
|
|
}
|
|
$this->success(['sample'=>$un_ship,'info'=>$first]);
|
|
}
|
|
|
|
//样品回寄
|
|
public function ship_post()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'device_id[]',
|
|
'label' => '样品',
|
|
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'name',
|
|
'label' => '姓名',
|
|
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => '请提供以下信息:%s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'tel',
|
|
'label' => '手机号',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'address',
|
|
'label' => '地址',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'province',
|
|
'label' => '省',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'city',
|
|
'label' => '市',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'district',
|
|
'label' => '区',
|
|
'rules' => 'required'
|
|
)
|
|
);
|
|
$receiver_address = array(
|
|
'cat' => array(
|
|
'd_province' => '广东省',
|
|
'd_city' => '深圳市',
|
|
'd_county' => '大鹏新区',
|
|
'd_company' => '有哈科技',
|
|
'd_contact' => '有哈收样组(侯佩彤)',
|
|
'd_tel' => '13723470168',
|
|
'd_address' => '大鹏街道鹏飞路7号中国农科院中国农业科学院深圳农业基因组研究所',
|
|
),
|
|
'dog' => array(
|
|
'd_province' => '广东省',
|
|
'd_city' => '深圳市',
|
|
'd_county' => '大鹏新区',
|
|
'd_company' => '有哈科技',
|
|
'd_contact' => '有哈收样组(侯佩彤)',
|
|
'd_tel' => '13723470168',
|
|
'd_address' => '大鹏街道鹏飞路7号中国农科院中国农业科学院深圳农业基因组研究所',
|
|
)
|
|
);
|
|
$data = $this->json_validation($config);
|
|
$sample_ids = [];
|
|
$dog_cat = [false, false];
|
|
$samples = array(
|
|
'cat' => [],
|
|
'cat_device_ids' =>[],
|
|
'dog' => [],
|
|
'dog_device_ids' =>[],
|
|
);
|
|
foreach ($data['device_id'] as $device_id) {
|
|
$sample = $this->sample_model->get($device_id,'device_id');
|
|
if($sample['user_id'] != $this->_user_id){
|
|
$this->error('该样品不在您名下');
|
|
}
|
|
if ($sample['pet_species'] == 1){
|
|
$dog_cat[0] = true;
|
|
$samples['dog'][] = $sample['id'];
|
|
$samples['dog_device_ids'][] = $device_id;
|
|
}else if ($sample['pet_species'] == 2){
|
|
$dog_cat[1] = true;
|
|
$samples['cat'][] = $sample['id'];
|
|
$samples['cat_device_ids'][] = $device_id;
|
|
}
|
|
$sample_ids[] = $sample['id'];
|
|
}
|
|
//创建订单
|
|
$data['user_id'] = $this->_user_id;
|
|
$this->load->model('sf_express_model');
|
|
if ($dog_cat[0] && $dog_cat[1]){
|
|
// $this->error("ship -> dog: $dog_cat[0], cat: $dog_cat[1]");
|
|
$data['d_province'] = $receiver_address['dog']['d_province'];
|
|
$data['d_city'] = $receiver_address['dog']['d_city'];
|
|
$data['d_county'] = $receiver_address['dog']['d_county'];
|
|
$data['d_company'] = $receiver_address['dog']['d_company'];
|
|
$data['d_contact'] = $receiver_address['dog']['d_contact'];
|
|
$data['d_tel'] = $receiver_address['dog']['d_tel'];
|
|
$data['d_address'] = $receiver_address['dog']['d_address'];
|
|
$data['trade_id'] = $samples['dog'][0];
|
|
$ret = $this->sf_express_model->shipSample($data);
|
|
//$ret = [true];
|
|
error_log("shipSample dog: $ret[0] $ret[1]");
|
|
if($ret[0]){
|
|
//快递id写到样品中
|
|
$this->sample_model->update(['ship_order_id'=>$ret[1],'step'=>Sample_model::STEP_SENT],'id in ('.implode(',',$samples['dog']).')');
|
|
try{
|
|
//发送微信通知
|
|
$this->load->model('weixin_message_model');
|
|
$user = $this->customer_model->get($this->_user_id);
|
|
//如果没关系,会抛出错误,忽略
|
|
$this->weixin_message_model->send(
|
|
$user['openid'],
|
|
Weixin_message_model::TEMPLATE_SENT,
|
|
null,
|
|
[
|
|
'first'=>'尊敬的用户:我们已为您分配了快递员,请保持手机畅通,快递员会尽快与您联系。',
|
|
'keyword1'=>implode(',',$samples['dog_device_ids']),
|
|
//'keyword2'=>'上门取货后获取',
|
|
'keyword2'=>$ret[1],
|
|
'keyword3'=>'预估两小时内',
|
|
//'remark'=>'物流信息只能在中通官网查看,请保管好回寄单号方便日后物流查询。',
|
|
'remark'=>'我们已为您呼叫了顺丰速运,请耐心等待。物流信息可在“顺丰速运”公众号查看。',
|
|
]
|
|
);
|
|
}catch (Exception $e){
|
|
}
|
|
}else{
|
|
if (strpos($ret[1], '您的预约超出今日营业时间') !== false){
|
|
$this->error('快递营业时间:8-18点,现已超出今日营业时间,请于明日8点后进行预约取件。');
|
|
}else{
|
|
$this->error('快递未能使用,请添加微信号“uap_pet”咨询客服,错误信息:'.$ret[1]);
|
|
|
|
}
|
|
}
|
|
sleep(1);
|
|
$data['d_province'] = $receiver_address['cat']['d_province'];
|
|
$data['d_city'] = $receiver_address['cat']['d_city'];
|
|
$data['d_county'] = $receiver_address['cat']['d_county'];
|
|
$data['d_company'] = $receiver_address['cat']['d_company'];
|
|
$data['d_contact'] = $receiver_address['cat']['d_contact'];
|
|
$data['d_tel'] = $receiver_address['cat']['d_tel'];
|
|
$data['d_address'] = $receiver_address['cat']['d_address'];
|
|
$data['trade_id'] = $samples['cat'][0];
|
|
$ret = $this->sf_express_model->shipSample($data);
|
|
//$ret = [true];
|
|
error_log("shipSample cat: $ret[0] $ret[1]");
|
|
if($ret[0]){
|
|
//快递id写到样品中
|
|
$this->sample_model->update(['ship_order_id'=>$ret[1],'step'=>Sample_model::STEP_SENT],'id in ('.implode(',',$samples['dog']).')');
|
|
try{
|
|
//发送微信通知
|
|
$this->load->model('weixin_message_model');
|
|
$user = $this->customer_model->get($this->_user_id);
|
|
//如果没关系,会抛出错误,忽略
|
|
$this->weixin_message_model->send(
|
|
$user['openid'],
|
|
Weixin_message_model::TEMPLATE_SENT,
|
|
null,
|
|
[
|
|
'first'=>'尊敬的用户:我们已为您分配了快递员,请保持手机畅通,快递员会尽快与您联系。',
|
|
'keyword1'=>implode(',',$samples['cat_device_ids']),
|
|
//'keyword2'=>'上门取货后获取',
|
|
'keyword2'=>$ret[1],
|
|
'keyword3'=>'预估两小时内',
|
|
//'remark'=>'物流信息只能在中通官网查看,请保管好回寄单号方便日后物流查询。',
|
|
'remark'=>'我们已为您呼叫了顺丰速运,请耐心等待。物流信息可在“顺丰速运”公众号查看。',
|
|
]
|
|
);
|
|
}catch (Exception $e){
|
|
}
|
|
$this->success();
|
|
}else{
|
|
if (strpos($ret[1], '您的预约超出今日营业时间') !== false){
|
|
$this->error('快递营业时间:8-18点,现已超出今日营业时间,请于明日8点后进行预约取件。');
|
|
}else{
|
|
$this->error('快递未能使用,请添加微信号“uap_pet”咨询客服,错误信息:'.$ret[1]);
|
|
|
|
}
|
|
}
|
|
}else if ($dog_cat[1] || $dog_cat[0]){
|
|
$data['trade_id'] = $data['device_id'][0];
|
|
if ($dog_cat[0]){
|
|
$data['d_province'] = $receiver_address['dog']['d_province'];
|
|
$data['d_city'] = $receiver_address['dog']['d_city'];
|
|
$data['d_county'] = $receiver_address['dog']['d_county'];
|
|
$data['d_company'] = $receiver_address['dog']['d_company'];
|
|
$data['d_contact'] = $receiver_address['dog']['d_contact'];
|
|
$data['d_tel'] = $receiver_address['dog']['d_tel'];
|
|
$data['d_address'] = $receiver_address['dog']['d_address'];
|
|
}else{
|
|
$data['d_province'] = $receiver_address['cat']['d_province'];
|
|
$data['d_city'] = $receiver_address['cat']['d_city'];
|
|
$data['d_county'] = $receiver_address['cat']['d_county'];
|
|
$data['d_company'] = $receiver_address['cat']['d_company'];
|
|
$data['d_contact'] = $receiver_address['cat']['d_contact'];
|
|
$data['d_tel'] = $receiver_address['cat']['d_tel'];
|
|
$data['d_address'] = $receiver_address['cat']['d_address'];
|
|
}
|
|
$ret = $this->sf_express_model->shipSample($data);
|
|
//$ret = [true];
|
|
if($ret[0]){
|
|
//快递id写到样品中
|
|
$this->sample_model->update(['ship_order_id'=>$ret[1],'step'=>Sample_model::STEP_SENT],'id in ('.implode(',',$sample_ids).')');
|
|
try{
|
|
//发送微信通知
|
|
$this->load->model('weixin_message_model');
|
|
$user = $this->customer_model->get($this->_user_id);
|
|
//如果没关系,会抛出错误,忽略
|
|
$this->weixin_message_model->send(
|
|
$user['openid'],
|
|
Weixin_message_model::TEMPLATE_SENT,
|
|
null,
|
|
[
|
|
'first'=>'尊敬的用户:我们已为您分配了快递员,请保持手机畅通,快递员会尽快与您联系。',
|
|
'keyword1'=>implode(',',$data['device_id']),
|
|
//'keyword2'=>'上门取货后获取',
|
|
'keyword2'=>$ret[1],
|
|
'keyword3'=>'预估两小时内',
|
|
//'remark'=>'物流信息只能在中通官网查看,请保管好回寄单号方便日后物流查询。',
|
|
'remark'=>'我们已为您呼叫了顺丰速运,请耐心等待。物流信息可在“顺丰速运”公众号查看。',
|
|
]
|
|
);
|
|
}catch (Exception $e){
|
|
}
|
|
$this->success();
|
|
}else{
|
|
if (strpos($ret[1], '您的预约超出今日营业时间') !== false){
|
|
$this->error('快递营业时间:8-18点,现已超出今日营业时间,请于明日8点后进行预约取件。');
|
|
}else{
|
|
$this->error('快递未能使用,请添加微信号“uap_pet”咨询客服,错误信息:'.$ret[1]);
|
|
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
if($data['name'] == '有哈'){
|
|
$this->load->model('sf_express_model');
|
|
$ret = $this->sf_express_model->shipSample($data);
|
|
}else{
|
|
$this->load->model('zto_model');
|
|
$ret = $this->zto_model->shipSample($data);
|
|
}*/
|
|
}
|
|
|
|
//进度查询:样品列表
|
|
public function list_get()
|
|
{
|
|
$ret = $this->sample_model->get($this->_user_id,'user_id',true);
|
|
$list = [];
|
|
if($ret)foreach ($ret as $item) {
|
|
//废弃的样品不呈现
|
|
if($item['step'] == Sample_model::STEP_DISCARD){
|
|
continue;
|
|
}
|
|
$item['step_fail'] = $item['step'] == Sample_model::STEP_UNQUALIFIED;
|
|
$list[] = $item;
|
|
}
|
|
$this->success($list);
|
|
}
|
|
|
|
//进度查询:样品进度详情
|
|
public function detail_get()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'id',
|
|
'label' => '样品ID',
|
|
'rules' => 'trim|required|min_length[4]|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());
|
|
}
|
|
$sample = $this->sample_model->get(trim($data['id']),'device_id');
|
|
if($sample['user_id'] != $this->_user_id){
|
|
$this->error('您没有权限查看该样品');
|
|
}
|
|
if($sample['step'] == Sample_model::STEP_DISCARD){
|
|
$this->error('该样品已作废');
|
|
}
|
|
//获取摘要版的进度
|
|
$steps = $this->sample_model->step_summary;
|
|
//当前进度
|
|
$sample['step_desc'] = $steps[$sample['step']];
|
|
//成功与失败状态不能同时存在
|
|
$sample['step_fail'] = $sample['step'] == Sample_model::STEP_UNQUALIFIED;
|
|
if($sample['step_fail']){
|
|
//隐藏成功项目
|
|
unset($steps[Sample_model::STEP_DNA_EXTRACTED]);
|
|
}else{
|
|
//隐藏失败项目
|
|
unset($steps[Sample_model::STEP_UNQUALIFIED]);
|
|
}
|
|
//删除重复的进度
|
|
$steps = array_keys(array_flip($steps));
|
|
//当前在哪一个步骤
|
|
$sample['step_active'] = array_search($sample['step_desc'],$steps);
|
|
$sample['step_active_fail'] = $sample['step_fail'] ? $sample['step_active'] : -1;
|
|
|
|
//状态描述改成小描述
|
|
$sample['step_desc'] = $this->sample_model->step[$sample['step']];
|
|
//获取物流信息
|
|
$track = [];
|
|
$this->load->model('zto_model');
|
|
$ship_order = false;
|
|
//$ship_order = $this->zto_model->get(trim($sample['id']),'sample_id');
|
|
if($ship_order){
|
|
$track = $this->zto_model->traceInterfaceNewTraces($ship_order['order_code']);
|
|
}
|
|
$this->success([
|
|
'sample'=>$sample,
|
|
'ship_order'=>$ship_order,
|
|
//步骤需要提醒
|
|
'error_step'=>Sample_model::STEP_UNQUALIFIED,
|
|
'track'=>$track,
|
|
'steps'=>$steps,
|
|
]);
|
|
}
|
|
|
|
//升级样品:获取可升级的套餐
|
|
public function upgrade_post()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'id',
|
|
'label' => '样品ID',
|
|
'rules' => 'trim|required|min_length[4]|max_length[20]'
|
|
)
|
|
);
|
|
$data = $this->json_validation($config);
|
|
$sample = $this->sample_model->get(trim($data['id']),'device_id');
|
|
/*
|
|
if($sample['user_id'] != $this->_user_id){
|
|
$this->error('您没有权限查看该样品');
|
|
}*/
|
|
//查询可升级套餐,即同物种的更高价格的套餐
|
|
$packages = $this->package_model->get(trim($sample['pet_species']),'species',true);
|
|
$cur_package = null;
|
|
$up_packages = [];
|
|
foreach ($packages as $package) {
|
|
if($package['id'] == $sample['package_id']){
|
|
$cur_package = $package;
|
|
}else{
|
|
//只输出特定信息给用户前端
|
|
$up_packages[] = [
|
|
'id'=>$package['id'],
|
|
'name'=>$package['name'],
|
|
'description'=>$package['description'],
|
|
'price'=>$package['price']
|
|
];
|
|
}
|
|
}
|
|
if(is_null($cur_package)){
|
|
$this->error('样品原套餐信息丢失,暂不可升级');
|
|
}
|
|
//过滤比当前套餐价格低的套餐
|
|
foreach ($up_packages as $key=> $package) {
|
|
if($package['price'] <= $cur_package['price']){
|
|
unset($up_packages[$key]);
|
|
continue;
|
|
}
|
|
//输出升级差价
|
|
$up_packages[$key]['balance'] = round($package['price'] - $cur_package['price'],2);
|
|
}
|
|
if(empty($up_packages)){
|
|
$this->success();
|
|
}
|
|
//按照价格从低到高排序
|
|
array_multisort(array_column($up_packages,'price'),SORT_DESC,$up_packages);
|
|
$this->success(['packages'=>$up_packages]);
|
|
}
|
|
|
|
public function test_get(){
|
|
$this->load->library('uploads');
|
|
echo $this->uploads->get_upload_path();
|
|
}
|
|
|
|
}
|