作者 liyuhang

gx

... ... @@ -26,11 +26,9 @@ class ComController extends BaseController
'mobile'=>['required'],
'password'=>['required'],
],[
'mobile.required'=>'标题必须填写',
'mobile.string'=>'标题中含有非法文字',
'mobile.required'=>'电话号码必须填写',
'password.required'=>'内容必须填写',
'password.string'=>'内容中含有非法文字',
'mobile.max' => 'account不大于12字符.',
'mobile.max' => 'mobile不大于12字符.',
]);
$userModel = new UserModel();
$res = $userModel->login($this->param);
... ...
... ... @@ -19,12 +19,14 @@ class BaseLogic extends Logic
protected $param;
protected $request;
protected $user;
public function __construct()
{
$this->request = request();
$this->requestAll = request()->all();
$this->user = Cache::get(request()->header('token'));
}
... ... @@ -93,14 +95,14 @@ class BaseLogic extends Logic
* @author :liyuhang
* @method
*/
public function upload(Request $request,ImageModel $imageModel){
$image = $request->file('image');
public function upload(){
$image = $this->request->file('image');
if(empty($image)){
return $this->fail('没有上传图片',Code::USER_ERROR);
}
$url = './../uploads/images/';
$filename = date('ymdHis').rand(10000,99999);
$res = $request->file('image')->move($url,$filename);
$res = $this->request->file('image')->move($url,$filename);
if ($res === false) {
return $this->fail($image->getError(), Code::USER_ERROR);
}
... ... @@ -112,6 +114,7 @@ class BaseLogic extends Logic
'type'=>$image->getClientOriginalExtension(),
// 'mime'=>$image->getMimeType()
];
$imageModel = new ImageModel();
$rs = $imageModel->add($data);
if ($rs === false) {
return $this->fail('添加失败', Code::USER_ERROR);
... ...
... ... @@ -51,16 +51,19 @@ class BlogLogic extends BaseLogic
* @method
*/
public function blog_add(){
$this->param['create_id'] = $this->uid;
$this->param['operator_id'] = $this->uid;
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s',time());
$this->param['updated_at'] = date('Y-m-d H:i:s',time());
$this->param['category_id'] = ','.$this->param['category_id'].',';
DB::beginTransaction();
try {
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data;
}
$rs = $this->model->insertGetId($this->param);
$this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
... ...
... ... @@ -53,22 +53,26 @@ class NewsLogic extends BaseLogic
* @method
*/
public function news_add(){
$this->param['create_id'] = $this->uid;
$this->param['operator_id'] = $this->uid;
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s',time());
$this->param['updated_at'] = date('Y-m-d H:i:s',time());
$this->param['category_id'] = ','.$this->param['category_id'].',';
DB::beginTransaction();
try {
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data;
}
$rs = $this->model->insertGetId($this->param);
$this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
$this->fail('添加失败',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
... ...