Skip to content

Commit

Permalink
services方法去掉action开头的形式,全部改为public函数,以及代码格式的调整
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed May 9, 2020
1 parent b999199 commit dac5588
Show file tree
Hide file tree
Showing 99 changed files with 744 additions and 1,620 deletions.
2 changes: 1 addition & 1 deletion services/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class Blog extends Service
{
public functiongetCategoryMenu()
public function getCategoryMenu()
{
}

Expand Down
2 changes: 2 additions & 0 deletions services/admin/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ public function save($one)
$this->_model->attributes = $one;
if ($this->_model->validate()) {
$this->_model->save();

return $this->_model[$primaryKey];
} else {
$errors = $this->_model->errors;
Yii::$service->helper->errors->addByModelErrors($errors);
}

return null;
}

Expand Down
2 changes: 2 additions & 0 deletions services/admin/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public function getLeftMenuTreeHtml($treeArr='', $i=1){
foreach($treeArr as $node){
// 二次开发的过程中,如果fecshop后台的某些菜单想不显示,那么可以在配置中将active设置成false
if (isset($node['active']) && $node['active'] === false) {

continue;
}
$name = Yii::$service->page->translate->__($node["label"]);
$url_key = $node["url_key"];
$roleUrlKeys = $this->getRoleUrlKey();
if($url_key && (!isset($roleUrlKeys[$url_key]) || !$roleUrlKeys[$url_key])){

continue;
}
if($i == 1){
Expand Down
6 changes: 5 additions & 1 deletion services/admin/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class Role extends Service
{

const ADMIN_ROLEIDS_RESOURCES = 'admin_roleids_resources';

public $numPerPage = 20;
Expand Down Expand Up @@ -64,6 +63,7 @@ public function getByPrimaryKey($primaryKey)

return $one;
} else {

return new $this->_roleModelName();
}
}
Expand Down Expand Up @@ -158,6 +158,7 @@ public function saveRoleAndResources($one){
$roleData['role_name'] = $one['role_name'];
} else {
Yii::$service->helper->errors->add('role name can not empty');

return false;
}
if (isset($one['role_description'])) {
Expand Down Expand Up @@ -196,6 +197,7 @@ protected function validateRoleName($one)
}
$one = $query->one();
if (!empty($one)) {

return false;
}

Expand Down Expand Up @@ -237,6 +239,7 @@ public function remove($ids)
public function getCurrentRoleResources(){
if (!$this->_current_role_resources) {
if (Yii::$app->user->isGuest) {

return [];
}
$user = Yii::$app->user->identity;
Expand All @@ -257,6 +260,7 @@ public function getCurrentRoleResources(){
}
}
if (empty($role_ids)) {

return [];
}

Expand Down
6 changes: 5 additions & 1 deletion services/admin/RoleUrlKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function getByPrimaryKey($primaryKey)

return $one;
} else {

return new $this->_modelName();
}
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public function coll($filter = '')
$coll[$k] = $one;
}
}
//var_dump($one);

return [
'coll' => $coll,
'count'=> $query->limit(null)->offset(null)->count(),
Expand Down Expand Up @@ -147,8 +148,10 @@ public function repeatSaveRoleUrlKey($roleId, $url_key_ids){
$model->role_id = $roleId;
$model->save();
}

return true;
}

return false;
}

Expand All @@ -169,6 +172,7 @@ protected function validateUrlKeyRoleId($one)
}
$one = $query->one();
if (!empty($one)) {

return false;
}

Expand Down
11 changes: 8 additions & 3 deletions services/admin/SystemLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function init()
list($this->_modelName, $this->_model) = Yii::mapGet($this->_modelName);
}

public function getSystemLogModel(){
public function getSystemLogModel()
{
return $this->_model;
}

Expand All @@ -60,6 +61,7 @@ public function getByPrimaryKey($primaryKey)

return $one;
} else {

return new $this->_modelName();
}
}
Expand Down Expand Up @@ -90,7 +92,7 @@ public function coll($filter = '')
$coll[$k] = $one;
}
}
//var_dump($one);

return [
'coll' => $coll,
'count'=> $query->limit(null)->offset(null)->count(),
Expand All @@ -100,6 +102,7 @@ public function coll($filter = '')
# 保存系统日志。
public function save(){
if (!$this->enableLog) {

return false;
}
$systemLog = $this->_model;
Expand All @@ -116,14 +119,16 @@ public function save(){
$systemLog->url = $url;
$systemLog->url_key = $url_key;
$systemLog->menu = $this->getMenuByUrlKey($url_key);
$systemLog->save();
return $systemLog->save();
}
}

public function getMenuByUrlKey($url_key){
if(!$url_key)

return null;
$menuArr = Yii::$service->admin->urlKey->getUrlKeyAndLabelArr();

return isset($menuArr[$url_key]) ? $menuArr[$url_key] : null;
}

Expand Down
7 changes: 4 additions & 3 deletions services/admin/UrlKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function getTags($translate = true){
}
}
}

return $this->_urlKeyTags[$key];
}

Expand All @@ -82,6 +83,7 @@ public function getByPrimaryKey($primaryKey)

return $one;
} else {

return new $this->_modelName();
}
}
Expand Down Expand Up @@ -112,7 +114,7 @@ public function coll($filter = '')
$coll[$k] = $one;
}
}
//var_dump($one);

return [
'coll' => $coll,
'count'=> $query->limit(null)->offset(null)->count(),
Expand Down Expand Up @@ -273,6 +275,7 @@ protected function validateUrlKey($one)
}
$one = $query->one();
if (!empty($one)) {

return false;
}

Expand All @@ -296,7 +299,6 @@ public function remove($ids)
}

$model->delete();
// delete roleUrlKey
Yii::$service->admin->roleUrlKey->removeByUrlKeyId($id);
}
} else {
Expand All @@ -308,7 +310,6 @@ public function remove($ids)
return false;
}
$model->delete();
// delete roleUrlKey
Yii::$service->admin->roleUrlKey->removeByUrlKeyId($id);
}

Expand Down
3 changes: 2 additions & 1 deletion services/admin/UserRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function getByPrimaryKey($primaryKey)

return $one;
} else {

return new $this->_roleModelName();
}
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public function coll($filter = '')
$coll[$k] = $one;
}
}
//var_dump($one);

return [
'coll' => $coll,
'count'=> $query->limit(null)->offset(null)->count(),
Expand Down
9 changes: 3 additions & 6 deletions services/adminUser/AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public function getPrimaryKey()

public function getActiveStatus(){
$model = $this->_model;

return $model::STATUS_ACTIVE;
}
public function getDeleteStatus(){
$model = $this->_model;

return $model::STATUS_DELETED;
}

Expand Down Expand Up @@ -117,7 +119,7 @@ public function coll($filter = '')
$coll[$k] = $one;
}
}
//var_dump($one);

return [
'coll' => $coll,
'count'=> $query->limit(null)->offset(null)->count(),
Expand Down Expand Up @@ -167,7 +169,6 @@ public function save($data) {

return null;
}

if ($this->_userFormModel[$primaryKey]) {
if ($this->_userFormModel->validate()) {
$this->_userFormModel->save();
Expand Down Expand Up @@ -237,10 +238,6 @@ public function remove($ids){
return $removeIds;
}





/**
* @param $ids | Int Array
* @return 得到相应用户的数组。
Expand Down
9 changes: 8 additions & 1 deletion services/adminUser/UserLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function init()
* @param $data|array
* 数组格式:['username'=>'[email protected]','password'=>'xxxx']
*/
public function actionLogin($data)
public function login($data)
{
$model = new $this->_adminUserLoginModelName();
$model->username = $data['username'];
Expand Down Expand Up @@ -67,6 +67,7 @@ public function loginAndGetAccessToken($username, $password)
$access_token_created_at = $identity->access_token_created_at;
$timeout = Yii::$service->session->timeout;
if ($access_token_created_at + $timeout > time()) {

return $accessToken;
}
}
Expand All @@ -83,8 +84,10 @@ public function loginAndGetAccessToken($username, $password)
$identity->access_token_created_at = time();
$identity->save();
$this->setHeaderAccessToken($identity->access_token);

return $identity->access_token;
}

return null;
}

Expand All @@ -94,8 +97,10 @@ public function setHeaderAccessToken($accessToken)
{
if ($accessToken) {
Yii::$app->response->getHeaders()->set('access-token', $accessToken);

return true;
}

return false;
}

Expand Down Expand Up @@ -125,9 +130,11 @@ public function loginByAccessToken($type = null)
$identity->access_token_created_at = time();
$identity->save();
}

return $identity;
} else {
$this->logoutByAccessToken();

return false;
}
}
Expand Down
Loading

0 comments on commit dac5588

Please sign in to comment.