diff --git a/app/Common/function.php b/app/Common/function.php index 2eb4385..7f8b233 100644 --- a/app/Common/function.php +++ b/app/Common/function.php @@ -1155,7 +1155,35 @@ function http_host($flag=true) return $res; } - +/** + * 获取数据属性 + * @param $dataModel 数据模型 + * @param $data 数据 + * @return array + */ +function getDataAttr($dataModel,$data = []) +{ + if(empty($dataModel) || empty($data)) + { + return false; + } + + foreach($data as $k=>$v) + { + $_method_str=ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) { + return strtoupper($match[1]); + }, $k)); + + $_method = 'get' . $_method_str . 'Attr'; + + if(method_exists($dataModel, $_method)) + { + $data[$k.'_text'] = $dataModel::$_method($data); + } + } + + return $data; +} diff --git a/app/Http/Controllers/Admin/ArticleController.php b/app/Http/Controllers/Admin/ArticleController.php index 9803ea7..45f5a22 100644 --- a/app/Http/Controllers/Admin/ArticleController.php +++ b/app/Http/Controllers/Admin/ArticleController.php @@ -4,8 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Admin\CommonController; use DB; use Illuminate\Http\Request; -use App\Http\Requests\ArticleRequest; -use Validator; +use App\Http\Logic\ArticleLogic; class ArticleController extends CommonController { @@ -14,6 +13,11 @@ class ArticleController extends CommonController parent::__construct(); } + public function getLogic() + { + return new ArticleLogic(); + } + public function index() { $res = ''; @@ -39,13 +43,7 @@ class ArticleController extends CommonController } }; - $posts = parent::pageList('article', $where); - foreach($posts as $key=>$value) - { - $info = DB::table('arctype')->select('name')->where("id", $value->typeid)->first(); - $posts[$key]->name = $info->name; - $posts[$key]->body = ''; - } + $posts = $this->getLogic()->getPaginate($where); $data['posts'] = $posts; diff --git a/app/Http/Logic/ArctypeLogic.php b/app/Http/Logic/ArctypeLogic.php new file mode 100644 index 0000000..fa9001d --- /dev/null +++ b/app/Http/Logic/ArctypeLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/ArticleLogic.php b/app/Http/Logic/ArticleLogic.php new file mode 100644 index 0000000..6920297 --- /dev/null +++ b/app/Http/Logic/ArticleLogic.php @@ -0,0 +1,134 @@ +getSceneRules($scene_name), $validate->getSceneRulesMessages()); + } + + //列表 + public function getList($where = array(), $order = '', $field = '*', $offset = '', $limit = '') + { + $res = Article::getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + $res['list'][$k]['typename'] = Article::getTypenameAttr(array('typeid'=>$v->typeid)); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = Article::getPaginate($where, $order, $field, $limit); + foreach($res as $k=>$v) + { + $res[$k]->typename = Article::getTypenameAttr(array('typeid'=>$v->typeid)); + } + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = Article::getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = Article::getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + $res['typename'] = Article::getTypenameAttr(array('typeid'=>$res->typeid)); + + Article::getDb()->increment('click', 1); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $validator = $this->getValidate($_REQUEST,'add'); + if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());} + + $res = Article::add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = Article::edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $validator = $this->getValidate($where,'del'); + if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());} + + $res = Article::del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/BaseLogic.php b/app/Http/Logic/BaseLogic.php new file mode 100644 index 0000000..ca0749b --- /dev/null +++ b/app/Http/Logic/BaseLogic.php @@ -0,0 +1,10 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/FriendlinkLogic.php b/app/Http/Logic/FriendlinkLogic.php new file mode 100644 index 0000000..ccafb5c --- /dev/null +++ b/app/Http/Logic/FriendlinkLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/GoodsBrandLogic.php b/app/Http/Logic/GoodsBrandLogic.php new file mode 100644 index 0000000..857da95 --- /dev/null +++ b/app/Http/Logic/GoodsBrandLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/GoodsLogic.php b/app/Http/Logic/GoodsLogic.php new file mode 100644 index 0000000..fc89d7f --- /dev/null +++ b/app/Http/Logic/GoodsLogic.php @@ -0,0 +1,127 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + $res['list'][$k]['typename'] = $this->getModel()->getTypenameAttr($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + $res['typename'] = $this->getModel()->getTypenameAttr($res); + + $this->getModel()->getDb()->where($where)->setInc('click', 1); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/GoodsTypeLogic.php b/app/Http/Logic/GoodsTypeLogic.php new file mode 100644 index 0000000..cd630a4 --- /dev/null +++ b/app/Http/Logic/GoodsTypeLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/GuestbookLogic.php b/app/Http/Logic/GuestbookLogic.php new file mode 100644 index 0000000..3c9d1ae --- /dev/null +++ b/app/Http/Logic/GuestbookLogic.php @@ -0,0 +1,125 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + $this->getModel()->getDb()->where($where)->setInc('click', 1); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/PageLogic.php b/app/Http/Logic/PageLogic.php new file mode 100644 index 0000000..ce3bf19 --- /dev/null +++ b/app/Http/Logic/PageLogic.php @@ -0,0 +1,125 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + $this->getModel()->getDb()->where($where)->setInc('click', 1); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/PaymentLogic.php b/app/Http/Logic/PaymentLogic.php new file mode 100644 index 0000000..6d96e61 --- /dev/null +++ b/app/Http/Logic/PaymentLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/RegionLogic.php b/app/Http/Logic/RegionLogic.php new file mode 100644 index 0000000..3c677fa --- /dev/null +++ b/app/Http/Logic/RegionLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/SlideLogic.php b/app/Http/Logic/SlideLogic.php new file mode 100644 index 0000000..b30e0bc --- /dev/null +++ b/app/Http/Logic/SlideLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/SmsLogLogic.php b/app/Http/Logic/SmsLogLogic.php new file mode 100644 index 0000000..e44ec9c --- /dev/null +++ b/app/Http/Logic/SmsLogLogic.php @@ -0,0 +1,107 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/SysconfigLogic.php b/app/Http/Logic/SysconfigLogic.php new file mode 100644 index 0000000..1cadc59 --- /dev/null +++ b/app/Http/Logic/SysconfigLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/TagindexLogic.php b/app/Http/Logic/TagindexLogic.php new file mode 100644 index 0000000..fc2fb34 --- /dev/null +++ b/app/Http/Logic/TagindexLogic.php @@ -0,0 +1,107 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/TokenLogic.php b/app/Http/Logic/TokenLogic.php new file mode 100644 index 0000000..8e8c590 --- /dev/null +++ b/app/Http/Logic/TokenLogic.php @@ -0,0 +1,107 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/UserLogic.php b/app/Http/Logic/UserLogic.php new file mode 100644 index 0000000..02b5a84 --- /dev/null +++ b/app/Http/Logic/UserLogic.php @@ -0,0 +1,123 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //全部列表 + public function getAll($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getAll($where, $order, $field, $limit); + + /* if($res) + { + foreach($res as $k=>$v) + { + $res[$k] = $this->getDataView($v); + } + } */ + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Logic/VerifyCodeLogic.php b/app/Http/Logic/VerifyCodeLogic.php new file mode 100644 index 0000000..6103602 --- /dev/null +++ b/app/Http/Logic/VerifyCodeLogic.php @@ -0,0 +1,107 @@ +getModel()->getList($where, $order, $field, $offset, $limit); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k] = $this->getDataView($v); + } + } + + return $res; + } + + //分页html + public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = $this->getModel()->getPaginate($where, $order, $field, $limit); + + return $res; + } + + //详情 + public function getOne($where = array(), $field = '*') + { + $res = $this->getModel()->getOne($where, $field); + if(!$res){return false;} + + $res = $this->getDataView($res); + + return $res; + } + + //添加 + public function add($data = array(), $type=0) + { + if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('add')->check($data); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->add($data,$type); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改 + public function edit($data, $where = array()) + { + if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} + + $res = $this->getModel()->edit($data,$where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除 + public function del($where) + { + if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $check = $this->getValidate()->scene('del')->check($where); + if($check === false){return ReturnData::create(ReturnData::PARAMS_ERROR,null,$this->getValidate()->getError());} + + $res = $this->getModel()->del($where); + if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 数据获取器 + * @param array $data 要转化的数据 + * @return array + */ + private function getDataView($data = array()) + { + return getDataAttr($this->getModel(),$data); + } +} \ No newline at end of file diff --git a/app/Http/Model/Article.php b/app/Http/Model/Article.php index ad621a7..b3041cf 100644 --- a/app/Http/Model/Article.php +++ b/app/Http/Model/Article.php @@ -1,5 +1,6 @@ belongsTo(Arctype::class, 'typeid', 'id'); } - public static function getList(array $param) + /** + * 列表 + * @param array $where 查询条件 + * @param string $order 排序 + * @param string $field 字段 + * @param int $offset 偏移量 + * @param int $limit 取多少条 + * @return array + */ + public static function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 10) + { + $model = self::getDb(); + if($where){$res = $res->where($where);} + + $res['count'] = $model->count(); + $res['list'] = array(); + + if($res['count'] > 0) + { + if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}} + if($order){$model = $model->orderBy($order);} + if($offset){}else{$offset = 0;} + if($limit){}else{$limit = 10;} + + $res['list'] = $model->skip($offset)->take($limit)->get(); + } + + return $res; + } + + /* public static function getList(array $param) { extract($param); //参数:group_id,limit,offset @@ -89,35 +125,107 @@ class Article extends BaseModel } return $res; + } */ + + /** + * 分页,用于前端html输出 + * @param array $where 查询条件 + * @param string $order 排序 + * @param string $field 字段 + * @param int $limit 每页几条 + * @param int $page 当前第几页 + * @return array + */ + public static function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = self::getDb(); + + if($where){$res = $res->where($where);} + if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} + if($order){$res = $res->orderBy($order);} + if($limit){}else{$limit = 10;} + + return $res->paginate($limit); } - public static function getOne(array $param) + /** + * 查询全部 + * @param array $where 查询条件 + * @param string $order 排序 + * @param string $field 字段 + * @param int $limit 取多少条 + * @return array + */ + public static function getAll($where = array(), $order = '', $field = '*', $limit = 10, $offset = 0) { - extract($param); + $res = self::getDb(); - $where['id'] = $id; - if(isset($ischeck)){$where['ischeck'] = $ischeck;} + if($where){$res = $res->where($where);} + if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} + if($order){$res = $res->orderBy($order);} + if($offset){}else{$offset = 0;} + if($limit){}else{$limit = 10;} - $res = self::where($where)->first(); + $res = $res->skip($offset)->take($limit)->get(); - if($res){$res->type_name = Arctype::where('id', $res->typeid)->value('name');} + return $res; + } + + /** + * 获取一条 + * @param array $where 条件 + * @param string $field 字段 + * @return array + */ + public static function getOne($where, $field = '*') + { + $res = self::getDb(); + + if($where){$res = $res->where($where);} + if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} + + $res = $res->find(); return $res; } - public static function add(array $data) + /** + * 添加 + * @param array $data 数据 + * @return int + */ + public static function add(array $data,$type = 0) { - if ($id = self::insertGetId($data)) + if($type==0) { - return $id; + // 新增单条数据并返回主键值 + return self::insertGetId(parent::filterTableColumn($data,$this->table)); + } + elseif($type==1) + { + /** + * 添加单条数据 + * $data = ['foo' => 'bar', 'bar' => 'foo']; + * 添加多条数据 + * $data = [ + * ['foo' => 'bar', 'bar' => 'foo'], + * ['foo' => 'bar1', 'bar' => 'foo1'], + * ['foo' => 'bar2', 'bar' => 'foo2'] + * ]; + */ + return self::insert($data); } - - return false; } - public static function modify($where, array $data) + /** + * 修改 + * @param array $data 数据 + * @param array $where 条件 + * @return bool + */ + public static function edit($data, $where = array()) { - if (self::where($where)->update($data)!==false) + if (self::where($where)->update(parent::filterTableColumn($data,$this->table)) !== false) { return true; } @@ -125,14 +233,42 @@ class Article extends BaseModel return false; } - //删除一条记录 - public static function remove($id) + /* public static function modify($where, array $data) { - if (!self::whereIn('id', explode(',', $id))->delete()) + if (self::where($where)->update($data)!==false) { - return false; + return true; } - return true; + return false; + } */ + + //删除一条记录 + /* public static function remove($id) + { + return self::whereIn('id', explode(',', $id))->delete(); + } */ + + /** + * 删除 + * @param array $where 条件 + * @return bool + */ + public static function del($where) + { + return self::where($where)->delete(); + } + + //是否审核 + public static function getIscheckAttr($data) + { + $arr = array(0 => '已审核', 1 => '未审核'); + return $arr[$data['ischeck']]; + } + + //是否栏目名称 + public static function getTypenameAttr($data) + { + return DB::table('arctype')->where(array('id'=>$data['typeid']))->value('name'); } -} +} \ No newline at end of file diff --git a/app/Http/Model/BaseModel.php b/app/Http/Model/BaseModel.php index 000c9ce..cc67ae4 100644 --- a/app/Http/Model/BaseModel.php +++ b/app/Http/Model/BaseModel.php @@ -1,8 +1,34 @@ $v) + { + if (!in_array($k,$table_column)) + { + unset($data[$k]); + } + } + + return $data; + } } \ No newline at end of file diff --git a/app/Http/Requests/ArctypeRequest.php b/app/Http/Requests/ArctypeRequest.php new file mode 100644 index 0000000..ec2dc93 --- /dev/null +++ b/app/Http/Requests/ArctypeRequest.php @@ -0,0 +1,29 @@ + ['typename', 'typedir', 'reid', 'addtime', 'seotitle', 'keywords', 'description', 'listorder', 'templist', 'temparticle', 'litpic', 'seokeyword'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/ArticleRequest.php b/app/Http/Requests/ArticleRequest.php index bf8092f..8d6ae40 100644 --- a/app/Http/Requests/ArticleRequest.php +++ b/app/Http/Requests/ArticleRequest.php @@ -8,27 +8,49 @@ class ArticleRequest extends Request //总的验证规则 protected $rules = [ 'id' => 'required|integer', - 'title' => 'required|max:150', 'typeid' => 'required|integer', - 'click' => ['required','integer'], + 'tuijian' => 'integer', + 'click' => 'required|integer', + 'title' => 'required|max:150', + 'writer' => 'max:20', + 'source' => 'max:30', + 'litpic' => 'max:100', + 'pubdate' => 'integer', + 'add_time' => 'required|integer', + 'keywords' => 'max:60', + 'seotitle' => 'max:150', + 'description' => 'max:250', + 'ischeck' => 'between:[0,2]', + 'user_id' => 'integer', ]; //总的自定义错误信息 protected $messages = [ - 'title.max' => '标题不能大于150个字', - 'title.required' => '必须填写标题', - 'typeid.required' => '类目ID必填', - 'typeid.integer' => '栏目ID必须为数字', - 'click.required' => '必须填写点击量', - 'click.integer' => '点击必须为数字', 'id.required' => 'ID必填', 'id.integer' => 'ID必须为数字', + 'typeid.required' => '栏目ID必填', + 'typeid.integer' => '栏目ID必须为数字', + 'tuijian.integer' => '推荐等级必须是数字', + 'click.integer' => '点击必须为数字', + 'title.max' => '标题不能大于150个字', + 'title.required' => '必须填写标题', + 'writer.max' => '作者不能超过20个字符', + 'source.max' => '来源不能超过30个字符', + 'litpic.max' => '缩略图不能超过100个字符', + 'pubdate.integer' => '更新时间格式不正确', + 'add_time.required' => '添加时间必填', + 'add_time.integer' => '添加时间必须是数字', + 'keywords.max' => '关键词不能超过60个字符', + 'seotitle.max' => 'seo标题不能超过150个字符', + 'description.max' => '描述不能超过250个字符', + 'ischeck.between' => '审核状态:0审核,1未审核', + 'user_id.integer' => '发布者ID必须是数字', ]; //场景验证规则 protected $scene = [ - 'add' => ['title','typeid','click'], - 'edit' => ['title','typeid'], + 'add' => ['typeid', 'title', 'tuijian', 'click', 'writer', 'source', 'litpic', 'pubdate', 'addtime', 'keywords', 'seotitle', 'description', 'ischeck', 'user_id'], + 'edit' => ['typeid', 'title', 'tuijian', 'click', 'writer', 'source', 'litpic', 'pubdate', 'addtime', 'keywords', 'seotitle', 'description', 'ischeck', 'user_id'], 'del' => ['id'], ]; diff --git a/app/Http/Requests/FeedbackRequest.php b/app/Http/Requests/FeedbackRequest.php new file mode 100644 index 0000000..d6a2176 --- /dev/null +++ b/app/Http/Requests/FeedbackRequest.php @@ -0,0 +1,20 @@ + ['content', 'title', 'user_id'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/FriendlinkRequest.php b/app/Http/Requests/FriendlinkRequest.php new file mode 100644 index 0000000..76661e9 --- /dev/null +++ b/app/Http/Requests/FriendlinkRequest.php @@ -0,0 +1,21 @@ + ['webname', 'url', 'target', 'group_id', 'rank'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/GoodsBrandRequest.php b/app/Http/Requests/GoodsBrandRequest.php new file mode 100644 index 0000000..29db6a1 --- /dev/null +++ b/app/Http/Requests/GoodsBrandRequest.php @@ -0,0 +1,28 @@ + ['pid', 'add_time', 'title', 'keywords', 'seotitle', 'description', 'litpic', 'status', 'cover_img', 'click', 'listorder'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/GoodsTypeRequest.php b/app/Http/Requests/GoodsTypeRequest.php new file mode 100644 index 0000000..541c646 --- /dev/null +++ b/app/Http/Requests/GoodsTypeRequest.php @@ -0,0 +1,31 @@ + ['reid', 'addtime', 'name', 'seotitle', 'keywords', 'description', 'typedir', 'templist', 'temparticle', 'litpic', 'seokeyword', 'status', 'listorder', 'cover_img'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/GuestbookRequest.php b/app/Http/Requests/GuestbookRequest.php new file mode 100644 index 0000000..f4554f9 --- /dev/null +++ b/app/Http/Requests/GuestbookRequest.php @@ -0,0 +1,24 @@ + ['varname', 'info', 'value'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/PageRequest.php b/app/Http/Requests/PageRequest.php new file mode 100644 index 0000000..c06a4d2 --- /dev/null +++ b/app/Http/Requests/PageRequest.php @@ -0,0 +1,26 @@ + ['title', 'tuijian', 'click', 'filename', 'template', 'litpic', 'pubdate', 'keywords', 'seotitle', 'description'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/PaymentRequest.php b/app/Http/Requests/PaymentRequest.php new file mode 100644 index 0000000..ddc4848 --- /dev/null +++ b/app/Http/Requests/PaymentRequest.php @@ -0,0 +1,22 @@ + ['pay_code', 'pay_name', 'pay_fee', 'status', 'listorder'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/RegionRequest.php b/app/Http/Requests/RegionRequest.php new file mode 100644 index 0000000..869d0a4 --- /dev/null +++ b/app/Http/Requests/RegionRequest.php @@ -0,0 +1,22 @@ + ['name', 'parent_id', 'type', 'sort_name', 'area_code'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/SlideRequest.php b/app/Http/Requests/SlideRequest.php new file mode 100644 index 0000000..93b5846 --- /dev/null +++ b/app/Http/Requests/SlideRequest.php @@ -0,0 +1,24 @@ + ['title', 'url', 'target', 'group_id', 'rank', 'pic', 'is_show'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/SmsLogRequest.php b/app/Http/Requests/SmsLogRequest.php new file mode 100644 index 0000000..0cdcdd9 --- /dev/null +++ b/app/Http/Requests/SmsLogRequest.php @@ -0,0 +1,21 @@ + ['mobile', 'text', 'status', 'result'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/SysconfigRequest.php b/app/Http/Requests/SysconfigRequest.php new file mode 100644 index 0000000..18b60ad --- /dev/null +++ b/app/Http/Requests/SysconfigRequest.php @@ -0,0 +1,20 @@ + ['varname', 'info', 'value'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/TagindexRequest.php b/app/Http/Requests/TagindexRequest.php new file mode 100644 index 0000000..b9bcdd1 --- /dev/null +++ b/app/Http/Requests/TagindexRequest.php @@ -0,0 +1,19 @@ + ['tag', 'filename'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/TokenRequest.php b/app/Http/Requests/TokenRequest.php new file mode 100644 index 0000000..ed86160 --- /dev/null +++ b/app/Http/Requests/TokenRequest.php @@ -0,0 +1,20 @@ + ['token', 'type', 'uid'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/UserRequest.php b/app/Http/Requests/UserRequest.php new file mode 100644 index 0000000..673b2f9 --- /dev/null +++ b/app/Http/Requests/UserRequest.php @@ -0,0 +1,21 @@ + ['user_name', 'text', 'status', 'result'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/app/Http/Requests/VerifyCodeRequest.php b/app/Http/Requests/VerifyCodeRequest.php new file mode 100644 index 0000000..f9f2541 --- /dev/null +++ b/app/Http/Requests/VerifyCodeRequest.php @@ -0,0 +1,22 @@ + ['mobile', 'text', 'status', 'result'], + 'del' => ['id'], + ]; +} \ No newline at end of file diff --git a/resources/views/admin/article/index.blade.php b/resources/views/admin/article/index.blade.php index d4ec7e4..dabd04f 100644 --- a/resources/views/admin/article/index.blade.php +++ b/resources/views/admin/article/index.blade.php @@ -22,7 +22,7 @@ title; ?> litpic)){echo "[图]";}if($row->tuijian==1){echo "[荐]";} ?> pubdate); ?> - name; ?>click; ?>"content","catid"=>$row->typeid,"id"=>$row->id)); ?>">预览 修改 删除 + typename; ?>click; ?>"content","catid"=>$row->typeid,"id"=>$row->id)); ?>">预览 修改 删除