feat: init project codebase
This commit is contained in:
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use \Firebase\JWT\JWT; //导入JWT
|
||||
require 'vendor/php-sdk-7.2.8/autoload.php';
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
/**
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Example extends RestController {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
|
||||
// Configure limits on our controller methods
|
||||
// Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
|
||||
$this->methods['users_get']['limit'] = 500; // 500 requests per hour per user/key
|
||||
$this->methods['users_post']['limit'] = 100; // 100 requests per hour per user/key
|
||||
$this->methods['users_delete']['limit'] = 50; // 50 requests per hour per user/key
|
||||
}
|
||||
|
||||
|
||||
public function users_get()
|
||||
{
|
||||
// var_dump($this->input->server('REQUEST_METHOD'));
|
||||
|
||||
// var_dump($this->get('id')); // 参数带id
|
||||
// var_dump($this->get('blah')); // http://www.cirest.com:8889/api/example/users/id/2/di/3 可以传多个参数
|
||||
//
|
||||
// //通过query获取 url 传参 测试失败?
|
||||
// var_dump($this->query('id'));
|
||||
// var_dump($this->query('blah'));
|
||||
// var_dump($this->query());
|
||||
|
||||
// Users from a data store e.g. database
|
||||
$users = [
|
||||
['id' => 1, 'name' => 'John', 'email' => 'john@example.com', 'fact' => 'Loves coding'],
|
||||
['id' => 2, 'name' => 'Jim', 'email' => 'jim@example.com', 'fact' => 'Developed on CodeIgniter'],
|
||||
['id' => 3, 'name' => 'Jane', 'email' => 'jane@example.com', 'fact' => 'Lives in the USA', ['hobbies' => ['guitar', 'cycling']]],
|
||||
];
|
||||
|
||||
$id = $this->get('id');
|
||||
|
||||
// If the id parameter doesn't exist return all the users
|
||||
|
||||
if ($id === NULL)
|
||||
{
|
||||
// Check if the users data store contains users (in case the database result returns NULL)
|
||||
if ($users)
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response($users, RestController::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'No users were found'
|
||||
], RestController::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
// Find and return a single record for a particular user.
|
||||
|
||||
$id = (int) $id;
|
||||
|
||||
// Validate the id.
|
||||
if ($id <= 0)
|
||||
{
|
||||
// Invalid id, set the response and exit.
|
||||
$this->response(NULL, RestController::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Get the user from the array, using the id as key for retrieval.
|
||||
// Usually a model is to be used for this.
|
||||
|
||||
$user = NULL;
|
||||
|
||||
if (!empty($users))
|
||||
{
|
||||
foreach ($users as $key => $value)
|
||||
{
|
||||
if (isset($value['id']) && $value['id'] === $id)
|
||||
{
|
||||
$user = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($user))
|
||||
{
|
||||
$this->set_response($user, RestController::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->set_response([
|
||||
'status' => FALSE,
|
||||
'message' => 'User could not be found'
|
||||
], RestController::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
public function users_post()
|
||||
{
|
||||
// $this->some_model->update_user( ... );
|
||||
$message = [
|
||||
'id' => 100, // Automatically generated by the model
|
||||
'name' => $this->post('name'),
|
||||
'email' => $this->post('email'),
|
||||
'message' => 'Added a resource'
|
||||
];
|
||||
|
||||
$this->set_response($message, RestController::HTTP_CREATED); // CREATED (201) being the HTTP response code
|
||||
}
|
||||
|
||||
public function users_delete()
|
||||
{
|
||||
|
||||
// $this->>delete获取不到参数
|
||||
// 可以使用 url 传参数方式获取 使用 $this->get('id')来接收
|
||||
// DELETE http://www.cirest.com:8889/api/example/users/2 使用中路由重写了 成/users/id/2
|
||||
// DELETE http://www.cirest.com:8889/api/example/users/id/2
|
||||
var_dump($this->get('id')); // 参数带id
|
||||
var_dump($this->get('blah')); // http://www.cirest.com:8889/api/example/users/id/2/blah/3 可以传多个参数
|
||||
|
||||
$id = (int) $this->get('id');
|
||||
var_dump($id);
|
||||
|
||||
// Validate the id.
|
||||
if ($id <= 0)
|
||||
{
|
||||
// Set the response and exit
|
||||
$this->response(NULL, RestController::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// $this->some_model->delete_something($id);
|
||||
$message = [
|
||||
'id' => $id,
|
||||
'message' => 'Deleted the resource'
|
||||
];
|
||||
|
||||
$this->set_response($message, RestController::HTTP_NO_CONTENT); // NO_CONTENT (204) being the HTTP response code
|
||||
}
|
||||
|
||||
// 签发Token
|
||||
public function issue_get()
|
||||
{
|
||||
$key = '344'; //key
|
||||
$time = time(); //当前时间
|
||||
$token = [
|
||||
'iss' => 'http://www.helloweba.net', //签发者 可选
|
||||
'aud' => 'http://www.helloweba.net', //接收该JWT的一方,可选
|
||||
'iat' => $time, //签发时间
|
||||
'nbf' => $time, //(Not Before):某个时间点后才能访问,比如设置time+30,表示当前时间30秒后才能使用
|
||||
'exp' => $time + 7200, //过期时间,这里设置2个小时
|
||||
'data' => [ //自定义信息,不要定义敏感信息
|
||||
'userid' => 1,
|
||||
'username' => '李小龙'
|
||||
]
|
||||
];
|
||||
|
||||
$jsonList = [
|
||||
'access_token' => JWT::encode($token, $key),
|
||||
];
|
||||
|
||||
$this->set_response($jsonList, RestController::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function verification_post()
|
||||
{
|
||||
|
||||
$key = '344'; //key要和签发的时候一样
|
||||
|
||||
$jwt = $this->post('access_token'); //签发的Token
|
||||
try {
|
||||
JWT::$leeway = 60;//当前时间减去60,把时间留点余地
|
||||
$decoded = JWT::decode($jwt, $key, ['HS256']); //HS256方式,这里要和签发的时候对应
|
||||
$arr = (array)$decoded;
|
||||
print_r($arr);
|
||||
} catch (\Firebase\JWT\SignatureInvalidException $e) { //签名不正确
|
||||
echo $e->getMessage();
|
||||
} catch (\Firebase\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用
|
||||
echo $e->getMessage();
|
||||
} catch (\Firebase\JWT\ExpiredException $e) { // token过期
|
||||
echo $e->getMessage();
|
||||
} catch (Exception $e) { //其他错误
|
||||
echo $e->getMessage();
|
||||
}
|
||||
//Firebase定义了多个 throw new,我们可以捕获多个catch来定义问题,catch加入自己的业务,比如token过期可以用当前Token刷新一个新Token
|
||||
|
||||
}
|
||||
|
||||
// 七牛 上传图片测试
|
||||
public function qiniu_get()
|
||||
{
|
||||
$cfg = [
|
||||
'access' => 'K5w2Fe4XowpU6kuklgLlAhGkXWt111WVssI1R0ff',
|
||||
'secret' => 'i9QhgiUvdO5AgpPnQkPXO6n9wA9jILLeaskqP0Iz',
|
||||
'bucket' => 'pocoyo_bucket',
|
||||
'domain' => 'http://pub8vjaao.bkt.clouddn.com'
|
||||
];
|
||||
|
||||
$auth = new Auth($cfg['access'], $cfg['secret']);
|
||||
// 创建一个过期时间为1小时的临时上传令牌
|
||||
$token = $auth->uploadToken($cfg['bucket'], null, 3600);
|
||||
|
||||
// 中文名需要转换编码?
|
||||
$filePath = iconv('UTF-8', 'GBK', APPPATH . 'controllers\api\QQ图片20160922141622.png');
|
||||
|
||||
$uploadMgr = new UploadManager();
|
||||
list($ret, $err) = $uploadMgr->putFile($token, null, $filePath);
|
||||
if($err !== null) {
|
||||
$this->err = $err;
|
||||
var_dump($err);
|
||||
} else {
|
||||
echo $cfg['domain'] . '/' . $ret['key'];
|
||||
}
|
||||
}
|
||||
|
||||
// Chevereto 图床免费版本地址:https://github.com/Chevereto/Chevereto-Free
|
||||
// https://chevereto.com/docs/api-v1
|
||||
// 上传图片测试
|
||||
public function chevereto_post()
|
||||
{
|
||||
// 1. 上传本地文件时应使用 $fields post base64_encode方法
|
||||
// Always use POST when uploading local files. Url encoding may alter the base64 source
|
||||
// due to encoded characters or just by URL request length limit due to GET request.
|
||||
// base64编码 会导致过长 url request
|
||||
// var_dump($_FILES); 参考 uploadimg 可以做一些前置校验处理 // 前置判断 if (empty($_FILES) === false)
|
||||
$key = '5486424e4dfb6b87453dd4bb25c0dcb0';
|
||||
$url = 'http://172.17.1.110/chevereto/api/1/upload';
|
||||
|
||||
// What do we send to chevereto api?
|
||||
$fields = array(
|
||||
'key' => urlencode($key),
|
||||
// The image encoded in base64
|
||||
'source' => base64_encode(file_get_contents($_FILES["file"]['tmp_name'])),
|
||||
// format: txt / json txt 只返回图片地址或错误信息 eg.Duplicated upload 较为简洁
|
||||
'format' => urlencode('json')
|
||||
);
|
||||
|
||||
//open connection
|
||||
$ch = curl_init();
|
||||
|
||||
//set the url, number of POST vars, POST data
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, sizeof($fields));
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));
|
||||
|
||||
//execute post
|
||||
$result = curl_exec($ch);
|
||||
//释放curl句柄
|
||||
curl_close($ch);
|
||||
echo $result;
|
||||
//close connection
|
||||
|
||||
// 2. 上传远程图片地址可使用 _get source=urlencode{source} 方法即可
|
||||
|
||||
// $key = '6a55c7f9fa13813c2da613dc7b5b920b';
|
||||
// // 设定远程图片地址
|
||||
// $source = 'https://img3.doubanio.com/view/group_topic/large/public/p67032015.jpg';
|
||||
// // format: txt / json txt 只返回图片地址或错误信息 eg.Duplicated upload 较为简洁
|
||||
// $url = 'http://172.17.1.110:8888/api/1/upload/?key={key}&source={source}&format=txt';
|
||||
// $url = str_replace(array('{key}','{source}'),array($key,urlencode($source)),$url);
|
||||
//
|
||||
// //初始化
|
||||
// $ch = curl_init();
|
||||
// //设置选项,包括URL
|
||||
// curl_setopt($ch, CURLOPT_URL, $url);
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
// //执行并获取HTML文档内容
|
||||
// $output = curl_exec($ch);
|
||||
// //释放curl句柄
|
||||
// curl_close($ch);
|
||||
// echo $output;
|
||||
|
||||
|
||||
// 失败
|
||||
// {
|
||||
// "status_txt": "Bad Request",
|
||||
// "error": {
|
||||
// "context": "Exception",
|
||||
// "code": 102,
|
||||
// "message": "Duplicated upload"
|
||||
// },
|
||||
// "status_code": 400
|
||||
// }
|
||||
// 成功
|
||||
// {
|
||||
// "status_txt": "OK",
|
||||
// "image": {
|
||||
// "image": {
|
||||
// "size": "89163",
|
||||
// "url": "http://172.17.1.110:8888/images/2019/07/09/p67032015.jpg",
|
||||
// "extension": "jpg",
|
||||
// "mime": "image/jpeg",
|
||||
// "name": "p67032015",
|
||||
// "filename": "p67032015.jpg"
|
||||
// },
|
||||
// },
|
||||
// "success": {
|
||||
// "code": 200,
|
||||
// "message": "image uploaded"
|
||||
// },
|
||||
// "status_code": 200
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
/**
|
||||
* Keys Controller
|
||||
* This is a basic Key Management REST controller to make and delete keys
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class Key extends RestController
|
||||
{
|
||||
|
||||
protected $methods = [
|
||||
'index_put' => ['level' => 10, 'limit' => 10],
|
||||
'index_delete' => ['level' => 10],
|
||||
'level_post' => ['level' => 10],
|
||||
'regenerate_post' => ['level' => 10],
|
||||
];
|
||||
|
||||
/**
|
||||
* Insert a key into the database
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function index_put()
|
||||
{
|
||||
// Build a new key
|
||||
$key = $this->_generate_key();
|
||||
|
||||
// If no key level provided, provide a generic key
|
||||
$level = $this->put('level') ? $this->put('level') : 1;
|
||||
$ignore_limits = ctype_digit($this->put('ignore_limits')) ? (int)$this->put('ignore_limits') : 1;
|
||||
|
||||
// Insert the new key
|
||||
if ($this->_insert_key($key, ['level' => $level, 'ignore_limits' => $ignore_limits])) {
|
||||
$this->response([
|
||||
'status' => TRUE,
|
||||
'key' => $key
|
||||
], RestController::HTTP_CREATED); // CREATED (201) being the HTTP response code
|
||||
} else {
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Could not save the key'
|
||||
], RestController::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a key from the database to stop it working
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function index_delete($key)
|
||||
{
|
||||
// $this->>delete获取不到参数
|
||||
// 可以使用 url 传参数方式获取
|
||||
// DELETE http://www.cirest.com:8889/api/key/8ww0sgk0sogs0ocg4gsw0gwsosk8wwcwoks044ws
|
||||
// $key = $this->delete('key');
|
||||
// $key='oocwo8cs88g4c8w8c08ow00ss844cc4osko0s0ks';
|
||||
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key)) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid API key'
|
||||
], RestController::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Destroy it
|
||||
$this->_delete_key($key);
|
||||
|
||||
// Respond that the key was destroyed
|
||||
$this->response([
|
||||
'status' => TRUE,
|
||||
'message' => 'API key was deleted'
|
||||
], RestController::HTTP_NO_CONTENT); // NO_CONTENT (204) being the HTTP response code
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the level
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function level_post()
|
||||
{
|
||||
$key = $this->post('key');
|
||||
$new_level = $this->post('level');
|
||||
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key)) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid API key'
|
||||
], RestController::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Update the key level
|
||||
if ($this->_update_key($key, ['level' => $new_level])) {
|
||||
$this->response([
|
||||
'status' => TRUE,
|
||||
'message' => 'API key was updated'
|
||||
], RestController::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Could not update the key level'
|
||||
], RestController::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend a key
|
||||
* 挂起api key 则key 的level 设置为0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function suspend_post()
|
||||
{
|
||||
$key = $this->post('key');
|
||||
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key)) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid API key'
|
||||
], RestController::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Update the key level
|
||||
if ($this->_update_key($key, ['level' => 0])) {
|
||||
$this->response([
|
||||
'status' => TRUE,
|
||||
'message' => 'Key was suspended'
|
||||
], RestController::HTTP_OK); // OK (200) being the HTTP response code
|
||||
} else {
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Could not suspend the user'
|
||||
], RestController::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate a key
|
||||
* 将 key level 设置为0 (禁用),数据库里生成一条新的key记录并且延用原来level,ignore_limits
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function regenerate_post()
|
||||
{
|
||||
$old_key = $this->post('key');
|
||||
$key_details = $this->_get_key($old_key);
|
||||
|
||||
// Does this key exist?
|
||||
if (!$key_details) {
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Invalid API key'
|
||||
], RestController::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Build a new key
|
||||
$new_key = $this->_generate_key();
|
||||
|
||||
// Insert the new key
|
||||
if ($this->_insert_key($new_key, ['level' => $key_details->level, 'ignore_limits' => $key_details->ignore_limits])) {
|
||||
// Suspend old key
|
||||
$this->_update_key($old_key, ['level' => 0]);
|
||||
|
||||
$this->response([
|
||||
'status' => TRUE,
|
||||
'key' => $new_key
|
||||
], RestController::HTTP_CREATED); // CREATED (201) being the HTTP response code
|
||||
} else {
|
||||
$this->response([
|
||||
'status' => FALSE,
|
||||
'message' => 'Could not save the key'
|
||||
], RestController::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper Methods */
|
||||
|
||||
private function _generate_key()
|
||||
{
|
||||
do {
|
||||
// Generate a random salt
|
||||
$salt = base_convert(bin2hex($this->security->get_random_bytes(64)), 16, 36);
|
||||
|
||||
// If an error occurred, then fall back to the previous method
|
||||
if ($salt === FALSE) {
|
||||
$salt = hash('sha256', time() . mt_rand());
|
||||
}
|
||||
|
||||
$new_key = substr($salt, 0, config_item('rest_key_length'));
|
||||
} while ($this->_key_exists($new_key));
|
||||
|
||||
return $new_key;
|
||||
}
|
||||
|
||||
/* Private Data Methods */
|
||||
|
||||
private function _get_key($key)
|
||||
{
|
||||
return $this->rest->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->get(config_item('rest_keys_table'))
|
||||
->row();
|
||||
}
|
||||
|
||||
private function _key_exists($key)
|
||||
{
|
||||
return $this->rest->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->count_all_results(config_item('rest_keys_table')) > 0;
|
||||
}
|
||||
|
||||
private function _insert_key($key, $data)
|
||||
{
|
||||
$data[config_item('rest_key_column')] = $key;
|
||||
$data['date_created'] = function_exists('now') ? now() : time();
|
||||
|
||||
return $this->rest->db
|
||||
->set($data)
|
||||
->insert(config_item('rest_keys_table'));
|
||||
}
|
||||
|
||||
private function _update_key($key, $data)
|
||||
{
|
||||
return $this->rest->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->update(config_item('rest_keys_table'), $data);
|
||||
}
|
||||
|
||||
private function _delete_key($key)
|
||||
{
|
||||
return $this->rest->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->delete(config_item('rest_keys_table'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
|
||||
/**
|
||||
* @author luoxuancai 2017/7/13
|
||||
*/
|
||||
class Index extends ApiController {
|
||||
|
||||
const TEST_SUFFIX = '-Test';
|
||||
protected $_is_test = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
parent::__construct();
|
||||
$this->load->model('sample_model');
|
||||
$this->load->model('report_model');
|
||||
}
|
||||
|
||||
public function index_get()
|
||||
{
|
||||
if(empty($_GET['id'])){
|
||||
$this->setError('请求错误');
|
||||
}
|
||||
$id = trim($_GET['id']);
|
||||
$id = $this->getDeviceId($id);
|
||||
//报告文件
|
||||
$ret = $this->report_model->get_result($id,$this->_is_test);
|
||||
if(empty($ret)){
|
||||
$this->setError('报告未生成');
|
||||
die;
|
||||
}
|
||||
|
||||
$this->setSuccess($ret);
|
||||
}
|
||||
|
||||
//获取犬类疾病的列表,需要挂钩报告编号,以便显示锁定与解锁的疾病
|
||||
protected function disease_list($need_category,$need_detail)
|
||||
{
|
||||
/*
|
||||
* 从库中读取
|
||||
$params = [];
|
||||
//区分单基因/多基因
|
||||
if(!empty($_GET['gene_type'])){
|
||||
$params['gene_type'] = $_GET['gene_type'];
|
||||
}
|
||||
|
||||
$this->load->model('disease_model');
|
||||
$list = $this->disease_model->listing($params, 0,50000,'base.*');
|
||||
*/
|
||||
|
||||
/*
|
||||
* 从素材分类
|
||||
$material = $this->report_model->get_material();
|
||||
$info = [];
|
||||
$list = array_merge($material['犬类单基因疾病'],$material['犬类复杂疾病']);
|
||||
//类别描述删除多余字符
|
||||
$searchStrOne = explode('|','类遗传疾病|类疾病|系统遗传病|遗传病|遗传疾病|疾病');
|
||||
$searchStrTwo = explode('|','类|系统类|系统');
|
||||
foreach ($list as $key=>$val) {
|
||||
if(empty($val['所属类别'])){
|
||||
$name = '其他';
|
||||
}else{
|
||||
//删除多余的描述
|
||||
$name = str_replace($searchStrOne,'',$val['所属类别']);
|
||||
$name = str_replace($searchStrTwo,'',$name);
|
||||
}
|
||||
$info[$name][] = [
|
||||
'name'=>$key,
|
||||
'lock'=>$lock && !in_array($key,$lockDisease)
|
||||
];
|
||||
}
|
||||
*/
|
||||
|
||||
if(empty($_GET['id'])){
|
||||
$this->setError('请求错误');
|
||||
}
|
||||
|
||||
$id = trim($_GET['id']);
|
||||
$id = $this->getDeviceId($id);
|
||||
|
||||
//样品及套餐信息
|
||||
$this->load->model('sample_model');
|
||||
$this->load->model('package_model');
|
||||
$sample = $this->sample_model->get($id,'device_id');
|
||||
if(empty($sample)){
|
||||
$this->setError('样品不存在');
|
||||
die;
|
||||
}
|
||||
//报告文件
|
||||
$json = $this->report_model->get_report_json($id,$sample['pet_species']);
|
||||
|
||||
//套餐设置成1,上线后删除
|
||||
//$sample['package_id'] = 1;
|
||||
$package = $this->package_model->get($sample['package_id']);
|
||||
if(!$package){
|
||||
return [];
|
||||
}
|
||||
$gene_type = !empty($_GET['gene_type'])?$_GET['gene_type']:0;
|
||||
return $this->report_model->get_disease_list($gene_type,$sample,$json,$package,$need_category,$need_detail);
|
||||
}
|
||||
|
||||
//疾病列表
|
||||
public function disease_list_get(){
|
||||
$ret = $this->disease_list(!empty($_GET['need_category']),false);
|
||||
if(!empty($_GET['need_category'])){
|
||||
//需要分类的疾病是单基因疾病,将解锁的放前面
|
||||
foreach ($ret as $category_name => $list) {
|
||||
$lock = [];
|
||||
$unlock = [];
|
||||
foreach ($list as $key=>$val) {
|
||||
if($val['lock']){
|
||||
$lock[] = $val;
|
||||
}else{
|
||||
$unlock[] = $val;
|
||||
}
|
||||
}
|
||||
$ret[$category_name] = array_merge($unlock,$lock);
|
||||
}
|
||||
}
|
||||
$this->setSuccess($ret);
|
||||
}
|
||||
|
||||
//疾病列表
|
||||
public function disease_get()
|
||||
{
|
||||
/*
|
||||
$this->load->model('disease_model');
|
||||
$row = $this->disease_model->get($_GET['disease_name'],'base.name');
|
||||
*/
|
||||
if(empty($_GET['disease_name'])){
|
||||
$this->setError('请求错误');
|
||||
}
|
||||
$ret = [];
|
||||
$material = $this->disease_list(false,true);
|
||||
foreach ($material as $item) {
|
||||
if($item['name'] == $_GET['disease_name']){
|
||||
$ret = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//根据基因类型,做低风险描述调整,未检测出时没有描述
|
||||
if(!$ret['risk']){
|
||||
$ret['risk_desc'] = $ret['gene_type'] == 1?'未检测到致病突变':'低发病风险';
|
||||
}
|
||||
$this->setSuccess($ret);
|
||||
}
|
||||
|
||||
//证书图片信息
|
||||
public function cert_health_list_get()
|
||||
{
|
||||
//疾病描述
|
||||
$this->load->model('Cat_disease_desc_model');
|
||||
|
||||
$disease = [];
|
||||
$material = $this->disease_list(false,true);
|
||||
foreach ($material as $item) {
|
||||
$description = $this->Cat_disease_desc_model->breeding_single_detail($item['name']);
|
||||
if(empty($description)){
|
||||
continue;
|
||||
}
|
||||
//风险等级
|
||||
$risk_tag = 'N/N';
|
||||
if($item['risk']){
|
||||
$risk_tag = $item['risk_level'] == 1?'N/F':'F/F';
|
||||
}
|
||||
$disease[] = [
|
||||
//疾病名称
|
||||
'name'=>$item['name'],
|
||||
//疾病N/N
|
||||
'risk_tag'=>$risk_tag,
|
||||
//结果说明
|
||||
'risk_desc'=>$description['检测结果'][$risk_tag],
|
||||
//检测手段
|
||||
'method'=>$description['检测手段'],
|
||||
//基因型
|
||||
'gene_type'=>$description['基因型'],
|
||||
//N/N
|
||||
'NN'=>$description['结果说明']['N/N'],
|
||||
'NF'=>$description['结果说明']['N/F'],
|
||||
'FF'=>$description['结果说明']['F/F'],
|
||||
];
|
||||
}
|
||||
$this->success($disease);
|
||||
}
|
||||
|
||||
//证书图片单张
|
||||
public function cert_health_get()
|
||||
{
|
||||
|
||||
if(empty($_GET['name'])){
|
||||
$this->setError('请求错误');
|
||||
}
|
||||
$disease = [];
|
||||
$material = $this->disease_list(false,true);
|
||||
foreach ($material as $item) {
|
||||
if($item['name'] == $_GET['name']){
|
||||
$disease = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//根据基因类型,做低风险描述调整,未检测出时没有描述
|
||||
if(!$disease['risk']){
|
||||
$disease['risk_desc'] = $disease['gene_type'] == 1?'未检测到致病突变':'低发病风险';
|
||||
}
|
||||
|
||||
|
||||
//样本信息
|
||||
$id = trim($_GET['id']);
|
||||
$id = $this->getDeviceId($id);
|
||||
|
||||
//样品及套餐信息
|
||||
$this->load->model('sample_model');
|
||||
$this->load->model('package_model');
|
||||
$sample = $this->sample_model->get($id,'device_id');
|
||||
if(empty($sample)){
|
||||
$this->setError('样品不存在');
|
||||
die;
|
||||
}
|
||||
|
||||
//疾病描述
|
||||
$this->load->model('Cat_disease_desc_model');
|
||||
$description = $this->Cat_disease_desc_model->breeding_single_detail($_GET['name']);
|
||||
if(empty($description)){
|
||||
die('empty');
|
||||
}
|
||||
|
||||
|
||||
//证书文件如果有就直接输出
|
||||
$this->load->library('uploads');
|
||||
$id = strtoupper($id);
|
||||
$upload_path = $this->uploads->get_upload_path();
|
||||
$cert_img_path = $upload_path.Uploads::DIR_PER_CERT_IMG.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR;
|
||||
$cert_file_name = $cert_img_path.$_GET['name'].'.jpg';
|
||||
if(file_exists($cert_file_name)){
|
||||
//声明需要创建的图层的图片格式
|
||||
header("Content-Type:image/jpg");
|
||||
echo file_get_contents($cert_file_name);
|
||||
die();
|
||||
}
|
||||
|
||||
//风险等级
|
||||
$risk_tag = 'N/N';
|
||||
if($disease['risk']){
|
||||
$risk_tag = $disease['risk_level'] == 1?'N/F':'F/F';
|
||||
}
|
||||
|
||||
//图片
|
||||
header("Content-type: image/png");
|
||||
$file = APPPATH."uahpet/cert_template/health.png";//图片跟路径
|
||||
$font = APPPATH."uahpet/font/SourceHanSansCN-Regular.otf";
|
||||
$font_bold = APPPATH."uahpet/font/SourceHanSansCN-Bold.otf";
|
||||
$img = imagecreatefrompng($file);
|
||||
$blue = imagecolorallocate($img, 17, 182, 179);
|
||||
$black = imagecolorallocate($img, 62, 62, 62);
|
||||
|
||||
//名字
|
||||
$sting = $sample['pet_name'];
|
||||
imagettftext($img, 15, 0, 288, 705, $black, $font, $sting);
|
||||
|
||||
//养育人
|
||||
$sting = $sample['name'];
|
||||
imagettftext($img, 15, 0, 600, 705, $black, $font, $sting);
|
||||
|
||||
//测试日期
|
||||
$sting = date('Y-m-d',$sample['create_time']);
|
||||
imagettftext($img, 15, 0, 970, 705, $black, $font, $sting);
|
||||
|
||||
//疾病名称
|
||||
$sting = $_GET['name'];
|
||||
imagettftext($img, 27, 0, 186, 965, $blue, $font_bold, $sting);
|
||||
|
||||
//疾病N/N
|
||||
$sting = $risk_tag;
|
||||
imagettftext($img, 27, 0, 638, 965, $blue, $font_bold, $sting);
|
||||
|
||||
//结果说明
|
||||
$sting = $description['检测结果'][$risk_tag] ;
|
||||
imagettftext($img, 15, 0, 736, 960, $black, $font, $sting);
|
||||
|
||||
/* 证书左侧段落 */
|
||||
|
||||
//检测手段
|
||||
$sting = '检测手段:'.$description['检测手段'];
|
||||
imagettftext($img, 13, 0, 188, 1030, $black, $font, $sting);
|
||||
|
||||
//检测手段解释
|
||||
$sting = '基 因 型:';
|
||||
imagettftext($img, 13, 0, 188, 1061, $black, $font, $sting);
|
||||
|
||||
//检测手段解释
|
||||
$sting_arr = explode("\n",$description['基因型']);
|
||||
//右侧,处理换行
|
||||
foreach ($sting_arr as $key=>$val) {
|
||||
imagettftext($img, 13, 0, 188+85, 1061+$key*25, $black, $font, $val);
|
||||
}
|
||||
|
||||
/* 证书右侧段落 */
|
||||
|
||||
//N/N
|
||||
$sting = 'N/N:'.$description['结果说明']['N/N'];
|
||||
imagettftext($img, 13, 0, 644, 1030, $black, $font, $sting);
|
||||
|
||||
//N/F
|
||||
//标题
|
||||
$sting_arr = $this->cutImgString($description['结果说明']['N/F'],26);
|
||||
$sting = 'N/F:';
|
||||
imagettftext($img, 13, 0, 644, 1061, $black, $font, $sting);
|
||||
//右侧,处理换行
|
||||
foreach ($sting_arr as $key=>$val) {
|
||||
imagettftext($img, 13, 0, 644+45, 1061+$key*25, $black, $font, $val);
|
||||
}
|
||||
|
||||
//F/F
|
||||
$sting = 'F/F:'.$description['结果说明']['F/F'];
|
||||
imagettftext($img, 13, 0, 644, 1093+(count($sting_arr)-1)*16, $black, $font, $sting);
|
||||
|
||||
imagejpeg($img,$cert_file_name,75);
|
||||
imagedestroy($img);
|
||||
|
||||
echo file_get_contents($cert_file_name);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function cert_health_down_post()
|
||||
{
|
||||
//接口禁用
|
||||
die('');
|
||||
$data = $this->json_input();
|
||||
if(empty($data) || empty($data['id'])){
|
||||
$this->setError('请求错误');
|
||||
}
|
||||
|
||||
//样本序列号
|
||||
$device_id = trim($data['id']);
|
||||
$device_id = $this->getDeviceId($device_id);
|
||||
|
||||
//接收血统证书,血统证书很难在服务器端生成
|
||||
$base64_cert_lineage = trim($data['cert_lineage']);
|
||||
|
||||
$this->load->library('uploads');
|
||||
$this->load->library('MakeZip');
|
||||
|
||||
//报告id
|
||||
$device_id = strtoupper($device_id);
|
||||
|
||||
//图片
|
||||
$pet_img = $this->uploads->save_cert_img_base64(
|
||||
$base64_cert_lineage,
|
||||
$device_id,
|
||||
'健康证书'
|
||||
);
|
||||
|
||||
if(!$pet_img){
|
||||
$this->error('健康证书输出失败');
|
||||
}
|
||||
|
||||
//压缩
|
||||
$path = (Uploads::DIR).DIRECTORY_SEPARATOR;
|
||||
$sourceDir = $path.(Uploads::DIR_PER_CERT_IMG).DIRECTORY_SEPARATOR.$device_id.DIRECTORY_SEPARATOR;
|
||||
$targetFile = $path.(Uploads::DIR_PER_CERT_ZIP).DIRECTORY_SEPARATOR.uniqid().'.zip';
|
||||
$res = $this->makezip->zip(FCPATH.$sourceDir,FCPATH.$targetFile);
|
||||
if(!$res){
|
||||
throw new Exception('压缩失败');
|
||||
}
|
||||
$this->success(['file'=>base_url().$targetFile]);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function setError($err,$code = 0){
|
||||
echo json_encode(['code'=>$code,'msg'=>$err]);
|
||||
die;
|
||||
}
|
||||
private function setSuccess($data){
|
||||
echo json_encode(['code'=>1,'msg'=>'','data'=>$data]);
|
||||
die;
|
||||
}
|
||||
|
||||
protected function getDeviceId($deviceID){
|
||||
//是否预置了测试参数
|
||||
$this->_is_test = substr($deviceID,-strlen(self::TEST_SUFFIX)) == self::TEST_SUFFIX;
|
||||
if($this->_is_test){
|
||||
return substr($deviceID,0,-strlen(self::TEST_SUFFIX));
|
||||
}
|
||||
return $deviceID;
|
||||
}
|
||||
|
||||
//字数太长要折行,统计折行的行数
|
||||
protected function cutImgString($str,$len){
|
||||
if(mb_strlen($str)<$len){
|
||||
return [$str];
|
||||
}
|
||||
$str_len = mb_strlen($str);
|
||||
$count = ceil($str_len/$len);
|
||||
$result = [];
|
||||
for($x = 0; $x <= $count; $x++){
|
||||
$result[] =mb_substr($str,$len*$x,$len);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -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; // 返回处理完成
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
class Table extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Api_model');
|
||||
// $this->load->model('Record_model');
|
||||
// $this->load->model('Dept_model', 'Dept');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function testapi()
|
||||
{
|
||||
echo "test api ok...";
|
||||
}
|
||||
|
||||
public function phpinfo()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
|
||||
$items = [
|
||||
["id" => 1,
|
||||
"title" => "www",
|
||||
"status" => "draft",
|
||||
"author" => "qiaokun",
|
||||
"display_time" => "",
|
||||
"pageviews" => 300
|
||||
],
|
||||
["id" => 3,
|
||||
"title" => "bbb",
|
||||
"status" => "bbbb",
|
||||
"author" => "乔锟",
|
||||
"display_time" => "",
|
||||
"pageviews" => 300
|
||||
],
|
||||
];
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
function goods_get()
|
||||
{
|
||||
|
||||
$items = array(
|
||||
array('id' => 1, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 2, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 3, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 4, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 5, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 6, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 7, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 8, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 9, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 10, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 11, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 31, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 13, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 24, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 35, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 19, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 22, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 33, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file welcome.php */
|
||||
/* Location: ./application/controllers/welcome.php */
|
||||
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
//require APPPATH . 'libraries/kindeditor/php/JSON.php';
|
||||
|
||||
class Uploadimg extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Api_model');
|
||||
}
|
||||
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
}
|
||||
|
||||
public function upload_post()
|
||||
{
|
||||
$uploadDir = FCPATH . 'uploads/';
|
||||
$id = 'T' . $this->POST('identify');
|
||||
$php_path = dirname(__FILE__) . '/';//dirname($_SERVER['DOCUMENT_ROOT']); dirname(__FILE__)
|
||||
// $php_url = "";//dirname($_SERVER['HTTP_HOST']) . '/';//PHP_SELF
|
||||
$php_url = $_SERVER['HTTP_HOST'] . '/'; //PHP_SELF
|
||||
|
||||
$save_path = $uploadDir;
|
||||
//文件保存目录URL
|
||||
$save_url = $php_url . 'uploads/';
|
||||
// nginx服务器端修改绝对路径
|
||||
//$save_url = "http://172.30.3.11/static/home/kindeditor/attached/";
|
||||
|
||||
// var_dump($save_path);
|
||||
// var_dump($save_url);
|
||||
// string(46) "D:\Q\code\vue\CodeIgniter-3.1.10\uploads\imgs\"
|
||||
// string(28) "www.cirest.com:8889/uploads/"
|
||||
|
||||
|
||||
//定义允许上传的文件扩展名
|
||||
$ext_arr = array(
|
||||
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
|
||||
'flash' => array('swf', 'flv'),
|
||||
'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
|
||||
'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'),
|
||||
);
|
||||
//最大文件大小 10M 默认是1M
|
||||
$max_size = 10000000;
|
||||
|
||||
$save_path = realpath($save_path) . '/';
|
||||
$save_path = str_replace('\\', '/', $save_path);
|
||||
|
||||
//PHP上传失败
|
||||
if (!empty($_FILES['file']['error'])) {
|
||||
switch ($_FILES['file']['error']) {
|
||||
case '1':
|
||||
$error = '超过php.ini允许的大小。';
|
||||
break;
|
||||
case '2':
|
||||
$error = '超过表单允许的大小。';
|
||||
break;
|
||||
case '3':
|
||||
$error = '图片只有部分被上传。';
|
||||
break;
|
||||
case '4':
|
||||
$error = '请选择图片。';
|
||||
break;
|
||||
case '6':
|
||||
$error = '找不到临时目录。';
|
||||
break;
|
||||
case '7':
|
||||
$error = '写文件到硬盘出错。';
|
||||
break;
|
||||
case '8':
|
||||
$error = 'File upload stopped by extension。';
|
||||
break;
|
||||
case '999':
|
||||
default:
|
||||
$error = '未知错误。';
|
||||
}
|
||||
$this->alert($error);
|
||||
}
|
||||
|
||||
//有上传文件时
|
||||
if (empty($_FILES) === false) {
|
||||
//原文件名
|
||||
$file_name = $_FILES['file']['name'];
|
||||
//服务器上临时文件名
|
||||
$tmp_name = $_FILES['file']['tmp_name'];
|
||||
//文件大小
|
||||
$file_size = $_FILES['file']['size'];
|
||||
//检查文件名
|
||||
if (!$file_name) {
|
||||
$this->alert("请选择文件。");
|
||||
}
|
||||
//检查目录
|
||||
if (@is_dir($save_path) === false) {
|
||||
$this->alert("上传目录不存在。");
|
||||
}
|
||||
//检查目录写权限
|
||||
if (@is_writable($save_path) === false) {
|
||||
$this->alert("上传目录没有写权限。");
|
||||
}
|
||||
//检查是否已上传
|
||||
if (@is_uploaded_file($tmp_name) === false) {
|
||||
$this->alert("上传失败。");
|
||||
}
|
||||
//检查文件大小
|
||||
if ($file_size > $max_size) {
|
||||
$this->alert("上传文件大小超过限制(<10M)。");
|
||||
}
|
||||
//检查目录名
|
||||
$dir_name = empty($_GET['dir']) ? 'image' : trim($_GET['dir']);
|
||||
if (empty($ext_arr[$dir_name])) {
|
||||
$this->alert("目录名不正确。");
|
||||
}
|
||||
//获得文件扩展名
|
||||
$temp_arr = explode(".", $file_name);
|
||||
$file_ext = array_pop($temp_arr);
|
||||
$file_ext = trim($file_ext);
|
||||
$file_ext = strtolower($file_ext);
|
||||
|
||||
//检查扩展名
|
||||
if (!in_array($file_ext, $ext_arr[$dir_name])) {
|
||||
$this->alert("上传文件扩展名是不允许的扩展名。\n只允许" . implode(",", $ext_arr[$dir_name]) . "格式。");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 以 T+身份证号作为临时目录 , 以身份证作为正式目录
|
||||
*/
|
||||
$identify = empty($id) ? '' : trim($id);
|
||||
|
||||
if ($identify == '') {
|
||||
echo "Invalid session identify.";
|
||||
exit;
|
||||
}
|
||||
//创建文件夹
|
||||
if ($dir_name !== '') {
|
||||
$save_path .= $dir_name . "/" . $identify . "/";
|
||||
$save_url .= $dir_name . "/" . $identify . "/";
|
||||
if (!file_exists($save_path)) {
|
||||
mkdir($save_path, 0777, true); // true 允许创建多级目录
|
||||
}
|
||||
}
|
||||
$ymd = date("Ym");
|
||||
$save_path .= $ymd . "/";
|
||||
$save_url .= $ymd . "/";
|
||||
if (!file_exists($save_path)) {
|
||||
mkdir($save_path);
|
||||
}
|
||||
//新文件名
|
||||
$new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
|
||||
//移动文件
|
||||
$file_path = $save_path . $new_file_name;
|
||||
if (move_uploaded_file($tmp_name, $file_path) === false) {
|
||||
$this->alert("上传文件失败。");
|
||||
}
|
||||
@chmod($file_path, 0644);
|
||||
$file_url = $save_url . $new_file_name;
|
||||
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
// Insert file information in the database
|
||||
// $insert = $db->query("INSERT INTO files (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
|
||||
$link = "http://" . $file_url;
|
||||
// http://www.cirest.com:8889/uploads/image/T410000000000000000/201902/20190228071354_96833.png
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"error" => 0,
|
||||
"message" => "上传成功",
|
||||
"link" => $link,
|
||||
"filepath" => preg_replace('/^http.*uploads/', '/uploads', $link)
|
||||
];
|
||||
|
||||
echo json_encode($message);
|
||||
// $this->set_response($message, REST_Controller::HTTP_OK);
|
||||
// alert里面使用时 exit() 产生的是空,或字符串,使用原生的json_encode返回统一的字符串,在客户端在统一处理成对象
|
||||
}
|
||||
}
|
||||
|
||||
public function delimg_post()
|
||||
{
|
||||
$php_path = dirname(__FILE__) . '/';//dirname($_SERVER['DOCUMENT_ROOT']); dirname(__FILE__)
|
||||
|
||||
//文件保存目录路径
|
||||
$save_path = $php_path . '../../../../';
|
||||
|
||||
$save_path = realpath($save_path) . '/';
|
||||
$save_path = str_replace('\\', '/', $save_path);
|
||||
// var_dump($save_path);
|
||||
// "D:/Q/code/vue/CodeIgniter-3.1.10/"
|
||||
|
||||
$DelFileName = $this->POST('filename');
|
||||
$DelFileType = $this->POST('isdir');
|
||||
|
||||
$FilePath = $save_path . $DelFileName;
|
||||
|
||||
// var_dump($FilePath);return;
|
||||
|
||||
if ($DelFileType == 'F') {
|
||||
if (!is_file($FilePath)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => "文件不存在 - " . $DelFileName,
|
||||
"message" => "文件不存在 - " . $DelFileName
|
||||
];
|
||||
|
||||
echo json_encode($message);
|
||||
|
||||
} else {
|
||||
|
||||
if (!unlink($FilePath)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => "Error deleting " . $FilePath,
|
||||
"message" => "Error deleting " . $FilePath
|
||||
];
|
||||
echo json_encode($message);
|
||||
|
||||
} else {
|
||||
// 必须返回code 由于前端vue封装的 request 请求,返回数据对code进行判断
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => '服务器删除成功!',
|
||||
"message" => '服务器删除成功!'
|
||||
];
|
||||
echo json_encode($message);
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($DelFileType == 'D') {
|
||||
if (!@rmdir($FilePath)) {
|
||||
echo "文件夹 " . $FilePath . " 不为空,不能删除!";
|
||||
} else {
|
||||
echo "succeed";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function alert($msg)
|
||||
{
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"error" => 1,
|
||||
"message" => $msg
|
||||
];
|
||||
echo json_encode($message);
|
||||
exit();
|
||||
// var_dump($message);
|
||||
// $this->set_response($message, REST_Controller::HTTP_OK);
|
||||
// die();
|
||||
}
|
||||
|
||||
|
||||
public function onsubmit_post()
|
||||
{
|
||||
$identify = $this->POST('identify');
|
||||
$phone = $this->POST('phone');
|
||||
$idinfo = $this->POST('idinfo');
|
||||
$bankinfo = $this->POST('bankinfo');
|
||||
// $data = [
|
||||
// 'identify' => $identify,
|
||||
// 'phone' => $phone,
|
||||
// 'idinfo' => $idinfo,
|
||||
// 'check' => '待审核'
|
||||
// ];
|
||||
|
||||
// 写入数据库表 身份证号,手机号,证件照,文件路径等
|
||||
$where = [
|
||||
'identify' => $identify,
|
||||
'phone' => $phone,
|
||||
];
|
||||
|
||||
$data = [
|
||||
'idinfo' => $idinfo,
|
||||
'bankinfo' => $bankinfo,
|
||||
'check' => '待审核'
|
||||
];
|
||||
|
||||
$result = $this->Api_model->saveEdit('upload_tbl', $data, $where);
|
||||
|
||||
if ($result) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"message" => '写入数据库表成功,请请待审核通知!',
|
||||
"data" => array_merge($where, $data)
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"message" => '写入数据库表失败!',
|
||||
"data" => array_merge($where, $data)
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file welcome.php */
|
||||
/* Location: ./application/controllers/welcome.php */
|
||||
@@ -0,0 +1,559 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
class User extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Api_model');
|
||||
// $this->load->model('Record_model');
|
||||
// $this->load->model('Dept_model', 'Dept');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index_get()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
|
||||
}
|
||||
|
||||
public function phpinfo_get()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb_get()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
|
||||
/* Helper Methods */
|
||||
/**
|
||||
* 生成 token
|
||||
* @param
|
||||
* @return string 40个字符
|
||||
*/
|
||||
private function _generate_token()
|
||||
{
|
||||
do {
|
||||
// Generate a random salt
|
||||
$salt = base_convert(bin2hex($this->security->get_random_bytes(64)), 16, 36);
|
||||
|
||||
// If an error occurred, then fall back to the previous method
|
||||
if ($salt === FALSE) {
|
||||
$salt = hash('sha256', time() . mt_rand());
|
||||
}
|
||||
|
||||
$new_key = substr($salt, 0, config_item('rest_key_length'));
|
||||
} while ($this->_token_exists($new_key));
|
||||
|
||||
return $new_key;
|
||||
}
|
||||
|
||||
/* Private Data Methods */
|
||||
|
||||
private function _token_exists($token)
|
||||
{
|
||||
return $this->rest->db
|
||||
->where('token', $token)
|
||||
->count_all_results('auth') > 0;
|
||||
}
|
||||
|
||||
private function _insert_token($token, $data)
|
||||
{
|
||||
$data['token'] = $token;
|
||||
$data['date_created'] = function_exists('now') ? now() : time();
|
||||
|
||||
return $this->rest->db
|
||||
->set($data)
|
||||
->insert('auth');
|
||||
}
|
||||
|
||||
private function _update_token($token, $data)
|
||||
{
|
||||
return $this->rest->db
|
||||
->where('token', $token)
|
||||
->update('auth', $data);
|
||||
}
|
||||
|
||||
|
||||
function login_post()
|
||||
{
|
||||
$username = $this->post('username'); // POST param
|
||||
$password = $this->post('password'); // POST param
|
||||
// var_dump($username);
|
||||
// var_dump($password);
|
||||
$input_account = $username;
|
||||
$input_password = md5($password);
|
||||
// $result = $this->Api_model->app_user_login_validate($input_account, $input_password);
|
||||
// 用户名密码正确 生成token 返回
|
||||
if (1) {
|
||||
$token = $this->_generate_token();
|
||||
// "token" => $token
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"token" => "admin-token"
|
||||
]
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 60204,
|
||||
"message" => 'Account and password are incorrect.'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据token拉取用户信息 get
|
||||
function info_get()
|
||||
{
|
||||
// $result = $this->some_model();
|
||||
$result['success'] = TRUE;
|
||||
|
||||
// 获取用户信息成功
|
||||
if ($result['success']) {
|
||||
$info = [
|
||||
"roles" => ["editor"],
|
||||
"introduction" => "I am a super administrator",
|
||||
"avatar" => "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
|
||||
"name" => "Super Admin",
|
||||
"identify" => "410000000000000000",
|
||||
"phone" => "13633838282"
|
||||
];
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $info,
|
||||
"_SERVER" => $_SERVER,
|
||||
"_GET" => $_GET
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 50008,
|
||||
"message" => 'Login failed, unable to get user details.'
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function logout_post()
|
||||
{
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => 'success'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
function login()
|
||||
{
|
||||
$this->SET_HEADER; // 设置php CI 处理 CORS 自定义头部
|
||||
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == 'POST') { // 只处理post请求,否则options请求 500错误
|
||||
$json_params = file_get_contents('php://input');
|
||||
$data = json_decode($json_params, true);
|
||||
|
||||
if (!empty($data)) {
|
||||
if (!empty($data['username']) && !empty($data['password'])) {
|
||||
$username = $data['username'];
|
||||
$password = $data['password'];
|
||||
$input_account = $username;
|
||||
$input_password = md5($password);
|
||||
// $results = $this->phpIonicLoginAuthValidateLogin($username, $password);
|
||||
$result = $this->Api_model->app_user_login_validate($input_account, $input_password);
|
||||
|
||||
// $token=$_SERVER['x-auth-token'];
|
||||
// 用户名密码正确 生成token 返回
|
||||
$token = $this->createToken(10000);
|
||||
|
||||
$data = array(
|
||||
"code" => 20000,
|
||||
"data" => array(
|
||||
"token" => "admin-token"
|
||||
// "token" => $token
|
||||
),
|
||||
"params" => $json_params
|
||||
);
|
||||
|
||||
echo json_encode($data);
|
||||
// 用户名密码不正确
|
||||
// return {
|
||||
// code:
|
||||
// 60204,
|
||||
// message: 'Account and password are incorrect.'
|
||||
// }
|
||||
|
||||
|
||||
if ($result['success']) {
|
||||
echo json_encode($this->saveLoginInfo($result['userinfo']));
|
||||
} else {
|
||||
// 校验失败,写入token
|
||||
$this->output->set_status_header(300);
|
||||
echo '{"success": false,"message": "用户名或密码错误","jump":"","user":"' . $username . '"}';
|
||||
}
|
||||
|
||||
} else {
|
||||
$results = array(
|
||||
"result" => "Error - data incomplete!",
|
||||
);
|
||||
|
||||
$jsonData = json_encode($results);
|
||||
echo $jsonData;
|
||||
}
|
||||
} else { // no data post
|
||||
$results = array(
|
||||
"result" => "Error - no data!",
|
||||
);
|
||||
$jsonData = json_encode($results);
|
||||
echo $jsonData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据token拉取用户信息 get
|
||||
function info()
|
||||
{
|
||||
$this->SET_HEADER; // 设置php CI 处理 CORS 自定义头部
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == 'GET') { // 只处理post请求,否则options请求 500错误
|
||||
$json_params = file_get_contents('php://input');
|
||||
$data = json_decode($json_params, true);
|
||||
|
||||
// $token=$_SERVER['x-auth-token'];
|
||||
|
||||
// 获取用户信息成功
|
||||
$info = array(
|
||||
"roles" => array(
|
||||
"admin"
|
||||
),
|
||||
"introduction" => "I am a super administrator",
|
||||
"avatar" => "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
|
||||
"name" => "Super Admin",
|
||||
);
|
||||
|
||||
echo json_encode(
|
||||
array(
|
||||
"code" => 20000,
|
||||
"data" => $info,
|
||||
"_SERVER" => $_SERVER,
|
||||
"_GET" => $_GET
|
||||
)
|
||||
);
|
||||
|
||||
// 获取用户信息失败
|
||||
// return {
|
||||
// code: 50008,
|
||||
// message: 'Login failed, unable to get user details.'
|
||||
// }
|
||||
// echo json_encode(
|
||||
// array(
|
||||
// "code" => 50008,
|
||||
// "message" => "Login failed, unable to get user details."
|
||||
// )
|
||||
// );
|
||||
|
||||
return;
|
||||
|
||||
if (!empty($data)) {
|
||||
if (!empty($data['username']) && !empty($data['password'])) {
|
||||
$username = $data['username'];
|
||||
$password = $data['password'];
|
||||
$input_account = $username;
|
||||
$input_password = md5($password);
|
||||
// $results = $this->phpIonicLoginAuthValidateLogin($username, $password);
|
||||
$result = $this->Api_model->app_user_login_validate($input_account, $input_password);
|
||||
|
||||
if ($result['success']) {
|
||||
echo json_encode($this->saveLoginInfo($result['userinfo']));
|
||||
} else {
|
||||
// 校验失败,写入token
|
||||
$this->output->set_status_header(300);
|
||||
echo '{"success": false,"message": "用户名或密码错误","jump":"","user":"' . $username . '"}';
|
||||
}
|
||||
|
||||
} else {
|
||||
$results = array(
|
||||
"result" => "Error - data incomplete!",
|
||||
);
|
||||
|
||||
$jsonData = json_encode($results);
|
||||
echo $jsonData;
|
||||
}
|
||||
} else { // no data post
|
||||
$results = array(
|
||||
"result" => "Error - no data!",
|
||||
);
|
||||
$jsonData = json_encode($results);
|
||||
echo $jsonData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
$this->SET_HEADER; // 设置php CI 处理 CORS 自定义头部
|
||||
if ($_SERVER["REQUEST_METHOD"] == 'POST') { // 只处理post请求,否则options请求 500错误
|
||||
echo json_encode(array(
|
||||
"code" => 20000,
|
||||
"data" => 'sucess'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* For 微信认证及全登录时保留登录日志信息
|
||||
*/
|
||||
function saveLoginInfo($userinfo)
|
||||
{
|
||||
$token = md5($userinfo["name"] . date('y-m-d H:i:s', time()));
|
||||
$arr2 = array('token' => $token);
|
||||
$userinfo["token"] = $token;
|
||||
$this->Bas->saveAdd(
|
||||
'auth',
|
||||
array(
|
||||
'token' => $token,
|
||||
'expiredAt' => date('Y-m-d H:i:s', strtotime('+1 day')),
|
||||
'onlineIp' => $this->input->ip_address(),
|
||||
'userLoginInfo' => json_encode($userinfo),
|
||||
'creatorId' => $userinfo["name"],
|
||||
'createdAt' => date('Y-m-d H:i:s')
|
||||
)
|
||||
);
|
||||
|
||||
// 返回信息
|
||||
$results = array(
|
||||
"success" => true,
|
||||
"message" => "APP登陆成功",
|
||||
"user" => $userinfo,
|
||||
'session' => $_SESSION,
|
||||
);
|
||||
|
||||
$this->Bas->saveEdit('userinfo', array('LASTLOGIN' => date('y-m-d H:i:s', time()), 'LASTIP' => $this->input->ip_address()), array('USERNAME' => $userinfo["name"]));
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行CURL请求,并封装返回对象
|
||||
*/
|
||||
private function execCURL($ch)
|
||||
{
|
||||
$response = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
$result = array('header' => '',
|
||||
'content' => '',
|
||||
'curl_error' => '',
|
||||
'http_code' => '',
|
||||
'last_url' => '');
|
||||
|
||||
if ($error != "") {
|
||||
$result['curl_error'] = $error;
|
||||
return $result;
|
||||
}
|
||||
|
||||
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
$result['header'] = str_replace(array("\r\n", "\r", "\n"), "<br/>", substr($response, 0, $header_size));
|
||||
$result['content'] = substr($response, $header_size);
|
||||
$result['http_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$result['last_url'] = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
|
||||
$result["base_resp"] = array();
|
||||
$result["base_resp"]["ret"] = $result['http_code'] == 200 ? 0 : $result['http_code'];
|
||||
$result["base_resp"]["err_msg"] = $result['http_code'] == 200 ? "ok" : $result["curl_error"];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET 请求
|
||||
* @param string $url
|
||||
*/
|
||||
private function http_get($url)
|
||||
{
|
||||
$oCurl = curl_init();
|
||||
if (stripos($url, "https://") !== FALSE) {
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
|
||||
}
|
||||
curl_setopt($oCurl, CURLOPT_URL, $url);
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($oCurl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($oCurl, CURLOPT_HEADER, 1);
|
||||
|
||||
// $sContent = curl_exec($oCurl);
|
||||
// $aStatus = curl_getinfo($oCurl);
|
||||
$sContent = $this->execCURL($oCurl);
|
||||
curl_close($oCurl);
|
||||
|
||||
return $sContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求
|
||||
* @param string $url
|
||||
* @param array $param
|
||||
* @param boolean $post_file 是否文件上传
|
||||
* @return string content
|
||||
*/
|
||||
private function http_post($url, $param, $post_file = false)
|
||||
{
|
||||
$oCurl = curl_init();
|
||||
|
||||
if (stripos($url, "https://") !== FALSE) {
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
|
||||
}
|
||||
if (PHP_VERSION_ID >= 50500 && class_exists('\CURLFile')) {
|
||||
$is_curlFile = true;
|
||||
} else {
|
||||
$is_curlFile = false;
|
||||
if (defined('CURLOPT_SAFE_UPLOAD')) {
|
||||
curl_setopt($oCurl, CURLOPT_SAFE_UPLOAD, false);
|
||||
}
|
||||
}
|
||||
|
||||
if ($post_file) {
|
||||
if ($is_curlFile) {
|
||||
foreach ($param as $key => $val) {
|
||||
if (isset($val["tmp_name"])) {
|
||||
$param[$key] = new \CURLFile(realpath($val["tmp_name"]), $val["type"], $val["name"]);
|
||||
} else if (substr($val, 0, 1) == '@') {
|
||||
$param[$key] = new \CURLFile(realpath(substr($val, 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
$strPOST = $param;
|
||||
} else {
|
||||
$strPOST = json_encode($param);
|
||||
}
|
||||
|
||||
curl_setopt($oCurl, CURLOPT_URL, $url);
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($oCurl, CURLOPT_POST, true);
|
||||
curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST);
|
||||
curl_setopt($oCurl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($oCurl, CURLOPT_HEADER, 1);
|
||||
|
||||
// $sContent = curl_exec($oCurl);
|
||||
// $aStatus = curl_getinfo($oCurl);
|
||||
|
||||
$sContent = $this->execCURL($oCurl);
|
||||
curl_close($oCurl);
|
||||
|
||||
return $sContent;
|
||||
}
|
||||
|
||||
function weixinAuth()
|
||||
{
|
||||
session_start();
|
||||
if ($_SERVER["REQUEST_METHOD"] == 'OPTIONS') {
|
||||
echo "options";
|
||||
die();
|
||||
}
|
||||
// $corpId = "wwxxxxxxxx";
|
||||
// $agentId = "100000";
|
||||
// $appSecret = "fsdfsfsdf";
|
||||
// $localAuthUrl = "http://dj.xxx.com:7000/hotcode/";
|
||||
|
||||
if (!array_key_exists("code", $_REQUEST)) {
|
||||
$redirectUri = urlencode("http://yw.cttha.com/ksh/get-corp-weixin-code.html?redirect_uri=" . urlencode($localAuthUrl));
|
||||
$authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $corpId . "&redirect_uri=" . $redirectUri . "&response_type=code&scope=snsapi_privateinfo&agentid=" . $agentId . "&state=STATE#wechat_redirect";
|
||||
echo json_encode(array("success" => false, "authUrl" => $authUrl));
|
||||
die();
|
||||
}
|
||||
$getCorpAccessTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" . $corpId . "&corpsecret=" . $appSecret;
|
||||
$accessToken = "";
|
||||
if (false && $_SESSION["weixinAuth_accessToken"] && $_SESSION["weixinAuth_tokenTime"] && $_SESSION["weixinAuth_tokenExpires"] && time() - intval($_SESSION["weixinAuth_tokenTime"]) < intval($_SESSION["tokenExpires"])) {
|
||||
$accessToken = $_SESSION["weixinAuth_accessToken"];
|
||||
} else {
|
||||
$tokenInfo = $this->http_get($getCorpAccessTokenUrl);
|
||||
$tokenInfo = json_decode($tokenInfo["content"], true);
|
||||
if ($tokenInfo["errcode"] == 0) {
|
||||
$accessToken = $tokenInfo["access_token"];
|
||||
$_SESSION["weixinAuth_accessToke"] = $accessToken;
|
||||
$_SESSION["weixinAuth_tokenTime"] = time();
|
||||
$_SESSION["weixinAuth_tokenExpires"] = $tokenInfo["expires_in"];
|
||||
} else {
|
||||
echo json_encode(array("success" => false, "msg" => $tokenInfo["errmsg"] ? $tokenInfo["errmsg"] : "企业认证失败!"));
|
||||
die();
|
||||
}
|
||||
}
|
||||
$getUserIdUrl = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=" . $accessToken . "&code=" . $_REQUEST["code"];
|
||||
$ajaxUserIdInfo = $this->http_get($getUserIdUrl);
|
||||
// var_dump($ajaxUserIdInfo);die();
|
||||
$userIdInfo = json_decode($ajaxUserIdInfo["content"], true);
|
||||
if ($userIdInfo["errcode"] == 0) {
|
||||
if (array_key_exists("OpenId", $userIdInfo)) {
|
||||
echo json_encode(array("success" => false, "msg" => "不是企业成员!请联系企业管理员,添加您的账号的企业通讯录!"));
|
||||
die();
|
||||
// next(U.error("不是企业成员!请联系企业管理员,添加您的账号的企业通讯录!"));
|
||||
} else if (array_key_exists("UserId", $userIdInfo)) {
|
||||
$getUserInfoUrl = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail?access_token=" . $accessToken;
|
||||
// 44468cd93cdfefb8a7f911b5e1f7dfd0
|
||||
$data = array("user_ticket" => $userIdInfo["user_ticket"]);
|
||||
$ajaxUserInfo = $this->http_post($getUserInfoUrl, $data);
|
||||
$userInfo = json_decode($ajaxUserInfo["content"], true);
|
||||
if ($userInfo["errcode"] == 0) {
|
||||
$user = $this->Api_model->getUserByWxUserId($userIdInfo["UserId"]);
|
||||
if ($user["success"]) {
|
||||
echo json_encode($this->saveLoginInfo($user['userinfo']));
|
||||
die();
|
||||
} else {
|
||||
$_SESSION["wxUserInfo"] = $userInfo;
|
||||
echo json_encode(array("sessionid" => session_id(), "status" => -1, "success" => false, "msg" => "此微信账号(" . $userInfo["name"] . ")没有与系统账号关联,请用您的账号密码登录一次,完成首次绑定!"));
|
||||
die();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
echo json_encode(array("success" => false, "msg" => $userInfo["errmsg"]));
|
||||
die();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo json_encode(array("success" => false, "msg" => $userIdInfo["errmsg"]));
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file welcome.php */
|
||||
/* Location: ./application/controllers/welcome.php */
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
class Article extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
// $this->load->model('Record_model');
|
||||
// $this->load->model('Dept_model', 'Dept');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function testapi()
|
||||
{
|
||||
echo "test api ok...";
|
||||
}
|
||||
|
||||
public function phpinfo()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
|
||||
$items = [
|
||||
["id" => 1,
|
||||
"timestamp" => "20180808",
|
||||
|
||||
"author" => "qiaokun",
|
||||
"reviewer" => "draft",
|
||||
"title" => "draft",
|
||||
"content_short" => "我是测试数据",
|
||||
"content" => "<p>我是测试数据我是测试数据</p><p><img src=\"https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943\"></p>",
|
||||
"forecast" => '3.1515',
|
||||
"importance" => '1',
|
||||
"type|1" => 'CN',
|
||||
"status" => 'published',
|
||||
"display_time" => "",
|
||||
"comment_disabled" => true,
|
||||
"pageviews" => 300,
|
||||
"image_uri" => "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'",
|
||||
"platforms" =>"a-platform"
|
||||
],
|
||||
["id" => 2,
|
||||
"timestamp" => "20180808",
|
||||
|
||||
"author" => "qiaokun",
|
||||
"reviewer" => "draft",
|
||||
"title" => "draft",
|
||||
"content_short" => "我是测试数据",
|
||||
"content" => "<p>我是测试数据我是测试数据</p><p><img src=\"https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943\"></p>",
|
||||
"forecast" => '3.1515',
|
||||
"importance" => '1',
|
||||
"type|1" => 'CN',
|
||||
"status" => 'published',
|
||||
"display_time" => "",
|
||||
"comment_disabled" => true,
|
||||
"pageviews" => 300,
|
||||
"image_uri" => "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'",
|
||||
"platforms" =>"a-platform"
|
||||
],
|
||||
];
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items,
|
||||
"total" => count($items)
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
function goods_get()
|
||||
{
|
||||
|
||||
$items = array(
|
||||
array('id' => 1, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 2, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 3, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 4, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 5, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 6, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 7, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 8, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 9, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 10, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 11, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 31, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 13, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 24, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 35, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 19, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 22, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 33, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file welcome.php */
|
||||
/* Location: ./application/controllers/welcome.php */
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
class Table extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
// $this->load->model('Record_model');
|
||||
// $this->load->model('Dept_model', 'Dept');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function testapi()
|
||||
{
|
||||
echo "test api ok...";
|
||||
}
|
||||
|
||||
public function phpinfo()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
|
||||
$items = [
|
||||
["id" => 1,
|
||||
"title" => "www",
|
||||
"status" => "draft",
|
||||
"author" => "qiaokun",
|
||||
"display_time" => "",
|
||||
"pageviews" => 300
|
||||
],
|
||||
["id" => 3,
|
||||
"title" => "bbb",
|
||||
"status" => "bbbb",
|
||||
"author" => "乔锟",
|
||||
"display_time" => "",
|
||||
"pageviews" => 300
|
||||
],
|
||||
];
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
function goods_get()
|
||||
{
|
||||
|
||||
$items = array(
|
||||
array('id' => 1, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 2, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 3, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 4, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 5, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 6, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 7, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 8, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 9, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 10, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 11, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 31, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 13, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 24, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 35, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 19, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 22, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 33, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file welcome.php */
|
||||
/* Location: ./application/controllers/welcome.php */
|
||||
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
//require APPPATH . 'libraries/kindeditor/php/JSON.php';
|
||||
|
||||
class Uploadimg extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
}
|
||||
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
}
|
||||
|
||||
public function upload_post()
|
||||
{
|
||||
$uploadDir = FCPATH . 'uploads/';
|
||||
$id = 'T' . $this->POST('identify');
|
||||
$php_path = dirname(__FILE__) . '/';//dirname($_SERVER['DOCUMENT_ROOT']); dirname(__FILE__)
|
||||
// $php_url = "";//dirname($_SERVER['HTTP_HOST']) . '/';//PHP_SELF
|
||||
$php_url = $_SERVER['HTTP_HOST'] . '/'; //PHP_SELF
|
||||
|
||||
$save_path = $uploadDir;
|
||||
//文件保存目录URL
|
||||
$save_url = $php_url . 'uploads/';
|
||||
// nginx服务器端修改绝对路径
|
||||
//$save_url = "http://172.30.3.11/static/home/kindeditor/attached/";
|
||||
|
||||
// var_dump($save_path);
|
||||
// var_dump($save_url);
|
||||
// string(46) "D:\Q\code\vue\CodeIgniter-3.1.10\uploads\imgs\"
|
||||
// string(28) "www.cirest.com:8889/uploads/"
|
||||
|
||||
|
||||
//定义允许上传的文件扩展名
|
||||
$ext_arr = array(
|
||||
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
|
||||
'flash' => array('swf', 'flv'),
|
||||
'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
|
||||
'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'),
|
||||
);
|
||||
//最大文件大小 10M 默认是1M
|
||||
$max_size = 10000000;
|
||||
|
||||
$save_path = realpath($save_path) . '/';
|
||||
$save_path = str_replace('\\', '/', $save_path);
|
||||
|
||||
//PHP上传失败
|
||||
if (!empty($_FILES['file']['error'])) {
|
||||
switch ($_FILES['file']['error']) {
|
||||
case '1':
|
||||
$error = '超过php.ini允许的大小。';
|
||||
break;
|
||||
case '2':
|
||||
$error = '超过表单允许的大小。';
|
||||
break;
|
||||
case '3':
|
||||
$error = '图片只有部分被上传。';
|
||||
break;
|
||||
case '4':
|
||||
$error = '请选择图片。';
|
||||
break;
|
||||
case '6':
|
||||
$error = '找不到临时目录。';
|
||||
break;
|
||||
case '7':
|
||||
$error = '写文件到硬盘出错。';
|
||||
break;
|
||||
case '8':
|
||||
$error = 'File upload stopped by extension。';
|
||||
break;
|
||||
case '999':
|
||||
default:
|
||||
$error = '未知错误。';
|
||||
}
|
||||
$this->alert($error);
|
||||
}
|
||||
|
||||
//有上传文件时
|
||||
if (empty($_FILES) === false) {
|
||||
//原文件名
|
||||
$file_name = $_FILES['file']['name'];
|
||||
//服务器上临时文件名
|
||||
$tmp_name = $_FILES['file']['tmp_name'];
|
||||
//文件大小
|
||||
$file_size = $_FILES['file']['size'];
|
||||
//检查文件名
|
||||
if (!$file_name) {
|
||||
$this->alert("请选择文件。");
|
||||
}
|
||||
//检查目录
|
||||
if (@is_dir($save_path) === false) {
|
||||
$this->alert("上传目录不存在。");
|
||||
}
|
||||
//检查目录写权限
|
||||
if (@is_writable($save_path) === false) {
|
||||
$this->alert("上传目录没有写权限。");
|
||||
}
|
||||
//检查是否已上传
|
||||
if (@is_uploaded_file($tmp_name) === false) {
|
||||
$this->alert("上传失败。");
|
||||
}
|
||||
//检查文件大小
|
||||
if ($file_size > $max_size) {
|
||||
$this->alert("上传文件大小超过限制(<10M)。");
|
||||
}
|
||||
//检查目录名
|
||||
$dir_name = empty($_GET['dir']) ? 'image' : trim($_GET['dir']);
|
||||
if (empty($ext_arr[$dir_name])) {
|
||||
$this->alert("目录名不正确。");
|
||||
}
|
||||
//获得文件扩展名
|
||||
$temp_arr = explode(".", $file_name);
|
||||
$file_ext = array_pop($temp_arr);
|
||||
$file_ext = trim($file_ext);
|
||||
$file_ext = strtolower($file_ext);
|
||||
|
||||
//检查扩展名
|
||||
if (!in_array($file_ext, $ext_arr[$dir_name])) {
|
||||
$this->alert("上传文件扩展名是不允许的扩展名。\n只允许" . implode(",", $ext_arr[$dir_name]) . "格式。");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 以 T+身份证号作为临时目录 , 以身份证作为正式目录
|
||||
*/
|
||||
$identify = empty($id) ? '' : trim($id);
|
||||
|
||||
if ($identify == '') {
|
||||
echo "Invalid session identify.";
|
||||
exit;
|
||||
}
|
||||
//创建文件夹
|
||||
if ($dir_name !== '') {
|
||||
$save_path .= $dir_name . "/" . $identify . "/";
|
||||
$save_url .= $dir_name . "/" . $identify . "/";
|
||||
if (!file_exists($save_path)) {
|
||||
mkdir($save_path, 0777, true); // true 允许创建多级目录
|
||||
}
|
||||
}
|
||||
$ymd = date("Ym");
|
||||
$save_path .= $ymd . "/";
|
||||
$save_url .= $ymd . "/";
|
||||
if (!file_exists($save_path)) {
|
||||
mkdir($save_path);
|
||||
}
|
||||
//新文件名
|
||||
$new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
|
||||
//移动文件
|
||||
$file_path = $save_path . $new_file_name;
|
||||
if (move_uploaded_file($tmp_name, $file_path) === false) {
|
||||
$this->alert("上传文件失败。");
|
||||
}
|
||||
@chmod($file_path, 0644);
|
||||
$file_url = $save_url . $new_file_name;
|
||||
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
// Insert file information in the database
|
||||
// $insert = $db->query("INSERT INTO files (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
|
||||
$link = "http://" . $file_url;
|
||||
// http://www.cirest.com:8889/uploads/image/T410000000000000000/201902/20190228071354_96833.png
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"error" => 0,
|
||||
"message" => "上传成功",
|
||||
"link" => $link,
|
||||
"filepath" => preg_replace('/^http.*uploads/', '/uploads', $link)
|
||||
];
|
||||
|
||||
echo json_encode($message);
|
||||
// $this->set_response($message, REST_Controller::HTTP_OK);
|
||||
// alert里面使用时 exit() 产生的是空,或字符串,使用原生的json_encode返回统一的字符串,在客户端在统一处理成对象
|
||||
}
|
||||
}
|
||||
|
||||
public function delimg_post()
|
||||
{
|
||||
$php_path = dirname(__FILE__) . '/';//dirname($_SERVER['DOCUMENT_ROOT']); dirname(__FILE__)
|
||||
|
||||
//文件保存目录路径
|
||||
$save_path = $php_path . '../../../../';
|
||||
|
||||
$save_path = realpath($save_path) . '/';
|
||||
$save_path = str_replace('\\', '/', $save_path);
|
||||
// var_dump($save_path);
|
||||
// "D:/Q/code/vue/CodeIgniter-3.1.10/"
|
||||
|
||||
$DelFileName = $this->POST('filename');
|
||||
$DelFileType = $this->POST('isdir');
|
||||
|
||||
$FilePath = $save_path . $DelFileName;
|
||||
|
||||
// var_dump($FilePath);return;
|
||||
|
||||
if ($DelFileType == 'F') {
|
||||
if (!is_file($FilePath)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => "文件不存在 - " . $DelFileName,
|
||||
"message" => "文件不存在 - " . $DelFileName
|
||||
];
|
||||
|
||||
echo json_encode($message);
|
||||
|
||||
} else {
|
||||
|
||||
if (!unlink($FilePath)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => "Error deleting " . $FilePath,
|
||||
"message" => "Error deleting " . $FilePath
|
||||
];
|
||||
echo json_encode($message);
|
||||
|
||||
} else {
|
||||
// 必须返回code 由于前端vue封装的 request 请求,返回数据对code进行判断
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => '服务器删除成功!',
|
||||
"message" => '服务器删除成功!'
|
||||
];
|
||||
echo json_encode($message);
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($DelFileType == 'D') {
|
||||
if (!@rmdir($FilePath)) {
|
||||
echo "文件夹 " . $FilePath . " 不为空,不能删除!";
|
||||
} else {
|
||||
echo "succeed";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function alert($msg)
|
||||
{
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"error" => 1,
|
||||
"message" => $msg
|
||||
];
|
||||
echo json_encode($message);
|
||||
exit();
|
||||
// var_dump($message);
|
||||
// $this->set_response($message, REST_Controller::HTTP_OK);
|
||||
// die();
|
||||
}
|
||||
|
||||
|
||||
public function onsubmit_post()
|
||||
{
|
||||
$identify = $this->POST('identify');
|
||||
$phone = $this->POST('phone');
|
||||
$idinfo = $this->POST('idinfo');
|
||||
$bankinfo = $this->POST('bankinfo');
|
||||
// $data = [
|
||||
// 'identify' => $identify,
|
||||
// 'phone' => $phone,
|
||||
// 'idinfo' => $idinfo,
|
||||
// 'check' => '待审核'
|
||||
// ];
|
||||
|
||||
// 写入数据库表 身份证号,手机号,证件照,文件路径等
|
||||
$where = [
|
||||
'identify' => $identify,
|
||||
'phone' => $phone,
|
||||
];
|
||||
|
||||
$data = [
|
||||
'idinfo' => $idinfo,
|
||||
'bankinfo' => $bankinfo,
|
||||
'check' => '待审核'
|
||||
];
|
||||
|
||||
$result = $this->Base_model->_update_key('upload_tbl', $data, $where);
|
||||
|
||||
if ($result) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"message" => '写入数据库表成功,请请待审核通知!',
|
||||
"data" => array_merge($where, $data)
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"message" => '写入数据库表失败!',
|
||||
"data" => array_merge($where, $data)
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
// Chevereto 图床免费版本地址:https://github.com/Chevereto/Chevereto-Free
|
||||
// https://chevereto.com/docs/api-v1
|
||||
// 上传图片测试
|
||||
public function chevereto_post()
|
||||
{
|
||||
// 1. 上传本地文件时应使用 $fields post base64_encode方法
|
||||
// Always use POST when uploading local files. Url encoding may alter the base64 source
|
||||
// due to encoded characters or just by URL request length limit due to GET request.
|
||||
// base64编码 会导致过长 url request
|
||||
// var_dump($_FILES); 参考 uploadimg 可以做一些前置校验处理 // 前置判断 if (empty($_FILES) === false)
|
||||
$key = '5486424e4dfb6b87453dd4bb25c0dcb0';
|
||||
$url = 'http://172.17.1.110/chevereto/api/1/upload';
|
||||
|
||||
// What do we send to chevereto api?
|
||||
$fields = array(
|
||||
'key' => urlencode($key),
|
||||
// The image encoded in base64
|
||||
'source' => base64_encode(file_get_contents($_FILES["file"]['tmp_name'])),
|
||||
// format: txt / json txt 只返回图片地址或错误信息 eg.Duplicated upload 较为简洁
|
||||
'format' => urlencode('json')
|
||||
);
|
||||
|
||||
//open connection
|
||||
$ch = curl_init();
|
||||
|
||||
//set the url, number of POST vars, POST data
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, sizeof($fields));
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));
|
||||
|
||||
//execute post
|
||||
$result = curl_exec($ch);
|
||||
//释放curl句柄
|
||||
curl_close($ch);
|
||||
echo $result;
|
||||
//close connection
|
||||
|
||||
// 2. 上传远程图片地址可使用 _get source=urlencode{source} 方法即可
|
||||
|
||||
// $key = '6a55c7f9fa13813c2da613dc7b5b920b';
|
||||
// // 设定远程图片地址
|
||||
// $source = 'https://img3.doubanio.com/view/group_topic/large/public/p67032015.jpg';
|
||||
// // format: txt / json txt 只返回图片地址或错误信息 eg.Duplicated upload 较为简洁
|
||||
// $url = 'http://172.17.1.110:8888/api/1/upload/?key={key}&source={source}&format=txt';
|
||||
// $url = str_replace(array('{key}','{source}'),array($key,urlencode($source)),$url);
|
||||
//
|
||||
// //初始化
|
||||
// $ch = curl_init();
|
||||
// //设置选项,包括URL
|
||||
// curl_setopt($ch, CURLOPT_URL, $url);
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
// //执行并获取HTML文档内容
|
||||
// $output = curl_exec($ch);
|
||||
// //释放curl句柄
|
||||
// curl_close($ch);
|
||||
// echo $output;
|
||||
|
||||
|
||||
// 失败
|
||||
// {
|
||||
// "status_txt": "Bad Request",
|
||||
// "error": {
|
||||
// "context": "Exception",
|
||||
// "code": 102,
|
||||
// "message": "Duplicated upload"
|
||||
// },
|
||||
// "status_code": 400
|
||||
// }
|
||||
// 成功
|
||||
// {
|
||||
// "status_txt": "OK",
|
||||
// "image": {
|
||||
// "image": {
|
||||
// "size": "89163",
|
||||
// "url": "http://172.17.1.110:8888/images/2019/07/09/p67032015.jpg",
|
||||
// "extension": "jpg",
|
||||
// "mime": "image/jpeg",
|
||||
// "name": "p67032015",
|
||||
// "filename": "p67032015.jpg"
|
||||
// },
|
||||
// },
|
||||
// "success": {
|
||||
// "code": 200,
|
||||
// "message": "image uploaded"
|
||||
// },
|
||||
// "status_code": 200
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
class Menu extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index_get()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function insertx_post()
|
||||
{
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
var_dump($parms);
|
||||
$result = $this->Base_model->_insert_key('sys_role_perm', $parms);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
public function gettest_post()
|
||||
{
|
||||
$result = $this->Base_model->_get_key('sys_perm', 'perm_type,r_id rid', 'perm_type="role" and r_id=1');
|
||||
var_dump($result);
|
||||
var_dump($result[0]['perm_type']);
|
||||
var_dump($this->uri->uri_string);
|
||||
var_dump($this->uri);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
|
||||
// $message = [
|
||||
// "code" => 20000,
|
||||
// "data" => [
|
||||
// "__FUNCTION__" => __FUNCTION__,
|
||||
// "__CLASS__" => __CLASS__,
|
||||
// "uri" => $this->uri
|
||||
// ],
|
||||
//
|
||||
// ];
|
||||
// "data": {
|
||||
// "__FUNCTION__": "router_get",
|
||||
// "__CLASS__": "User",
|
||||
// "uri": {
|
||||
// "keyval": [],
|
||||
// "uri_string": "api/v2/user/router",
|
||||
// "segments": {
|
||||
// "1": "api",
|
||||
// "2": "v2",
|
||||
// "3": "user",
|
||||
// "4": "router"
|
||||
// },
|
||||
}
|
||||
|
||||
public function phpinfo_get()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb_get()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
// 增
|
||||
function add_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms);
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 菜单类型为目录
|
||||
if (!$parms['type']) {
|
||||
$parms['component'] = 'Layout';
|
||||
}
|
||||
|
||||
$menu_id = $this->Base_model->_insert_key('sys_menu', $parms);
|
||||
if (!$menu_id) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 菜单添加失败'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成该菜单对应的权限: sys_perm, 权限类型为: menu, 生成唯一的 perm_id
|
||||
$perm_id = $this->Base_model->_insert_key('sys_perm', ['perm_type' => 'menu', "r_id" => $menu_id]);
|
||||
if (!$perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 生成该菜单对应的权限: sys_perm, 失败...');
|
||||
var_dump(['perm_type' => 'menu', "r_id" => $menu_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 超级管理员角色自动拥有该权限 perm_id
|
||||
$role_perm_id = $this->Base_model->_insert_key('sys_role_perm', ["role_id" => 1, "perm_id" => $perm_id]);
|
||||
if (!$role_perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 超级管理员角色自动拥有该权限 perm_id, 失败...');
|
||||
var_dump(["role_id" => 1, "perm_id" => $perm_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['title'] . ' - 菜单添加成功'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 改
|
||||
function edit_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
if ($parms['id'] == $parms['pid']) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '父节点不能是自己'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
// 菜单类型为目录
|
||||
if ($parms['type'] == 0) {
|
||||
$parms['component'] = 'Layout';
|
||||
}
|
||||
// 菜单类型为功能按钮时
|
||||
if ($parms['type'] == 2) {
|
||||
$parms['component'] = '';
|
||||
$parms['icon'] = '';
|
||||
}
|
||||
|
||||
$id = $parms['id'];
|
||||
unset($parms['id']); // 择出索引id
|
||||
$where = ["id" => $id];
|
||||
|
||||
if (!$this->Base_model->_update_key('sys_menu', $parms, $where)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 菜单更新错误'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['title'] . ' - 菜单更新成功'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删
|
||||
function del_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 存在子节点 不能删除返回
|
||||
$hasChild = $this->Base_model->hasChildMenu($parms['id']);
|
||||
if ($hasChild) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 存在子节点不能删除'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除外键关联表 sys_role_perm , sys_perm, sys_menu
|
||||
// 1. 根据sys_menu id及'menu' 查找 perm_id
|
||||
// 2. 删除sys_role_perm 中perm_id记录
|
||||
// 3. 删除sys_perm中 perm_type='menu' and r_id = menu_id 记录,即第1步中获取的 perm_id, 一一对应
|
||||
// 4. 删除sys_menu 中 id = menu_id 的记录
|
||||
$where = 'perm_type="menu" and r_id=' . $parms['id'];
|
||||
$arr = $this->Base_model->_get_key('sys_perm', '*', $where);
|
||||
if (empty($arr)) {
|
||||
var_dump($this->uri->uri_string . ' 未查找到 sys_perm 表中记录');
|
||||
var_dump($where);
|
||||
return;
|
||||
}
|
||||
|
||||
$perm_id = $arr[0]['id']; // 正常只有一条记录
|
||||
$this->Base_model->_delete_key('sys_role_perm', ['perm_id' => $perm_id]);
|
||||
$this->Base_model->_delete_key('sys_perm', ['id' => $perm_id]);
|
||||
|
||||
// 删除基础表 sys_menu
|
||||
if (!$this->Base_model->_delete_key('sys_menu', $parms)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 菜单删除错误'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['title'] . ' - 菜单删除成功'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
// 查
|
||||
function view_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$MenuTreeArr = $this->permission->getPermission($Token, 'menu', true);
|
||||
$MenuTree = $this->permission->genVueMenuTree($MenuTreeArr, 'id', 'pid', 0);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTree,
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 根据token拉取 treeselect 下拉选项菜单
|
||||
function treeoptions_get()
|
||||
{
|
||||
// 此 uri 可不做权限/token过期验证,则在菜单里,可以不加入此项路由path /sys/menu/treeoptions。
|
||||
//
|
||||
// $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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
// return;
|
||||
// }
|
||||
|
||||
$Token = $this->input->get_request_header('X-Token', TRUE);
|
||||
|
||||
$MenuTreeArr = $this->permission->getPermission($Token, 'menu', false);
|
||||
array_unshift($MenuTreeArr, ['id' => 0, 'pid' => -1, 'title' => '顶级菜单']);
|
||||
$MenuTree = $this->permission->genVueMenuTree($MenuTreeArr, 'id', 'pid', -1);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTree,
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
// $result = $this->some_model();
|
||||
$result['success'] = TRUE;
|
||||
|
||||
if ($result['success']) {
|
||||
$List = array(
|
||||
array('order_no' => '201805138451313131', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '300000000000000000', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
array('order_no' => '444444444444444444', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '888888888888888888', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"total" => count($List),
|
||||
"items" => $List
|
||||
]
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 50008,
|
||||
"message" => 'Login failed, unable to get user details.'
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
//To Solve File REST_Controller not found
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
class Role extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
$this->load->model('Role_model');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index_get()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function insertx_post()
|
||||
{
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
var_dump($parms);
|
||||
$result = $this->Base_model->_insert_key('sys_role_perm', $parms);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
public function gettest_post()
|
||||
{
|
||||
$result = $this->Base_model->_get_key('sys_perm', 'perm_type,r_id rid', 'perm_type="role" and r_id=1');
|
||||
var_dump($result);
|
||||
var_dump($result[0]['perm_type']);
|
||||
var_dump($this->uri->uri_string);
|
||||
var_dump($this->uri);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
|
||||
// $message = [
|
||||
// "code" => 20000,
|
||||
// "data" => [
|
||||
// "__FUNCTION__" => __FUNCTION__,
|
||||
// "__CLASS__" => __CLASS__,
|
||||
// "uri" => $this->uri
|
||||
// ],
|
||||
//
|
||||
// ];
|
||||
// "data": {
|
||||
// "__FUNCTION__": "router_get",
|
||||
// "__CLASS__": "User",
|
||||
// "uri": {
|
||||
// "keyval": [],
|
||||
// "uri_string": "api/v2/user/router",
|
||||
// "segments": {
|
||||
// "1": "api",
|
||||
// "2": "v2",
|
||||
// "3": "user",
|
||||
// "4": "router"
|
||||
// },
|
||||
}
|
||||
|
||||
public function phpinfo_get()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb_get()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
// 增
|
||||
function add_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
|
||||
if ($this->Base_model->_key_exists('sys_role', ['name' => $parms['name']])) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色名重复'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// 加入新增时间
|
||||
$parms['create_time'] = time();
|
||||
|
||||
$role_id = $this->Base_model->_insert_key('sys_role', $parms);
|
||||
if (!$role_id) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色新增失败'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成该角色对应的权限: sys_perm, 权限类型为: role, 生成唯一的 perm_id
|
||||
$perm_id = $this->Base_model->_insert_key('sys_perm', ['perm_type' => 'role', "r_id" => $role_id]);
|
||||
if (!$perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 生成该角色对应的权限: sys_perm, 失败...');
|
||||
var_dump(['perm_type' => 'role', "r_id" => $role_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 超级管理员角色自动拥有该权限 perm_id
|
||||
$role_perm_id = $this->Base_model->_insert_key('sys_role_perm', ["role_id" => 1, "perm_id" => $perm_id]);
|
||||
if (!$role_perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 超级管理员角色自动拥有该权限 perm_id, 失败...');
|
||||
var_dump(["role_id" => 1, "perm_id" => $perm_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 角色新增成功'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 改
|
||||
function edit_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 超级管理员角色不允许修改
|
||||
if ($parms['id'] == 1) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色不允许修改'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $parms['id'];
|
||||
unset($parms['id']); // 剃除索引id
|
||||
|
||||
// 加入更新时间
|
||||
$parms['update_time'] = time();
|
||||
$where = ["id" => $id];
|
||||
|
||||
if (!$this->Base_model->_update_key('sys_role', $parms, $where)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色更新错误'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 角色更新成功'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删
|
||||
function del_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 超级管理员角色不允许删除
|
||||
if ($parms['id'] == 1) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色不允许删除'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除外键关联表 sys_role_perm , sys_perm, sys_role
|
||||
// 1. 根据sys_role id及'menu' 查找 perm_id
|
||||
// 2. 删除sys_role_perm 中perm_id记录
|
||||
// 3. 删除sys_perm中 perm_type='role' and r_id = role_id 记录,即第1步中获取的 perm_id, 一一对应
|
||||
// 4. 删除sys_role 中 id = role_id 的记录
|
||||
$where = 'perm_type="role" and r_id=' . $parms['id'];
|
||||
$arr = $this->Base_model->_get_key('sys_perm', '*', $where);
|
||||
if (empty($arr)) {
|
||||
var_dump($this->uri->uri_string . ' 未查找到 sys_perm 表中记录');
|
||||
var_dump($where);
|
||||
return;
|
||||
}
|
||||
|
||||
$perm_id = $arr[0]['id']; // 正常只有一条记录
|
||||
$this->Base_model->_delete_key('sys_role_perm', ['perm_id' => $perm_id]); // 必须删除权限id 因为超级管理员角色自动拥有该权限否则会造成删除关联错误
|
||||
$this->Base_model->_delete_key('sys_role_perm', ['role_id' => $parms['id']]); // 再删除该角色对应的权限id(原有的菜单)
|
||||
$this->Base_model->_delete_key('sys_perm', ['id' => $perm_id]);
|
||||
|
||||
$this->Base_model->_delete_key('sys_user_role', ['role_id' => $parms['id']]);
|
||||
|
||||
// 删除基础表 sys_role
|
||||
if (!$this->Base_model->_delete_key('sys_role', $parms)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色删除错误'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 角色删除成功'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
// 查
|
||||
function view_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->set_response($retPerm, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$RoleArr = $this->Role_model->getRoleList();
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $RoleArr,
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取所有菜单 不需权限验证
|
||||
function allmenus_get()
|
||||
{
|
||||
$MenuTreeArr = $this->Role_model->getAllMenus();
|
||||
if (empty($MenuTreeArr)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTreeArr,
|
||||
"message" => "数据库表中没有菜单"
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$MenuTree = $this->permission->genVueMenuTree($MenuTreeArr, 'id', 'pid', 0);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTree,
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取所有角色带perm_id 不需权限验证
|
||||
function allroles_get()
|
||||
{
|
||||
$AllRolesArr = $this->Role_model->getAllRoles();
|
||||
if (empty($AllRolesArr)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $AllRolesArr,
|
||||
"message" => "数据库表中没有角色"
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $AllRolesArr,
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取角色拥有的菜单权限 不需权限验证
|
||||
function rolemenu_post()
|
||||
{
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
$RoleId = $parms['roleId'];
|
||||
|
||||
$MenuTreeArr = $this->Role_model->getRoleMenu($RoleId);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTreeArr,
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取角色拥有的角色权限 不需权限验证
|
||||
function rolerole_post()
|
||||
{
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
$RoleId = $parms['roleId'];
|
||||
|
||||
$RoleRoleArr = $this->Role_model->getRoleRole($RoleId);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $RoleRoleArr,
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
// 保存角色对应权限
|
||||
function saveroleperm_post()
|
||||
{
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['roleId']);
|
||||
// var_dump($parms['rolePerms']);
|
||||
// 参数检验/数据预处理
|
||||
// 超级管理员角色不允许删除
|
||||
if ($parms['roleId'] == 1) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '超级管理员角色拥有所有权限,不允许修改!'
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$RolePermArr = $this->Role_model->getRolePerm($parms['roleId']);
|
||||
|
||||
$AddArr = $this->permission->array_diff_assoc2($parms['rolePerms'], $RolePermArr);
|
||||
// var_dump('------------只存在于前台传参 做添加操作-------------');
|
||||
// var_dump($AddArr);
|
||||
$failed = false;
|
||||
$failedArr = [];
|
||||
foreach ($AddArr as $k => $v) {
|
||||
$ret = $this->Base_model->_insert_key('sys_role_perm', $v);
|
||||
if (!$ret) {
|
||||
$failed = true;
|
||||
array_push($failedArr, $v);
|
||||
}
|
||||
}
|
||||
if ($failed) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '授权失败 ' . json_encode($failedArr)
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$DelArr = $this->permission->array_diff_assoc2($RolePermArr, $parms['rolePerms']);
|
||||
// var_dump('------------只存在于后台数据库 删除操作-------------');
|
||||
// var_dump($DelArr);
|
||||
$failed = false;
|
||||
$failedArr = [];
|
||||
foreach ($DelArr as $k => $v) {
|
||||
$ret = $this->Base_model->_delete_key('sys_role_perm', $v);
|
||||
if (!$ret) {
|
||||
$failed = true;
|
||||
array_push($failedArr, $v);
|
||||
}
|
||||
}
|
||||
if ($failed) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '授权失败 ' . json_encode($failedArr)
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"data" => $parms,
|
||||
"message" => '授权操作成功',
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
// $result = $this->some_model();
|
||||
$result['success'] = TRUE;
|
||||
|
||||
if ($result['success']) {
|
||||
$List = array(
|
||||
array('order_no' => '201805138451313131', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '300000000000000000', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
array('order_no' => '444444444444444444', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '888888888888888888', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"total" => count($List),
|
||||
"items" => $List
|
||||
]
|
||||
];
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 50008,
|
||||
"message" => 'Login failed, unable to get user details.'
|
||||
];
|
||||
|
||||
$this->set_response($message, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
class Article extends RestController
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
// $this->load->model('Record_model');
|
||||
// $this->load->model('Dept_model', 'Dept');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function testapi()
|
||||
{
|
||||
echo "test api ok...";
|
||||
}
|
||||
|
||||
public function phpinfo()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
|
||||
$items = [
|
||||
["id" => 1,
|
||||
"timestamp" => "20180808",
|
||||
|
||||
"author" => "qiaokun",
|
||||
"reviewer" => "draft",
|
||||
"title" => "draft",
|
||||
"content_short" => "我是测试数据",
|
||||
"content" => "<p>我是测试数据我是测试数据</p><p><img src=\"https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943\"></p>",
|
||||
"forecast" => '3.1515',
|
||||
"importance" => '1',
|
||||
"type|1" => 'CN',
|
||||
"status" => 'published',
|
||||
"display_time" => "",
|
||||
"comment_disabled" => true,
|
||||
"pageviews" => 300,
|
||||
"image_uri" => "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'",
|
||||
"platforms" =>"a-platform"
|
||||
],
|
||||
["id" => 2,
|
||||
"timestamp" => "20180808",
|
||||
|
||||
"author" => "pocoyo",
|
||||
"reviewer" => "draft",
|
||||
"title" => "draft",
|
||||
"content_short" => "我是测试数据",
|
||||
"content" => "<p>我是测试数据我是测试数据</p><p><img src=\"https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943\"></p>",
|
||||
"forecast" => '3.1515',
|
||||
"importance" => '1',
|
||||
"type|1" => 'CN',
|
||||
"status" => 'published',
|
||||
"display_time" => "",
|
||||
"comment_disabled" => true,
|
||||
"pageviews" => 300,
|
||||
"image_uri" => "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'",
|
||||
"platforms" =>"a-platform"
|
||||
],
|
||||
];
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items,
|
||||
"total" => count($items)
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
$this->set_response($message, RestController::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
function goods_get()
|
||||
{
|
||||
|
||||
$items = array(
|
||||
array('id' => 1, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 2, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 3, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 4, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 5, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 6, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 7, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 8, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 9, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 10, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 11, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 31, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 13, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 24, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 35, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 19, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 22, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 33, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->set_response($message, RestController::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file welcome.php */
|
||||
/* Location: ./application/controllers/welcome.php */
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Dashboard extends AdminController
|
||||
{
|
||||
protected $base_model = 'package_model';
|
||||
|
||||
function count_total_get()
|
||||
{
|
||||
$ret = [
|
||||
'count'=>[]
|
||||
];
|
||||
foreach (['sample','customer','sample_upgrade_order'] as $model) {
|
||||
$this->load->model($model.'_model');
|
||||
$ret['count'][$model] = (int)$this->{$model.'_model'}->total();
|
||||
}
|
||||
$ret['count']['order_total'] = 0;
|
||||
$this->success($ret);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 样品
|
||||
*/
|
||||
class Disease extends AdminController
|
||||
{
|
||||
protected $base_model = 'disease_model';
|
||||
|
||||
protected function _validate_rule(){
|
||||
return array(
|
||||
array(
|
||||
'field' => 'id',
|
||||
'label' => '序号',
|
||||
'rules' => 'trim|min_length[0]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'name',
|
||||
'label' => '名称',
|
||||
'rules' => 'trim|min_length[0]|max_length[40]'
|
||||
),
|
||||
array(
|
||||
'field' => 'pathogenesis',
|
||||
'label' => '致病机理',
|
||||
'rules' => 'trim|min_length[0]|max_length[800]'
|
||||
),
|
||||
array(
|
||||
'field' => 'clinical_symptoms',
|
||||
'label' => '临床症状',
|
||||
'rules' => 'trim|min_length[0]|max_length[800]'
|
||||
),
|
||||
array(
|
||||
'field' => 'category',
|
||||
'label' => '所属类别',
|
||||
'rules' => 'trim|min_length[0]|max_length[50]'
|
||||
),
|
||||
array(
|
||||
'field' => 'advice_treatment',
|
||||
'label' => '诊疗建议',
|
||||
'rules' => 'trim|min_length[0]|max_length[800]'
|
||||
),
|
||||
array(
|
||||
'field' => 'advice_parenting',
|
||||
'label' => '养育建议',
|
||||
'rules' => 'trim|min_length[0]|max_length[800]'
|
||||
),
|
||||
array(
|
||||
'field' => 'reference',
|
||||
'label' => '参考文献',
|
||||
'rules' => 'trim|min_length[0]|max_length[800]'
|
||||
),
|
||||
array(
|
||||
'field' => 'species',
|
||||
'label' => '物种',
|
||||
'rules' => 'trim|integer|min_length[0]|max_length[2]'
|
||||
),
|
||||
array(
|
||||
'field' => 'gene_type',
|
||||
'label' => '基因类别',
|
||||
'rules' => 'trim|integer|min_length[0]|max_length[2]'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function _import_field_map(){
|
||||
return [
|
||||
'名称'=>'name',
|
||||
'致病机理'=>'pathogenesis',
|
||||
'临床症状'=>'clinical_symptoms',
|
||||
'所属类别'=>'category',
|
||||
'诊疗建议'=>'advice_treatment',
|
||||
'养育建议'=>'advice_parenting',
|
||||
'参考文献'=>'reference',
|
||||
'species'=>'species',
|
||||
'gene_type'=>'gene_type',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Package extends AdminController
|
||||
{
|
||||
protected $base_model = 'package_model';
|
||||
|
||||
function list_get()
|
||||
{
|
||||
$data = $this->_list_get(true);
|
||||
$package_up_ids = [];
|
||||
$disease_ids = [];
|
||||
foreach ($data['items'] as &$item) {
|
||||
$item['content'] = empty($item['content'])?[]:json_decode($item['content'],true);
|
||||
$item['structure'] = array_values(array_filter(explode(',',$item['structure'])));
|
||||
$item['structure_hide'] = array_values(array_filter(explode(',',$item['structure_hide'])));
|
||||
$item['cert'] = array_values(array_filter(explode(',',$item['cert'])));
|
||||
$item['disease'] = array_values(array_filter(explode(',',$item['disease'])));
|
||||
//套餐升级目标
|
||||
$package_up_ids[] = $item['package_up'];
|
||||
//套餐自带疾病
|
||||
$disease_ids = array_merge($disease_ids,$item['disease']);
|
||||
//套餐疾病选项
|
||||
foreach ($item['content'] as $val) {
|
||||
$disease_ids = array_merge($disease_ids,$val['disease_id']);
|
||||
}
|
||||
}
|
||||
//提供所有升级目标套餐的值
|
||||
$data['options']['package'] = $this->package_model->get($package_up_ids,null,true,'base.id,base.name');
|
||||
//提供所有疾病选项
|
||||
$this->load->model('disease_model');
|
||||
$data['options']['disease'] = $this->disease_model->get($disease_ids,null,true,'base.id,base.name');
|
||||
$this->success($data);
|
||||
}
|
||||
|
||||
function update_post()
|
||||
{
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'id',
|
||||
'label' => '序号',
|
||||
'rules' => 'trim|min_length[0]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'name',
|
||||
'label' => '套餐名称',
|
||||
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'field' => 'is_breed',
|
||||
'label' => '繁育套餐',
|
||||
'rules' => 'trim|min_length[1]|max_length[2]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'field' => 'species',
|
||||
'label' => '物种',
|
||||
'rules' => 'trim|required|min_length[1]|max_length[2]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'field' => 'package_up',
|
||||
'label' => '升级目标',
|
||||
'rules' => 'trim|min_length[1]|max_length[2]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'field' => 'description',
|
||||
'label' => '描述',
|
||||
'rules' => 'trim|min_length[0]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'price',
|
||||
'label' => '价格',
|
||||
'rules' => 'trim|min_length[0]|max_length[20]'
|
||||
)
|
||||
);
|
||||
//涉及字段序列化的特殊操作
|
||||
$data = $this->json_validation($config);
|
||||
//处理content字段
|
||||
if(!is_array($data['content'])){
|
||||
$this->error('套餐内容需要传入数组');
|
||||
}
|
||||
if(!empty($data['content']))foreach ($data['content'] as $item) {
|
||||
if(empty($item['name'])){
|
||||
$this->error('套餐选项名称不能为空');
|
||||
}
|
||||
if(empty($item['disease_id'])){
|
||||
$this->error('套餐疾病选项不能为空');
|
||||
}
|
||||
}
|
||||
$data['content'] = json_encode($data['content']);
|
||||
$data['structure'] = implode(',',$data['structure']);
|
||||
$data['structure_hide'] = implode(',',$data['structure_hide']);
|
||||
$data['cert'] = implode(',',$data['cert']);
|
||||
$data['disease'] = implode(',',$data['disease']);
|
||||
$fields = array_column($config,'field');
|
||||
$fields[] = 'content';
|
||||
$fields[] = 'structure';
|
||||
$fields[] = 'structure_hide';
|
||||
$fields[] = 'cert';
|
||||
$fields[] = 'disease';
|
||||
foreach ($data as $key => $val) {
|
||||
if(!in_array($key,$fields)){
|
||||
unset($data[$key]);
|
||||
}
|
||||
}
|
||||
//print_r($data);die;
|
||||
if(empty($data['id'])){
|
||||
$ret = $this->{$this->base_model}->add($data);
|
||||
if($ret === -1){
|
||||
$this->error('名称不能与已有的重复');
|
||||
}
|
||||
}else{
|
||||
$this->{$this->base_model}->update($data, ['id'=>$data['id']]);
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 样品升级订单管理
|
||||
*/
|
||||
class Sample_upgrade_order extends AdminController
|
||||
{
|
||||
protected $base_model = 'sample_upgrade_order_model';
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 通用搜索控件,如用户等
|
||||
*/
|
||||
class Search extends AdminController
|
||||
{
|
||||
|
||||
function _get($model,$nama_field = 'name')
|
||||
{
|
||||
$this->load->model($model);
|
||||
$searchText = $this->input->get('name');
|
||||
$searchId = $this->input->get('id');
|
||||
$param = [];
|
||||
if(!empty($searchId)){
|
||||
$param['id'] = $searchId;
|
||||
}else{
|
||||
$param[$nama_field] = $searchText;
|
||||
}
|
||||
$page = 1;
|
||||
$limit = 100;
|
||||
$items = $this->$model->listing($param, ($page-1)*$limit,$limit,'base.id,base.'.$nama_field);
|
||||
$this->success($items);
|
||||
}
|
||||
|
||||
function user_get()
|
||||
{
|
||||
$this->_get('customer_model','nickname');
|
||||
}
|
||||
|
||||
function package_get()
|
||||
{
|
||||
$this->_get('package_model');
|
||||
}
|
||||
|
||||
function disease_get()
|
||||
{
|
||||
$this->_get('disease_model');
|
||||
}
|
||||
|
||||
function series_number_get()
|
||||
{
|
||||
$this->_get('series_number_model','device_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 序列号
|
||||
*/
|
||||
|
||||
class Series_number extends AdminController
|
||||
{
|
||||
protected $base_model = 'series_number_model';
|
||||
|
||||
function list_get()
|
||||
{
|
||||
$items = parent::_list_get(true);
|
||||
$this->load->model('package_model');
|
||||
$package = $this->package_model->get(false,'id,name',true);
|
||||
$package_map = [
|
||||
'0'=>'未绑定套餐'
|
||||
];
|
||||
foreach ($package as $item) {
|
||||
$package_map[$item['id']] = $item['name'];
|
||||
}
|
||||
foreach ($items['items'] as &$item) {
|
||||
$item['status_desc'] = !empty($item['sample_id'])?'已激活':'未激活';
|
||||
$item['package_name'] = $package_map[$item['package_ori']];
|
||||
}
|
||||
//统计
|
||||
$items['stat'] = [
|
||||
'total'=>(int)$this->{$this->base_model}->total(),
|
||||
'used'=>(int)$this->{$this->base_model}->total(['s.id>0'],true),
|
||||
'unused'=>(int)$this->{$this->base_model}->total(['s.id is null'],true),
|
||||
];
|
||||
$this->success($items);
|
||||
}
|
||||
|
||||
//批量新建
|
||||
function batch_create_post()
|
||||
{
|
||||
$data = $this->json_input();
|
||||
if(empty($data['package_ori'])){
|
||||
$this->error('套餐不能为空');
|
||||
}
|
||||
$package_id = trim($data['package_ori']);
|
||||
$number = explode("\n",trim($data['device_id']));
|
||||
$devices = [];
|
||||
foreach ($number as $item) {
|
||||
$item = trim($item);
|
||||
if(empty($item)){
|
||||
continue;
|
||||
}
|
||||
$devices[] = [
|
||||
'device_id'=>$item,
|
||||
'package_ori'=>$package_id
|
||||
];
|
||||
}
|
||||
if(empty($devices)){
|
||||
$this->error('序列号为空');
|
||||
}
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'device_id',
|
||||
'label' => '序号',
|
||||
'rules' => 'trim|min_length[0]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'package_ori',
|
||||
'label' => '套餐名称',
|
||||
'rules' => 'trim|required|min_length[1]|max_length[11]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->_batch_create_post($config,$devices);
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 样品升级订单管理
|
||||
*/
|
||||
class Ship_order extends AdminController
|
||||
{
|
||||
protected $base_model = 'ship_order_model';
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
class Table extends RestController
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
// $this->load->model('Record_model');
|
||||
// $this->load->model('Dept_model', 'Dept');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function testapi()
|
||||
{
|
||||
echo "test api ok...";
|
||||
}
|
||||
|
||||
public function phpinfo()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
|
||||
$items = [
|
||||
["id" => 1,
|
||||
"title" => "www",
|
||||
"status" => "draft",
|
||||
"author" => "qiaokun",
|
||||
"display_time" => "",
|
||||
"pageviews" => 300
|
||||
],
|
||||
["id" => 3,
|
||||
"title" => "bbb",
|
||||
"status" => "bbbb",
|
||||
"author" => "乔锟",
|
||||
"display_time" => "",
|
||||
"pageviews" => 300
|
||||
],
|
||||
];
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
function goods_get()
|
||||
{
|
||||
|
||||
$items = array(
|
||||
array('id' => 1, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 2, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 3, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 4, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 5, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 6, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 7, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 8, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 9, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 10, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 11, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 31, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 13, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 24, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 35, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 19, 'title' => 'iphone 7 ', 'price' => 399, 'num' => 1),
|
||||
array('id' => 22, 'title' => 'hdcms 7 ', 'price' => 2000, 'num' => 2),
|
||||
array('id' => 33, 'title' => 'aaaas 7 ', 'price' => 2000, 'num' => 2),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"items" => $items
|
||||
]
|
||||
];
|
||||
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file welcome.php */
|
||||
/* Location: ./application/controllers/welcome.php */
|
||||
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
|
||||
class Uploadimg extends RestController
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
}
|
||||
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
}
|
||||
|
||||
public function upload_post()
|
||||
{
|
||||
$uploadDir = FCPATH . 'uploads/';
|
||||
$id = 'T' . $this->POST('identify');
|
||||
$php_path = dirname(__FILE__) . '/';//dirname($_SERVER['DOCUMENT_ROOT']); dirname(__FILE__)
|
||||
// $php_url = "";//dirname($_SERVER['HTTP_HOST']) . '/';//PHP_SELF
|
||||
$php_url = $_SERVER['HTTP_HOST'] . '/'; //PHP_SELF
|
||||
|
||||
$save_path = $uploadDir;
|
||||
//文件保存目录URL
|
||||
$save_url = $php_url . 'uploads/';
|
||||
// nginx服务器端修改绝对路径
|
||||
//$save_url = "http://172.30.3.11/static/home/kindeditor/attached/";
|
||||
|
||||
// var_dump($save_path);
|
||||
// var_dump($save_url);
|
||||
// string(46) "D:\Q\code\vue\CodeIgniter-3.1.10\uploads\imgs\"
|
||||
// string(28) "www.cirest.com:8889/uploads/"
|
||||
|
||||
|
||||
//定义允许上传的文件扩展名
|
||||
$ext_arr = array(
|
||||
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
|
||||
'flash' => array('swf', 'flv'),
|
||||
'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
|
||||
'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'),
|
||||
);
|
||||
//最大文件大小 10M 默认是1M
|
||||
$max_size = 10000000;
|
||||
|
||||
$save_path = realpath($save_path) . '/';
|
||||
$save_path = str_replace('\\', '/', $save_path);
|
||||
|
||||
//PHP上传失败
|
||||
if (!empty($_FILES['file']['error'])) {
|
||||
switch ($_FILES['file']['error']) {
|
||||
case '1':
|
||||
$error = '超过php.ini允许的大小。';
|
||||
break;
|
||||
case '2':
|
||||
$error = '超过表单允许的大小。';
|
||||
break;
|
||||
case '3':
|
||||
$error = '图片只有部分被上传。';
|
||||
break;
|
||||
case '4':
|
||||
$error = '请选择图片。';
|
||||
break;
|
||||
case '6':
|
||||
$error = '找不到临时目录。';
|
||||
break;
|
||||
case '7':
|
||||
$error = '写文件到硬盘出错。';
|
||||
break;
|
||||
case '8':
|
||||
$error = 'File upload stopped by extension。';
|
||||
break;
|
||||
case '999':
|
||||
default:
|
||||
$error = '未知错误。';
|
||||
}
|
||||
$this->alert($error);
|
||||
}
|
||||
|
||||
//有上传文件时
|
||||
if (empty($_FILES) === false) {
|
||||
//原文件名
|
||||
$file_name = $_FILES['file']['name'];
|
||||
//服务器上临时文件名
|
||||
$tmp_name = $_FILES['file']['tmp_name'];
|
||||
//文件大小
|
||||
$file_size = $_FILES['file']['size'];
|
||||
//检查文件名
|
||||
if (!$file_name) {
|
||||
$this->alert("请选择文件。");
|
||||
}
|
||||
//检查目录
|
||||
if (@is_dir($save_path) === false) {
|
||||
$this->alert("上传目录不存在。");
|
||||
}
|
||||
//检查目录写权限
|
||||
if (@is_writable($save_path) === false) {
|
||||
$this->alert("上传目录没有写权限。");
|
||||
}
|
||||
//检查是否已上传
|
||||
if (@is_uploaded_file($tmp_name) === false) {
|
||||
$this->alert("上传失败。");
|
||||
}
|
||||
//检查文件大小
|
||||
if ($file_size > $max_size) {
|
||||
$this->alert("上传文件大小超过限制(<10M)。");
|
||||
}
|
||||
//检查目录名
|
||||
$dir_name = empty($_GET['dir']) ? 'image' : trim($_GET['dir']);
|
||||
if (empty($ext_arr[$dir_name])) {
|
||||
$this->alert("目录名不正确。");
|
||||
}
|
||||
//获得文件扩展名
|
||||
$temp_arr = explode(".", $file_name);
|
||||
$file_ext = array_pop($temp_arr);
|
||||
$file_ext = trim($file_ext);
|
||||
$file_ext = strtolower($file_ext);
|
||||
|
||||
//检查扩展名
|
||||
if (!in_array($file_ext, $ext_arr[$dir_name])) {
|
||||
$this->alert("上传文件扩展名是不允许的扩展名。\n只允许" . implode(",", $ext_arr[$dir_name]) . "格式。");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 以 T+身份证号作为临时目录 , 以身份证作为正式目录
|
||||
*/
|
||||
$identify = empty($id) ? '' : trim($id);
|
||||
|
||||
if ($identify == '') {
|
||||
echo "Invalid session identify.";
|
||||
exit;
|
||||
}
|
||||
//创建文件夹
|
||||
if ($dir_name !== '') {
|
||||
$save_path .= $dir_name . "/" . $identify . "/";
|
||||
$save_url .= $dir_name . "/" . $identify . "/";
|
||||
if (!file_exists($save_path)) {
|
||||
mkdir($save_path, 0777, true); // true 允许创建多级目录
|
||||
}
|
||||
}
|
||||
$ymd = date("Ym");
|
||||
$save_path .= $ymd . "/";
|
||||
$save_url .= $ymd . "/";
|
||||
if (!file_exists($save_path)) {
|
||||
mkdir($save_path);
|
||||
}
|
||||
//新文件名
|
||||
$new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
|
||||
//移动文件
|
||||
$file_path = $save_path . $new_file_name;
|
||||
if (move_uploaded_file($tmp_name, $file_path) === false) {
|
||||
$this->alert("上传文件失败。");
|
||||
}
|
||||
@chmod($file_path, 0644);
|
||||
$file_url = $save_url . $new_file_name;
|
||||
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
// Insert file information in the database
|
||||
// $insert = $db->query("INSERT INTO files (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
|
||||
$link = "http://" . $file_url;
|
||||
// http://www.cirest.com:8889/uploads/image/T410000000000000000/201902/20190228071354_96833.png
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"error" => 0,
|
||||
"message" => "上传成功",
|
||||
"link" => $link,
|
||||
"filepath" => preg_replace('/^http.*uploads/', '/uploads', $link)
|
||||
];
|
||||
|
||||
echo json_encode($message);
|
||||
// $this->response($message, RestController::HTTP_OK);
|
||||
// alert里面使用时 exit() 产生的是空,或字符串,使用原生的json_encode返回统一的字符串,在客户端在统一处理成对象
|
||||
}
|
||||
}
|
||||
|
||||
public function delimg_post()
|
||||
{
|
||||
$php_path = dirname(__FILE__) . '/';//dirname($_SERVER['DOCUMENT_ROOT']); dirname(__FILE__)
|
||||
|
||||
//文件保存目录路径
|
||||
$save_path = $php_path . '../../../../';
|
||||
|
||||
$save_path = realpath($save_path) . '/';
|
||||
$save_path = str_replace('\\', '/', $save_path);
|
||||
// var_dump($save_path);
|
||||
// "D:/Q/code/vue/CodeIgniter-3.1.10/"
|
||||
|
||||
$DelFileName = $this->POST('filename');
|
||||
$DelFileType = $this->POST('isdir');
|
||||
|
||||
$FilePath = $save_path . $DelFileName;
|
||||
|
||||
// var_dump($FilePath);return;
|
||||
|
||||
if ($DelFileType == 'F') {
|
||||
if (!is_file($FilePath)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => "文件不存在 - " . $DelFileName,
|
||||
"message" => "文件不存在 - " . $DelFileName
|
||||
];
|
||||
|
||||
echo json_encode($message);
|
||||
|
||||
} else {
|
||||
|
||||
if (!unlink($FilePath)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => "Error deleting " . $FilePath,
|
||||
"message" => "Error deleting " . $FilePath
|
||||
];
|
||||
echo json_encode($message);
|
||||
|
||||
} else {
|
||||
// 必须返回code 由于前端vue封装的 request 请求,返回数据对code进行判断
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => '服务器删除成功!',
|
||||
"message" => '服务器删除成功!'
|
||||
];
|
||||
echo json_encode($message);
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($DelFileType == 'D') {
|
||||
if (!@rmdir($FilePath)) {
|
||||
echo "文件夹 " . $FilePath . " 不为空,不能删除!";
|
||||
} else {
|
||||
echo "succeed";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function alert($msg)
|
||||
{
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"error" => 1,
|
||||
"message" => $msg
|
||||
];
|
||||
echo json_encode($message);
|
||||
exit();
|
||||
// var_dump($message);
|
||||
// $this->response($message, RestController::HTTP_OK);
|
||||
// die();
|
||||
}
|
||||
|
||||
|
||||
public function onsubmit_post()
|
||||
{
|
||||
$identify = $this->POST('identify');
|
||||
$phone = $this->POST('phone');
|
||||
$idinfo = $this->POST('idinfo');
|
||||
$bankinfo = $this->POST('bankinfo');
|
||||
// $data = [
|
||||
// 'identify' => $identify,
|
||||
// 'phone' => $phone,
|
||||
// 'idinfo' => $idinfo,
|
||||
// 'check' => '待审核'
|
||||
// ];
|
||||
|
||||
// 写入数据库表 身份证号,手机号,证件照,文件路径等
|
||||
$where = [
|
||||
'identify' => $identify,
|
||||
'phone' => $phone,
|
||||
];
|
||||
|
||||
$data = [
|
||||
'idinfo' => $idinfo,
|
||||
'bankinfo' => $bankinfo,
|
||||
'check' => '待审核'
|
||||
];
|
||||
|
||||
$result = $this->Base_model->_update_key('upload_tbl', $data, $where);
|
||||
|
||||
if ($result) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"message" => '写入数据库表成功,请请待审核通知!',
|
||||
"data" => array_merge($where, $data)
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"message" => '写入数据库表失败!',
|
||||
"data" => array_merge($where, $data)
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
// Chevereto 图床免费版本地址:https://github.com/Chevereto/Chevereto-Free
|
||||
// https://chevereto.com/docs/api-v1
|
||||
// 上传图片测试
|
||||
public function chevereto_post()
|
||||
{
|
||||
// 1. 上传本地文件时应使用 $fields post base64_encode方法
|
||||
// Always use POST when uploading local files. Url encoding may alter the base64 source
|
||||
// due to encoded characters or just by URL request length limit due to GET request.
|
||||
// base64编码 会导致过长 url request
|
||||
// var_dump($_FILES); 参考 uploadimg 可以做一些前置校验处理 // 前置判断 if (empty($_FILES) === false)
|
||||
$key = '5486424e4dfb6b87453dd4bb25c0dcb0';
|
||||
$url = 'http://172.17.1.110/chevereto/api/1/upload';
|
||||
|
||||
// What do we send to chevereto api?
|
||||
$fields = array(
|
||||
'key' => urlencode($key),
|
||||
// The image encoded in base64
|
||||
'source' => base64_encode(file_get_contents($_FILES["file"]['tmp_name'])),
|
||||
// format: txt / json txt 只返回图片地址或错误信息 eg.Duplicated upload 较为简洁
|
||||
'format' => urlencode('json')
|
||||
);
|
||||
|
||||
//open connection
|
||||
$ch = curl_init();
|
||||
|
||||
//set the url, number of POST vars, POST data
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, sizeof($fields));
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));
|
||||
|
||||
//execute post
|
||||
$result = curl_exec($ch);
|
||||
//释放curl句柄
|
||||
curl_close($ch);
|
||||
echo $result;
|
||||
//close connection
|
||||
|
||||
// 2. 上传远程图片地址可使用 _get source=urlencode{source} 方法即可
|
||||
|
||||
// $key = '6a55c7f9fa13813c2da613dc7b5b920b';
|
||||
// // 设定远程图片地址
|
||||
// $source = 'https://img3.doubanio.com/view/group_topic/large/public/p67032015.jpg';
|
||||
// // format: txt / json txt 只返回图片地址或错误信息 eg.Duplicated upload 较为简洁
|
||||
// $url = 'http://172.17.1.110:8888/api/1/upload/?key={key}&source={source}&format=txt';
|
||||
// $url = str_replace(array('{key}','{source}'),array($key,urlencode($source)),$url);
|
||||
//
|
||||
// //初始化
|
||||
// $ch = curl_init();
|
||||
// //设置选项,包括URL
|
||||
// curl_setopt($ch, CURLOPT_URL, $url);
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
// //执行并获取HTML文档内容
|
||||
// $output = curl_exec($ch);
|
||||
// //释放curl句柄
|
||||
// curl_close($ch);
|
||||
// echo $output;
|
||||
|
||||
|
||||
// 失败
|
||||
// {
|
||||
// "status_txt": "Bad Request",
|
||||
// "error": {
|
||||
// "context": "Exception",
|
||||
// "code": 102,
|
||||
// "message": "Duplicated upload"
|
||||
// },
|
||||
// "status_code": 400
|
||||
// }
|
||||
// 成功
|
||||
// {
|
||||
// "status_txt": "OK",
|
||||
// "image": {
|
||||
// "image": {
|
||||
// "size": "89163",
|
||||
// "url": "http://172.17.1.110:8888/images/2019/07/09/p67032015.jpg",
|
||||
// "extension": "jpg",
|
||||
// "mime": "image/jpeg",
|
||||
// "name": "p67032015",
|
||||
// "filename": "p67032015.jpg"
|
||||
// },
|
||||
// },
|
||||
// "success": {
|
||||
// "code": 200,
|
||||
// "message": "image uploaded"
|
||||
// },
|
||||
// "status_code": 200
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
class User extends AdminController
|
||||
{
|
||||
protected $base_model = 'customer_model';
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 样品
|
||||
*/
|
||||
class Variety extends AdminController
|
||||
{
|
||||
protected $base_model = 'variety_model';
|
||||
|
||||
protected function _validate_rule(){
|
||||
return array(
|
||||
array(
|
||||
'field' => 'id',
|
||||
'label' => '序号',
|
||||
'rules' => 'trim|min_length[0]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'name',
|
||||
'label' => '名称',
|
||||
'rules' => 'trim|min_length[0]|max_length[100]'
|
||||
),
|
||||
array(
|
||||
'field' => 'origin',
|
||||
'label' => '历史起源',
|
||||
'rules' => 'trim|min_length[0]|max_length[100]'
|
||||
),
|
||||
array(
|
||||
'field' => 'migration',
|
||||
'label' => '迁徙发展',
|
||||
'rules' => 'trim|min_length[0]|max_length[100]'
|
||||
),
|
||||
array(
|
||||
'field' => 'characteristic',
|
||||
'label' => '品种特点',
|
||||
'rules' => 'trim|min_length[0]|max_length[2000]'
|
||||
),
|
||||
array(
|
||||
'field' => 'fun_story',
|
||||
'label' => '趣事',
|
||||
'rules' => 'trim|min_length[0]|max_length[2000]'
|
||||
),
|
||||
array(
|
||||
'field' => 'gene_disease',
|
||||
'label' => '常见遗传病',
|
||||
'rules' => 'trim|min_length[0]|max_length[2000]'
|
||||
),
|
||||
array(
|
||||
'field' => 'species',
|
||||
'label' => '物种',
|
||||
'rules' => 'trim|integer|min_length[0]|max_length[2]'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function _import_field_map(){
|
||||
return [
|
||||
'名称'=>'name',
|
||||
'历史起源'=>'origin',
|
||||
'迁徙发展'=>'migration',
|
||||
'犬种特点'=>'characteristic',
|
||||
'品种特点'=>'characteristic',
|
||||
'趣事'=>'fun_story',
|
||||
'常见遗传病'=>'gene_disease',
|
||||
'species'=>'species',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
class Dept extends RestController
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
$this->load->model('Dept_model');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
// 增
|
||||
function add_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);
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
|
||||
// var_dump($parms);return;
|
||||
if ($this->Base_model->_key_exists('sys_dept', ['name' => $parms['name']])) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 机构名称重复'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$dept_id = $this->Base_model->_insert_key('sys_dept', $parms);
|
||||
if (!$dept_id) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 机构新增失败'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 超级管理员用户的超级管理员角色自动归属该机构
|
||||
$user_role_id = $this->Base_model->_insert_key('sys_user_role', ["user_id" => 1, "role_id" => 1, "dept_id" => $dept_id]);
|
||||
if (!$user_role_id) {
|
||||
var_dump($this->uri->uri_string . ' 超级管理员用户的超级管理员角色自动归属该机构, 失败...');
|
||||
var_dump(["user_id" => 1, "role_id" => 1, "dept_id" => $dept_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 机构新增成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 改
|
||||
function edit_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);
|
||||
}
|
||||
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
$id = $parms['id'];
|
||||
unset($parms['id']); // 剃除索引id
|
||||
unset($parms['children']); // 剃除传递上来的子节点信息
|
||||
|
||||
if ($id == $parms['pid']) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 上级机构不能为自己'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$where = ["id" => $id];
|
||||
|
||||
if (!$this->Base_model->_update_key('sys_dept', $parms, $where)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 机构更新错误'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 机构更新成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删
|
||||
function del_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);
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 含有子节点不允许删除
|
||||
$hasChild = $this->Dept_model->hasChildDept($parms['id']);
|
||||
if ($hasChild) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 存在子节点不能删除'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 先删除外键关联表
|
||||
if (!$this->Base_model->_delete_key('sys_user_role', ['dept_id' => $parms['id']])) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '删除关联表失败 ' . json_encode($parms)
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删除基础表 sys_dept
|
||||
if (!$this->Base_model->_delete_key('sys_dept', ['id' => $parms['id']])) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 机构删除失败'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 机构删除成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 查
|
||||
function view_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);
|
||||
}
|
||||
|
||||
$DeptArr = $this->Dept_model->getDeptList();
|
||||
$DeptTree = $this->permission->genDeptTree($DeptArr, 'id', 'pid', 0);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $DeptTree,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
class Menu extends RestController
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index_get()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function insertx_post()
|
||||
{
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
var_dump($parms);
|
||||
$result = $this->Base_model->_insert_key('sys_role_perm', $parms);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
public function gettest_post()
|
||||
{
|
||||
$result = $this->Base_model->_get_key('sys_perm', 'perm_type,r_id rid', 'perm_type="role" and r_id=1');
|
||||
var_dump($result);
|
||||
var_dump($result[0]['perm_type']);
|
||||
var_dump($this->uri->uri_string);
|
||||
var_dump($this->uri);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
|
||||
// $message = [
|
||||
// "code" => 20000,
|
||||
// "data" => [
|
||||
// "__FUNCTION__" => __FUNCTION__,
|
||||
// "__CLASS__" => __CLASS__,
|
||||
// "uri" => $this->uri
|
||||
// ],
|
||||
//
|
||||
// ];
|
||||
// "data": {
|
||||
// "__FUNCTION__": "router_get",
|
||||
// "__CLASS__": "User",
|
||||
// "uri": {
|
||||
// "keyval": [],
|
||||
// "uri_string": "api/v2/user/router",
|
||||
// "segments": {
|
||||
// "1": "api",
|
||||
// "2": "v2",
|
||||
// "3": "user",
|
||||
// "4": "router"
|
||||
// },
|
||||
}
|
||||
|
||||
public function phpinfo_get()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb_get()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
// 增
|
||||
function add_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);
|
||||
}
|
||||
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms);
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 菜单类型为目录
|
||||
if (!$parms['type']) {
|
||||
$parms['component'] = 'Layout';
|
||||
}
|
||||
|
||||
$menu_id = $this->Base_model->_insert_key('sys_menu', $parms);
|
||||
if (!$menu_id) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 菜单添加失败'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 生成该菜单对应的权限: sys_perm, 权限类型为: menu, 生成唯一的 perm_id
|
||||
$perm_id = $this->Base_model->_insert_key('sys_perm', ['perm_type' => 'menu', "r_id" => $menu_id]);
|
||||
if (!$perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 生成该菜单对应的权限: sys_perm, 失败...');
|
||||
var_dump(['perm_type' => 'menu', "r_id" => $menu_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 超级管理员角色自动拥有该权限 perm_id
|
||||
$role_perm_id = $this->Base_model->_insert_key('sys_role_perm', ["role_id" => 1, "perm_id" => $perm_id]);
|
||||
if (!$role_perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 超级管理员角色自动拥有该权限 perm_id, 失败...');
|
||||
var_dump(["role_id" => 1, "perm_id" => $perm_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['title'] . ' - 菜单添加成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 改
|
||||
function edit_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);
|
||||
}
|
||||
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
if ($parms['id'] == $parms['pid']) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '父节点不能是自己'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
// 菜单类型为目录
|
||||
if ($parms['type'] == 0) {
|
||||
$parms['component'] = 'Layout';
|
||||
}
|
||||
// 菜单类型为功能按钮时
|
||||
if ($parms['type'] == 2) {
|
||||
$parms['component'] = '';
|
||||
$parms['icon'] = '';
|
||||
}
|
||||
|
||||
$id = $parms['id'];
|
||||
unset($parms['id']); // 择出索引id
|
||||
$where = ["id" => $id];
|
||||
|
||||
if (!$this->Base_model->_update_key('sys_menu', $parms, $where)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 菜单更新错误'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['title'] . ' - 菜单更新成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删
|
||||
function del_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);
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 存在子节点 不能删除返回
|
||||
$hasChild = $this->Base_model->hasChildMenu($parms['id']);
|
||||
if ($hasChild) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 存在子节点不能删除'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删除外键关联表 sys_role_perm , sys_perm, sys_menu
|
||||
// 1. 根据sys_menu id及'menu' 查找 perm_id
|
||||
// 2. 删除sys_role_perm 中perm_id记录
|
||||
// 3. 删除sys_perm中 perm_type='menu' and r_id = menu_id 记录,即第1步中获取的 perm_id, 一一对应
|
||||
// 4. 删除sys_menu 中 id = menu_id 的记录
|
||||
$where = 'perm_type="menu" and r_id=' . $parms['id'];
|
||||
$arr = $this->Base_model->_get_key('sys_perm', '*', $where);
|
||||
if (empty($arr)) {
|
||||
var_dump($this->uri->uri_string . ' 未查找到 sys_perm 表中记录');
|
||||
var_dump($where);
|
||||
return;
|
||||
}
|
||||
|
||||
$perm_id = $arr[0]['id']; // 正常只有一条记录
|
||||
$this->Base_model->_delete_key('sys_role_perm', ['perm_id' => $perm_id]);
|
||||
$this->Base_model->_delete_key('sys_perm', ['id' => $perm_id]);
|
||||
|
||||
// 删除基础表 sys_menu
|
||||
if (!$this->Base_model->_delete_key('sys_menu', $parms)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['title'] . ' - 菜单删除错误'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['title'] . ' - 菜单删除成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 查
|
||||
function view_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);
|
||||
}
|
||||
|
||||
$MenuTreeArr = $this->permission->getPermission($Token, 'menu', true);
|
||||
$MenuTree = $this->permission->genVueMenuTree($MenuTreeArr, 'id', 'pid', 0);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTree,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 根据token拉取 treeselect 下拉选项菜单
|
||||
function treeoptions_get()
|
||||
{
|
||||
// 此 uri 可不做权限/token过期验证,则在菜单里,可以不加入此项路由path /sys/menu/treeoptions。
|
||||
//
|
||||
// $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);
|
||||
// return;
|
||||
// }
|
||||
|
||||
$Token = $this->input->get_request_header('X-Token', TRUE);
|
||||
|
||||
$MenuTreeArr = $this->permission->getPermission($Token, 'menu', false);
|
||||
array_unshift($MenuTreeArr, ['id' => 0, 'pid' => -1, 'title' => '顶级菜单']);
|
||||
$MenuTree = $this->permission->genVueMenuTree($MenuTreeArr, 'id', 'pid', -1);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTree,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
// $result = $this->some_model();
|
||||
$result['success'] = TRUE;
|
||||
|
||||
if ($result['success']) {
|
||||
$List = array(
|
||||
array('order_no' => '201805138451313131', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '300000000000000000', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
array('order_no' => '444444444444444444', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '888888888888888888', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"total" => count($List),
|
||||
"items" => $List
|
||||
]
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 50008,
|
||||
"message" => 'Login failed, unable to get user details.'
|
||||
];
|
||||
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,455 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
class Role extends RestController
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Base_model');
|
||||
$this->load->model('Role_model');
|
||||
// $this->config->load('config', true);
|
||||
}
|
||||
|
||||
public function index_get()
|
||||
{
|
||||
$this->load->view('login_view');
|
||||
}
|
||||
|
||||
public function insertx_post()
|
||||
{
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
var_dump($parms);
|
||||
$result = $this->Base_model->_insert_key('sys_role_perm', $parms);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
public function gettest_post()
|
||||
{
|
||||
$result = $this->Base_model->_get_key('sys_perm', 'perm_type,r_id rid', 'perm_type="role" and r_id=1');
|
||||
var_dump($result);
|
||||
var_dump($result[0]['perm_type']);
|
||||
var_dump($this->uri->uri_string);
|
||||
var_dump($this->uri);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testapi_get()
|
||||
{
|
||||
echo "test api ok...";
|
||||
|
||||
echo APPPATH . "\n";
|
||||
echo SELF . "\n";
|
||||
echo BASEPATH . "\n";
|
||||
echo FCPATH . "\n";
|
||||
echo SYSDIR . "\n";
|
||||
var_dump($this->config->item('rest_language'));
|
||||
var_dump($this->config->item('language'));
|
||||
|
||||
var_dump($this->config);
|
||||
|
||||
// $message = [
|
||||
// "code" => 20000,
|
||||
// "data" => [
|
||||
// "__FUNCTION__" => __FUNCTION__,
|
||||
// "__CLASS__" => __CLASS__,
|
||||
// "uri" => $this->uri
|
||||
// ],
|
||||
//
|
||||
// ];
|
||||
// "data": {
|
||||
// "__FUNCTION__": "router_get",
|
||||
// "__CLASS__": "User",
|
||||
// "uri": {
|
||||
// "keyval": [],
|
||||
// "uri_string": "api/v2/user/router",
|
||||
// "segments": {
|
||||
// "1": "api",
|
||||
// "2": "v2",
|
||||
// "3": "user",
|
||||
// "4": "router"
|
||||
// },
|
||||
}
|
||||
|
||||
public function phpinfo_get()
|
||||
{
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testdb_get()
|
||||
{
|
||||
$this->load->database();
|
||||
$query = $this->db->query("show tables");
|
||||
var_dump($query);
|
||||
var_dump($query->result());
|
||||
var_dump($query->row_array());
|
||||
// 有结果表明数据库连接正常 reslut() 与 row_array 结果有时不太一样
|
||||
// 一般加载到时model里面使用。
|
||||
}
|
||||
|
||||
// 增
|
||||
function add_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);
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
|
||||
if ($this->Base_model->_key_exists('sys_role', ['name' => $parms['name']])) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色名重复'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 加入新增时间
|
||||
$parms['create_time'] = time();
|
||||
|
||||
$role_id = $this->Base_model->_insert_key('sys_role', $parms);
|
||||
if (!$role_id) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色新增失败'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 生成该角色对应的权限: sys_perm, 权限类型为: role, 生成唯一的 perm_id
|
||||
$perm_id = $this->Base_model->_insert_key('sys_perm', ['perm_type' => 'role', "r_id" => $role_id]);
|
||||
if (!$perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 生成该角色对应的权限: sys_perm, 失败...');
|
||||
var_dump(['perm_type' => 'role', "r_id" => $role_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
// 超级管理员角色自动拥有该权限 perm_id
|
||||
$role_perm_id = $this->Base_model->_insert_key('sys_role_perm', ["role_id" => 1, "perm_id" => $perm_id]);
|
||||
if (!$role_perm_id) {
|
||||
var_dump($this->uri->uri_string . ' 超级管理员角色自动拥有该权限 perm_id, 失败...');
|
||||
var_dump(["role_id" => 1, "perm_id" => $perm_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 角色新增成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 改
|
||||
function edit_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);
|
||||
}
|
||||
|
||||
// $id = $this->post('id'); // POST param
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 超级管理员角色不允许修改
|
||||
if ($parms['id'] == 1) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色不允许修改'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$id = $parms['id'];
|
||||
unset($parms['id']); // 剃除索引id
|
||||
|
||||
// 加入更新时间
|
||||
$parms['update_time'] = time();
|
||||
$where = ["id" => $id];
|
||||
|
||||
if (!$this->Base_model->_update_key('sys_role', $parms, $where)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色更新错误'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 角色更新成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删
|
||||
function del_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);
|
||||
}
|
||||
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['path']);
|
||||
|
||||
// 参数检验/数据预处理
|
||||
// 超级管理员角色不允许删除
|
||||
if ($parms['id'] == 1) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色不允许删除'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 删除外键关联表 sys_role_perm , sys_perm, sys_role, sys_user_role
|
||||
// 1. 根据sys_role id及'role' 查找 perm_id
|
||||
// 2. 删除sys_role_perm 中perm_id记录
|
||||
// 3. 删除sys_perm中 perm_type='role' and r_id = role_id 记录,即第1步中获取的 perm_id, 一一对应
|
||||
// 4. 删除sys_user_role role_id 记录
|
||||
// 5. 删除sys_role 中 id = role_id 的记录
|
||||
$where = 'perm_type="role" and r_id=' . $parms['id'];
|
||||
$arr = $this->Base_model->_get_key('sys_perm', '*', $where);
|
||||
if (empty($arr)) {
|
||||
var_dump($this->uri->uri_string . ' 未查找到 sys_perm 表中记录');
|
||||
var_dump($where);
|
||||
return;
|
||||
}
|
||||
|
||||
$perm_id = $arr[0]['id']; // 正常只有一条记录
|
||||
$this->Base_model->_delete_key('sys_role_perm', ['perm_id' => $perm_id]); // 必须删除权限id 因为超级管理员角色自动拥有该权限否则会造成删除关联错误
|
||||
$this->Base_model->_delete_key('sys_role_perm', ['role_id' => $parms['id']]); // 再删除该角色对应的权限id(原有的菜单)
|
||||
$this->Base_model->_delete_key('sys_perm', ['id' => $perm_id]);
|
||||
|
||||
$this->Base_model->_delete_key('sys_user_role', ['role_id' => $parms['id']]);
|
||||
// 删除基础表 sys_role
|
||||
if (!$this->Base_model->_delete_key('sys_role', $parms)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => $parms['name'] . ' - 角色删除错误'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"message" => $parms['name'] . ' - 角色删除成功'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 查
|
||||
function view_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);
|
||||
}
|
||||
|
||||
$RoleArr = $this->Role_model->getRoleList();
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $RoleArr,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取所有菜单 不需权限验证
|
||||
function allmenus_get()
|
||||
{
|
||||
$MenuTreeArr = $this->Role_model->getAllMenus();
|
||||
if (empty($MenuTreeArr)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTreeArr,
|
||||
"message" => "数据库表中没有菜单"
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$MenuTree = $this->permission->genVueMenuTree($MenuTreeArr, 'id', 'pid', 0);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTree,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取所有角色带perm_id 不需权限验证
|
||||
function allroles_get()
|
||||
{
|
||||
$AllRolesArr = $this->Role_model->getAllRoles();
|
||||
if (empty($AllRolesArr)) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $AllRolesArr,
|
||||
"message" => "数据库表中没有角色"
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $AllRolesArr,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取角色拥有的菜单权限 不需权限验证
|
||||
function rolemenu_post()
|
||||
{
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
$RoleId = $parms['roleId'];
|
||||
|
||||
$MenuTreeArr = $this->Role_model->getRoleMenu($RoleId);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $MenuTreeArr,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 获取角色拥有的角色权限 不需权限验证
|
||||
function rolerole_post()
|
||||
{
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
$RoleId = $parms['roleId'];
|
||||
|
||||
$RoleRoleArr = $this->Role_model->getRoleRole($RoleId);
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => $RoleRoleArr,
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
// 保存角色对应权限
|
||||
function saveroleperm_post()
|
||||
{
|
||||
$parms = $this->post(); // 获取表单参数,类型为数组
|
||||
// var_dump($parms['roleId']);
|
||||
// var_dump($parms['rolePerms']);
|
||||
// 参数检验/数据预处理
|
||||
// 超级管理员角色不允许删除
|
||||
if ($parms['roleId'] == 1) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '超级管理员角色拥有所有权限,不允许修改!'
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$RolePermArr = $this->Role_model->getRolePerm($parms['roleId']);
|
||||
|
||||
$AddArr = $this->permission->array_diff_assoc2($parms['rolePerms'], $RolePermArr);
|
||||
// var_dump('------------只存在于前台传参 做添加操作-------------');
|
||||
// var_dump($AddArr);
|
||||
$failed = false;
|
||||
$failedArr = [];
|
||||
foreach ($AddArr as $k => $v) {
|
||||
$ret = $this->Base_model->_insert_key('sys_role_perm', $v);
|
||||
if (!$ret) {
|
||||
$failed = true;
|
||||
array_push($failedArr, $v);
|
||||
}
|
||||
}
|
||||
if ($failed) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '授权失败 ' . json_encode($failedArr)
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$DelArr = $this->permission->array_diff_assoc2($RolePermArr, $parms['rolePerms']);
|
||||
// var_dump('------------只存在于后台数据库 删除操作-------------');
|
||||
// var_dump($DelArr);
|
||||
$failed = false;
|
||||
$failedArr = [];
|
||||
foreach ($DelArr as $k => $v) {
|
||||
$ret = $this->Base_model->_delete_key('sys_role_perm', $v);
|
||||
if (!$ret) {
|
||||
$failed = true;
|
||||
array_push($failedArr, $v);
|
||||
}
|
||||
}
|
||||
if ($failed) {
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'error',
|
||||
"message" => '授权失败 ' . json_encode($failedArr)
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"type" => 'success',
|
||||
"data" => $parms,
|
||||
"message" => '授权操作成功',
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
|
||||
function list_get()
|
||||
{
|
||||
// $result = $this->some_model();
|
||||
$result['success'] = TRUE;
|
||||
|
||||
if ($result['success']) {
|
||||
$List = array(
|
||||
array('order_no' => '201805138451313131', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '300000000000000000', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
array('order_no' => '444444444444444444', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'success'),
|
||||
array('order_no' => '888888888888888888', 'timestamp' => 'iphone 7 ', 'username' => 'iphone 7 ', 'price' => 399, 'status' => 'pending'),
|
||||
);
|
||||
|
||||
$message = [
|
||||
"code" => 20000,
|
||||
"data" => [
|
||||
"total" => count($List),
|
||||
"items" => $List
|
||||
]
|
||||
];
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
} else {
|
||||
$message = [
|
||||
"code" => 50008,
|
||||
"message" => 'Login failed, unable to get user details.'
|
||||
];
|
||||
|
||||
$this->response($message, RestController::HTTP_OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
class Widgets extends RestController
|
||||
{
|
||||
|
||||
function index_get($id = '')
|
||||
{
|
||||
// Example data for testing.
|
||||
$widgets = array(
|
||||
1 => array('id' => 1, 'name' => 'sprocket'),
|
||||
2 => array('id' => 2, 'name' => 'gear')
|
||||
);
|
||||
|
||||
// get参数为空
|
||||
if (!$id) {
|
||||
$id = $this->get('id');
|
||||
var_dump($id);
|
||||
}
|
||||
if (!$id) {
|
||||
//$widgets = $this->widgets_model->getWidgets();
|
||||
if ($widgets)
|
||||
$this->response($widgets, 200); // 200 being the HTTP response code
|
||||
else
|
||||
$this->response(array('error' => 'Couldn\'t find any widgets!'), 404);
|
||||
}
|
||||
|
||||
// get参数不为空
|
||||
//$widget = $this->widgets_model->getWidget($id);
|
||||
$widget = @$widgets[$id]; // test code
|
||||
|
||||
if ($widget)
|
||||
$this->response($widget, 200); // 200 being the HTTP response code
|
||||
else
|
||||
$this->response(array('error' => 'Widget could not be found'), 404);
|
||||
}
|
||||
|
||||
function index_post()
|
||||
{
|
||||
$data = $this->_post_args;
|
||||
echo json_encode($data);
|
||||
try {
|
||||
//$id = $this->widgets_model->createWidget($data);
|
||||
$id = 3; // test code
|
||||
//throw new Exception('Invalid request data', 400); // test code
|
||||
//throw new Exception('Widget already exists', 409); // test code
|
||||
} catch (Exception $e) {
|
||||
// Here the model can throw exceptions like the following:
|
||||
// * For invalid input data: new Exception('Invalid request data', 400)
|
||||
// * For a conflict when attempting to create, like a resubmit: new Exception('Widget already exists', 409)
|
||||
$this->response(array('error' => $e->getMessage()), $e->getCode());
|
||||
}
|
||||
if ($id) {
|
||||
$widget = array('id' => $id, 'name' => $data['name']); // test code
|
||||
//$widget = $this->widgets_model->getWidget($id);
|
||||
$this->response($widget, 201); // 201 being the HTTP response code
|
||||
} else
|
||||
$this->response(array('error' => 'Widget could not be created'), 404);
|
||||
}
|
||||
|
||||
public function index_put()
|
||||
{
|
||||
$data = $this->_put_args;
|
||||
try {
|
||||
//$id = $this->widgets_model->updateWidget($data);
|
||||
$id = $data['id']; // test code
|
||||
//throw new Exception('Invalid request data', 400); // test code
|
||||
} catch (Exception $e) {
|
||||
// Here the model can throw exceptions like the following:
|
||||
// * For invalid input data: new Exception('Invalid request data', 400)
|
||||
// * For a conflict when attempting to create, like a resubmit: new Exception('Widget already exists', 409)
|
||||
$this->response(array('error' => $e->getMessage()), $e->getCode());
|
||||
}
|
||||
if ($id) {
|
||||
$widget = array('id' => $data['id'], 'name' => $data['name']); // test code
|
||||
//$widget = $this->widgets_model->getWidget($id);
|
||||
$this->response($widget, 200); // 200 being the HTTP response code
|
||||
} else
|
||||
$this->response(array('error' => 'Widget could not be found'), 404);
|
||||
}
|
||||
|
||||
function index_delete($id = '')
|
||||
{
|
||||
|
||||
// Example data for testing.
|
||||
$widgets = array(
|
||||
1 => array('id' => 1, 'name' => 'sprocket'),
|
||||
2 => array('id' => 2, 'name' => 'gear'),
|
||||
3 => array('id' => 3, 'name' => 'nut')
|
||||
);
|
||||
if (!$id) {
|
||||
$id = $this->get('id');
|
||||
}
|
||||
if (!$id) {
|
||||
$this->response(array('error' => 'An ID must be supplied to delete a widget'), 400);
|
||||
}
|
||||
|
||||
//$widget = $this->widgets_model->getWidget($id);
|
||||
$widget = @$widgets[$id]; // test code
|
||||
|
||||
if ($widget) {
|
||||
try {
|
||||
//$this->widgets_model->deleteWidget($id);
|
||||
//throw new Exception('Forbidden', 403); // test code
|
||||
} catch (Exception $e) {
|
||||
// Here the model can throw exceptions like the following:
|
||||
// * Client is not authorized: new Exception('Forbidden', 403)
|
||||
$this->response(array('error' => $e->getMessage()), $e->getCode());
|
||||
}
|
||||
$this->response($widget, 200); // 200 being the HTTP response code
|
||||
} else
|
||||
$this->response(array('error' => 'Widget could not be found'), 404);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
use EasyWeChat\Foundation\Application as OfficialAccount;
|
||||
class Active extends ApiController
|
||||
{
|
||||
private $_user_id = 0;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('session');
|
||||
$this->load->model('series_number_model');
|
||||
$this->load->model('package_model');
|
||||
$this->load->model('series_number_model');
|
||||
$this->load->model('sample_model');
|
||||
$this->load->model('customer_model');
|
||||
|
||||
//跨域
|
||||
header("Access-Control-Allow-Origin: ".$this->config->config['allow-origin']['user']);
|
||||
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
|
||||
header('Access-Control-Allow-Headers:x-requested-with,content-type');
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
//未登录告警
|
||||
if(empty($this->session->{Customer_model::SESSION_KEY})){
|
||||
$this->error('您的授权信息不存在或已过期,请从微信公众号菜单进入');
|
||||
}
|
||||
$this->_user_id = $this->session->{Customer_model::SESSION_KEY};
|
||||
}
|
||||
|
||||
public function ticket_get()
|
||||
{
|
||||
$config = [
|
||||
'app_id' => WEIXIN_APPID,
|
||||
'secret' => WEIXIN_APPSECERT,
|
||||
'token' => WEIXIN_TOKEN,
|
||||
'aes_key' => WEIXIN_EncodingAESKey,
|
||||
'response_type' => 'array',
|
||||
];
|
||||
$app = new OfficialAccount($config);
|
||||
$app->js->setUrl($_SERVER['HTTP_REFERER']);
|
||||
$config = $app->js->config(array('updateAppMessageShareData', 'updateTimelineShareData', 'scanQRCode'), $debug = false, $beta = false, $json = true);
|
||||
$this->success(['config'=>json_decode($config)]);
|
||||
}
|
||||
|
||||
public function check_number_post()
|
||||
{
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'device_id',
|
||||
'label' => '序列号',
|
||||
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
||||
),
|
||||
);
|
||||
$data = $this->json_validation($config);
|
||||
$series = $this->series_number_model->get($data['device_id'],'device_id');
|
||||
if(!$series){
|
||||
$this->error('序列号不存在');
|
||||
}
|
||||
$sample = $this->sample_model->get($series['id'],'series_id');
|
||||
if($sample){
|
||||
$this->error('序列号已使用');
|
||||
}
|
||||
$package = $this->package_model->get($series['package_ori']);
|
||||
if(!$package){
|
||||
$this->error('套餐不存在');
|
||||
}
|
||||
$this->success(['package'=>$package]);
|
||||
|
||||
}
|
||||
|
||||
public function create_post()
|
||||
{
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'device_id',
|
||||
'label' => '序列号',
|
||||
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'name',
|
||||
'label' => '用户姓名',
|
||||
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'field' => 'tel',
|
||||
'label' => '手机',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'email',
|
||||
'label' => '邮箱',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_name',
|
||||
'label' => '宠物名称',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_age',
|
||||
'label' => '宠物年龄',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_breed',
|
||||
'label' => '宠物品系',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_sex',
|
||||
'label' => '宠物性别',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_birthday',
|
||||
'label' => '宠物生日',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_species',
|
||||
'label' => '物种',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_img',
|
||||
'label' => '宠物头像地址',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'package_id',
|
||||
'label' => '检测套餐',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'note',
|
||||
'label' => '其他需求',
|
||||
'rules' => 'required'
|
||||
)
|
||||
);
|
||||
$data = $this->json_validation($config);
|
||||
$series = $this->series_number_model->get($data['device_id'],'device_id');
|
||||
if(!$series){
|
||||
$this->error('序列号不存在');
|
||||
}
|
||||
$sample = $this->sample_model->get($series['id'],'series_id');
|
||||
if($sample){
|
||||
$this->error('序列号已使用');
|
||||
}
|
||||
$package = $this->package_model->get($series['package_ori']);
|
||||
if(!$package){
|
||||
$this->error('套餐不存在');
|
||||
}
|
||||
$ret = $this->sample_model->add(
|
||||
array_intersect_key(array_column($config,'field'),$data)
|
||||
);
|
||||
if($ret){
|
||||
$this->success();
|
||||
}else{
|
||||
$this->error('提交失败');
|
||||
}
|
||||
}
|
||||
|
||||
//获取需回寄的样品
|
||||
public function ship_get()
|
||||
{
|
||||
$ret = $this->sample_model->get($this->_user_id,'user_id',true);
|
||||
//只展示需回寄样品
|
||||
foreach ($ret as $key=>$item) {
|
||||
if($item['step'] >= Sample_model::STEP_SENT){
|
||||
unset($ret[$key]);
|
||||
}
|
||||
}
|
||||
$this->success($ret);
|
||||
}
|
||||
|
||||
//样品回寄
|
||||
public function ship_post()
|
||||
{
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'device_id',
|
||||
'label' => '序列号',
|
||||
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'name',
|
||||
'label' => '用户姓名',
|
||||
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'field' => 'tel',
|
||||
'label' => '手机',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'email',
|
||||
'label' => '邮箱',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_name',
|
||||
'label' => '宠物名称',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_age',
|
||||
'label' => '宠物年龄',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_breed',
|
||||
'label' => '宠物品系',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_sex',
|
||||
'label' => '宠物性别',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_birthday',
|
||||
'label' => '宠物生日',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_species',
|
||||
'label' => '物种',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_img',
|
||||
'label' => '宠物头像地址',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'package_id',
|
||||
'label' => '检测套餐',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'note',
|
||||
'label' => '其他需求',
|
||||
'rules' => 'required'
|
||||
)
|
||||
);
|
||||
$data = $this->json_validation($config);
|
||||
$series = $this->series_number_model->get($data['device_id'],'device_id');
|
||||
|
||||
}
|
||||
|
||||
//进度查询:样品列表
|
||||
public function list_get()
|
||||
{
|
||||
$ret = $this->sample_model->get($this->_user_id,'user_id',true);
|
||||
$this->success($ret);
|
||||
}
|
||||
|
||||
//进度查询:样品进度详情
|
||||
public function detail_get()
|
||||
{
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'id',
|
||||
'label' => '样品ID',
|
||||
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
||||
)
|
||||
);
|
||||
$this->load->library('form_validation');
|
||||
$data = $this->input->get();
|
||||
$this->form_validation->set_data($data);
|
||||
$this->form_validation->set_rules($config);
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
$this->error('参数错误',$this->form_validation->error_array());
|
||||
}
|
||||
$row = $this->sample_model->get(trim($data['id']),'device_id');
|
||||
if($row['user_id'] != $this->_user_id){
|
||||
$this->error('您没有权限查看该样品');
|
||||
}
|
||||
$this->success($row);
|
||||
}
|
||||
|
||||
//进度查询:快递详情
|
||||
public function track_get()
|
||||
{
|
||||
$json_params = file_get_contents('php://input');
|
||||
$data = json_decode($json_params, true);
|
||||
|
||||
$config = array(
|
||||
array(
|
||||
'field' => 'device_id',
|
||||
'label' => '序列号',
|
||||
'rules' => 'trim|required|min_length[5]|max_length[20]'
|
||||
),
|
||||
array(
|
||||
'field' => 'name',
|
||||
'label' => '用户姓名',
|
||||
'rules' => 'trim|required|min_length[2]|max_length[20]',
|
||||
'errors' => array(
|
||||
'required' => 'You must provide a %s.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'field' => 'tel',
|
||||
'label' => '手机',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'email',
|
||||
'label' => '邮箱',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_name',
|
||||
'label' => '宠物名称',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_age',
|
||||
'label' => '宠物年龄',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_breed',
|
||||
'label' => '宠物品系',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_sex',
|
||||
'label' => '宠物性别',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_birthday',
|
||||
'label' => '宠物生日',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_species',
|
||||
'label' => '物种',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'pet_img',
|
||||
'label' => '宠物头像地址',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'package_id',
|
||||
'label' => '检测套餐',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'note',
|
||||
'label' => '其他需求',
|
||||
'rules' => 'required'
|
||||
)
|
||||
);
|
||||
$this->load->library('form_validation');
|
||||
$this->load->model('package_model');
|
||||
$this->form_validation->set_data($data);
|
||||
$this->form_validation->set_rules($config);
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
print_r($this->form_validation->error_array());
|
||||
$this->error('错误');
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '成功';
|
||||
}
|
||||
|
||||
$this->success();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user