作者 景龙
1 个管道 的构建 失败 耗费 2 秒

新建消防项目

要显示太多修改。

为保证性能只显示 43 of 43+ 个文件。

.buildpath
.DS_Store
.project
.settings
.idea
/data/runtime
/public/api
/public/assets/dist
/node_modules
Vagrantfile
.vagrant
\ No newline at end of file
... ...
# 定义 stages
stages:
- pull
# 定义 job
job1:
stage: pull
script:
- cd /alidata/www/w/xiaofang
- git pull
\ No newline at end of file
... ...
如何贡献我的源代码
===
... ...
ThinkCMF遵循Apache2开源协议发布,并提供免费使用。
版权所有Copyright © 2013-2018 by ThinkCMF (https://www.thinkcmf.com)
All rights reserved。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1. 需要给代码的用户一份Apache Licence ;
2. 如果你修改了代码,需要在被修改的文件中说明;
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可,但不可以表现为对Apache Licence构成更改。
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
... ...
ThinkCMF 5.0 API 1.1.0
===============
### 环境推荐
> php5.5+
> mysql 5.6+
> 打开rewrite
### 安装步骤
1. 请先安装ThinkCMF5 https://github.com/thinkcmf/thinkcmf
2. 再把本项目代码覆盖到 thinkcmf5根目录(最终目录参考http://www.kancloud.cn/thinkcmf/doc/266477)
```
thinkcmf 根目录
├─api api目录
├─app 应用目录
│ ├─portal 门户应用目录
│ │ ├─config.php 应用配置文件
│ │ ├─common.php 模块函数文件
│ │ ├─controller 控制器目录
│ │ ├─model 模型目录
│ │ └─ ... 更多类库目录
│ ├─ ... 更多应用
│ ├─command.php 命令行工具配置文件
│ ├─common.php 应用公共(函数)文件
│ ├─config.php 应用(公共)配置文件
│ ├─database.php 数据库配置文件
│ ├─tags.php 应用行为扩展定义文件
│ └─route.php 路由配置文件
├─data 数据目录
│ ├─conf 动态配置目录
│ ├─runtime 应用的运行时目录(可写)
│ └─ ... 更多
├─public WEB 部署目录(对外访问目录)
│ ├─api api入口目录
│ ├─plugins 插件目录
│ ├─static 静态资源存放目录(css,js,image)
│ ├─themes 前后台主题目录
│ │ ├─admin_simpleboot3 后台默认主题
│ │ └─simpleboot3 前台默认主题
│ ├─upload 文件上传目录
│ ├─index.php 入口文件
│ ├─robots.txt 爬虫协议文件
│ ├─router.php 快速测试文件
│ └─.htaccess apache重写文件
├─simplewind
│ ├─cmf CMF核心库目录
│ ├─extend 扩展类库目录
│ ├─thinkphp thinkphp目录
│ └─vendor 第三方类库目录(Composer)
├─composer.json composer 定义文件
├─LICENSE.txt 授权说明文件
├─README.md README 文件
├─think 命令行入口文件
```
### API手册
http://www.kancloud.cn/thinkcmf/cmf5api
QQ群:100828313 (付费)
### ThinkCMF小程序 ThinkCMFlite发布
https://www.kancloud.cn/thinkcmf/cmf5api/451391
### 更新日志
#### 1.1.0
[核心]
* 增加是否收藏判断
* 增加登录API,返回用户信息
* 优化登录时设备类型判断
* 优化手机号验证,支持国际手机号
* 优化评论列表,无须用户登录
* 优化rest api基类设备类型获取
* 优化rest api用户token生成逻辑
* 修复幻灯片列表,后台排序无效 #8
* 修复UserModel.php被写死了cmf_前缀 #9
* 修复文章附件url转化问题
* 修复评论成功后,评论对象评论数字段没有加1
* 修复添加收藏报错
* 修复收藏判断错误
* 修复文章列表发布时间格式问题,统一为时间戳
* 修复评论用户头像链接错误
* 修复不加载动态路由
[门户应用]
* 增加指定分类的子分类列表
* 增加文章点击数更新
* 增加相关文章接口
* 增加文章收藏接口
* 增加取消文章收藏接口
... ...
theme: jekyll-theme-cayman
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\admin\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
use app\portal\model\MobileCodeModel;
use app\portal\model\UserModel;
use cmf\lib\Storage;
use cmf\lib\Upload;
/**
* @title 用户中心
*/
class PersonController extends RestBaseController
{
/**
* @title 用户密码登录
* @description 接口说明
* @author 开发者
* @url /api/admin/person/login
* @method POST
* @param name:is_token type:int require:1 default: other: desc:不用带token标识(传1)
* @param name:mobile type:int require:1 default: other: desc:登录手机号
* @param name:password type:string require:1 default: other: desc:登录密码
* @return token:be8a600721c417207b45925cba4075f77a8d789b18637c7b7dfe49c883bc5996
*/
public function login(){
if($this->request->isPost()){
$validate = new Validate([
'mobile' => 'require',
'password' => 'require'
]);
$validate->message([
'mobile.require' => '请输入您的手机号!',
'password.require' => '请输入您的密码!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$userQuery = Db::name("user");
$findUser = $userQuery->where(['mobile'=>$data['mobile'],'user_type'=>2])->find();
if (empty($findUser)) {
$this->error("用户不存在!");
} else {
switch ($findUser['user_status']) {
case 0:
$this->error('您已被拉黑!');
case 2:
$this->error('账户还没有验证成功!');
}
if (!cmf_compare_password($data['password'], $findUser['user_pass'])) {
$this->error("密码不正确!");
}
}
//验证设备
// $allowedDeviceTypes = ['mobile', 'android', 'iphone', 'ipad', 'web', 'pc', 'mac'];
// if (empty($data['device_type']) || !in_array($data['device_type'], $allowedDeviceTypes)) {
// $this->error("请求错误,未知设备!");
// }
$userTokenQuery = Db::name("user_token")
->where('user_id', $findUser['id']);
// ->where('device_type', $data['device_type']);
$findUserToken = $userTokenQuery->find();
$currentTime = time();
$expireTime = $currentTime + 24 * 3600 * 180;
$token = md5(uniqid()) . md5(uniqid());
if (empty($findUserToken)) {
$result = $userTokenQuery->insert([
'token' => $token,
'user_id' => $findUser['id'],
'expire_time' => $expireTime,
'create_time' => $currentTime,
// 'device_type' => $data['device_type']
]);
} else {
$result = $userTokenQuery
->where('user_id', $findUser['id'])
// ->where('device_type', $data['device_type'])
->update([
'token' => $token,
'expire_time' => $expireTime,
'create_time' => $currentTime
]);
}
if (empty($result)) {
$this->error("登录失败!");
}
$this->success("登录成功!", ['token' => $token]);
}else{
$this->error("请求方式错误!");
}
}
/**
* @title 手机验证码登录
* @description 接口说明
* @author 开发者
* @url /api/admin/person/verifyLogin
* @method POST
* @param name:is_token type:int require:1 default: other: desc:不用带token标识(传1)
* @param name:mobile type:int require:1 default: other: desc:登录手机号
* @param name:mobile_code type:init require:1 default: other: desc:验证码
* @return token:be8a600721c417207b45925cba4075f77a8d789b18637c7b7dfe49c883bc5996
*/
public function verifyLogin(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.v_code');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
//验证验证码是否正确
$this->validateMobileCode($data);
$userQuery = Db::name("user");
$findUser = $userQuery->where(['mobile'=>$data['mobile'],'user_type'=>2])->find();
if (empty($findUser)) {
$this->error("用户不存在!");
} else {
switch ($findUser['user_status']) {
case 0:
$this->error('您已被拉黑!');
case 2:
$this->error('账户还没有验证成功!');
}
}
$userTokenQuery = Db::name("user_token")
->where('user_id', $findUser['id']);
$findUserToken = $userTokenQuery->find();
$currentTime = time();
$expireTime = $currentTime + 24 * 3600 * 180;
$token = md5(uniqid()) . md5(uniqid());
if (empty($findUserToken)) {
$result = $userTokenQuery->insert([
'token' => $token,
'user_id' => $findUser['id'],
'expire_time' => $expireTime,
'create_time' => $currentTime,
]);
} else {
$result = $userTokenQuery
->where('user_id', $findUser['id'])
->update([
'token' => $token,
'expire_time' => $expireTime,
'create_time' => $currentTime
]);
}
if (empty($result)) {
$this->error("登录失败!");
}
$this->success("登录成功!", ['token' => $token]);
}else{
$this->error("请求方式错误!");
}
}
/**
* @title 忘记密码
* @description 接口说明
* @author 开发者
* @url /api/admin/person/forgetPassword
* @method POST
* @param name:is_token type:int require:1 default: other: desc:不用带token标识(传1)
* @param name:mobile type:int require:1 default: other: desc:登录手机号
* @param name:mobile_code type:init require:1 default: other: desc:验证码
*/
public function forgetPassword(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.v_code');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
//验证验证码是否正确
$this->validateMobileCode($data);
$this->success('成功');
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 重置密码
* @description 接口说明
* @author 开发者
* @url /api/admin/person/resetPassword
* @method POST
* @param name:is_token type:int require:1 default: other: desc:不用带token标识(传1)
* @param name:mobile type:int require:1 default: other: desc:登录手机号
* @param name:password type:string require:1 default: other: desc:重置密码
* @param name:password_again type:string require:1 default: other: desc:重置密码(再次输入)
*/
public function resetPassword(){
if($this->request->isPost()){
$data = $this->request->post();
$userModel = new UserModel();
$rule = config('site.f_pass');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if($data['password_again'] != $data['password']){
$this->error('两次输入的密码不一致');
}
$password = cmf_password($data['password_again']);
$res = $userModel
->where('mobile',$data['mobile'])
->update(['user_pass'=>$password]);
if($res){
$this->success('重置密码成功');
}else{
$this->error('重置密码失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 发送手机验证码
* @description 接口说明
* @author 开发者
* @url /api/admin/person/sendMobileCode
* @method POST
* @param name:is_token type:int require:1 default: other: desc:不用带token标识(传1)
* @param name:mobile type:int require:1 default: other: desc:登录手机号
*/
public function sendMobileCode(){
if($this->request->isPost()){
// Db::startTrans();
$mobile = $this->request->post('mobile','');
$mc = new MobileCodeModel();
$search = '/^0?1[3|4|5|6|7|8][0-9]\d{8}$/';
if (!preg_match($search,$mobile)) {
$this->error('手机号格式有误');
}
$mobile_code = rand(100000, 999999);
$content = "【恒瑞消防】您的验证码为".$mobile_code.",如非本人操作请忽略本短信!";
$info = $mc->where([
'mobile' => $mobile,
'create_date' => date('Y-m-d')
])->find();
if($info){
if(time() < $info['create_time']+60 && $info['is_use'] == 0){
$this->error('不能频繁发送验证码');
}
if($info['count'] > 10){
$this->error('今天发送验证码的次数已达到了上限');
}
$res = $mc->where('id',$info['id'])->data([
'mobile' => $mobile,
'mobile_code' => $mobile_code,
'is_use' => 0,
'expire_time' => time()+300,
'count' => $info['count'] +1
])->update();
}else{
$res = $mc->insert([
'mobile' => $mobile,
'mobile_code' => $mobile_code,
'is_use' => 0,
'expire_time' => time()+300,
'count' => 1,
'create_time' => time(),
'create_date' => date('Y-m-d')
]);
}
if($res) {
//发送验证码
$this->sendCode($mobile, $content);
$this->success('验证码发送成功,请注意查收!');
}
}else{
$this->error('请求方式错误!');
}
}
//发送手机验证码
private function sendCode($mobile,$content){
date_default_timezone_set('PRC');//设置时区
$url = "http://www.ztsms.cn/sendNSms.do";//提交地址
$username = 'zhenweishoujizhan';//用户名
$password = 'Cxz307312';//原密码
$data = array(
'content' => $content,//短信内容
'mobile' => $mobile,//手机号码
'productid' => '676767',//产品id
'xh' => ''//小号
);
$isTranscoding = false;
$data['content'] = $isTranscoding === true ? mb_convert_encoding($data['content'], "UTF-8") : $data['content'];
$data['username']=$username;
$data['tkey'] = date('YmdHis');
$data['password'] = md5(md5($password) . $data['tkey']);
$curl = curl_init();// 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
$result = curl_exec($curl); // 执行操作
return $result;
}
//验证验证码是否正确
private function validateMobileCode($post){
$mc = new MobileCodeModel();
$res_find = $mc->where(['mobile' => $post['mobile'], 'mobile_code' => $post['mobile_code'], 'is_use' => 0, 'create_date' => date('Y-m-d'),])
->where('expire_time','gt',time())->find();
if($res_find){
$res_update = $mc->where('id',$res_find['id'])->setField('is_use',1);
if($res_update){
return true;
}
}else{
$this->error('验证未通过');
}
}
/**
* @title 退出登录
* @description 接口说明
* @author 开发者
* @url /api/admin/person/logout
* @method GET
* @header name:token type:string require:1 default: other: desc:header
*/
public function logout(){
if($this->request->isGet()){
$userId = $this->getUserId();
Db::name('user_token')
->where(['token' => $this->token, 'user_id' => $userId])
->update(['token' => '']);
$this->success("退出成功!");
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取个人信息
* @description 接口说明
* @author 开发者
* @url /api/admin/person/info
* @method GET
* @header name:token type:string require:1 default: other: desc:header
* @return id:用户id
* @return user_login:姓名
* @return identity:身份 1:甲方员工,2:乙方员工 3:甲方领导,4:乙方领导 5:甲方总领导
* @return avatar:图片
* @return is_update:姓名是否可以修改 0:允许,1:禁止
* @return is_work:上班状态 1:上班,2:下班
*/
public function info(){
if($this->request->isGet()){
$info = $this->user;
$info1 = $this->getIndexData();
$info['identity'] = $info1['identity'];
$info['company_name'] = isset($info1['company_name'])&&!empty($info1['company_name'])?$info1['company_name']:'';
$this->success('成功',$info);
}else{
$this->error('请求方式错误!');
}
}
//获取身份有关信息(identity: :1:甲方员工,2:乙方员工,3:甲方领导,4:乙方领导,5:甲方总领导)
public function getIndexData(){
//查询用户所属公司
$identity = $this->user['identity'];
if($identity == 0){
//员工
//找到公司名称,甲方或者乙方企业
$result = [];
$where = ['u_s_id'=>['like','%,'.$this->userId.',%']];
$field = 'id c_id,company_name,pid';
$res = $this->getCompany($where,$field);
if($res){
$result['company_name'] = $res['company_name'];
//查找企业拥有的服务
if($res['pid'] == 0){
//甲方企业
$result['identity'] = config('site.a_staff');
}else{
//乙方企业
$result['identity'] = config('site.b_staff');
}
}
}else if($identity == 1){
//领导
$where = ['u_l_id' => $this->userId];
$field = 'id c_id,company_name,pid';
$res = $this->getCompany($where,$field);
$result['company_name'] = $res['company_name'];
if($res['pid'] == 0){
//甲方
$result['identity'] = config('site.a_leader');
}else{
//乙方
$result['identity'] = config('site.b_leader');
}
}else{
//总领导
$result['identity'] = config('site.a_leaders');
}
return $result;
}
//获取企业相关信息
public function getCompany($where,$field){
$res = Db::name('company')
->where($where)
->field($field)
->order('id desc')
->find();
return $res;
}
/**
* @title 上下班
* @description 接口说明
* @author 开发者
* @url /api/admin/person/work
* @method GET
* @header name:token type:string require:1 default: other: desc:header
* @param name:is_work type:int require:1 default: other: desc:上下班状态(下班:2,上班:1)
*/
public function work(){
if($this->request->isGet()){
$data = $this->request->get();
$userModel = new UserModel();
$rule = config('site.is_work');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$res = $userModel->where('id',$this->userId)->update($data);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 修改个人资料
* @description 接口说明
* @author 开发者
* @url /api/admin/person/updateInfo
* @method POST
* @header name:token type:string require:1 default: other: desc:header
* @param name:user_login type:string require:1 default: other: desc:姓名
* @param name:avatar type:string require:1 default: other: desc:照片
*/
public function updateInfo(){
if($this->request->isPost()){
$data = $this->request->post();
$userModel = new UserModel();
$info = $this->user;
if($info['is_update'] == 0){
$data['is_update'] = 1;
}
$res = $userModel->where('id',$this->userId)->update($data);
if($res){
$this->success('修改成功');
}else{
$this->error('修改失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 上传文件
* @description 接口说明
* @author 开发者
* @url /api/admin/person/uploadFile
* @method POST
* @header name:token type:string require:1 default: other: desc:header
* @param name:source[] type:file require:1 default: other: desc:文件
* @return src:文件全路径 多张返回以逗号隔开
*/
public function uploadFile(){
$files = request()->file('source');
if (empty($files)) {
$this->error('未检出文件上传');
}
$countFile = count($files);
if($countFile > 9){
$this->error('最多上传9张图片');
}
$date = date('Ymd',time());
$host = config('site.host');
$images = '';
foreach($files as $file){
//移动到框架应用根目录/public/uploads/ 目录下
//允许文件大小200k
$info = $file->validate(['size'=>20480000,'ext'=>'jpg,png,gif,mp3,wma,wav,mp4,avi,wmv,rm,rmvb,mkv'])->move(ROOT_PATH . 'public' . DS . 'uploads');
if($info){
$images .= $host.'/uploads/'.$date.'/'.$info->getFilename().',';
}else{
// 上传失败获取错误信息
$this->error($file->getError());
}
}
$this->success('上传成功',['src'=>rtrim($images,',')]);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
$apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR);
$returnCommands = [];
foreach ($apps as $app) {
$commandFile = APP_PATH . $app . '/command.php';
if (file_exists($commandFile)) {
$commands = include $commandFile;
$returnCommands = array_merge($returnCommands, $commands);
}
}
return $returnCommands;
\ No newline at end of file
... ...
<?php
namespace api\common\exception;
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/11/28
* Time: 15:27
*/
use Exception;
use think\exception\Handle;
use think\exception\HttpException;
class Http extends Handle
{
public function render(Exception $e)
{
if (APP_DEBUG==true) {
return parent::render($e);
} elseif ($e instanceof ValidateException) {
$msg=$e->getMessage();
} else {
$msg= '系统错误!';
}
$code=0;
$httpCode=500;
$result = [
'code' => $code,
'msg' => $msg,
'data' => [],
];
return json($result, $httpCode);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\common\model;
use think\Model;
use think\Loader;
class CommonModel extends Model
{
// 关联模型过滤
protected $relationFilter = [];
/**
* 内容查询
* @access public
* @param array $params 过滤参数
* @return array|false|\PDOStatement|string|\think\Collection|Model 查询结果
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getDatas($params = [])
{
if (empty($params)) {
return $this->select();
}
$this->setCondition($params);
if (!empty($params['id'])) {
$datas = $this->find();
} else {
$datas = $this->select();
}
if (!empty($params['relation'])) {
$allowedRelations = $this->allowedRelations($params['relation']);
if (!empty($allowedRelations)) {
if (!empty($params['id'])) {
if (!empty($datas)) {
$datas->append($allowedRelations);
}
} else {
if (count($datas) > 0) {
$datas->load($allowedRelations);
$datas->append($allowedRelations);
}
}
}
}
return $datas;
}
/**
* @access public
* @param array $params 过滤参数
* @return $this
*/
public function setCondition($params)
{
if (empty($params)) {
return $this;
}
if (!empty($params['relation'])) {
$allowedRelations = $this->allowedRelations($params['relation']);
if (!empty($allowedRelations)) {
if (!empty($params['id']) && count($allowedRelations) == 1) {
$this->paramsFilter($params);
} else {
$this->paramsFilter($params);//->with($allowedRelations);
}
}
} else {
$this->paramsFilter($params);
}
return $this;
}
/**
* @access public
* @param array $params 过滤参数
* @param model $model 关联模型
* @return model|array $this|链式查询条件数组
*/
public function paramsFilter($params, $model = null)
{
if (!empty($model)) {
$_this = $model;
} else {
$_this = $this;
}
if (isset($_this->visible)) {
$whiteParams = $_this->visible;
}
// 设置field字段过滤
if (!empty($params['field'])) {
$filterParams = $this->strToArr($params['field']);
if (!empty($whiteParams)) {
$mixedField = array_intersect($filterParams, $whiteParams);
} else {
$mixedField = $filterParams;
}
if (!empty($mixedField)) {
$_this->field($mixedField);
}
}
// 设置id,ids
if (!empty($params['ids'])) {
$ids = $this->strToArr($params['ids']);
foreach ($ids as $key => $value) {
$ids[$key] = intval($value);
}
}
if (!empty($params['where']) && !is_string($params['where'])) {
if (empty($model)) {
$_this->where($params['where']);
}
}
if (!empty($params['id'])) {
$id = intval($params['id']);
if (!empty($id)) {
return $_this->where('id', $id);
}
} elseif (!empty($ids)) {
$_this->where('id', 'in', $ids);
}
// 设置分页
if (!empty($params['page'])) {
$pageArr = $this->strToArr($params['page']);
$page = [];
foreach ($pageArr as $value) {
$page[] = intval($value);
}
if (count($page) == 1) {
$_this->page($page[0]);
} elseif (count($page) == 2) {
$_this->page($page[0], $page[1]);
}
} elseif (!empty($params['limit'])) { // 设置limit查询
$limitArr = $this->strToArr($params['limit']);
$limit = [];
foreach ($limitArr as $value) {
$limit[] = intval($value);
}
if (count($limit) == 1) {
$_this->limit($limit[0]);
} elseif (count($limit) == 2) {
$_this->limit($limit[0], $limit[1]);
}
} else {
$_this->limit(10);
}
//设置排序
if (!empty($params['order'])) {
$order = $this->strToArr($params['order']);
foreach ($order as $key => $value) {
$upDwn = substr($value, 0, 1);
$orderType = $upDwn == '-' ? 'desc' : 'asc';
$orderField = substr($value, 1);
if (!empty($whiteParams)) {
if (in_array($orderField, $whiteParams)) {
$orderWhere[$orderField] = $orderType;
}
} else {
$orderWhere[$orderField] = $orderType;
}
}
if (!empty($orderWhere)) {
$_this->order($orderWhere);
}
}
return $_this;
}
/**
* 设置链式查询
* @access public
* @param array $params 链式查询条件
* @param model $model 模型
* @return $this
*/
public function setParamsQuery($params, $model = null)
{
if (!empty($model)) {
$_this = $model;
} else {
$_this = $this;
}
$_this->alias('articles');
if (!empty($params['field'])) {
$_this->field($params['field']);
}
if (!empty($params['ids'])) {
$_this->where('articles.id', $params['ids'][1], $params['ids'][2]);
}
if (!empty($params['limit'])) {
$_this->limit($params['limit']);
}
if (!empty($params['page'])) {
$_this->page($params['page']);
}
if (!empty($params['order'])) {
$_this->order($params['order']);
}
return $_this;
}
public function allowedRelations($relations)
{
if (is_string($relations)) {
$relations = explode(',', $relations);
}
if (!is_array($relations)) {
return false;
}
return array_intersect($this->relationFilter, $relations);
}
/**
* 是否允许关联
* @access public
* @param string $relationName 模型关联方法名
* @return boolean
*/
public function isWhite($relationName)
{
if (!is_string($relationName)) {
return false;
}
$name = Loader::parseName($relationName, 1, false);
if (in_array($name, $this->relationFilter)) {
return true;
} else {
return false;
}
}
/**
* 懒人函数
* @access public
* @param string $value 字符串
* @return array
*/
public function strToArr($string)
{
return is_string($string) ? explode(',', $string) : $string;
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
return [
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
// 应用命名空间
'app_namespace' => 'api',
// 应用模式状态
'app_status' => APP_DEBUG ? 'debug' : 'release',
// 是否支持多模块
'app_multi_module' => true,
// 入口自动绑定模块
'auto_bind_module' => false,
// 注册的根命名空间
'root_namespace' => ['cmf' => CMF_PATH, 'plugins' => PLUGINS_PATH, 'app' => CMF_ROOT . 'app/'],
// 扩展函数文件
'extra_file_list' => [THINK_PATH . 'helper' . EXT, CMF_PATH . 'common' . EXT],
// 默认输出类型
'default_return_type' => 'json',
// 默认AJAX 数据返回格式,可选json xml ...
'default_ajax_return' => 'json',
// 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
// 默认时区
'default_timezone' => 'PRC',
// 是否开启多语言
'lang_switch_on' => false,
// 默认全局过滤方法 用逗号分隔多个
'default_filter' => 'htmlspecialchars',
// 默认语言
'default_lang' => 'zh-cn',
// 应用类库后缀
'class_suffix' => true,
// 控制器类后缀
'controller_suffix' => true,
// +----------------------------------------------------------------------
// | 模块设置
// +----------------------------------------------------------------------
// 默认模块名
'default_module' => 'home',
// 禁止访问模块
'deny_module_list' => ['common'],
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 默认验证器
'default_validate' => '',
// 默认的空控制器名
'empty_controller' => 'Error',
// 自动搜索控制器
'controller_auto_search' => false,
// +----------------------------------------------------------------------
// | URL设置
// +----------------------------------------------------------------------
'pathinfo_depr' => '/',
// URL伪静态后缀
'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成
'url_common_param' => false,
// URL参数方式 0 按名称成对解析 1 按顺序解析
'url_param_type' => 0,
// 是否开启路由
'url_route_on' => true,
// 路由配置文件(支持配置多个)
'route_config_file' => ['route'],
// 是否强制使用路由
'url_route_must' => false,
// 域名部署
'url_domain_deploy' => false,
// 域名根,如thinkphp.cn
'url_domain_root' => '',
// 是否自动转换URL中的控制器和操作名
'url_convert' => true,
// 默认的访问控制器层
'url_controller_layer' => 'controller',
// 表单请求类型伪装变量
'var_method' => '_method',
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
'template' => [
// 模板引擎类型 支持 php think 支持扩展
'type' => 'Think',
// 视图根目录
'view_base' => '',
// 模板路径
'view_path' => '',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DS,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '<',
// 标签库标签结束标记
'taglib_end' => '>',
],
// 视图输出字符串内容替换
'view_replace_str' => [],
// 默认跳转页面对应的模板文件
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
// +----------------------------------------------------------------------
// | 异常及错误设置
// +----------------------------------------------------------------------
// 异常页面的模板文件
'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
// 异常处理handle类 留空使用 \think\exception\Handle
'exception_handle' => '\\api\\common\\exception\\Http',
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
'log' => [
// 日志记录方式,内置 file socket 支持扩展
'type' => 'File',
// 日志保存目录
'path' => LOG_PATH,
// 日志记录级别
'level' => [],
],
// +----------------------------------------------------------------------
// | Trace设置 开启 app_trace 后 有效
// +----------------------------------------------------------------------
'trace' => [
// 内置Html Console 支持扩展
'type' => 'Html',
],
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
'cache' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => CACHE_PATH,
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
],
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
'session' => [
'id' => '',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// SESSION 前缀
'prefix' => 'think',
// 驱动方式 支持redis memcache memcached
'type' => '',
// 是否自动开启 SESSION
'auto_start' => true,
],
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
'cookie' => [
// cookie 名称前缀
'prefix' => '',
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => '',
// 是否使用 setcookie
'setcookie' => true,
],
// +----------------------------------------------------------------------
// | 数据库设置
// +----------------------------------------------------------------------
'database' => [
// 数据库调试模式
'debug' => true,
// 数据集返回类型
'resultset_type' => 'collection',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => false,
// 是否需要进行SQL性能分析
'sql_explain' => false,
],
//分页配置
'paginate' => [
'type' => 'bootstrap',
'var_page' => 'page',
'list_rows' => 15,
],
//图片验证码
'captcha' => [
// 验证码字符集合
'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',
// 验证码字体大小(px)
'fontSize' => 25,
// 是否画混淆曲线
'useCurve' => true,
// 验证码图片高度
'imageH' => 30,
// 验证码图片宽度
'imageW' => 100,
// 验证码位数
'length' => 5,
// 验证成功后是否重置
'reset' => true
],
// +----------------------------------------------------------------------
// | CMF 设置
// +----------------------------------------------------------------------
'cmf_theme_path' => 'themes/home/',
'cmf_default_theme' => 'simpleboot3',
'cmf_admin_theme_path' => 'themes/admin/',
'cmf_admin_default_theme' => 'simpleboot3',
// +----------------------------------------------------------------------
// | 验证接口数据
// +----------------------------------------------------------------------
];
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
if(file_exists(ROOT_PATH."data/conf/database.php")){
$database=include ROOT_PATH."data/conf/database.php";
}else{
$database=[];
}
return $database;
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
return [
// 应用调试模式
'app_debug' => true,
// 应用Trace
'app_trace' => true,
];
\ No newline at end of file
... ...
ThinkCMF API演示应用
===============
### 加载第三方库
支持使用`composer`加载第三方库
```
composer require phpoffice/phpspreadsheet
```
\ No newline at end of file
... ...
{
"name": "thinkcmf/apis-demo",
"description": "ThinkCMF demo api",
"type": "cmf-api",
"license": "MIT",
"authors": [
{
"name": "catman",
"email": "catman@thinkcmf.com"
}
],
"require": {}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\demo\controller;
use cmf\controller\RestBaseController;
class ArticlesController extends RestBaseController
{
public function index()
{
$articles = [
['title' => 'article title1'],
['title' => 'article title2'],
];
$this->success('请求成功!', ['articles' => $articles]);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\demo\controller;
use cmf\controller\RestBaseController;
/**
* @title 测试demo
*/
class IndexController extends RestBaseController
{
/**
* @title 测试demo接口
* @description 接口说明
* @author 开发者
* @url /api/demo/index/index
* @method GET
*
* @header name:device require:1 default: desc:设备号
*
* @param name:id type:int require:1 default:1 other: desc:唯一ID
*
* @return name:名称
* @return mobile:手机号
* @return list_messages:消息列表@
* @list_messages message_id:消息ID content:消息内容
* @return object:对象信息@!
* @object attribute1:对象属性1 attribute2:对象属性2
* @return array:数组值#
* @return list_user:用户列表@
* @list_user name:名称 mobile:手机号 list_follow:关注列表@
* @list_follow user_id:用户id name:名称
*/
public function index()
{
$this->success('请求成功!', ['test'=>'test']);
}
}
... ...
<?php
use think\facade\Route;
Route::resource('demo/articles', 'demo/Articles');
... ...
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971::getLoader();
... ...
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}
... ...
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
... ...
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
... ...
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
... ...
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
... ...
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitba11d0d49ab8a6cda13c6c7344f77971::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}
... ...
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInitba11d0d49ab8a6cda13c6c7344f77971
{
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
}, null, ClassLoader::class);
}
}
... ...
<?php
return array (
//用户身份
//甲方员工
'a_staff' => 1,
//乙方员工
'b_staff' => 2,
//甲方领导
'a_leader' => 3,
//乙方领导
'b_leader' => 4,
//甲方总领导
'a_leaders' => 5,
//分页数据
'limit' => 10,
//域名
'host' => 'http://xiaofang.w.bronet.cn',
//甲方提交报修流程
'a_step' => ['甲方提交报修信息','乙方确认信息','乙方维修设备','乙方提交维修单','甲方验收维修结果','甲方验收完成'],
//乙方提交报修流程
'b_step' => ['乙方提交报修信息','甲方确认信息','乙方维修设备','乙方提交维修单','甲方验收维修结果','甲方验收完成'],
//验证规则
'v_code' => [
'rule' => [
'mobile' => ['require','regex'=>'/^0?1[3|4|5|6|7|8][0-9]\d{8}$/'],
'mobile_code' => 'require|number',
],
'msg' => [
'mobile.require' => '手机号不能为空',
'mobile' => '手机号格式不正确',
'mobile_code.require' => '验证码不能为空',
'mobile_code.number' => '验证码必须是数字',
]
],
'f_pass' => [
'rule' => [
'mobile' => ['require','regex'=>'/^0?1[3|4|5|6|7|8][0-9]\d{8}$/'],
'password' => 'require',
'password_again' => 'require',
],
'msg' => [
'mobile.require' => '手机号不能为空',
'mobile' => '手机号格式不正确',
'password.require' => '请输入密码',
'password_again.require' => '请再次输入密码',
]
],
'is_work' => [
'rule' => [
'is_work' => 'require|number',
],
'msg' => [
'is_work.require' => '工作状态不能为空',
'is_work.number' => '工作状态必须是数字',
]
],
'ins_add' => [
'rule' => [
'id' => 'require|number',
],
'msg' => [
'id.require' => 'id不能为空',
'id.number' => 'id必须是数字',
]
],
'type' => [
'rule' => [
'type' => 'require|number',
'page' => 'require|number',
],
'msg' => [
'type.require' => '工作类型不能为空',
'type.number' => '工作类型必须是数字',
'page.require' => '页码不能为空',
'page.number' => '页码必须是数字',
]
],
'ins_post' => [
'rule' => [
'point_id' => 'require|number',
'project_id' => 'require|number',
'status' => 'require|number',
'images' => 'require',
'create_time' => 'require',
],
'msg' => [
'point_id.require' => '巡检点id不能为空',
'point_id.number' => '巡检点id必须是数字',
'project_id.require' => '项目id不能为空',
'project_id.number' => '项目id必须是数字',
'status.require' => '巡检状态不能为空',
'status.number' => '巡检状态必须是数字',
'images.require' => '巡检图片不能为空',
'create_time.require' => '巡检时间不能为空',
]
],
'pages' => [
'rule' => [
'page' => 'require|number',
],
'msg' => [
'page.require' => '页码不能为空',
'page.number' => '页码必须是数字',
]
],
'pages_list' => [
'rule' => [
'page' => 'require|number',
'status' => 'require|number',
],
'msg' => [
'page.require' => '页码不能为空',
'page.number' => '页码必须是数字',
'status.require' => '状态码不能为空',
'status.number' => '状态码必须是数字',
]
],
'repair_post' => [
'rule' => [
'images' => 'require',
'video' => 'require',
'audio' => 'require',
'description' => 'require',
],
'msg' => [
'images.require' => '图片凭证不能为空',
'video.require' => '视频凭证不能为空',
'audio.require' => '音频凭证不能为空',
'description.require' => '故障问题不能为空',
]
],
'data' => [
'rule' => [
'id' => 'require|number',
],
'msg' => [
'id.require' => '列表id不能为空',
'id.number' => '列表id必须是数字',
]
],
'improve_post' => [
'rule' => [
'id' => 'require|number',
'repair_images' => 'require',
'repair_description' => 'require',
],
'msg' => [
'id.require' => '报修单id不能为空',
'id.number' => '报修的id必须为数字',
'repair_images.require' => '维修照片不能为空',
'repair_description.require' => '维修备注不能为空',
]
],
'check_post' => [
'rule' => [
'id' => 'require|number',
'confirm_images' => 'require',
],
'msg' => [
'id.require' => '报修单id不能为空',
'id.number' => '报修的id必须为数字',
'confirm_images.require' => '验收照片不能为空',
]
],
'ins_m_post' => [
'rule' => [
'ins_m_time' => 'require',
'address' => 'require',
'a_uid' => 'require|number',
'remark' => 'require',
],
'msg' => [
'ins_m_time.require' => '月检时间不能为空',
'address.require' => '月检地点不能为空',
'a_uid.require' => '月检甲方负责人不能为空',
'a_uid.number' => '月检甲方负责人必须是数字',
'remark.require' => '月检申请备注不能为空',
]
],
'confirm' => [
'rule' => [
'id' => 'require|number',
'type' => 'require|number',
],
'msg' => [
'id.require' => '列表id不能为空',
'id.number' => '列表id必须是数字',
'type.require' => '工作类型不能为空',
'type.number' => '工作类型必须是数字',
]
],
'ins_re_post' => [
'rule' => [
'id' => 'require|number',
'ins_m_time' => 'require',
'address' => 'require',
'a_uid' => 'require|number',
'remark' => 'require',
],
'msg' => [
'id.require' => '月检id不能为空',
'id.number' => '月检id必须是数字',
'ins_m_time.require' => '月检时间不能为空',
'address.require' => '月检地点不能为空',
'a_uid.require' => '月检甲方负责人不能为空',
'a_uid.number' => '月检甲方负责人必须是数字',
'remark.require' => '月检申请备注不能为空',
]
],
'train_post' => [
'rule' => [
'train_time' => 'require',
'address' => 'require',
'remark' => 'require',
],
'msg' => [
'train_time.require' => '培训时间不能为空',
'address.require' => '培训地点不能为空',
'remark.require' => '培训备注不能为空',
]
],
'improve_check_post' => [
'rule' => [
'id' => 'require|number',
'images' => 'require'
],
'msg' => [
'id.require' => '列表id不能为空',
'id.number' => '列表id必须是数字',
'images.require' => '图片不能为空',
]
],
);
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\CheckModel;
/**
* @title 月检
*/
class CheckController extends RestBaseController
{
/**
* @title 甲方项目组人员
* @description 接口说明
* @author 开发者
* @url /api/home/check/userAGroup
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return data:数据@
* @data id:负责人id user_login:负责人姓名
*/
public function userAGroup(){
if($this->request->isGet()){
$common = new CommonController();
//获取用户所在项目
$user = $common->getUserIdentity();
//根据项目id获取甲方uid
$users = $common->getUserByProject($user['project_id'],'id,a_sid');
$this->success('成功',['data'=>$users]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方发起月检申请
* @description 接口说明
* @author 开发者
* @url /api/home/check/applyCheck
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:ins_m_time type:string require:1 default: other desc:月检时间
* @param name:address type:string require:1 default: other desc:月检地点
* @param name:a_uid type:inter require:1 default: other desc:甲方负责人id
* @param name:remark type:string require:1 default: other desc:月检申请备注
*/
public function applyCheck(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.ins_m_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
$data['project_id'] = $user['project_id'];
$data['create_time'] = time();
$checkModel = new CheckModel();
$res = $checkModel->create($data);
if($res){
$this->success('月检信息提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 月检信息列表
* @description 接口说明
* @author 开发者
* @url /api/home/check/checkList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @return data: @
* @data id:月检id user_login:乙方发起人 status:月检状态(0:待甲方领导确认,1:甲方领导驳回,2:待乙方员工完成,3:已完成) project_name:项目名称 ins_m_time:月检时间
*/
public function checkList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('site.pages');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$res = $common->getCheckList($page);
$this->success('成功',['data'=>$res]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 重新编辑显示(甲方领导驳回)
* @description 接口说明
* @author 开发者
* @url /api/home/check/reEdit
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
* @return id:月检列表id
* @return ins_m_time:月检时间
* @return address:月检地点
* @return a_uid:月检甲方负责人uid
* @return remark:月检备注
*/
public function reEdit(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$field = 'id,ins_m_time,address,a_uid,remark';
$res = $common->getCheckById(['id'=>$id,'status'=>1],$field);
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方重新发起月检(被驳回)
* @description 接口说明
* @author 开发者
* @url /api/home/check/reApply
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
* @param name:ins_m_time type:string require:1 default: other desc:月检时间
* @param name:address type:string require:1 default: other desc:月检地点
* @param name:a_uid type:inter require:1 default: other desc:甲方负责人id
* @param name:remark type:string require:1 default: other desc:月检申请备注
*/
public function reApply(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.ins_re_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$arr['ins_m_time'] = $data['ins_m_time'];
$arr['address'] = $data['address'];
$arr['a_uid'] = $data['a_uid'];
$arr['remark'] = $data['remark'];
$arr['uid'] = $this->userId;
$arr['status'] = 0;
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$data['id']])->update($arr);
if($res){
$this->success('月检信息提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 完善月检单显示
* @description 接口说明
* @author 开发者
* @url /api/home/check/improveCheck
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
*
* @return id:月检id
* @return ins_m_time:月检日期
* @return project_name:月检项目名称
* @return user_login:确认甲方领导
* @return images:月检图片(多张以逗号隔开)
*/
public function improveCheck(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$arr = [];
$common = new CommonController();
$field = 'id,ins_m_time,a_leader,images,project_id';
$res = $common->getCheckById(['id'=>$id],$field);
if($res){
$arr['id'] = $res['id'];
$arr['ins_m_time'] = $res['ins_m_time'];
//查询项目名称
$project = $common->getProject(['id'=>$res['project_id']],'id,name project_name');
$arr['project_name'] = isset($project)&&!empty($project)?$project['project_name']:'';
//查询甲方领导人
$user = $common->getLeader(['id'=>$res['a_leader']]);
$arr['user_login'] = isset($user)&&!empty($user)?$user['user_login']:'';
$arr['images'] = $res['images'];
}
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 完善月检单提交
* @description 接口说明
* @author 开发者
* @url /api/home/check/improveCheckPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
* @param name:images type:file require:1 default: other desc:月检图片
*
*/
public function improveCheckPost(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.improve_check_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$data['id'],'status'=>2])->update(['images'=>$data['images']]);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方确认完成月检信息
* @description 接口说明
* @author 开发者
* @url /api/home/check/finishCheck
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
*/
public function finishCheck(){
if($this->request->isGet()){
$id = $this->request->get('id');
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$id,'status'=>2])->update(['finish_uid'=>$this->userId,'finish_time'=>time(),'status'=>3]);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\StepModel;
/**
* @title 巡检管理
*/
class CommonController extends RestBaseController
{
//获取首页用户身份信息
public function getIndexData(){
//查询用户所属公司
$identity = $this->user['identity'];
if($identity == 0){
//员工
//找到公司名称,甲方或者乙方企业
$result = [];
$where = ['u_s_id'=>['like','%,'.$this->userId.',%']];
$field = 'id c_id,company_name,pid,logo';
$res = $this->getCompany($where,$field);
$result['is_work'] = $this->user['is_work'];
if($res){
// $result['uid'] = $this->userId;
$result['company_name'] = $res['company_name'];
$result['logo'] = $res['logo'];
//查找企业拥有的服务
$rule = $this->getRule($res);
$result['service'] = $rule;
if($res['pid'] == 0){
//甲方企业
$result['identity'] = config('site.a_staff');
$where = ['a_sid'=>['like','%,'.$this->userId.',%'],'a_cid'=>$res['c_id']];
$field = 'id,name,create_time';
$res1 = $this->getProject($where,$field);
$result['run_time'] = 0;
$result['is_project'] = 0;
if($res1){
$result['run_time'] = $this->getRunTime($res1['create_time']);
$result['is_project'] = 1;
}
// $res['p_id'] = isset($res1['p_id']) && !empty($res1['p_id'])?$res1['p_id']:'';
//项目名称
$result['project_name'] = isset($res1['name']) && !empty($res1['name'])?$res1['name']:'';
// $res['point'] = isset($res1['point']) && !empty($res1['point'])?$res1['point']:'';
}else{
//乙方企业
$result['identity'] = config('site.b_staff');
$where = ['b_sid'=>['like','%,'.$this->userId.',%'],'b_cid'=>$res['c_id']];
$field = 'id,name,create_time';
$res1 = $this->getProject($where,$field);
//当前时间
$result['run_time'] = 0;
$result['is_project'] = 0;
if($res1){
$result['run_time'] = $this->getRunTime($res1['create_time']);
$result['is_project'] = 1;
}
// $res['p_id'] = isset($res1['p_id']) && !empty($res1['p_id'])?$res1['p_id']:'';
$result['project_name'] = isset($res1['name']) && !empty($res1['name'])?$res1['name']:'';
// $res['point'] = isset($res1['point']) && !empty($res1['point'])?$res1['point']:'';
}
}
}else if($identity == 1){
//领导
$where = ['u_l_id' => $this->userId];
$field = 'id c_id,company_name,pid,logo';
$res = $this->getCompany($where,$field);
$result['company_name'] = $res['company_name'];
$result['logo'] = $res['logo'];
// $res['uid'] = $this->userId;
//甲方
//查找企业拥有的服务
$rule = $this->getRule($res);
$result['service'] = $rule;
foreach($result['service'] as &$value){
$value['name'] = $value['name'].'报表';
}
if($res['pid'] == 0){
$result['identity'] = config('site.a_leader');
$where = ['a_cid'=>$res['c_id']];
$field = 'id,name,create_time';
$res1 = $this->getProject($where,$field);
}else{
//乙方
$result['identity'] = config('site.b_leader');
$where = ['b_cid'=>$res['c_id']];
$field = 'id,name,create_time';
$res1 = $this->getProject($where,$field);
}
$result['run_time'] = 0;
//是否有项目
$result['is_project'] = 0;
if($res1){
$result['run_time'] = $this->getRunTime($res1['create_time']);
$result['is_project'] = 1;
}
}else{
//总领导(待完善)
$result['identity'] = config('site.a_leaders');
}
return $result;
}
//查找企业拥有的服务权限
public function getRule($res){
$rule = Db::name('service_rule')
->alias('r')
->join('service s','r.s_id = s.id','LEFT')
->where('r.c_id','like','%,'.$res['c_id'].',%')
->field('s.id,s.name,s.english_name,s.icon')
->select()
->toArray();
return $rule;
}
//获取项目相关信息
public function getProject($where,$field){
$res = Db::name('project')
->where($where)
->field($field)
->order('id desc')
->find();
return $res;
}
//根据乙方企业id获取项目所关联的月检相关信息
public function getCheckByCompanyBId($b_company_id,$page){
$limit = config('site.limit');
$res = Db::name('project')
->alias('p')
->join('check c','p.id = c.project_id')
->where(['p.b_cid'=>$b_company_id,'c.status'=>0])
->field('c.id,p.id project_id,p.name project_name,c.ins_m_time')
->order('c.id desc')
->page($page,$limit)
->select()
->toArray();
return $res;
}
//获取企业相关信息
public function getCompany($where,$field){
$res = Db::name('company')
->where($where)
->field($field)
->order('id desc')
->find();
return $res;
}
//获取企业相关信息(总领导)
public function getTotalCompany($where,$field){
$res = Db::name('company')
->where($where)
->field($field)
->select()
->toArray();
return $res;
}
//获取项目运行时间
public function getRunTime($time){
$currentTime = time();
$cnt=$currentTime-strtotime(date('Y-m-d',$time));
$days = floor($cnt/(3600*24))+1;//算出天数
return $days;
}
//查询巡检点列表名称
public function getPoint($where,$field){
$res = Db::name('point')
->where($where)
->field($field)
->select()
->toArray();
return $res;
}
//获取巡检列表
public function getInsList(){
$identity = $this->user['identity'];
$result = [];
if($identity == 0){
//找到公司名称,甲方或者乙方企业
$where = ['u_s_id'=>['like','%,'.$this->userId.',%']];
$field = 'id c_id,company_name,pid';
$res = $this->getCompany($where,$field);
if($res){
if($res['pid'] == 0){
//甲方企业
$where = ['a_sid'=>['like','%,'.$this->userId.',%'],'a_cid'=>$res['c_id']];
$field = 'id,name project_name,point';
$result = $this->getProject($where,$field);
//获取该项目的巡检点
$where = ['p_id'=>$result['id']];
$field = 'id,point_name';
$arr = $this->getPoint($where,$field);
$party = 0;
}else{
//乙方企业
$where = ['b_sid'=>['like','%,'.$this->userId.',%'],'b_cid'=>$res['c_id']];
$field = 'id,name project_name,point';
$result = $this->getProject($where,$field);
$where = ['p_id'=>$result['id']];
$field = 'id,point_name';
$arr = $this->getPoint($where,$field);
$party = 1;
}
//获取今天的巡检信息(共同合作完成)
$time = date('Y-m-d',time());
$where = ['project_id'=>$result['id'],'create_time'=>$time,'party'=>$party];
$field = 'status,point_id';
$todayIns = $this->getTodayIns($where,$field);
$is_finish = 0;
foreach ($arr as &$value){
$value['status'] = 2;
foreach ($todayIns as $ins_value){
if($value['id'] == $ins_value['point_id']){
$value['status'] = $ins_value['status'];
}
}
if($value['status'] == 2){
$is_finish ++;
}
}
$result['point'] = $arr;
$result['is_finish'] = $is_finish;
}
}
return $result;
}
//获取今天的巡检信息
public function getTodayIns($where,$field){
$res = Db::name('inspect')
->where($where)
->field($field)
->select()
->toArray();
return $res;
}
//根据uid查询用户
public function getUser($where){
$res = Db::name('user')
->where($where)
->field('id,user_login,identity')
->find();
$res['other'] = '';
if(isset($res['identity']) && !empty($res['identity'])){
//获取用户身份,所属企业,项目
$other = $this->getUserIdentity($res['identity']);
$res['other'] = $other;
}
return $res;
}
//查看用户是甲方乙方(party 0:甲方,1:乙方)用户信息,企业信息,项目信息
public function getUserIdentity($user_identity=''){
$identity = empty($user_identity)?$this->user['identity']:$user_identity;
$result = [];
$result['project_id'] = '';
$result['company_id'] = '';
if($identity == 0){
//找到公司名称,甲方或者乙方企业
$where = ['u_s_id'=>['like','%,'.$this->userId.',%']];
$field = 'id c_id,company_name,pid,u_l_id';
$res = $this->getCompany($where,$field);
if($res){
if($res['pid'] == 0){
//甲方企业
$result['identity'] = config('site.a_staff');
$where = ['a_sid'=>['like','%,'.$this->userId.',%'],'a_cid'=>$res['c_id']];
$field = 'id,name project_name';
$res1 = $this->getProject($where,$field);
$result['party'] = 0;
}else{
//乙方企业
$result['identity'] = config('site.b_staff');
$where = ['b_sid'=>['like','%,'.$this->userId.',%'],'b_cid'=>$res['c_id']];
$field = 'id,name project_name';
$res1 = $this->getProject($where,$field);
$result['party'] = 1;
}
//企业
$result['company_id'] = $res['c_id'];
$result['company_name'] = $res['company_name'];
//查找所属领导id,姓名
$leader = $this->getLeader(['id'=>$res['u_l_id']]);
$result['leader'] = $leader['user_login'];
//查询所属项目
if($res1){
$result['project_id'] = $res1['id'];
$result['project_name'] = $res1['project_name'];
}else{
$result['project_id'] = 0;
$result['project_name'] = '';
}
}
}else if($identity == 1){
//领导
$where = ['u_l_id' => $this->userId];
$field = 'id c_id,company_name,pid';
$res = $this->getCompany($where,$field);
//甲方
if($res['pid'] == 0){
$result['identity'] = config('site.a_leader');
$result['party'] = 0;
//获取甲方领导管理的项目
// $res1 = $this->getProjectById(['a_cid'=>$res['c_id']],'id,name project_name');
}else{
//乙方
$result['identity'] = config('site.b_leader');
$result['party'] = 1;
//获取乙方领导管理的项目
// $res1 = $this->getProjectById(['b_cid'=>$res['c_id']],'id,name project_name');
}
//企业
$result['company_id'] = $res['c_id'];
$result['company_name'] = $res['company_name'];
//查询所属项目
// if($res1){
// $result['project'] = $res1;
// }else{
// $result['project'] = $res1;
// }
}else{
$result['identity'] = config('site.a_leaders');
$result['party'] = 0;
}
return $result;
}
//获取领导姓名
public function getLeader($where){
$leader = Db::name('user')
->where($where)
->field('id,user_login,identity')
->find();
return $leader;
}
//报修步骤
public function repairStep($r_id,$step_name){
$stepModel = new StepModel();
$data['r_id'] = $r_id;
$data['step_name'] = $step_name;
$data['create_time'] = time();
$stepModel->create($data);
}
//根据项目id获取乙方项目组人员
public function getUserByProjectId($project_id,$field){
$users = Db::name('project')
->where('id',$project_id)
->field($field)
->find();
$b_sid = explode(',',trim($users['b_sid'],','));
$user_login = Db::name('user')
->whereIn('id',$b_sid)
->where('user_status',1)
->field('id,user_login')
->select()
->toArray();
$users = trim(implode(array_column($user_login,'user_login'),'/'),'/');
return $users;
}
//根据项目id获取甲方项目组人员
public function getUserByProject($project_id,$field){
$users = Db::name('project')
->where('id',$project_id)
->field($field)
->find();
$a_sid = explode(',',trim($users['a_sid'],','));
$user_login = Db::name('user')
->whereIn('id',$a_sid)
->where('user_status',1)
->field('id,user_login')
->select()
->toArray();
return $user_login;
}
//查询是否已有乙方提交维修单流程
public function getStep($id){
$res = Db::name('step')
->where('r_id',$id)
->field('id,step_name')
->order('id desc')
->find();
$step_name = config('site.a_step')[3];
$stepModel = new StepModel();
if($res['step_name'] == $step_name){
//如果有,更新流程日期
$stepModel->where('id',$res['id'])->update(['create_time'=>time()]);
}else{
//如果没有,创建流程
$this->repairStep($id,$step_name);
}
}
//获取月检列表
public function getCheckList($page){
//获取登录人所在的项目
$limit = config('site.limit');
$user = $this->getUserIdentity();
$res = Db::name('check')
->alias('c')
->join('user u','c.uid = u.id','LEFT')
->where(['c.project_id'=>$user['project_id'],'u.user_status'=>1])
->field('c.id,u.user_login,c.status,c.ins_m_time')
->page($page,$limit)
->select()
->toArray();
foreach($res as &$value){
$value['leader'] = $user['leader'];
$value['project_name'] = $user['project_name'];
}
return $res;
}
//根据id查询月检信息
public function getCheckById($where,$field){
$res = Db::name('check')
->where($where)
->field($field)
->find();
return $res;
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
/**
* @title 首页
*/
class IndexController extends RestBaseController
{
/**
* @title 领导,员工首页
* @description 接口说明
* @author 开发者
* @url /api/home/index/index
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return is_work:上班状态(0:下班,1:上班)
* @return identity:身份(1:甲方员工,2:乙方员工,3:甲方领导,4:乙方领导,5:甲方总领导)
* @return company_name:公司名称
* @return service:企业拥有的服务@
* @service id:服务id(1:日常巡检,2:消防月检,3:维修/改造,4:故障报修,5:培训/演习) name:服务名称 icon:图标路径
* @return run_time:0 运行时间
* @return project_name:项目名称
* @return is_project:是否有项目(0:无,1:有)
* @return is_finish:未完成数量(甲乙方员工有此字段)
*/
public function index(){
if($this->request->isGet()){
$common = new CommonController();
$res = $common->getIndexData();
//获取未完成数量
$user = $common->getUserIdentity();
//如果是员工
if($user['identity'] == config('site.a_staff') || $user['identity'] == config('site.b_staff')){
$arr = $common->getInsList();
$res['is_finish'] = $arr['is_finish'];
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 总领导首页
* @description 接口说明
* @author 开发者
* @url /api/home/index/chiefLeaderIndex
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return data: @
* @data id:公司id company_name:甲方公司名称 company_name_head:甲方总公司名称 address:地区 run_time:运行时间 service:服务列表@
* @service id:服务id(1:日常巡检,2:消防月检,3:维修/改造,4:故障报修,5:培训/演习) name:服务名称 icon:图标路径 english_name:英文名称
* @return address: @
* @address id:地区id(和公司id对应) address:地区
*/
public function chiefLeaderIndex(){
if($this->request->isGet()){
$where = ['u_ls_id' => $this->userId];
$field = 'id,company_name,company_name_head,address,logo';
$common = new CommonController();
$res = $common->getTotalCompany($where,$field);
$city = [];
$i = 0;
foreach($res as &$value){
$i+=0;
$where = ['a_cid'=>$value['id']];
$field = 'id,name,create_time';
//查找企业拥有的服务
$data['c_id'] = $value['id'];
$rule = $common->getRule($data);
$value['service'] = $rule;
foreach($value['service'] as &$value1){
$value1['name'] = $value1['name'].'报表';
}
//查询企业拥有的项目
$res1 = $common->getProject($where,$field);
$value['run_time'] = 0;
if($res1){
$value['run_time'] = $common->getRunTime($res1['create_time']);
}
$city[$i]['id'] = $value['id'];
$city[$i]['address'] = $value['address'];
$i++;
}
$arr['data'] = $res;
$arr['address'] = $city;
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\CheckModel;
/**
* @title 消息审批
*/
class InformationController extends RestBaseController
{
/**
* @title 甲方领导消息审批列表
* @description 接口说明
* @author 开发者
* @url /api/home/information/informationList
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:维修改造,3:培训演习)
*
* @return data:列表@
* @data id:列表id project_id:项目id project_name:项目名称 ins_m_time:月检时间 user_group:项目组
* @return type:工作类型 (1:月检,2:维修改造,3:培训演习)
*/
public function informationList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$type = $this->request->get('type');
$rule = config('site.type');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['type'=>$type,'page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果不是甲方领导,则没有权限操作
if($user['identity'] != config('site.a_leader')){
$this->error('无权操作');
}
//查看甲方领导的对应的乙方
if($type == 1){
//月检
$b_company_id = $common->getCompany(['pid'=>$user['company_id']],'id');
$res['data'] = $common->getCheckByCompanyBId($b_company_id['id'],$page);
}else if($type == 2){
//维修改造
}else{
//培新演习
}
//查找乙方项目组下的乙方员工
foreach($res['data'] as &$value){
$value['user_group'] = $common->getUserByProjectId($value['project_id'],'id,b_sid');
}
//工作类型
$res['type'] = $type;
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方领导确认申请
* @description 接口说明
* @author 开发者
* @url /api/home/information/confirm
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:维修改造,3:培训演习)
*/
public function confirm(){
if($this->request->isGet()){
$id = $this->request->get('id');
$type = $this->request->get('type');
$rule = config('site.confirm');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['type'=>$type,'id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果不是甲方领导,则没有权限操作
if($user['identity'] != config('site.a_leader')){
$this->error('无权操作');
}
if($type == 1){
//月检
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$id,'status'=>0])->update(['a_leader'=>$this->userId,'status'=>2,'l_confirm_time'=>time()]);
}else if($type == 2){
//维修改造
}else{
//培新演习
}
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方领导驳回申请
* @description 接口说明
* @author 开发者
* @url /api/home/information/reject
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:维修改造,3:培训演习)
*/
public function reject(){
if($this->request->isGet()){
$id = $this->request->get('id');
$type = $this->request->get('type');
$rule = config('site.confirm');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['type'=>$type,'id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果不是甲方领导,则没有权限操作
if($user['identity'] != config('site.a_leader')){
$this->error('无权操作');
}
if($type == 1){
//月检
$checkModel = new CheckModel();
$data = ['a_leader'=>$this->userId,'status'=>1,'reject_time'=>time()];
$res = $checkModel->where(['id'=>$id,'status'=>0])->update($data);
}else if($type == 2){
//维修改造
}else{
//培新演习
}
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\InspectModel;
/**
* @title 日检
*/
class InspectionController extends RestBaseController
{
/**
* @title 巡检列表
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return id:项目id
* @return project_name:项目名称
* @return point: @
* @point id:巡检点id point_name:巡检名称 status:巡检状态(0:已检查,1:故障,2:未完成)
* @return is_finish: 未完成数量
*/
public function insList(){
if($this->request->isGet()){
$common = new CommonController();
$arr = $common->getInsList();
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 添加巡检页面
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insAdd
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:int require:1 default: other desc:巡检点id
* @return point_id:巡检点id
* @return point_name:巡检点名称
* @return project_id:项目id
* @return project_name:项目名称
*/
public function insAdd(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.ins_add');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
//查询巡检名称
$arr = Db::name('point')
->alias('po')
->join('project p','po.p_id = p.id','LEFT')
->where('po.id',$id)
->field('po.id point_id,po.point_name,p.id project_id,p.name project_name')
->find();
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 添加巡检提交
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insAddPost
* @method POST
*
* @header name:token require:1 default: desc:header
* @param name:point_id type:int require:1 default: other: desc:巡检点id
* @param name:project_id type:int require:1 default: other: desc:项目id
* @param name:status type:int require:1 default: other desc:巡检点状态(0:已检查,1:故障)
* @param name:create_time type:string require:1 default: other desc:巡检时间
* @param name:images type:string require:1 default: other desc:巡检图片
*
*/
public function insAddPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.ins_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
//获取甲方,乙方
$common = new CommonController();
$party = $common->getUserIdentity();
$where = [
'project_id'=>$data['project_id'],
'point_id'=>$data['point_id'],
'create_time'=>$data['create_time'],
'party'=>$party['party']
];
//查询是否已添加巡检
$result = Db::name('inspect')
->where($where)
->find();
if($result){
$this->error('您已提交过巡检点信息!');
}
$data['party'] = $party['party'];
$inspectModel = new InspectModel();
$res = $inspectModel->create($data);
if($res){
$this->success('您的巡检点信息添加成功!');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 编辑巡检页面
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insEdit
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:int require:1 default: other desc:巡检点id
* @return point_id:巡检点id
* @return point_name:巡检点名称
* @return project_id:项目id
* @return project_name:项目名称
* @return status:巡检点状态(0:已检查,1:故障)
* @return images:巡检图片,多张图片以逗号隔开
* @return create_time:巡检时间
*/
public function insEdit(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.ins_add');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
//查询巡检名称
$res = Db::name('point')
->alias('po')
->join('project p','po.p_id = p.id','LEFT')
->join('inspect i','po.id = i.point_id','LEFT')
->where(['po.id'=>$id])
->field('po.id point_id,po.point_name,p.id project_id,p.name project_name,i.status,i.images,i.create_time')
->find();
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 编辑巡检提交
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insEditPost
* @method POST
*
* @header name:token require:1 default: desc:header
* @param name:point_id type:int require:1 default: other: desc:巡检点id
* @param name:project_id type:int require:1 default: other: desc:项目id
* @param name:status type:int require:1 default: other desc:巡检点状态(0:已检查,1:故障)
* @param name:create_time type:string require:1 default: other desc:巡检时间
* @param name:images type:string require:1 default: other desc:巡检图片
*
*/
public function insEditPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.ins_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$arr['status'] = $data['status'];
$arr['images'] = $data['images'];
$inspectModel = new InspectModel();
$time = date('Y-m-d',time());
if($data['create_time'] != $time){
$this->error('只能修改当天的巡检信息');
}
$inspectModel->where(['uid'=>$this->userId,'point_id'=>$data['point_id'],'create_time'=>$time])->update($arr);
$this->success('保存成功!');
}else{
$this->error('请求方式错误!');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\InspectModel;
use app\portal\model\RepairModel;
/**
* @title 报修
*/
class RepairController extends RestBaseController
{
/**
* @title 新增报修提交
* @description 接口说明
* @author 开发者
* @url /api/home/repair/addRepairPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:images type:file require:1 default: other desc:图片凭证
* @param name:video type:file require:1 default: other desc:视频凭证
* @param name:audio type:file require:1 default: other desc:音频凭证
* @param name:description type:string require:1 default: other desc:故障问题描述
*/
public function addRepairPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.repair_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
$data['create_time'] = time();
//获取甲方,乙方
$common = new CommonController();
$party = $common->getUserIdentity();
$data['party'] = $party['party'];
//获取项目id
$project = $common->getUserIdentity();
$data['project_id'] = $project['project_id'];
//查询是否已提价保修单
// $result = Db::name('repair')
// ->where('uid',$this->userId)
// ->find();
// if($result){
// $this->error('您已提交过报修信息!');
// }
$repairModel = new RepairModel();
$res = $repairModel->create($data);
if($res){
$id = $res->id;
$data1['create_time'] = time();
if($party['party'] == 0){
//甲方
$step_name = config('site.a_step')[0];
}else{
//乙方
$step_name = config('site.b_step')[0];
}
$common->repairStep($id,$step_name);
$this->success('您的报修消息提交成功!请等待维修人员确认');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取甲方报修列表
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairAList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:status type:inter require:1 default: other desc:切换状态(全部:-1,处理中(待确认,维修中):1,已完成:2)
* @return data:报修列表@
* @data id:报修id uid:提交人id status:报修状态(0:待确认,1:维修中,2:已完成) description:报修问题 party:甲方,乙方(0:甲方员工,1:乙方员工) create_time:报修时间 user_login:提交员工姓名 confirm:是否有确认按钮(0:无,1:有)
*/
public function repairAList(){
if($this->request->isGet()){
//查询用户所属项目
$page = $this->request->get('page');
$status = $this->request->get('status');//切换状态(全部:-1,处理中:1,已完成:2)
$limit = config('site.limit');
$rule = config('site.pages_list');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['status'=>$status,'page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$project = $common->getUserIdentity();
if($status == 1){
$where = ['project_id' => $project['project_id'], 'status' => ['in',[0,1]]];
}else if($status == 2) {
$where = ['project_id' => $project['project_id'], 'status' => $status];
}else{
$where = ['project_id'=>$project['project_id']];
}
$res = Db::name('repair')
->where($where)
->page($page,$limit)
->field('id,uid,status,description,party,create_time')
->select()
->toArray();
foreach($res as &$value){
//查看用户信息
$user = $common->getUser(['id'=>$value['uid']]);
$value['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//查看是否有确认按钮
$value['confirm'] = 0;
//如果乙方提交报修,甲方有确认按钮
if($value['party'] == 1 && $value['status'] == 0){
//甲方有确认按钮
$value['confirm'] = 1;
}
$value['create_time'] = date('Y-m-d',$value['create_time']);
}
$this->success('成功',['data'=>$res]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取乙方报修列表
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairBList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:status type:inter require:1 default: other desc:切换状态(全部:-1,处理中(待确认,维修中):1,已完成:2)
* @return data:报修列表@
* @data id:报修id h_uid:处理人id status:报修状态(0:待确认,1:维修中,2:已完成) description:报修问题 party:甲方,乙方(0:甲方员工,1:乙方员工) create_time:报修时间 h_user_login:处理员工姓名 confirm:是否有确认按钮(0:无,1:有) title:表头信息
*/
public function repairBList(){
if($this->request->isGet()){
//查询用户所属项目
$page = $this->request->get('page');
$status = $this->request->get('status');//切换状态(全部:-1,处理中:1,已完成:2)
$limit = config('site.limit');
$rule = config('site.pages_list');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['status'=>$status,'page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$project = $common->getUserIdentity();
if($status == 1){
$where = ['project_id' => $project['project_id'], 'status' => ['in',[0,1]]];
}else if($status == 2) {
$where = ['project_id' => $project['project_id'], 'status' => $status];
}else{
$where = ['project_id'=>$project['project_id']];
}
$res = Db::name('repair')
->where($where)
->page($page,$limit)
->field('id,uid,h_uid,status,description,party,create_time,project_id')
->select()
->toArray();
foreach($res as &$value){
//查看处理人用户信息
//如果是甲方提交,处理人为乙方
if($value['party'] == 0) {
$user = $common->getUser(['id' => $value['h_uid']]);
}else{
$user = $common->getUser(['id' => $value['uid']]);
}
$title = $common->getProject(['id'=>$value['project_id']],'name project_name');
//表头信息
$value['title'] = isset($title)&&!empty($title)?$title['project_name'].'报修表':'';
//乙方处理人
$value['h_user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//查看是否有确认按钮
$value['confirm'] = 0;
//如果甲方提交报修,乙方有确认按钮
if($value['party'] == 0 && $value['status'] == 0){
//甲方有确认按钮
$value['confirm'] = 1;
}
$value['create_time'] = date('Y-m-d',$value['create_time']);
}
$this->success('成功',['data'=>$res]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方报修确认
* @description 接口说明
* @author 开发者
* @url /api/home/repair/confirmA
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修id
*/
public function confirmA(){
if($this->request->isGet()){
$id = $this->request->get('id');//报修列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
$this->error('无权操作');
}
$repairModel = new RepairModel();
$res = $repairModel->where(['id'=>$id,'status'=>0])->update(['status'=>1,'h_uid'=>$this->userId]);
if($res){
//甲方确认
$step_name = config('site.b_step')[1];
$common->repairStep($id,$step_name);
//乙方维修
$step_name = config('site.a_step')[2];
$common->repairStep($id,$step_name);
$this->success('成功!');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方报修确认
* @description 接口说明
* @author 开发者
* @url /api/home/repair/confirmB
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修id
*/
public function confirmB(){
if($this->request->isGet()){
$id = $this->request->get('id');//报修列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$repairModel = new RepairModel();
$res = $repairModel->where(['id'=>$id,'status'=>0])->update(['status'=>1,'h_uid'=>$this->userId]);
if($res){
//乙方确认
$step_name = config('site.a_step')[1];
$common->repairStep($id,$step_name);
//乙方维修
$step_name = config('site.a_step')[2];
$common->repairStep($id,$step_name);
$this->success('成功!');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 报修单详情
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairDetail
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修id
*
* @return id:报修id
* @return images:图片凭证
* @return video:视频凭证
* @return audio:音频凭证
* @return description:故障问题
*/
public function repairDetail(){
if($this->request->isGet()){
$id = $this->request->get('id');//报修列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$res = Db::name('repair')
->where('id',$id)
->field('id,images,video,audio,description')
->find();
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 报修流程
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairProcess
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修id
*
* @return data:流程数据@
* @data id:流程id step_name:流程名称 create_time:流程时间
*/
public function repairProcess(){
if($this->request->isGet()){
$id = $this->request->get('id');//报修列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$res = Db::name('step')
->where('r_id',$id)
->field('id,step_name,create_time')
->select()
->toArray();
foreach($res as &$value){
$value['create_time'] = date('Y-m-d',$value['create_time']);
}
$this->success('成功',['data'=>$res]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲乙方完善报修单详情
* @description 接口说明
* @author 开发者
* @url /api/home/repair/improveRepair
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修id
*
* @return user_login:甲方负责人
* @return h_user_login:乙方负责人
* @return create_time:故障报修时间
* @return description:故障描述
* @return repair_images:维修结果照片
* @return update_time:修复时间
* @return user_group:乙方项目组人员
* @return repair_description:备注
* @return confirm_status:甲方确认情况
*/
public function improveRepair(){
if($this->request->isGet()){
$id = $this->request->get('id');//报修列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$res = Db::name('repair')
->where('id',$id)
->find();
//如果是甲方提交报修
$common = new CommonController();
$arr = [];
if($res['party'] == 0){
//甲方负责人
$user = $common->getUser(['id' => $res['uid']]);
$arr['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//乙方负责人
$h_user = $common->getUser(['id' => $res['h_uid']]);
$arr['h_user_login'] = isset($h_user['user_login'])&&!empty($h_user['user_login'])?$h_user['user_login']:'';
}else{
//甲方负责人
$user = $common->getUser(['id' => $res['h_uid']]);
$arr['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//乙方负责人
$h_user = $common->getUser(['id' => $res['uid']]);
$arr['h_user_login'] = isset($h_user['user_login'])&&!empty($h_user['user_login'])?$h_user['user_login']:'';
}
//甲方确认情况
if($res['status'] == 2){
$arr['confirm_status'] = '已确认';
}else{
$arr['confirm_status'] = '未确认';
}
//故障报修时间
$arr['create_time'] = date('Y-m-d',$res['create_time']);
//故障描述
$arr['description'] = $res['description'];
//维修结果照片
$arr['repair_images'] = $res['repair_images'];
//修复时间
$arr['update_time'] = !empty($res['update_time'])?date('Y-m-d',$res['update_time']):'';
//查询乙方项目组人员
$arr['user_group'] = $common->getUserByProjectId($res['project_id'],'id,b_sid');
//维修结果备注
$arr['repair_description'] = $res['repair_description'];
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲乙方完善报修单提交
* @description 接口说明
* @author 开发者
* @url /api/home/repair/improveRepairPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修单id
* @param name:repair_images type:file require:1 default: other desc:报修照片
* @param name:repair_description type:string require:1 default: other desc:报修备注
*/
public function improveRepairPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.improve_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$repairModel = new RepairModel();
$res = $repairModel->where(['id'=>$data['id'],'status'=>1])->update(['repair_images'=>$data['repair_images'],'repair_description'=>$data['repair_description'],'update_time'=>time()]);
if($res){
//创建流程或更新流程日期
$common = new CommonController();
$common->getStep($data['id']);
$this->success('保存成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方验收维修结果
* @description 接口说明
* @author 开发者
* @url /api/home/repair/checkRepairPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修单id
* @param name:confirm_images type:file require:1 default: other desc:验收照片
*/
public function checkRepairPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.check_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
//如果是乙方,则无权操作
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
$this->error('无权操作');
}
$repairModel = new RepairModel();
$arr = ['confirm_images'=>$data['confirm_images'],'confirm_uid'=>$this->userId,'finish_time'=>time(),'status'=>2];
$res = $repairModel->where(['id'=>$data['id'],'status'=>1])->update($arr);
if($res){
//创建完成流程
$step_name = config('site.a_step')[4];
$common->repairStep($data['id'],$step_name);
$step_name = config('site.a_step')[5];
$common->repairStep($data['id'],$step_name);
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// API 模板文件,可以复制
namespace api\home\controller;
use cmf\controller\RestBaseController;
class RestController extends RestBaseController
{
/**
* 显示资源列表
*/
public function index()
{
}
/**
* 保存新建的资源
*/
public function save()
{
}
/**
* 显示指定的资源
*
* @param int $id
*/
public function read($id)
{
}
/**
* 保存更新的资源
*
* @param int $id
*/
public function update($id)
{
}
/**
* 删除指定资源
*
* @param int $id
*/
public function delete($id)
{
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\controller;
use api\home\model\SlideModel;
use cmf\controller\RestBaseController;
class SlidesController extends RestBaseController
{
/**
* [获取幻灯片]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T20:48:53+0800
* @since: 1.0
*/
public function read()
{
//slide为空或不存在抛出异常
$id = $this->request->param('id', 0, 'intval');
if (empty($id)) {
$this->error('缺少ID参数');
}
$map['id'] = $id;
$obj = new SlideModel();
$data = $obj->SlideList($map);
//剔除分类状态隐藏 剔除分类下显示数据为空
if (empty($data) || $data['items']->isEmpty()) {
$this->error('该组幻灯片显示数据为空');
}
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = [$data];
} else {
$response = $data;
}
$this->success("该组幻灯片获取成功!", $response);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace api\home\controller;
use api\home\model\ThemeFileModel;
use cmf\controller\RestBaseController;
class ThemeController extends RestBaseController
{
/**
* 获取模板扩展属性
*/
public function more()
{
$theme = $this->request->param('theme');
$themeFileModel = new ThemeFileModel();
$file = $this->request->param('file');
$file = $themeFileModel->where('theme', $theme)->where('file', $file)->find();
$vars = [];
$widgets = [];
$oldMore = $file['more'];
if (!empty($oldMore['vars'])) {
foreach ($oldMore['vars'] as $varName => $var) {
switch ($var['type']) {
case 'image':
$vars[$varName] = cmf_get_image_url($var['value']);
break;
case 'file':
$vars[$varName] = cmf_get_file_download_url($var['value']);
break;
case 'array':
foreach ($var['value'] as $varKey => $varValue) {
foreach ($varValue as $varValueKey => $varValueValue) {
switch ($var['item'][$varValueKey]['type']) {
case 'image':
$var['value'][$varKey][$varValueKey] = cmf_get_image_url($varValueValue);
break;
case 'file':
$var['value'][$varKey][$varValueKey] = cmf_get_file_download_url($varValueValue);
break;
default:
$var['value'][$varKey][$varValueKey] = $varValueValue;
}
}
}
$vars[$varName] = $var['value'];
break;
default:
$vars[$varName] = $var['value'];
}
}
}
if (!empty($oldMore['widgets'])) {
foreach ($oldMore['widgets'] as $widgetName => $widget) {
$widgetVars = [];
if (!empty($widget['vars'])) {
foreach ($widget['vars'] as $varName => $var) {
switch ($var['type']) {
case 'image':
$widgetVars[$varName] = cmf_get_image_url($var['value']);
break;
case 'file':
$widgetVars[$varName] = cmf_get_file_download_url($var['value']);
break;
case 'array':
foreach ($var['value'] as $varKey => $varValue) {
foreach ($varValue as $varValueKey => $varValueValue) {
switch ($var['item'][$varValueKey]['type']) {
case 'image':
$var['value'][$varKey][$varValueKey] = cmf_get_image_url($varValueValue);
break;
case 'file':
$var['value'][$varKey][$varValueKey] = cmf_get_file_download_url($varValueValue);
break;
default:
$var['value'][$varKey][$varValueKey] = $varValueValue;
}
}
}
$widgetVars[$varName]=$var['value'];
break;
default:
$widgetVars[$varName] = $var['value'];
}
}
}
$widget['vars'] = $widgetVars;
$widgets[$widgetName] = $widget;
}
}
$this->success('success', [
'vars' => $vars,
'widgets' => $widgets
]);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\TrainModel;
/**
* @title 培训演习
*/
class TrainController extends RestBaseController
{
/**
* @title 甲方提交培训演习申请
* @description 接口说明
* @author 开发者
* @url /api/home/train/applyTrain
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:train_time type:string require:1 default: other desc:培训时间
* @param name:address type:string require:1 default: other desc:培训地点
* @param name:remark type:string require:1 default: other desc:培训备注
*/
public function applyTrain(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
$this->error('无权操作');
}
$rule = config('site.train_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
$data['project_id'] = $user['project_id'];
$data['create_time'] = time();
$trainModel = new TrainModel();
$res = $trainModel->create($data);
if($res){
$this->success('培训信息提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:用户-幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\model;
use think\Model;
class SlideItemModel extends Model
{
/**
* [base 全局查询范围status=1显示状态]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T21:54:03+0800
* @since: 1.0
*/
protected function base($query)
{
$query->where('status', 1);
}
/**
* image 自动转化
* @param $value
* @return array
*/
public function getImageAttr($value)
{
return cmf_get_image_url($value);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:用户-幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\model;
use think\Model;
class SlideModel extends Model
{
/**
* [base 全局查询范围status=1显示状态]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T21:54:03+0800
* @since: 1.0
*/
protected function base($query)
{
$query->where('status', 1)->where('delete_time', 0);
}
/**
* [SlideItemModel 一对一关联模型 关联分类下的幻灯片]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T23:30:27+0800
* @since: 1.0
*/
protected function items()
{
return $this->hasMany('SlideItemModel')->order('list_order ASC');
}
/**
* [SlideList 幻灯片获取]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T20:52:27+0800
* @since: 1.0
*/
public function SlideList($map)
{
$data = $this->relation('items')->field(true)->where($map)->find();
return $data;
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:用户-幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\model;
use think\Model;
class ThemeFileModel extends Model
{
//类型转换
protected $type = [
'more' => 'array',
];
}
... ...
<?php
use think\Route;
Route::resource('home/slides', 'home/Slides');
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use api\user\model\UserFavoriteModel;
use api\user\model\UserLikeModel;
use cmf\controller\RestBaseController;
use api\portal\model\PortalPostModel;
use think\Db;
class ArticlesController extends RestBaseController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* 文章列表
*/
public function index()
{
$params = $this->request->get();
$params['where']['post_type'] = 1;
$data = $this->postModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data,];
}
$this->success('请求成功!', $response);
}
/**
* 获取指定的文章
* @param int $id
*/
public function read($id)
{
if (intval($id) === 0) {
$this->error('无效的文章id!');
} else {
$params = $this->request->get();
$params['where']['post_type'] = 1;
$params['id'] = $id;
$data = $this->postModel->getDatas($params);
if (empty($data)) {
$this->error('文章不存在!');
} else {
$this->postModel->where('id', $id)->setInc('post_hits');
$url = cmf_url('portal/Article/index', ['id' => $id, 'cid' => $data['categories'][0]['id']], true, true);
$data = $data->toArray();
$data['url'] = $url;
$this->success('请求成功!', $data);
}
}
}
/**
* 我的文章列表
*/
public function my()
{
$params = $this->request->get();
$userId = $this->getUserId();
$data = $this->postModel->getUserArticles($userId, $params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = [$data];
} else {
$response = ['list' => $data];
}
$this->success('请求成功!', $response);
}
/**
* 添加文章
*/
public function save()
{
$data = $this->request->post();
$data['user_id'] = $this->getUserId();
$result = $this->validate($data, 'Articles.article');
if ($result !== true) {
$this->error($result);
}
if (empty($data['published_time'])) {
$data['published_time'] = time();
}
$this->postModel->addArticle($data);
$this->success('添加成功!');
}
/**
* 更新文章
* @param int $id
*/
public function update($id)
{
$data = $this->request->put();
$result = $this->validate($data, 'Articles.article');
if ($result !== true) {
$this->error($result);
}
if (empty($id)) {
$this->error('无效的文章id');
}
$result = $this->postModel->editArticle($data, $id, $this->getUserId());
if ($result === false) {
$this->error('编辑失败!');
} else {
$this->success('编辑成功!');
}
}
/**
* 删除文章
* @param int $id
*/
public function delete($id)
{
if (empty($id)) {
$this->error('无效的文章id');
}
$result = $this->postModel->deleteArticle($id, $this->getUserId());
if ($result == -1) {
$this->error('文章已删除');
}
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败!');
}
}
/**
* 批量删除文章
*/
public function deletes()
{
$ids = $this->request->post('ids/a');
if (empty($ids)) {
$this->error('文章id不能为空');
}
$result = $this->postModel->deleteArticle($ids, $this->getUserId());
if ($result == -1) {
$this->error('文章已删除');
}
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败!');
}
}
public function search()
{
$params = $this->request->get();
if (!empty($params['keyword'])) {
$params['where'] = [
'post_type' => 1,
'post_title|post_keywords|post_excerpt' => ['like', '%' . $params['keyword'] . '%']
];
$data = $this->postModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data,];
}
$this->success('请求成功!', $response);
} else {
$this->error('搜索关键词不能为空!');
}
}
public function doLike()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userLikeModel = new UserLikeModel();
$findLikeCount = $userLikeModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (empty($findLikeCount)) {
$article = $this->postModel->where(['id' => $articleId])->field('id,post_title,post_excerpt,more')->find();
if (empty($article)) {
$this->error('文章不存在!');
}
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setInc('post_like');
$thumbnail = empty($article['more']['thumbnail']) ? '' : $article['more']['thumbnail'];
$userLikeModel->insert([
'user_id' => $userId,
'object_id' => $articleId,
'table_name' => 'portal_post',
'title' => $article['post_title'],
'thumbnail' => $thumbnail,
'description' => $article['post_excerpt'],
'url' => json_encode(['action' => 'portal/Article/index', 'param' => ['id' => $articleId, 'cid' => $article['categories'][0]['id']]]),
'create_time' => time()
]);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('点赞失败!');
}
$likeCount = $this->postModel->where('id', $articleId)->value('post_like');
$this->success("赞好啦!", ['post_like' => $likeCount]);
} else {
$this->error("您已赞过啦!");
}
}
/**
* 取消文章点赞
*/
public function cancelLike()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userLikeModel = new UserLikeModel();
$findLikeCount = $userLikeModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (!empty($findLikeCount)) {
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setDec('post_like');
$userLikeModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->delete();
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('取消点赞失败!');
}
$likeCount = $this->postModel->where('id', $articleId)->value('post_like');
$this->success("取消点赞成功!", ['post_like' => $likeCount]);
} else {
$this->error("您还没赞过!");
}
}
/**
* 文章收藏
* @throws \think\Exception
*/
public function doFavorite()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userFavoriteModel = new UserFavoriteModel();
$findFavoriteCount = $userFavoriteModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (empty($findFavoriteCount)) {
$article = $this->postModel->where(['id' => $articleId])->field('id,post_title,post_excerpt,more')->find();
if (empty($article)) {
$this->error('文章不存在!');
}
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setInc('post_favorites');
$thumbnail = empty($article['more']['thumbnail']) ? '' : $article['more']['thumbnail'];
$userFavoriteModel->insert([
'user_id' => $userId,
'object_id' => $articleId,
'table_name' => 'portal_post',
'thumbnail' => $thumbnail,
'title' => $article['post_title'],
'description' => $article['post_excerpt'],
'url' => json_encode(['action' => 'portal/Article/index', 'param' => ['id' => $articleId, 'cid' => $article['categories'][0]['id']]]),
'create_time' => time()
]);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('收藏失败!');
}
$favoriteCount = $this->postModel->where('id', $articleId)->value('post_favorites');
$this->success("收藏好啦!", ['post_favorites' => $favoriteCount]);
} else {
$this->error("您已收藏过啦!");
}
}
/**
* 取消文章收藏
*/
public function cancelFavorite()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userFavoriteModel = new UserFavoriteModel();
$findFavoriteCount = $userFavoriteModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (!empty($findFavoriteCount)) {
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setDec('post_favorites');
$userFavoriteModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->delete();
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('取消失败!');
}
$favoriteCount = $this->postModel->where('id', $articleId)->value('post_favorites');
$this->success("取消成功!", ['post_favorites' => $favoriteCount]);
} else {
$this->error("您还没收藏过!");
}
}
/**
* 相关文章列表
*/
public function relatedArticles()
{
$articleId = $this->request->param('id', 0, 'intval');
$categoryId = Db::name('portal_category_post')->where('post_id', $articleId)->value('category_id');
$articles = $this->postModel->alias('post')->join('__PORTAL_CATEGORY_POST__ category_post', 'post.id=category_post.post_id')
->where(['post.delete_time' => 0, 'post.post_status' => 1, 'category_post.category_id' => $categoryId])
->order(Db::raw('rand()'))
->limit(5)
->select();
$this->success('success', ['list' => $articles]);
}
}
\ No newline at end of file
... ...