feat: init project codebase
This commit is contained in:
@@ -0,0 +1,739 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,590 @@
|
||||
<?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'
|
||||
)
|
||||
);
|
||||
$data = $this->json_validation($config);
|
||||
$sample_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('该样品不在您名下');
|
||||
}
|
||||
$sample_ids[] = $sample['id'];
|
||||
}
|
||||
|
||||
//创建订单
|
||||
$data['user_id'] = $this->_user_id;
|
||||
$data['trade_id'] = $data['device_id'][0];
|
||||
/*
|
||||
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);
|
||||
}*/
|
||||
$this->load->model('sf_express_model');
|
||||
$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{
|
||||
$this->error('快递未能使用,请添加微信号“uap_pet”咨询客服,错误信息:'.$ret[1]);
|
||||
}
|
||||
}
|
||||
|
||||
//进度查询:样品列表
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,724 @@
|
||||
<?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' => '17596551135',
|
||||
'd_address' => '大鹏新区布新路97号农科院基因组所A栋',
|
||||
),
|
||||
'dog' => array(
|
||||
'd_province' => '江苏省',
|
||||
'd_city' => '南京市',
|
||||
'd_county' => '浦口区',
|
||||
'd_company' => '有哈科技',
|
||||
'd_contact' => '有哈收样组(犬)',
|
||||
'd_tel' => '17751784617',
|
||||
'd_address' => '行知路8号南京农创中心方舟实验室C栋南楼3层',
|
||||
)
|
||||
);
|
||||
$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{
|
||||
$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{
|
||||
$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{
|
||||
$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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,739 @@
|
||||
<?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' => '17751784617',
|
||||
'd_address' => '行知路8号南京农创中心方舟实验室C栋南楼3层',
|
||||
),
|
||||
'dog' => array(
|
||||
'd_province' => '江苏省',
|
||||
'd_city' => '南京市',
|
||||
'd_county' => '浦口区',
|
||||
'd_company' => '有哈科技',
|
||||
'd_contact' => '有哈收样组',
|
||||
'd_tel' => '17751784617',
|
||||
'd_address' => '行知路8号南京农创中心方舟实验室C栋南楼3层',
|
||||
)
|
||||
);
|
||||
$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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class Breeding extends ApiController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
parent::__construct();
|
||||
//跨域
|
||||
$this->load->library('session');
|
||||
$this->load->model('customer_model');
|
||||
//$this->session->{Customer_model::SESSION_KEY} = 1;
|
||||
$this->checkUser();
|
||||
}
|
||||
|
||||
//获取繁育人信息
|
||||
public function info_get(){
|
||||
$row = $this->customer_model->get($this->_user_id);
|
||||
//统计数量
|
||||
$this->load->model('sample_model');
|
||||
$this->load->model('breeding_plan_model');
|
||||
$row['total_sample'] = $this->sample_model->getUserTotal($this->_user_id);
|
||||
$row['total_breeding_plan'] = $this->breeding_plan_model->getUserTotal($this->_user_id);
|
||||
$this->success($row);
|
||||
}
|
||||
|
||||
//获取种猫/犬
|
||||
public function candidate_post(){
|
||||
$this->load->model('sample_model');
|
||||
$this->load->model('report_model');
|
||||
$data = $this->json_input();
|
||||
$ids = [];
|
||||
if(!empty($data['tree']) && is_array($data['tree'])){
|
||||
$ids = $this->_getTreeSampleIds($data['tree']);
|
||||
}
|
||||
$pet_sex = empty($data['pet_sex'])?0:(int)$data['pet_sex'];
|
||||
$pet_species = empty($data['pet_species'])?0:(int)$data['pet_species'];
|
||||
|
||||
$list = $this->sample_model->getBreeding($this->_user_id,$ids,$pet_species,$pet_sex,100);
|
||||
$ret = [];
|
||||
foreach ($list as $val) {
|
||||
$reportJson = $this->report_model->get_report_json($val['device_id'],$val['pet_species']);
|
||||
$ret[] = $this->_getCandidateItem($val,$reportJson);
|
||||
}
|
||||
$this->success($ret);
|
||||
}
|
||||
|
||||
//繁育计划保存
|
||||
public function plan_save_post()
|
||||
{
|
||||
$data = $this->json_input();
|
||||
if(empty($data['tree'])){
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$tree = $data['tree'];
|
||||
//保存孩子的样本id
|
||||
$children_ids = [];
|
||||
foreach ($tree['children'] as $item) {
|
||||
if(!empty($item['id'])){
|
||||
$children_ids[] = $item['id'];
|
||||
}
|
||||
}
|
||||
//雌性
|
||||
$female_id = !empty($tree['female']['self']['id'])?(int)$tree['female']['self']['id']:0;
|
||||
$female_father_id = !empty($tree['female']['father']['id'])?(int)$tree['female']['father']['id']:0;
|
||||
$female_mother_id = !empty($tree['female']['mother']['id'])?(int)$tree['female']['mother']['id']:0;
|
||||
|
||||
//雄性
|
||||
$male_id = !empty($tree['male']['self']['id'])?(int)$tree['male']['self']['id']:0;
|
||||
$male_father_id = !empty($tree['male']['father']['id'])?(int)$tree['male']['father']['id']:0;
|
||||
$male_mother_id = !empty($tree['male']['mother']['id'])?(int)$tree['male']['mother']['id']:0;
|
||||
|
||||
if(empty($female_id) || empty($male_id)){
|
||||
$this->error('关系不完整');
|
||||
}
|
||||
$this->load->model('breeding_plan_model');
|
||||
$entity = [
|
||||
'children_ids' => implode(',',$children_ids),
|
||||
'user_id' => $this->_user_id,
|
||||
'female_id' => $female_id,
|
||||
'female_father_id' => $female_father_id,
|
||||
'female_mother_id' => $female_mother_id,
|
||||
'male_id' => $male_id,
|
||||
'male_father_id' => $male_father_id,
|
||||
'male_mother_id' => $male_mother_id,
|
||||
];
|
||||
if(empty($data['id'])){
|
||||
$this->breeding_plan_model->add($entity);
|
||||
}else{
|
||||
$this->breeding_plan_model->update($entity,[
|
||||
'id'=>$data['id']
|
||||
]);
|
||||
}
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
|
||||
//繁育计划列表
|
||||
public function list_get()
|
||||
{
|
||||
$this->load->model('breeding_plan_model');
|
||||
$ret = $this->breeding_plan_model->get($this->_user_id,'user_id',true);
|
||||
$list = [];
|
||||
if($ret){
|
||||
//获取所有相关样品
|
||||
$sample_ids = [];
|
||||
foreach ($ret as $item) {
|
||||
$sample_ids[] = $item['male_id'];
|
||||
$sample_ids[] = $item['female_id'];
|
||||
}
|
||||
|
||||
$this->load->model('sample_model');
|
||||
//根据id获取样本信息
|
||||
$samples = $this->sample_model->getByUserIds($sample_ids);
|
||||
$sample_map = [];
|
||||
foreach ($samples as $item) {
|
||||
$this->sample_model->format($item);
|
||||
$sample_map[$item['id']] = $item;
|
||||
}
|
||||
|
||||
//格式化信息
|
||||
foreach ($ret as $item) {
|
||||
$male = [
|
||||
'name'=>$sample_map[$item['male_id']]['pet_name'],
|
||||
'pet_img'=>$sample_map[$item['male_id']]['pet_img'],
|
||||
'device_id'=>$sample_map[$item['male_id']]['device_id'],
|
||||
];
|
||||
$female = [
|
||||
'name'=>$sample_map[$item['female_id']]['pet_name'],
|
||||
'pet_img'=>$sample_map[$item['female_id']]['pet_img'],
|
||||
'device_id'=>$sample_map[$item['female_id']]['device_id'],
|
||||
];
|
||||
$tmp = [
|
||||
'id'=>$item['id'],
|
||||
'male'=>$male,
|
||||
'female'=>$female,
|
||||
];
|
||||
$list[] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
$this->success($list);
|
||||
}
|
||||
|
||||
//繁育计划列表
|
||||
public function detail_get()
|
||||
{
|
||||
$id = $this->input->get('id');
|
||||
if(empty($id)){
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$this->load->model('breeding_plan_model');
|
||||
$plan = $this->breeding_plan_model->get($id);
|
||||
if(!$plan){
|
||||
$this->error('计划不存在');
|
||||
}
|
||||
$tree = [
|
||||
'male'=>[
|
||||
'father'=>$this->_getNode($plan['male_father_id']),
|
||||
'mother'=>$this->_getNode($plan['male_mother_id']),
|
||||
'self'=>$this->_getNode($plan['male_id']),
|
||||
],
|
||||
'female'=>[
|
||||
'father'=>$this->_getNode($plan['female_father_id']),
|
||||
'mother'=>$this->_getNode($plan['female_mother_id']),
|
||||
'self'=>$this->_getNode($plan['female_id']),
|
||||
],
|
||||
'children'=>[]
|
||||
];
|
||||
if(!empty($plan['children_ids'])){
|
||||
$plan['children_ids'] = explode(',',$plan['children_ids']);
|
||||
foreach ($plan['children_ids'] as $val) {
|
||||
$tree['children'][] = $this->_getNode($val);
|
||||
}
|
||||
}
|
||||
//如果没有children,补一个
|
||||
if(empty($tree['children'])){
|
||||
$tree['children'][] = [
|
||||
'id'=>0,
|
||||
'pet_name'=>'',
|
||||
'pet_img'=>'',
|
||||
];
|
||||
}
|
||||
|
||||
$this->success($tree);
|
||||
}
|
||||
|
||||
|
||||
//繁育计划节点
|
||||
protected function _getNode($sample_id)
|
||||
{
|
||||
$this->load->model('sample_model');
|
||||
$sample = $this->sample_model->get($sample_id);
|
||||
if(!$sample){
|
||||
return [
|
||||
'id'=>0
|
||||
];
|
||||
}
|
||||
return $sample;
|
||||
}
|
||||
|
||||
//繁育计划候选列表项目
|
||||
protected function _getCandidateItem($sample,$reportJson)
|
||||
{
|
||||
$lineage = !empty($reportJson['血统分析']['body']['品系纯度'])?$reportJson['血统分析']['body']['品系纯度']:[];
|
||||
$lineage = implode(',',array_keys($lineage));
|
||||
|
||||
$item = [
|
||||
'id'=>$sample['id'],
|
||||
'pet_name'=>$sample['pet_name'],
|
||||
'pet_img'=>$sample['pet_img'],
|
||||
'pet_sex'=>$sample['pet_sex'],
|
||||
'lineage'=>$lineage,
|
||||
];
|
||||
return $item;
|
||||
}
|
||||
|
||||
//繁育计划树的所有id
|
||||
protected function _getTreeSampleIds($tree)
|
||||
{
|
||||
$ids = [];
|
||||
foreach ($tree as $key=>$val) {
|
||||
foreach ($val as $v) {
|
||||
$ids[] = $v['id'];
|
||||
}
|
||||
}
|
||||
return array_filter(array_unique($ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
* Class Active
|
||||
*/
|
||||
class Sync extends ApiController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
parent::__construct();
|
||||
$this->load->model('series_number_model');
|
||||
$this->load->model('package_model');
|
||||
$this->load->model('sample_model');
|
||||
$this->load->model('customer_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端请求创建用户
|
||||
* 绕过了前端授权
|
||||
*/
|
||||
public function user_post()
|
||||
{
|
||||
$ret = $this->serverSign();
|
||||
if(!$ret){
|
||||
$this->error('您的签名错误');
|
||||
}
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'openid',
|
||||
'label' => 'OPENID',
|
||||
'rules' => 'trim|required|min_length[3]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'unionid',
|
||||
'label' => 'UNIONID',
|
||||
'rules' => 'trim|required|min_length[3]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'nickname',
|
||||
'label' => 'nickname',
|
||||
'rules' => 'trim|required|min_length[1]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'sex',
|
||||
'label' => 'sex',
|
||||
'rules' => 'trim|min_length[1]|max_length[2]'
|
||||
),
|
||||
array(
|
||||
'field' => 'language',
|
||||
'label' => 'language',
|
||||
'rules' => 'trim|min_length[1]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'city',
|
||||
'label' => 'city',
|
||||
'rules' => 'trim|min_length[1]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'province',
|
||||
'label' => 'province',
|
||||
'rules' => 'trim|min_length[0]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'country',
|
||||
'label' => 'country',
|
||||
'rules' => 'trim|min_length[0]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'headimgurl',
|
||||
'label' => 'headimgurl',
|
||||
'rules' => 'trim|required|min_length[3]|max_length[1000]'
|
||||
),
|
||||
);
|
||||
$data = $this->json_validation($config);
|
||||
$data['is_server'] = 1;
|
||||
$ret = $this->customer_model->weixin_users($data);
|
||||
if($ret){
|
||||
$this->success('成功');
|
||||
}else{
|
||||
$this->error('创建失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
use EasyWeChat\Foundation\Application as OfficialAccount;
|
||||
use EasyWeChat\Payment\Order as WxPayOrder;
|
||||
class Upgrade extends ApiController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function getApp(){
|
||||
$conf = $this->config->item('weixin_uah');
|
||||
$config = [
|
||||
'app_id' => $conf['AppId'],
|
||||
'secret' => $conf['AppSecert'],
|
||||
'token' => $conf['Token'],
|
||||
'aes_key' => $conf['EncodingAESKey'],
|
||||
'response_type' => 'array',
|
||||
'payment'=>[
|
||||
// 必要配置
|
||||
'app_id' => $conf['AppId'],
|
||||
'mch_id' => $conf['mch_id'],
|
||||
'key' => $conf['pay_api_key'], // API 密钥
|
||||
|
||||
// 如需使用敏感接口(如退款、发送红包等)需要配置
|
||||
'cert_path' => $conf['pay_cert_path'], // 绝对路径
|
||||
'key_path' => $conf['pay_key_path'], // 绝对路径
|
||||
|
||||
'notify_url' => '默认的订单回调地址', // 下单时单独设置来覆盖它
|
||||
|
||||
//'sandbox_mode' => (ENVIRONMENT !== 'production'), // 设置为 false 或注释则关闭沙箱模式
|
||||
]
|
||||
];
|
||||
return new OfficialAccount($config);
|
||||
}
|
||||
|
||||
//创建升级订单
|
||||
public function order_post()
|
||||
{
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'id',
|
||||
'label' => 'ID',
|
||||
'rules' => 'trim|required|min_length[4]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'package_id',
|
||||
'label' => 'ID',
|
||||
'rules' => 'trim|required|min_length[1]|max_length[20]'
|
||||
)
|
||||
);
|
||||
$data = $this->json_validation($config);
|
||||
$this->load->model('sample_model');
|
||||
$sample = $this->sample_model->get($data['id'],'device_id');
|
||||
if(empty($sample)){
|
||||
$this->error('样品不存在');
|
||||
}
|
||||
if($sample['package_id'] == $data['package_id']){
|
||||
$this->error('升级信息不正确');
|
||||
}
|
||||
$this->load->model('package_model');
|
||||
$to_package = $this->package_model->get($data['package_id'],'id');
|
||||
$from_package = $this->package_model->get($sample['package_id'],'id');
|
||||
if(empty($to_package) || empty($from_package)){
|
||||
$this->error('套餐信息不存在');
|
||||
}
|
||||
$total = $to_package['price'] - $from_package['price'];
|
||||
//生成订单
|
||||
//同样订单升级方案只能创建一个订单
|
||||
$order_id = null;
|
||||
$this->load->model('sample_upgrade_order_model');
|
||||
$order_list = $this->sample_upgrade_order_model->get($sample['id'],'base.sample_id',true);
|
||||
foreach ($order_list as $value) {
|
||||
if($value['package_before'] == $from_package['id'] &&
|
||||
$value['package_after'] == $to_package['id']
|
||||
){
|
||||
if($value['paid_time'] > 0){
|
||||
$this->error('您的订单已支付');
|
||||
}
|
||||
$order_id = $value['id'];
|
||||
}
|
||||
}
|
||||
if(is_null($order_id)){
|
||||
$order_id = $this->sample_upgrade_order_model->add([
|
||||
'sample_id'=>$sample['id'],
|
||||
'grand_total'=>$total,
|
||||
'package_before'=>$from_package['id'],
|
||||
'package_after'=>$to_package['id'],
|
||||
'grand_total'=>$total,
|
||||
]);
|
||||
}
|
||||
if(!$order_id){
|
||||
$this->error('订单创建失败');
|
||||
}
|
||||
//获取用户的openid
|
||||
$this->load->model('customer_model');
|
||||
$customer = $this->customer_model->get($sample['user_id'],'id');
|
||||
|
||||
$attributes = [
|
||||
'body' => '有哈检测套餐升级',
|
||||
'out_trade_no' => 'testadsfdsffadsf',
|
||||
//'total_fee' => (ENVIRONMENT !== 'production'?101:$total*100),//沙箱环境固定为1.01,正式环境固定为分
|
||||
'total_fee' => $total*100,//单位:分
|
||||
//'spbill_create_ip' => '', // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
|
||||
'notify_url' => base_url().'api/user/'.strtolower(__CLASS__).'/callback', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
||||
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
|
||||
'openid' => $customer['openid'],
|
||||
];
|
||||
$order = new WxPayOrder($attributes);
|
||||
//print_r($attributes);die;
|
||||
$app = $this->getApp();
|
||||
$result = $app->payment->prepare($order);
|
||||
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS'){
|
||||
$prepayId = $result->prepay_id;
|
||||
$json = $app->payment->configForPayment($prepayId,false); // 返回 json 字符串,如果想返回数组,传第二个参数
|
||||
$this->success($json);
|
||||
}
|
||||
//print_r($result);die;
|
||||
log_message('error', json_encode($data).''.json_encode($result));
|
||||
$this->error('下单失败,请联系客服');
|
||||
}
|
||||
|
||||
public function callback_get()
|
||||
{
|
||||
log_message('error',json_encode($_GET));
|
||||
log_message('error',json_encode($_POST));
|
||||
log_message('error',json_encode(file_get_contents('php://input')));
|
||||
$app = $this->getApp();
|
||||
$this->$app->payment->handleNotify(function($notify, $successful){
|
||||
// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
|
||||
$this->load->model('sample_upgrade_order_model');
|
||||
$order = $this->sample_upgrade_order_model->get($notify->out_trade_no);
|
||||
if (!$order) { // 如果订单不存在
|
||||
return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
|
||||
}
|
||||
// 如果订单存在
|
||||
// 检查订单是否已经更新过支付状态
|
||||
if ($order['paid_time']) { // 假设订单字段“支付时间”不为空代表已经支付
|
||||
return true; // 已经支付成功了就不再更新了
|
||||
}
|
||||
$data = [];
|
||||
// 用户是否支付成功
|
||||
if ($successful) {
|
||||
// 不是已经支付状态则修改为已经支付状态
|
||||
$data['paid_time'] = time(); // 更新支付时间为当前时间
|
||||
$data['pay_status'] = 1;
|
||||
} else { // 用户支付失败
|
||||
$data['pay_status'] = 2;
|
||||
}
|
||||
$this->sample_upgrade_order_model->update($data,[
|
||||
'id'=>$notify->out_trade_no
|
||||
]);
|
||||
return true; // 返回处理完成
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
use EasyWeChat\Foundation\Application as OfficialAccount;
|
||||
use EasyWeChat\Payment\Order as WxPayOrder;
|
||||
class Upgrade extends ApiController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
parent::__construct();
|
||||
$this->load->library('session');
|
||||
}
|
||||
|
||||
protected function getApp(){
|
||||
$conf = $this->config->item('weixin_uah');
|
||||
$config = [
|
||||
'app_id' => $conf['AppId'],
|
||||
'secret' => $conf['AppSecert'],
|
||||
'token' => $conf['Token'],
|
||||
'aes_key' => $conf['EncodingAESKey'],
|
||||
'response_type' => 'array',
|
||||
'payment'=>[
|
||||
// 必要配置
|
||||
'app_id' => $conf['AppId'],
|
||||
'mch_id' => $conf['mch_id'],
|
||||
'key' => $conf['pay_api_key'], // API 密钥
|
||||
|
||||
// 如需使用敏感接口(如退款、发送红包等)需要配置
|
||||
'cert_path' => $conf['pay_cert_path'], // 绝对路径
|
||||
'key_path' => $conf['pay_key_path'], // 绝对路径
|
||||
|
||||
'notify_url' => '默认的订单回调地址', // 下单时单独设置来覆盖它
|
||||
|
||||
//'sandbox_mode' => (ENVIRONMENT !== 'production'), // 设置为 false 或注释则关闭沙箱模式
|
||||
]
|
||||
];
|
||||
return new OfficialAccount($config);
|
||||
}
|
||||
|
||||
//创建升级订单
|
||||
public function order_post()
|
||||
{
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'id',
|
||||
'label' => '样本编号',
|
||||
'rules' => 'trim|required|min_length[4]|max_length[20]',
|
||||
'errors' => array(
|
||||
'required' => '请提供以下信息:%s.',
|
||||
),
|
||||
)
|
||||
);
|
||||
$data = $this->json_validation($config);
|
||||
//样本信息
|
||||
$this->load->model('sample_model');
|
||||
$sample = $this->sample_model->get($data['id'],'device_id');
|
||||
if(!$sample){
|
||||
$this->error('样本不存在');
|
||||
}
|
||||
//序列号信息
|
||||
$this->load->model('series_number_model');
|
||||
$series = $this->series_number_model->get($data['id'],'device_id');
|
||||
if(empty($series)){
|
||||
$this->error('序列号信息不存在');
|
||||
}
|
||||
//如果样本中没有记录套餐,则根据序列号绑定的套餐做升级
|
||||
$package_ori = !empty($sample['package_id'])?$sample['package_id']:$series['package_ori'];
|
||||
//套餐信息
|
||||
$this->load->model('package_model');
|
||||
$from_package = $this->package_model->get($package_ori);
|
||||
if(empty($from_package['package_up'])){
|
||||
$this->error('您的套餐已经升级到最高套餐');
|
||||
}
|
||||
$to_package = $this->package_model->get($from_package['package_up']);
|
||||
if(empty($to_package)){
|
||||
$this->error('套餐信息不存在');
|
||||
}
|
||||
$total = round($to_package['price'] - $from_package['price'],2);
|
||||
if($total <= 0){
|
||||
$this->error('升级后套餐价格比当前套餐价格低');
|
||||
}
|
||||
|
||||
//用户信息处理,获取用户的openid
|
||||
$this->load->model('customer_model');
|
||||
if(!empty($this->session->{Customer_model::SESSION_KEY})){
|
||||
//如已登录,获取用户的open
|
||||
$customer = $this->customer_model->get(
|
||||
$this->session->{Customer_model::SESSION_KEY},
|
||||
'id'
|
||||
);
|
||||
//用户可能会被删除
|
||||
if($customer){
|
||||
$open_id = $customer['openid'];
|
||||
}
|
||||
}
|
||||
if(empty($open_id) && !empty($this->session->{Customer_model::SESSION_KEY_WX_OPEN_ID})){
|
||||
$open_id = $this->session->{Customer_model::SESSION_KEY_WX_OPEN_ID};
|
||||
}
|
||||
if(empty($open_id)){
|
||||
$this->success(['need_open_id'=>true]);
|
||||
}
|
||||
|
||||
|
||||
//生成订单,订单不能重复,每次都重新创建
|
||||
$this->load->model('sample_upgrade_order_model');
|
||||
/*
|
||||
//同样订单升级方案只能创建一个订单
|
||||
$order_id = null;
|
||||
$order_list = $this->sample_upgrade_order_model->get($sample['id'],'base.sample_id',true);
|
||||
foreach ($order_list as $value) {
|
||||
if($value['package_before'] == $from_package['id'] &&
|
||||
$value['package_after'] == $to_package['id']
|
||||
){
|
||||
if($value['paid_time'] > 0){
|
||||
$this->error('您的订单已支付');
|
||||
}
|
||||
//如果金额不一致,需要做金额修改
|
||||
if($total!=$value['grand_total']){
|
||||
$this->sample_upgrade_order_model->update([
|
||||
'grand_total'=>$total,
|
||||
],[
|
||||
'id'=>$value['id']
|
||||
]);
|
||||
}
|
||||
$order_id = $value['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(is_null($order_id)){
|
||||
}*/
|
||||
$order_id = $this->sample_upgrade_order_model->add([
|
||||
'sample_id'=>$sample['id'],
|
||||
'package_before'=>$from_package['id'],
|
||||
'package_after'=>$to_package['id'],
|
||||
'grand_total'=>$total,
|
||||
]);
|
||||
if(!$order_id){
|
||||
$this->error('订单创建失败');
|
||||
}
|
||||
|
||||
$attributes = [
|
||||
'body' => '有哈检测套餐升级',
|
||||
'out_trade_no' => $order_id,
|
||||
//'total_fee' => (ENVIRONMENT !== 'production'?101:$total*100),//沙箱环境固定为1.01,正式环境固定为分
|
||||
'total_fee' => round($total*100),//单位:分
|
||||
//'spbill_create_ip' => '', // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
|
||||
'notify_url' => base_url().'api/user/'.strtolower(__CLASS__).'/callback', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
||||
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
|
||||
'openid' => $open_id,
|
||||
];
|
||||
//echo base_url().'api/user/'.strtolower(__CLASS__).'/callback';die;
|
||||
$order = new WxPayOrder($attributes);
|
||||
//print_r($attributes);die;
|
||||
$app = $this->getApp();
|
||||
$result = $app->payment->prepare($order);
|
||||
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS'){
|
||||
$prepayId = $result->prepay_id;
|
||||
$json = $app->payment->configForPayment($prepayId,false); // 返回 json 字符串,如果想返回数组,传第二个参数
|
||||
$this->success($json);
|
||||
}
|
||||
//print_r($result);die;
|
||||
log_message('error', json_encode($data).''.json_encode($result));
|
||||
$this->error('下单失败,请联系客服');
|
||||
}
|
||||
|
||||
public function callback_post()
|
||||
{
|
||||
log_message('error',json_encode($_GET));
|
||||
log_message('error',json_encode($_POST));
|
||||
log_message('error',file_get_contents('php://input'));
|
||||
$app = $this->getApp();
|
||||
$app->payment->handleNotify(function($notify, $successful){
|
||||
// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
|
||||
$this->load->model('sample_upgrade_order_model');
|
||||
$order = $this->sample_upgrade_order_model->get($notify->out_trade_no);
|
||||
if (!$order) { // 如果订单不存在
|
||||
return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
|
||||
}
|
||||
// 如果订单存在
|
||||
// 检查订单是否已经更新过支付状态
|
||||
if ($order['paid_time']) { // 假设订单字段“支付时间”不为空代表已经支付
|
||||
return true; // 已经支付成功了就不再更新了
|
||||
}
|
||||
$data = [];
|
||||
|
||||
// 用户是否支付成功
|
||||
if(!$successful){
|
||||
$data['pay_status'] = 2;
|
||||
$this->sample_upgrade_order_model->update($data,[
|
||||
'id'=>$notify->out_trade_no
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
$this->load->model('sample_model');
|
||||
$this->sample_model->update([
|
||||
'package_id'=>$order['package_after']
|
||||
],[
|
||||
'id'=>$order['sample_id']
|
||||
]);
|
||||
|
||||
// 不是已经支付状态则修改为已经支付状态
|
||||
$data['paid_time'] = time(); // 更新支付时间为当前时间
|
||||
$data['pay_status'] = 1;
|
||||
$this->sample_upgrade_order_model->update($data,[
|
||||
'id'=>$notify->out_trade_no
|
||||
]);
|
||||
//样本更改套餐
|
||||
|
||||
|
||||
return true; // 返回处理完成
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user