175 lines
4.4 KiB
PHP
175 lines
4.4 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* 样品
|
|
*/
|
|
class Sample extends AdminController
|
|
{
|
|
protected $base_model = 'sample_model';
|
|
|
|
function image_post()
|
|
{
|
|
$uri = $this->uri->uri_string;
|
|
$Token = $this->input->get_request_header('X-Token', TRUE);
|
|
// $retPerm = $this->permission->HasPermit($Token, $uri);
|
|
// if ($retPerm['code'] != 50000) {
|
|
// $this->response($retPerm, RestController::HTTP_OK);
|
|
// }
|
|
$dir = 'pet_img_custom/';
|
|
$path = 'uploads/'.$dir;
|
|
$config['upload_path'] = './'.$path;
|
|
$config['allowed_types'] = 'gif|jpg|jpeg|png';
|
|
$config['max_size'] = 10000;
|
|
$config['max_width'] = 4000;
|
|
$config['max_height'] = 4000;
|
|
//设置文件名,前端传来的文件固定是png
|
|
$config['file_name'] = time();
|
|
|
|
$this->load->library('upload', $config);
|
|
|
|
if ( ! $this->upload->do_upload('avatar'))
|
|
{
|
|
$this->error( $this->upload->display_errors());
|
|
}
|
|
else
|
|
{
|
|
$data = $this->upload->data();
|
|
}
|
|
|
|
$this->success([
|
|
'path'=>$dir.$data['file_name'],
|
|
'full_path'=>base_url().$path.$data['file_name']
|
|
]);
|
|
}
|
|
|
|
function update_post()
|
|
{
|
|
$config = array(
|
|
array(
|
|
'field' => 'id',
|
|
'label' => '序号',
|
|
'rules' => 'trim|min_length[1]|max_length[10]'
|
|
),
|
|
array(
|
|
'field' => 'series_id',
|
|
'label' => '序列号',
|
|
'rules' => 'trim|required|min_length[1]|max_length[20]'
|
|
),
|
|
array(
|
|
'field' => 'user_id',
|
|
'label' => '用户',
|
|
'rules' => 'trim|required|min_length[1]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => '需要搜索绑定 %s',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'name',
|
|
'label' => '用户姓名',
|
|
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
|
'errors' => array(
|
|
'required' => 'You must provide a %s.',
|
|
),
|
|
),
|
|
array(
|
|
'field' => 'tel',
|
|
'label' => '手机',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_name',
|
|
'label' => '宠物名称',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_img',
|
|
'label' => '宠物头像',
|
|
),
|
|
array(
|
|
'field' => 'pet_sex',
|
|
'label' => '宠物性别',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'pet_species',
|
|
'label' => '宠物物种',
|
|
),
|
|
array(
|
|
'field' => 'pet_birthday',
|
|
'label' => '宠物生日',
|
|
'rules' => 'required'
|
|
),
|
|
array(
|
|
'field' => 'is_sterilized',
|
|
'label' => '是否绝育',
|
|
),
|
|
array(
|
|
'field' => 'package_id',
|
|
'label' => '套餐ID'
|
|
)
|
|
);
|
|
//读取输入数据
|
|
$data = $this->json_validation($config);
|
|
//不允许修改套餐
|
|
//unset($data['package_id']);
|
|
//对于新样品,从序列号读取套餐
|
|
if(empty($data['id'])){
|
|
$this->load->model('series_number_model');
|
|
$series = $this->series_number_model->get($data['series_id']);
|
|
if(!$series){
|
|
$this->error('序列号不存在');
|
|
}
|
|
if(empty($series['package_ori'])){
|
|
$this->error('序列号未绑定套餐');
|
|
}
|
|
$data['package_id'] = $series['package_ori'];
|
|
}
|
|
$this->_update_post($config,$data);
|
|
}
|
|
|
|
function list_get()
|
|
{
|
|
$ret = $this->_list_get(true);
|
|
$this->load->model('sample_model');
|
|
$ret['step'] = $this->sample_model->step_back;
|
|
$this->load->model('package_model');
|
|
$package_map = $this->package_model->get(false,null,true,'id,name');
|
|
$package_map = array_column($package_map,'name','id');
|
|
foreach ($ret['items'] as &$item) {
|
|
$item['package_ori_name'] = isset($package_map[$item['package_ori']])?$package_map[$item['package_ori']]:'';
|
|
$item['package_name'] = isset($package_map[$item['package_id']])?$package_map[$item['package_id']]:'';
|
|
}
|
|
$this->success($ret);
|
|
}
|
|
|
|
//批量更新状态
|
|
function batch_update_status_post()
|
|
{
|
|
$data_arr = $this->json_input();
|
|
$this->load->model('sample_model');
|
|
if(empty($data_arr['ids']) || !is_array($data_arr['ids'])){
|
|
$this->error('请选择要操作的样品');
|
|
}
|
|
if(empty($data_arr['step']) || !isset($this->sample_model->step_back[$data_arr['step']])){
|
|
$this->error('状态错误');
|
|
}
|
|
if(empty($data_arr['timestamp'])){
|
|
$data_arr['timestamp'] = time();
|
|
}
|
|
$ret = $this->sample_model->update(
|
|
['step'=>$data_arr['step']],
|
|
'id in ('.implode(',',$data_arr['ids']).')',
|
|
false
|
|
);
|
|
if($ret){
|
|
//记录状态变更时间
|
|
//如果完成,给用户发通知
|
|
if($data_arr['step'] == Sample_model::STEP_COMPLETE){
|
|
$this->sample_model->complete($data_arr['ids']);
|
|
}
|
|
}
|
|
$this->success();
|
|
}
|
|
}
|