9 changed files with 373 additions and 24 deletions
-
1.example.env
-
18app/controller/ArticleController.php
-
17app/controller/Index.php
-
9app/model/Article.php
-
164app/model/BaseModel.php
-
3composer.json
-
179composer.lock
-
4config/database.php
-
2route/app.php
@ -1 +0,0 @@ |
|||
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = username
PASSWORD = password
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn |
|||
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
class ArticleController |
|||
{ |
|||
|
|||
public function sendArticle() |
|||
{ |
|||
$list = Article::field("*")->select()->toArray(); |
|||
foreach($list as $value) { |
|||
dd(1231); |
|||
$content = json_decode(htmlspecialchars_decode($value['content']), true); |
|||
$tmp = new \PhpOffice\PhpWord\TemplateProcessor('tmp.docx');//打开模板
|
|||
$tmp->setValue('name', '李四');//替换变量name
|
|||
$tmp->setValue('mobile', '18888888888');//替换变量mobile
|
|||
$tmp->saveAs('简历.docx'); |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
<?php |
|||
namespace app\controller; |
|||
|
|||
use app\BaseController; |
|||
|
|||
class Index extends BaseController |
|||
{ |
|||
public function index() |
|||
{ |
|||
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>'; |
|||
} |
|||
|
|||
public function hello($name = 'ThinkPHP6') |
|||
{ |
|||
return 'hello,' . $name; |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
<?php |
|||
|
|||
use app\model\BaseModel; |
|||
|
|||
class Article extends BaseModel |
|||
{ |
|||
protected $table ='article'; |
|||
|
|||
} |
|||
@ -0,0 +1,164 @@ |
|||
<?php |
|||
|
|||
namespace app\model; |
|||
use app\model\admin\Admin; |
|||
use think\Model; |
|||
/** |
|||
* @mixin think\Model |
|||
*/ |
|||
class BaseModel extends Model |
|||
{ |
|||
// 可写入字段
|
|||
protected $createFields = []; |
|||
// 可更新字段
|
|||
protected $updateFields = []; |
|||
|
|||
/** |
|||
* 模型事件 |
|||
*/ |
|||
// 查询后
|
|||
public static function onAfterRead($M){ |
|||
|
|||
} |
|||
// 写入前
|
|||
public static function onBeforeWrite($M){ |
|||
// 过滤可写入字段
|
|||
if (!empty($M->createFields)) { |
|||
$M->allowField($M->createFields); |
|||
} |
|||
} |
|||
|
|||
// 更新前
|
|||
public static function onBeforeUpdate($M){ |
|||
// 过滤可更新字段
|
|||
if (!empty($M->updateFields)) { |
|||
$M->allowField($M->updateFields); |
|||
} |
|||
} |
|||
|
|||
// 定义全局的查询范围
|
|||
|
|||
/** |
|||
* 封装简化查询范围(更加语义化,重要) |
|||
*/ |
|||
// 开启状态
|
|||
public function scopeStatus($query,$status = 1){ |
|||
$query->where('status',$status); |
|||
} |
|||
|
|||
// 搜索器(非常重要)
|
|||
// 创建时间
|
|||
public function searchCreateTimeAttr($query, $value, $data) |
|||
{ |
|||
$query->whereBetweenTime('create_time', $value[0], $value[1]); |
|||
} |
|||
|
|||
// 更新时间
|
|||
public function searchUpdateTimeAttr($query, $value, $data) |
|||
{ |
|||
$query->whereBetweenTime('update_time', $value[0], $value[1]); |
|||
} |
|||
|
|||
// 获取器(处理输出字段)
|
|||
// 常用增删改查方法
|
|||
/** |
|||
* 1. 修改状态 |
|||
* 前提: |
|||
* (1) 参数:id和status |
|||
* (2) 使用 validate 的isExist |
|||
*/ |
|||
public function _UpdateStatus() |
|||
{ |
|||
$request = request(); |
|||
return $request->Model->save([ |
|||
'status'=>$request->param('status') |
|||
]); |
|||
} |
|||
|
|||
// 判断当前用户是否有操作该信息的权限
|
|||
public function __checkActionAuth(){ |
|||
$request = request(); |
|||
if ($request->Model->user_id !== $request->UserModel->id) { |
|||
return ApiException('非法操作'); |
|||
} |
|||
} |
|||
|
|||
// 获取文件完整url
|
|||
public function getFileUrl($url='') |
|||
{ |
|||
if (!$url) return; |
|||
//return url($url,'',false,true);
|
|||
return $url; |
|||
} |
|||
|
|||
|
|||
// 列表
|
|||
public function Mlist(){ |
|||
$param = request()->param(); |
|||
$limit = intval(getValByKey('limit',$param,10)); |
|||
$page = intval(getValByKey('page',$param,1)); |
|||
$totalCount = $this->count(); |
|||
$list = $this->page($page,$limit)->order([ |
|||
'order'=>'desc', |
|||
'id'=>'desc' |
|||
])->select(); |
|||
return [ |
|||
'list'=>$list, |
|||
'totalCount'=>$totalCount |
|||
]; |
|||
} |
|||
// 创建
|
|||
public function Mcreate(){ |
|||
return $this->create(request()->param()); |
|||
} |
|||
// 修改
|
|||
public function Mupdate(){ |
|||
$param = request()->param(); |
|||
return request()->Model->save($param); |
|||
} |
|||
// 删除
|
|||
public function Mdelete(){ |
|||
return request()->Model->delete(); |
|||
} |
|||
|
|||
public function MdeleteAll(){ |
|||
$param = request()->param('ids'); |
|||
// 找到所有数据并删除
|
|||
return $this->where('id','in',$param)->delete(); |
|||
} |
|||
|
|||
|
|||
//根据token 判断是用户端还是后台 编辑
|
|||
public function setAuthorAttr($value,$data) |
|||
{ |
|||
$token=request()->header('token'); |
|||
// 获取用户信息
|
|||
$user = cms_getUser([ |
|||
'token'=>$token, |
|||
'tag'=>'user' |
|||
]); |
|||
if($user['id']){ |
|||
if(isset($data['id'])&&$data['id']){ |
|||
$this->set('update_user',$data['author']); |
|||
}else{ |
|||
$this->set('create_user',$data['author']); |
|||
} |
|||
} else { |
|||
if(isset($data['id'])&&$data['id']){ |
|||
$this->set('update_author',$data['author']); |
|||
}else{ |
|||
$this->set('create_author',$data['author']); |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
protected $append = [ |
|||
// 'create_author'=>'create_author_text',
|
|||
// 'create_user'=>'create_user_text',
|
|||
// 'update_author'=>'update_author_text',
|
|||
// 'update_user'=>'update_user_text',
|
|||
]; |
|||
|
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue