作者 liyuhang

gx

@@ -26,11 +26,9 @@ class ComController extends BaseController @@ -26,11 +26,9 @@ class ComController extends BaseController
26 'mobile'=>['required'], 26 'mobile'=>['required'],
27 'password'=>['required'], 27 'password'=>['required'],
28 ],[ 28 ],[
29 - 'mobile.required'=>'标题必须填写',  
30 - 'mobile.string'=>'标题中含有非法文字', 29 + 'mobile.required'=>'电话号码必须填写',
31 'password.required'=>'内容必须填写', 30 'password.required'=>'内容必须填写',
32 - 'password.string'=>'内容中含有非法文字',  
33 - 'mobile.max' => 'account不大于12字符.', 31 + 'mobile.max' => 'mobile不大于12字符.',
34 ]); 32 ]);
35 $userModel = new UserModel(); 33 $userModel = new UserModel();
36 $res = $userModel->login($this->param); 34 $res = $userModel->login($this->param);
@@ -19,12 +19,14 @@ class BaseLogic extends Logic @@ -19,12 +19,14 @@ class BaseLogic extends Logic
19 19
20 protected $param; 20 protected $param;
21 21
  22 + protected $request;
  23 +
22 protected $user; 24 protected $user;
23 25
24 public function __construct() 26 public function __construct()
25 { 27 {
  28 + $this->request = request();
26 $this->requestAll = request()->all(); 29 $this->requestAll = request()->all();
27 -  
28 $this->user = Cache::get(request()->header('token')); 30 $this->user = Cache::get(request()->header('token'));
29 } 31 }
30 32
@@ -93,14 +95,14 @@ class BaseLogic extends Logic @@ -93,14 +95,14 @@ class BaseLogic extends Logic
93 * @author :liyuhang 95 * @author :liyuhang
94 * @method 96 * @method
95 */ 97 */
96 - public function upload(Request $request,ImageModel $imageModel){  
97 - $image = $request->file('image'); 98 + public function upload(){
  99 + $image = $this->request->file('image');
98 if(empty($image)){ 100 if(empty($image)){
99 return $this->fail('没有上传图片',Code::USER_ERROR); 101 return $this->fail('没有上传图片',Code::USER_ERROR);
100 } 102 }
101 $url = './../uploads/images/'; 103 $url = './../uploads/images/';
102 $filename = date('ymdHis').rand(10000,99999); 104 $filename = date('ymdHis').rand(10000,99999);
103 - $res = $request->file('image')->move($url,$filename); 105 + $res = $this->request->file('image')->move($url,$filename);
104 if ($res === false) { 106 if ($res === false) {
105 return $this->fail($image->getError(), Code::USER_ERROR); 107 return $this->fail($image->getError(), Code::USER_ERROR);
106 } 108 }
@@ -112,6 +114,7 @@ class BaseLogic extends Logic @@ -112,6 +114,7 @@ class BaseLogic extends Logic
112 'type'=>$image->getClientOriginalExtension(), 114 'type'=>$image->getClientOriginalExtension(),
113 // 'mime'=>$image->getMimeType() 115 // 'mime'=>$image->getMimeType()
114 ]; 116 ];
  117 + $imageModel = new ImageModel();
115 $rs = $imageModel->add($data); 118 $rs = $imageModel->add($data);
116 if ($rs === false) { 119 if ($rs === false) {
117 return $this->fail('添加失败', Code::USER_ERROR); 120 return $this->fail('添加失败', Code::USER_ERROR);
@@ -51,16 +51,19 @@ class BlogLogic extends BaseLogic @@ -51,16 +51,19 @@ class BlogLogic extends BaseLogic
51 * @method 51 * @method
52 */ 52 */
53 public function blog_add(){ 53 public function blog_add(){
54 - $this->param['create_id'] = $this->uid;  
55 - $this->param['operator_id'] = $this->uid; 54 + $this->param['create_id'] = $this->user['id'];
  55 + $this->param['operator_id'] = $this->user['id'];
56 $this->param['project_id'] = $this->user['project_id']; 56 $this->param['project_id'] = $this->user['project_id'];
  57 + $this->param['created_at'] = date('Y-m-d H:i:s',time());
  58 + $this->param['updated_at'] = date('Y-m-d H:i:s',time());
  59 + $this->param['category_id'] = ','.$this->param['category_id'].',';
57 DB::beginTransaction(); 60 DB::beginTransaction();
58 try { 61 try {
59 if(isset($this->param['image'])){ 62 if(isset($this->param['image'])){
60 $data = $this->upload(); 63 $data = $this->upload();
61 $this->param['image'] = $data; 64 $this->param['image'] = $data;
62 } 65 }
63 - $rs = $this->model->insertGetId($this->param); 66 + $this->model->insertGetId($this->param);
64 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']); 67 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
65 DB::commit(); 68 DB::commit();
66 }catch (\Exception $e){ 69 }catch (\Exception $e){
@@ -53,22 +53,26 @@ class NewsLogic extends BaseLogic @@ -53,22 +53,26 @@ class NewsLogic extends BaseLogic
53 * @method 53 * @method
54 */ 54 */
55 public function news_add(){ 55 public function news_add(){
56 - $this->param['create_id'] = $this->uid;  
57 - $this->param['operator_id'] = $this->uid; 56 + $this->param['create_id'] = $this->user['id'];
  57 + $this->param['operator_id'] = $this->user['id'];
58 $this->param['project_id'] = $this->user['project_id']; 58 $this->param['project_id'] = $this->user['project_id'];
  59 + $this->param['created_at'] = date('Y-m-d H:i:s',time());
  60 + $this->param['updated_at'] = date('Y-m-d H:i:s',time());
  61 + $this->param['category_id'] = ','.$this->param['category_id'].',';
59 DB::beginTransaction(); 62 DB::beginTransaction();
60 try { 63 try {
61 if(isset($this->param['image'])){ 64 if(isset($this->param['image'])){
62 $data = $this->upload(); 65 $data = $this->upload();
63 $this->param['image'] = $data; 66 $this->param['image'] = $data;
64 } 67 }
65 - $rs = $this->model->insertGetId($this->param); 68 + $this->model->insertGetId($this->param);
66 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); 69 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
67 DB::commit(); 70 DB::commit();
68 }catch (\Exception $e){ 71 }catch (\Exception $e){
69 DB::rollBack(); 72 DB::rollBack();
70 - $this->fail('error',Code::USER_ERROR); 73 + $this->fail('添加失败',Code::USER_ERROR);
71 } 74 }
  75 +
72 //TODO::写入日志 76 //TODO::写入日志
73 $this->success(); 77 $this->success();
74 } 78 }