初始化仓库
This commit is contained in:
91
admin/controllers/system/AdminController.php
Normal file
91
admin/controllers/system/AdminController.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use admin\controllers\AuthController;
|
||||
use admin\exceptions\ApiException;
|
||||
use admin\models\Admin;
|
||||
use common\core\BaseAdminController;
|
||||
use common\enums\UserRoleEnum;
|
||||
use common\models\Store;
|
||||
use yii\base\DynamicModel;
|
||||
use yii\base\Exception;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
class AdminController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* 管理员列表
|
||||
*/
|
||||
public function actionList()
|
||||
{
|
||||
$m = new DynamicModel(['page','pageSize']);
|
||||
//$m->addRule('aa',DateRangeValidator::class);
|
||||
//$m->addRule('xx','string');
|
||||
$m->addRule('page','default',['value'=>1]);
|
||||
$m->addRule('pageSize','default',['value'=>10]);
|
||||
$m->addRule('page','integer',['max'=>1000]);
|
||||
$m->addRule('pageSize','integer',['min'=>1,'max'=>50]);
|
||||
$m->load($this->post());
|
||||
if(!$m->validate()){
|
||||
throw new Exception(json_encode($m->getFirstErrors()));
|
||||
}
|
||||
$query = Admin::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort'=>[
|
||||
'defaultOrder'=>['uid'=>SORT_DESC]
|
||||
],
|
||||
'pagination'=>[
|
||||
'defaultPageSize'=>$m->pageSize,
|
||||
'params'=>['page'=>$m->page]
|
||||
]
|
||||
]);
|
||||
// add conditions that should always apply here
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
/**
|
||||
* 账号信息
|
||||
*/
|
||||
public function actionInfo()
|
||||
{
|
||||
$admin= \Yii::$app->user->identity;
|
||||
|
||||
if ($admin->role==UserRoleEnum::SUPER_ADMIN){
|
||||
$info= Admin::find()->where(['uid'=>$admin->uid,'role'=>UserRoleEnum::SUPER_ADMIN])->one();
|
||||
}
|
||||
if ($admin->role==UserRoleEnum::STORE_ADMIN){
|
||||
$info= Store::find()->where(['id'=>$admin->store_id,'is_delete'=>0])->one();
|
||||
}
|
||||
|
||||
if (!$info) throw new \yii\db\Exception('账号信息不存在');
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 账号禁用
|
||||
* @doc-param int admin_id 后台用户ID
|
||||
*/
|
||||
public function actionAccountDisabled()
|
||||
{
|
||||
$post = \Yii::$app->request->post();
|
||||
$this->requestValidate($post, [
|
||||
['admin_id', 'required']
|
||||
]);
|
||||
$role=\Yii::$app->user->identity->role;
|
||||
if ($role!=UserRoleEnum::SUPER_ADMIN) throw new \yii\db\Exception('非超级管理员,没有禁用账号的权限');
|
||||
$Admin = Admin::find()->where([
|
||||
'uid' => $post['admin_id'],
|
||||
])->one();
|
||||
if (!$Admin) throw new \yii\db\Exception('账号不存在');
|
||||
|
||||
|
||||
$status=$Admin->status==1?0:1;
|
||||
$Admin->status=$status;
|
||||
$Admin->saveOrFail();
|
||||
return ['修改成功'];
|
||||
}
|
||||
|
||||
}
|
||||
172
admin/controllers/system/AttachmentController.php
Normal file
172
admin/controllers/system/AttachmentController.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/25
|
||||
* Time: 2:08 PM
|
||||
*/
|
||||
|
||||
namespace admin\controllers\goods;
|
||||
|
||||
use common\core\BaseAdminController;
|
||||
use admin\models\forms\AttachmentUploadForm;
|
||||
use common\models\Attachment;
|
||||
use common\models\AttachmentGroup;
|
||||
use common\services\UploadService;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\UploadedFile;
|
||||
|
||||
/**
|
||||
* @doc-module 上传
|
||||
*/
|
||||
class AttachmentController extends BaseAdminController
|
||||
{
|
||||
|
||||
public function actionIndex(){
|
||||
return ['node'=>['nodeName'=>'fileManage']];
|
||||
return $this->render('index');
|
||||
}
|
||||
public function actionGroupList($type = null, $is_recycle = null)
|
||||
{
|
||||
$params = $this->requestValidate($this->get(),[
|
||||
['is_recycle','integer'],
|
||||
['type','string']
|
||||
]);
|
||||
$query = AttachmentGroup::find()->where([
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
'is_delete' => 0,
|
||||
]);
|
||||
|
||||
isset($params->type) || $query->andWhere(['type' => $params->type === 'video' ? 1 : 0]);
|
||||
|
||||
return $query->all();
|
||||
}
|
||||
|
||||
public function actionDo(){
|
||||
$params = $this->requestValidate($this->get(),[
|
||||
['type','in','range'=>['folder-create','files','folder-delete','folder']],
|
||||
['keyword','string'],
|
||||
['name','string'],
|
||||
['id','integer'],
|
||||
['page','integer']
|
||||
]);
|
||||
/**
|
||||
* upload: props.uploadUrl,
|
||||
list: props.fileUrl + '?type=files',
|
||||
del: props.fileUrl + '?type=files-delete',
|
||||
cateList: props.fileUrl + '?type=folder',
|
||||
cateAdd: props.fileUrl + '?type=folder-create',
|
||||
cateDel: props.fileUrl + '?type=folder-delete'
|
||||
*/
|
||||
switch ($params->type){
|
||||
case 'folder':
|
||||
$activeRecords = AttachmentGroup::find()->where(['mall_id' => \Yii::$app->mallId])->andWhere(['is_delete' => 0])->all();
|
||||
return ArrayHelper::toArray($activeRecords,[
|
||||
AttachmentGroup::class=>[
|
||||
'dir_id'=>'id','name'
|
||||
]
|
||||
]);
|
||||
break;
|
||||
case 'folder-create';
|
||||
$attachmentGroup = new AttachmentGroup();
|
||||
$attachmentGroup->setAttributes([
|
||||
'mall_id'=>\Yii::$app->mallId,
|
||||
'name'=>$params->name,
|
||||
]);
|
||||
if($attachmentGroup->save()){
|
||||
return ['id'=>$attachmentGroup->id,'name'=>$attachmentGroup->name];
|
||||
}else{
|
||||
return ['error'=>$attachmentGroup->getErrors()];
|
||||
}
|
||||
break;
|
||||
case 'folder-delete';
|
||||
Attachment::updateAll(['is_delete'=>1,'deleted_at'=>time()],['attachment_group_id'=>$params->id,'mall_id'=>\Yii::$app->mallId]);
|
||||
AttachmentGroup::updateAll(['is_delete'=>1,'deleted_at'=>time()],['id'=>$params->id,'mall_id'=>\Yii::$app->mallId]);
|
||||
return [];
|
||||
break;
|
||||
case 'files':
|
||||
$query = Attachment::find()->where(['mall_id' => \Yii::$app->mallId])->andWhere(['is_delete' => 0])->orderBy('id desc');;
|
||||
if(isset($params->id) && $params->id>0) {
|
||||
$query->andWhere(['attachment_group_id'=>$params->id]);
|
||||
}
|
||||
$query->andFilterWhere(['like','name',$params->keyword]);
|
||||
$this->field = [
|
||||
Attachment::class=>[
|
||||
'id',
|
||||
'title'=>'name',
|
||||
'url',
|
||||
'ext'=>function($m){
|
||||
$implode = explode('.', $m['name']);
|
||||
return mb_strtolower(array_pop($implode));
|
||||
},
|
||||
'time'=>function($model){
|
||||
return date("Y-m-d H:i:s",$model['created_at']);
|
||||
},
|
||||
'size'=>function($model){
|
||||
return app_filesize($model['size']);
|
||||
},
|
||||
]
|
||||
];
|
||||
$post = array_merge(\Yii::$app->request->post(),\Yii::$app->request->get());
|
||||
return $this->create($query,$post);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function actionUpload(){
|
||||
$params = $this->requestValidate($this->post(),[
|
||||
['id','integer'],
|
||||
['id','default','value'=>0],
|
||||
['file','file']
|
||||
]);
|
||||
|
||||
$form = new AttachmentUploadForm();
|
||||
$form->file = UploadedFile::getInstanceByName('file');
|
||||
$form->attachment_group_id = $params->id;
|
||||
return $form->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name oss直传-保存上传信息
|
||||
* @doc-param int attachment_group_id 上传的分组
|
||||
* @doc-param string name 上传的文件名称
|
||||
* @doc-param int size 上传的文件大小
|
||||
* @doc-param string url 上传的文件链接
|
||||
*/
|
||||
public function actionSave()
|
||||
{
|
||||
$post = \Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[['attachment_group_id','name','size','url'],'required']
|
||||
]);
|
||||
$ext = pathinfo($post['url'])['extension'];
|
||||
$type = (new AttachmentUploadForm())->checkExt($ext);
|
||||
|
||||
$attachment = new Attachment();
|
||||
$attachment->attributes = $post;
|
||||
$attachment->storage_id = 0;
|
||||
$attachment->user_id = 0;
|
||||
$attachment->type = $type;
|
||||
$attachment->mall_id = \Yii::$app->mallId;
|
||||
$attachment->thumb_url = $post['url'];
|
||||
$attachment->saveOrFail();
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name oss直传-获取上传参数
|
||||
*/
|
||||
public function actionParams()
|
||||
{
|
||||
$callbackUrl = \Yii::$app->request->hostInfo.'/api/v1/callback/upload-notify';
|
||||
$dir = \Yii::$app->mallId ? 'uploads/' . \Yii::$app->mallId.'/' . date('Ymd').'/' : 'uploads/' . date('Ymd').'/';
|
||||
|
||||
$data = [
|
||||
'callbackUrl' => $callbackUrl,
|
||||
'dir' => $dir
|
||||
];
|
||||
return (new UploadService())->redirectFile($data);
|
||||
}
|
||||
}
|
||||
167
admin/controllers/system/ConfigController.php
Normal file
167
admin/controllers/system/ConfigController.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use common\core\BaseAdminController;
|
||||
use common\helpers\ArrayHelper;
|
||||
use Yii;
|
||||
use common\models\Config;
|
||||
use admin\models\search\ConfigSearch;
|
||||
use yii\base\Exception;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
class ConfigController extends BaseAdminController
|
||||
{
|
||||
|
||||
/**
|
||||
* 配置项列表
|
||||
*/
|
||||
public function actionList()
|
||||
{
|
||||
$searchModel = new ConfigSearch();
|
||||
$this->field = $this->_listMap();
|
||||
return $searchModel->search(Yii::$app->request->queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置项
|
||||
*/
|
||||
public function actionSave()
|
||||
{
|
||||
$id = Yii::$app->request->get('id', 0);
|
||||
$model = $this->findModel($id);
|
||||
if ($model->load($this->post(),'') && $model->save()) {
|
||||
$event = 'add';
|
||||
if($id>0){
|
||||
$event = 'edit';
|
||||
}
|
||||
$this->callbackEvent(ArrayHelper::toArray([$model],$this->_listMap()),'id',$event);
|
||||
return [];
|
||||
}else{
|
||||
throw new Exception(current($model->getErrors())[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置项详情1
|
||||
* @doc-param int id ID
|
||||
* @doc-return mixed @Config{name,type-int-配置类型0数字1字符2文本3数组4单选5富文本6多选,title,group,extra,remark,value,sort,status,created_at} 配置信息
|
||||
*/
|
||||
public function actionInfo()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
['id','required']
|
||||
]);
|
||||
$config = Config::findOne($post['id']);
|
||||
if ($config['extra']) {
|
||||
$config['extra'] = Config::parse(3, $config['extra']);
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除配置项
|
||||
*/
|
||||
public function actionDel()
|
||||
{
|
||||
$id = (int)$this->get('id');
|
||||
if($id<1){
|
||||
throw new \Exception('删除失败!');
|
||||
}
|
||||
if(in_array($id,[1])){
|
||||
throw new \Exception('禁止删除!');
|
||||
}
|
||||
$model = $this->findModel($id);
|
||||
if ($model->delete()) {
|
||||
$this->callbackEvent([$model->toArray()],'id','del');
|
||||
return [];
|
||||
} else {
|
||||
throw new \Exception('删除失败!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* @doc-desc 20处理成number,1是text,2textarea,3textarea,4select或者radio,5富文本,6多选
|
||||
* @doc-return mixed Data{name-string-分组名称,@Groups{Config{name,type-int-配置类型0数字1字符2文本3数组4单选5富文本6多选,title,group,extra,remark,value,sort,status}}} 配置数据
|
||||
*/
|
||||
public function actionGroup()
|
||||
{
|
||||
$config = \common\models\Config::find()->where([
|
||||
'name' => 'GROUP'
|
||||
])->one();
|
||||
$tab_groups = Config::parse(3, $config['value']);
|
||||
|
||||
$data = [];
|
||||
foreach($tab_groups as $id => $group)
|
||||
{
|
||||
$groups = Config::find()
|
||||
->where(['and', ['group' => $id], ['status' => 1]])
|
||||
->orderBy('sort ASC')->asArray()->all();
|
||||
foreach ($groups as $key => $value) {
|
||||
if ($value['extra']) {
|
||||
$groups[$key]['extra'] = Config::parse(3, $value['extra']);
|
||||
}
|
||||
}
|
||||
$data[$id] = [
|
||||
'name' => $group,
|
||||
'groups' => $groups,
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置保存
|
||||
* @doc-param array param 提交的修改数据[配置项name=>配置项的值,配置项name=>配置项的值]
|
||||
*/
|
||||
public function actionGroupSave()
|
||||
{
|
||||
$data = Yii::$app->request->post('param');
|
||||
/* 更改配置值 */
|
||||
$isSuccess = true;
|
||||
foreach ($data as $name => $value) {
|
||||
$model = Config::findOne(['name' => $name]);
|
||||
$model->value = $value;
|
||||
$model->update_time = time();
|
||||
if (!$model->save()) {
|
||||
$isSuccess = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($isSuccess) {
|
||||
return [];
|
||||
} else {
|
||||
throw new Exception('有配置值修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
protected function findModel($id)
|
||||
{
|
||||
if ($id == 0) {
|
||||
return new Config();
|
||||
}
|
||||
if (($model = Config::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
private function _listMap()
|
||||
{
|
||||
return [
|
||||
Config::class=>[
|
||||
'id','title','name',
|
||||
'type'=>function($m){
|
||||
return Yii::$app->params['config_type'][$m->type];
|
||||
},
|
||||
'group','sort','status'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
135
admin/controllers/system/DeliveryController.php
Normal file
135
admin/controllers/system/DeliveryController.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/21
|
||||
* Time: 11:50 AM
|
||||
*/
|
||||
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use app\forms\common\CommonPostageRules;
|
||||
use admin\components\BaseAdminController;
|
||||
use admin\components\UI\Form;
|
||||
use admin\components\UI\Layout;
|
||||
use admin\components\UI\Table;
|
||||
use admin\components\UI\Tabs;
|
||||
use admin\exceptions\ApiException;
|
||||
use admin\models\forms\PostageRulesEditForm;
|
||||
use admin\models\search\CommonSearch;
|
||||
use common\models\FreeDeliveryRules;
|
||||
use common\models\PostageRules;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
class DeliveryController extends BaseAdminController
|
||||
{
|
||||
|
||||
public function actionPostageRule(){
|
||||
$table = new Table(new PostageRules());
|
||||
//$table->model();
|
||||
$table->title('角色管理');
|
||||
$table->key('id');
|
||||
$table->eventName(md5(get_called_class()));//设置事件名,后面更改数据对应
|
||||
$table->url(\Yii::$app->urlManager->createUrl("system/delivery/postage-rule-list"));
|
||||
$table->filter('配置名', 'name',false)->text('请输入配置名')->quick();
|
||||
$table->action()->button('添加', $this->createUrl('system/delivery/postage-edit'));
|
||||
$table->column('规则名','name');
|
||||
$table->column('是否默认','status')->status(['否','是'],['gray','red']);
|
||||
$column = $table->column('操作')->width(200);
|
||||
$column->link('设为默认',$this->createUrl('system/delivery/postage-status'), ['id' => 'id'])->type('ajax', ['method' => 'post']);
|
||||
$column->link('编辑', $this->createUrl('system/delivery/postage-edit'), ['id' => 'id']);
|
||||
$column->link('删除', $this->createUrl('system/delivery/postage-del'), ['id' => 'id'])->type('ajax', ['method' => 'post']);
|
||||
return $table->renderArray();
|
||||
}
|
||||
public function actionPostageStatus(){
|
||||
$params = $this->requestValidate($this->get(),[
|
||||
['id','required'],
|
||||
['id','integer']
|
||||
]);
|
||||
$this->callbackEvent([],'id','refresh');
|
||||
return PostageRules::setStatus($params->id);
|
||||
}
|
||||
public function actionPostageRuleList()
|
||||
{
|
||||
$commonSearch = new CommonSearch(['name']);
|
||||
$commonSearch->setQuery(PostageRules::find()
|
||||
->select(['id', 'name', 'status'])
|
||||
->where(['mall_id'=>\Yii::$app->mallId])->andWhere(['is_delete'=>0]));
|
||||
$commonSearch->additionRules = [
|
||||
['name', 'string']
|
||||
];
|
||||
$commonSearch->bindFilter(function(/** @var ActiveQuery $q */ $q) {
|
||||
$q->andFilterWhere(['like','name',$this->name]);
|
||||
});
|
||||
return $commonSearch->search($this->get());
|
||||
|
||||
}
|
||||
public function actionPostageInfo(){
|
||||
$id = $this->get('id');
|
||||
$model = PostageRules::findOne([
|
||||
'is_delete' => 0,
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
'id' => $id
|
||||
]);
|
||||
if (!$model) {
|
||||
$model = new PostageRules();
|
||||
$model->mall_id = \Yii::$app->mallId;
|
||||
} else {
|
||||
$model->detail = $model->decodeDetail();
|
||||
}
|
||||
|
||||
return [
|
||||
'model' => $model,
|
||||
];
|
||||
}
|
||||
public function actionPostageEditSave(){
|
||||
$id = $this->get('id');
|
||||
$model = PostageRules::findOne([
|
||||
'is_delete' => 0,
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
'id' => $id
|
||||
]);
|
||||
if (!$model) {
|
||||
$model = new PostageRules();
|
||||
$model->mall_id = \Yii::$app->mallId;
|
||||
} else {
|
||||
$model->detail = $model->decodeDetail();
|
||||
}
|
||||
$form = new PostageRulesEditForm();
|
||||
$form->attributes = \Yii::$app->request->post('form');
|
||||
$form->model = $model;
|
||||
return $form->save();
|
||||
}
|
||||
public function actionPostageEdit(){
|
||||
return $this->render('postage-edit');
|
||||
}
|
||||
|
||||
public function actionAllList(){
|
||||
$allList = PostageRules::find()->where([
|
||||
'is_delete' => 0,
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
])->select('id as value,name as label')->asArray()->all();
|
||||
foreach ($allList as &$v){
|
||||
$v['value'] = (int)$v['value'];
|
||||
}
|
||||
unset($v);
|
||||
array_unshift($allList, [
|
||||
'value' => 0,
|
||||
'label' => '默认运费'
|
||||
]);
|
||||
|
||||
return [
|
||||
'list' => $allList
|
||||
];
|
||||
}
|
||||
|
||||
public function actionPostageDel(){
|
||||
$id = $this->get('id');
|
||||
if(PostageRules::updateAll(['is_delete'=>1],['id'=>$id,'mall_id'=>\Yii::$app->mallId])){
|
||||
$this->callbackEvent([],'id','refresh');
|
||||
return [];
|
||||
}else{
|
||||
throw new ApiException("删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
39
admin/controllers/system/DistrictController.php
Normal file
39
admin/controllers/system/DistrictController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace admin\controllers\system;
|
||||
use admin\components\BaseAdminController;
|
||||
use common\models\DistrictArr;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/21
|
||||
* Time: 7:57 PM
|
||||
*/
|
||||
class DistrictController extends BaseAdminController{
|
||||
|
||||
public function actionIndex(){
|
||||
if (\Yii::$app->request->isPost) {
|
||||
$level = $this->post('level',3);
|
||||
} elseif (\Yii::$app->request->isGet) {
|
||||
$level = $this->get('level',3);
|
||||
}
|
||||
switch ($level) {
|
||||
case 3:
|
||||
$level = null;
|
||||
break;
|
||||
case 2:
|
||||
$level = 'district';
|
||||
break;
|
||||
case 1:
|
||||
$level = 'city';
|
||||
break;
|
||||
default:
|
||||
$level = null;
|
||||
}
|
||||
$list = DistrictArr::getArr();
|
||||
$district = DistrictArr::getList($list, $level);
|
||||
return [
|
||||
'district' => $district
|
||||
];
|
||||
}
|
||||
}
|
||||
140
admin/controllers/system/FreeRuleController.php
Normal file
140
admin/controllers/system/FreeRuleController.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/21
|
||||
* Time: 11:50 AM
|
||||
*/
|
||||
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use app\forms\common\CommonPostageRules;
|
||||
use admin\components\BaseAdminController;
|
||||
use admin\components\UI\Form;
|
||||
use admin\components\UI\Layout;
|
||||
use admin\components\UI\Table;
|
||||
use admin\components\UI\Tabs;
|
||||
use admin\exceptions\ApiException;
|
||||
use admin\models\forms\FreeRuleEditForm;
|
||||
use admin\models\forms\PostageRulesEditForm;
|
||||
use admin\models\search\CommonSearch;
|
||||
use common\models\FreeDeliveryRules;
|
||||
use common\models\PostageRules;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
class FreeRuleController extends BaseAdminController
|
||||
{
|
||||
public function actionIndex(){
|
||||
$table = new Table(new FreeDeliveryRules());
|
||||
//$table->model();
|
||||
$table->title('包邮设置');
|
||||
$table->key('id');
|
||||
$table->eventName(md5(get_called_class()));//设置事件名,后面更改数据对应
|
||||
$table->url(\Yii::$app->urlManager->createUrl("system/free-rule/list"));
|
||||
$table->filter('规则名称', 'name',false)->text('请输入配置名')->quick();
|
||||
$table->action()->button('添加', $this->createUrl('system/free-rule/edit'));
|
||||
$table->column('规则名称','name');
|
||||
$table->column('包邮类型','typeText');
|
||||
$table->column('是否默认','status')->status(['否','是'],['gray','red']);
|
||||
$column = $table->column('操作')->width(200);
|
||||
$column->link('设为默认',$this->createUrl('system/free-rule/status'), ['id' => 'id'])->type('ajax', ['method' => 'post']);
|
||||
$column->link('编辑', $this->createUrl('system/free-rule/edit'), ['id' => 'id']);
|
||||
$column->link('删除', $this->createUrl('system/free-rule/del'), ['id' => 'id'])->type('ajax', ['method' => 'post']);
|
||||
return $table->renderArray();
|
||||
}
|
||||
public function actionEdit(){
|
||||
return $this->render('edit');
|
||||
}
|
||||
public function actionStatus(){
|
||||
$params = $this->requestValidate($this->get(),[
|
||||
['id','required'],
|
||||
['id','integer']
|
||||
]);
|
||||
$this->callbackEvent([],'id','refresh');
|
||||
return FreeDeliveryRules::setStatus($params->id);
|
||||
}
|
||||
public function actionInfo(){
|
||||
$id = $this->get('id');
|
||||
$model = FreeDeliveryRules::findOne([
|
||||
'is_delete' => 0,
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
'id' => $id
|
||||
]);
|
||||
if (!$model) {
|
||||
$model = new FreeDeliveryRules();
|
||||
$model->mall_id = \Yii::$app->mallId;
|
||||
} else {
|
||||
$model->detail = $model->decodeDetail();
|
||||
}
|
||||
|
||||
return [
|
||||
'model' => $model,
|
||||
];
|
||||
}
|
||||
public function actionEditSave(){
|
||||
$id = $this->get('id');
|
||||
$model = FreeDeliveryRules::findOne([
|
||||
'is_delete' => 0,
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
'id' => $id
|
||||
]);
|
||||
if (!$model) {
|
||||
$model = new FreeDeliveryRules();
|
||||
$model->mall_id = \Yii::$app->mallId;
|
||||
} else {
|
||||
$model->detail = $model->decodeDetail();
|
||||
}
|
||||
$form = new FreeRuleEditForm();
|
||||
$form->attributes = \Yii::$app->request->post('form');
|
||||
$form->model = $model;
|
||||
return $form->save();
|
||||
}
|
||||
public function actionList()
|
||||
{
|
||||
$commonSearch = new CommonSearch(['name']);
|
||||
$commonSearch->setQuery(FreeDeliveryRules::find()
|
||||
->select(['id', 'name', 'type','status'])
|
||||
->where(['mall_id'=>\Yii::$app->mallId])->andWhere(['is_delete'=>0]));
|
||||
$commonSearch->additionRules = [
|
||||
['name', 'string']
|
||||
];
|
||||
$commonSearch->bindFilter(function(/** @var ActiveQuery $q */ $q) {
|
||||
$q->andFilterWhere(['like','name',$this->name]);
|
||||
});
|
||||
$this->field = [
|
||||
FreeDeliveryRules::class=>[
|
||||
'id','name','type','status','typeText'
|
||||
]
|
||||
];
|
||||
return $commonSearch->search($this->get());
|
||||
|
||||
}
|
||||
public function actionAllList(){
|
||||
$allList = FreeDeliveryRules::find()->where([
|
||||
'is_delete' => 0,
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
])->select('id as value,name as label')->asArray()->all();
|
||||
foreach ($allList as &$v){
|
||||
$v['value'] = (int)$v['value'];
|
||||
}
|
||||
unset($v);
|
||||
array_unshift($allList, [
|
||||
'value' => 0,
|
||||
'label' => '默认包邮规则'
|
||||
]);
|
||||
|
||||
return [
|
||||
'list' => $allList
|
||||
];
|
||||
}
|
||||
|
||||
public function actionDel(){
|
||||
$id = $this->get('id');
|
||||
if(FreeDeliveryRules::updateAll(['is_delete'=>1],['id'=>$id,'mall_id'=>\Yii::$app->mallId])){
|
||||
$this->callbackEvent([],'id','refresh');
|
||||
return [];
|
||||
}else{
|
||||
throw new ApiException("删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
117
admin/controllers/system/GeneratorController.php
Normal file
117
admin/controllers/system/GeneratorController.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use admin\components\BaseAdminController;
|
||||
use admin\exceptions\ApiException;
|
||||
use admin\generators\model\Generator;
|
||||
use admin\models\Menu;
|
||||
use common\enums\StatusEnum;
|
||||
use common\helpers\ArrayHelper;
|
||||
use common\models\Role;
|
||||
use common\modelsgii\Menu2;
|
||||
use common\modelsgii\RoleMenu;
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/14
|
||||
* Time: 7:43 PM
|
||||
*/
|
||||
class GeneratorController extends BaseAdminController {
|
||||
|
||||
public $enableCsrfValidation=false;
|
||||
public function actionTables(){
|
||||
$db = \Yii::$app->db;
|
||||
if ($db === null) {
|
||||
return [];
|
||||
}
|
||||
$tableNames = [];
|
||||
//if (strpos($this->tableName, '*') !== false) {
|
||||
// if (($pos = strrpos($this->tableName, '.')) !== false) {
|
||||
// $schema = substr($this->tableName, 0, $pos);
|
||||
// $pattern = '/^' . str_replace('*', '\w+', substr($this->tableName, $pos + 1)) . '$/';
|
||||
// } else {
|
||||
// $schema = '';
|
||||
// $pattern = '/^' . str_replace('*', '\w+', $this->tableName) . '$/';
|
||||
// }
|
||||
$schema = '';
|
||||
|
||||
foreach ($db->schema->getTableNames($schema) as $table) {
|
||||
$tableNames[] = $schema === '' ? $table : ($schema . '.' . $table);
|
||||
}
|
||||
//} elseif (($table = $db->getTableSchema($this->tableName, true)) !== null) {
|
||||
// $tableNames[] = $this->tableName;
|
||||
// $this->classNames[$this->tableName] = $this->modelClass;
|
||||
//}
|
||||
|
||||
return $tableNames;
|
||||
}
|
||||
public function actionFields(){
|
||||
$tableName = $this->post('table_name');
|
||||
$db = \Yii::$app->db;
|
||||
if ($db === null) {
|
||||
return [];
|
||||
}
|
||||
$tableSchema = $db->getTableSchema($tableName);
|
||||
return $tableSchema->columns;
|
||||
}
|
||||
|
||||
public function actionConfig(){
|
||||
return [
|
||||
'controllerClass'=>'backend\controllers\\',
|
||||
'baseControllerClass'=>'backend\components\BaseBackendController',
|
||||
'actionIds'=>'list,save,info,del',
|
||||
'vuePath'=>'/Users/chatfeed/arco-work/',
|
||||
'controllerNamespace'=>'backend\controllers\\',
|
||||
];
|
||||
}
|
||||
public function actionGenerate(){
|
||||
//model generate
|
||||
$modelGen = new Generator();
|
||||
$modelGen->setAttributes(
|
||||
[
|
||||
'db'=>'db',
|
||||
'useTablePrefix'=>$this->post('useTablePrefix'),
|
||||
'ns'=>'common\modelsgii',
|
||||
'tableName'=>$this->post('table_name'),
|
||||
'baseClass'=>'common\core\BaseActiveRecord',
|
||||
'queryNs'=>'common\models',
|
||||
],
|
||||
);
|
||||
$modelClass = $modelGen->generateClassName($this->post('table_name'));
|
||||
$files = $modelGen->generate();
|
||||
//controller 生成
|
||||
$conGEn = new \backend\generators\controller\Generator();
|
||||
$conGEn->setAttributes([
|
||||
'controllerClass'=>$this->post('controllerClass'),
|
||||
'baseClass'=>$this->post('baseControllerClass'),
|
||||
'actions'=>$this->post('actionIds'),
|
||||
'controllerNamespace'=>$this->post('controllerNamespace')
|
||||
]);
|
||||
$files = $conGEn->generate();
|
||||
foreach ($files as $f){
|
||||
$f->save();
|
||||
}
|
||||
//vue生成
|
||||
$vueGen = new \backend\generators\vue\Generator();
|
||||
$vueGen->setAttributes([
|
||||
'className'=>$modelClass,
|
||||
'vuePath'=>$this->post('vuePath'),
|
||||
'columns'=>$this->post('columns'),
|
||||
'pagePath'=>$this->post('pagePath'),
|
||||
'apiPath'=>$conGEn->getControllerSubPath().$conGEn->getControllerID(),
|
||||
'actions'=>$this->post('actionIds'),
|
||||
]);
|
||||
$files = $vueGen->generate();
|
||||
|
||||
foreach ($files as $f){
|
||||
$f->save();
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
private function generatePHP(){
|
||||
|
||||
}
|
||||
}
|
||||
127
admin/controllers/system/IndexController.php
Normal file
127
admin/controllers/system/IndexController.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/18
|
||||
* Time: 3:19 PM
|
||||
*/
|
||||
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use admin\components\BaseAdminController;
|
||||
use admin\components\UI\Elements\Button;
|
||||
use admin\components\UI\Form;
|
||||
use admin\components\UI\Layout;
|
||||
use admin\components\UI\Node;
|
||||
use admin\components\UI\Tabs;
|
||||
use admin\components\UI\Widget;
|
||||
use admin\models\Config;
|
||||
use common\enums\StatusEnum;
|
||||
use common\helpers\ArrayHelper;
|
||||
|
||||
class IndexController extends BaseAdminController
|
||||
{
|
||||
public function actionIndex2()
|
||||
{
|
||||
$configs = Config::find()->where(['status'=>StatusEnum::ACTIVE])->orderBy('sort ASC')->asArray()->all();
|
||||
$configGroups = [];
|
||||
foreach ($configs as $config){
|
||||
$configGroups[$config['group']][] = $config;
|
||||
}
|
||||
foreach (\Yii::$app->params['config_group'] as $idx=>$name){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function actionIndex(){
|
||||
$layout = new Layout("基础配置");
|
||||
$tabs = new Tabs();
|
||||
//return ['node'=>$layout->render(),'setupScript'=>"\n return {}"];
|
||||
//$data = [];
|
||||
$layout->addChild(Widget::alert("非专业人士或不清楚选项请勿随意修改,否则可能会导致系统崩溃",'安全提示',function ($alert){
|
||||
return $alert->type('warning');
|
||||
}));
|
||||
$configs = Config::find()->where(['status'=>StatusEnum::ACTIVE])->orderBy('sort ASC')->asArray()->all();
|
||||
$configGroups = [];
|
||||
foreach ($configs as $config){
|
||||
$configGroups[$config['group']][] = $config;
|
||||
}
|
||||
foreach (\Yii::$app->params['config_group'] as $idx=>$name){
|
||||
$configGroup = isset($configGroups[$idx])?$configGroups[$idx]:[];
|
||||
if(!empty($configGroup)){
|
||||
$data = ArrayHelper::map($configGroup, 'name', 'value');
|
||||
$form = new Form($data);
|
||||
$form->action(\Yii::$app->urlManager->createUrl('system/index/save'));
|
||||
foreach ($configGroup as $config){
|
||||
$this->buildItem($form,$config);
|
||||
}
|
||||
$tabs->addTab($name,$idx,'',$form->renderFormWithoutNode());
|
||||
}
|
||||
}
|
||||
$layout->addChild($tabs->render());
|
||||
return $layout->render();
|
||||
}
|
||||
|
||||
public function actionSave(){
|
||||
/* 表单验证 */
|
||||
$data =$this->post();
|
||||
|
||||
//var_dump($data);exit;
|
||||
/* 更改配置值 */
|
||||
$error = [];
|
||||
foreach ($data as $name => $value) {
|
||||
$model = Config::findOne(['name' => $name]);
|
||||
$model->value = (string)$value;
|
||||
$model->update_time = time();
|
||||
if (!$model->save()) {
|
||||
$error[$model->name] = $model->getFirstErrors();
|
||||
}
|
||||
}
|
||||
if (empty($error)) {
|
||||
return [];
|
||||
} else {
|
||||
return ['error'=>$error];
|
||||
}
|
||||
}
|
||||
private function buildItem(Form $form,$config){
|
||||
//params config_type
|
||||
/**
|
||||
* 'config_type' => [
|
||||
0 => '数字',
|
||||
1 => '字符',
|
||||
2 => '文本',
|
||||
3 => '数组',
|
||||
4 => '枚举',
|
||||
5 => '富文本'
|
||||
],
|
||||
*/
|
||||
switch ($config['type']){
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
$form->text($config['title'], $config['name'])->help($config['remark']);
|
||||
break;
|
||||
case 3:
|
||||
$form->radio($config['title'],$config['name'],Config::parse(3,$config['extra']))->help($config['remark']);
|
||||
break;
|
||||
case 4:
|
||||
$form->textarea($config['title'],$config['name'])->help($config['remark']);
|
||||
break;
|
||||
case 5:
|
||||
$form->editor($config['title'],$config['name']);
|
||||
//@todo
|
||||
break;
|
||||
}
|
||||
}
|
||||
private function _parseExtra($str){
|
||||
$explode = explode("\n", trim($str));
|
||||
$ret =[];
|
||||
foreach ($explode as $itemStr){
|
||||
list($name,$val) = explode(":",$itemStr);
|
||||
$ret[$val] = $name;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
40
admin/controllers/system/MenuController.php
Normal file
40
admin/controllers/system/MenuController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use common\core\BaseAdminController;
|
||||
use admin\models\Menu;
|
||||
use common\helpers\ArrayHelper;
|
||||
use yii\base\Exception;
|
||||
|
||||
class MenuController extends BaseAdminController {
|
||||
|
||||
public $modelClass = Menu::class;
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$menu2s = Menu::find()->asArray()->all();
|
||||
return ArrayHelper::itemsMerge($menu2s,0,'menuUrl','parentPath','children');
|
||||
}
|
||||
public function actionSave(){
|
||||
$menuUrl = $this->post('menuUrl');
|
||||
$model = Menu::findOne($menuUrl);
|
||||
if(!$model){
|
||||
$model = new Menu();
|
||||
}
|
||||
$model->load($this->post());
|
||||
if( $model->load($this->post(),'') && $model->save()){
|
||||
return $model->getAttributes();
|
||||
}else{
|
||||
throw new Exception("参数不对");
|
||||
}
|
||||
}
|
||||
|
||||
public function actionDel(){
|
||||
$menuUrl = $this->post('menuUrl');
|
||||
$model = Menu::findOne($menuUrl);
|
||||
if($model->delete()){
|
||||
Menu::updateAll(['parentPath'=>''],['parentPath'=>$menuUrl]);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
139
admin/controllers/system/RefundAddressController.php
Normal file
139
admin/controllers/system/RefundAddressController.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/21
|
||||
* Time: 11:50 AM
|
||||
*/
|
||||
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use app\forms\common\CommonPostageRules;
|
||||
use admin\components\BaseAdminController;
|
||||
use admin\components\UI\Form;
|
||||
use admin\components\UI\Layout;
|
||||
use admin\components\UI\Table;
|
||||
use admin\components\UI\Tabs;
|
||||
use admin\exceptions\ApiException;
|
||||
use admin\models\forms\FreeRuleEditForm;
|
||||
use admin\models\forms\PostageRulesEditForm;
|
||||
use admin\models\forms\RefundAddressEditForm;
|
||||
use admin\models\search\CommonSearch;
|
||||
use common\models\DistrictArr;
|
||||
use common\models\FreeDeliveryRules;
|
||||
use common\models\PostageRules;
|
||||
use common\models\RefundAddress;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class RefundAddressController extends BaseAdminController
|
||||
{
|
||||
public function actionIndex(){
|
||||
$table = new Table(new RefundAddress());
|
||||
//$table->model();
|
||||
$table->title('退货地址');
|
||||
$table->key('id');
|
||||
$table->eventName(md5(get_called_class()));//设置事件名,后面更改数据对应
|
||||
$table->url(\Yii::$app->urlManager->createUrl("system/refund-address/list"));
|
||||
$table->filter('关键字', 'keyword',false)->text('请输入收件人姓名或联系方式')->quick();
|
||||
$table->action()->button('添加', $this->createUrl('system/refund-address/edit'))->type('dialog');
|
||||
$table->column('ID','id');
|
||||
$table->column('收件人姓名','name');
|
||||
$table->column('详细地址','full_address');
|
||||
$table->column('备注','remark');
|
||||
$column = $table->column('操作')->width(200);
|
||||
$column->link('编辑', $this->createUrl('system/refund-address/edit'), ['id' => 'id'])->type('dialog');
|
||||
$column->link('删除', $this->createUrl('system/refund-address/del'), ['id' => 'id'])->type('ajax', ['method' => 'post']);
|
||||
return $table->renderArray();
|
||||
}
|
||||
public function actionEdit(){
|
||||
$id = (int)$this->get('id');
|
||||
$config = $this->findModel($id);
|
||||
$form = new Form($config->getAttributes(['id','name','mobile','address_id','address_detail','remark']),false);
|
||||
$form->title('配置信息');
|
||||
$form->action($this->createUrl('system/refund-address/edit-save'));
|
||||
$arr = DistrictArr::getArr();
|
||||
unset($arr['1']);
|
||||
$form->card(function (/** @var Form $form */$form) use($arr) {
|
||||
$form->text("收件人姓名",'name');
|
||||
$form->text("联系方式",'mobile');
|
||||
$form->cascader('省市区','address_id',$arr);
|
||||
$form->textarea('详细地址','address_detail');
|
||||
$form->textarea('备注','remark');
|
||||
});
|
||||
return $form->renderArray();
|
||||
}
|
||||
|
||||
public function actionDistrict()
|
||||
{
|
||||
$district_arr = DistrictArr::getArr();
|
||||
$arr = DistrictArr::getList($district_arr);
|
||||
$str = str_replace('list','children',json_encode($arr));
|
||||
$arr = json_decode($str,true);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
public function actionEditSave(){
|
||||
$id = $this->get('id');
|
||||
$model = RefundAddress::findOne([
|
||||
'is_delete' => 0,
|
||||
'mall_id' => \Yii::$app->mallId,
|
||||
'id' => $id
|
||||
]);
|
||||
|
||||
if (!$model) {
|
||||
$model = new RefundAddress();
|
||||
$model->mall_id = \Yii::$app->mallId;
|
||||
}
|
||||
$model->load($this->post(),'');
|
||||
if($model->save()){
|
||||
$this->callbackEvent([],'id','refresh');
|
||||
return [];
|
||||
}else{
|
||||
return ['error'=>$model->getErrors()];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionDel(){
|
||||
$id = $this->get('id');
|
||||
if(RefundAddress::updateAll(['is_delete'=>1],['id'=>$id,'mall_id'=>\Yii::$app->mallId])){
|
||||
$this->callbackEvent([],'id','refresh');
|
||||
return [];
|
||||
}else{
|
||||
throw new ApiException("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$commonSearch = new CommonSearch(['keyword']);
|
||||
$commonSearch->setQuery(RefundAddress::find()
|
||||
->select(['id', 'name','address','address_detail','remark'])
|
||||
->where(['mall_id'=>\Yii::$app->mallId])->andWhere(['is_delete'=>0]));
|
||||
$commonSearch->additionRules = [
|
||||
['keyword', 'string']
|
||||
];
|
||||
$commonSearch->bindFilter(function(/** @var ActiveQuery $q */ $q) {
|
||||
$q->andFilterWhere(['like','name',$this->keyword]);
|
||||
});
|
||||
$this->field = [
|
||||
RefundAddress::class =>[
|
||||
'id','name','full_address','remark'
|
||||
]
|
||||
];
|
||||
return $commonSearch->search($this->get());
|
||||
|
||||
}
|
||||
protected function findModel($id)
|
||||
{
|
||||
if ($id == 0) {
|
||||
return new RefundAddress();
|
||||
}
|
||||
if (($model = RefundAddress::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
}
|
||||
64
admin/controllers/system/RoleController.php
Normal file
64
admin/controllers/system/RoleController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace admin\controllers\system;
|
||||
use common\core\BaseAdminController;
|
||||
use admin\models\Menu;
|
||||
use common\enums\StatusEnum;
|
||||
use common\helpers\ArrayHelper;
|
||||
use common\models\Role;
|
||||
use common\modelsgii\RoleMenu;
|
||||
|
||||
class RoleController extends BaseAdminController {
|
||||
|
||||
public $modelClass = Role::class;
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$roles = Role::find()->asArray()->all();
|
||||
return $roles;
|
||||
}
|
||||
public function actionSaveUserMenu(){
|
||||
$params = $this->requestValidate($this->post(),[
|
||||
['role_id','required'],
|
||||
['role_id','integer'],
|
||||
['ids','required']
|
||||
]);
|
||||
if(is_array($params->ids)){
|
||||
$insert = [];
|
||||
foreach ($params->ids as $id){
|
||||
$insert[] = [
|
||||
'role_id'=>$params->role_id,
|
||||
'menuUrl'=>$id,
|
||||
'created_at'=>time(),
|
||||
'updated_at'=>time()
|
||||
];
|
||||
}
|
||||
RoleMenu::deleteAll(['role_id'=>$params->role_id]);
|
||||
RoleMenu::getDb()->createCommand()->batchInsert(RoleMenu::tableName(),array_keys($insert[0]),$insert)->execute();
|
||||
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function actionMenuByRoleId(){
|
||||
$params = $this->requestValidate($this->post(),[
|
||||
['roleId','required'],
|
||||
]);
|
||||
$roleMenus = RoleMenu::findAll(['role_id' => $params->roleId]);
|
||||
$keys = ArrayHelper::getColumn($roleMenus,'menuUrl');
|
||||
$menus = Menu::find()->asArray()->all();
|
||||
return[
|
||||
'menus'=>ArrayHelper::itemsMerge($menus,0,'menuUrl','parentPath','children'),
|
||||
'checked'=>$keys
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
public function actionDel(){
|
||||
$menuUrl = $this->post('menuUrl');
|
||||
$model = Menu::findOne($menuUrl);
|
||||
if($model->delete()){
|
||||
Menu::updateAll(['parentPath'=>''],['parentPath'=>$menuUrl]);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
147
admin/controllers/system/SubAccountController.php
Normal file
147
admin/controllers/system/SubAccountController.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use admin\models\Admin;
|
||||
use admin\models\Menu;
|
||||
use common\helpers\ArrayHelper;
|
||||
use common\models\SubAccountMenu;
|
||||
use common\modelsgii\RoleMenu;
|
||||
use common\validators\DateRangeValidator;
|
||||
use yii\base\DynamicModel;
|
||||
use yii\base\Exception;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use common\core\BaseAdminController;
|
||||
|
||||
class SubAccountController extends BaseAdminController
|
||||
{
|
||||
public $modelClass = Admin::class;
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$m = new DynamicModel(['page','pageSize']);
|
||||
//$m->addRule('aa',DateRangeValidator::class);
|
||||
//$m->addRule('xx','string');
|
||||
$m->addRule('page','default',['value'=>1]);
|
||||
$m->addRule('pageSize','default',['value'=>10]);
|
||||
$m->addRule('page','integer',['max'=>1000]);
|
||||
$m->addRule('pageSize','integer',['min'=>1,'max'=>50]);
|
||||
$m->load($this->post());
|
||||
if(!$m->validate()){
|
||||
throw new Exception(json_encode($m->getFirstErrors()));
|
||||
}
|
||||
$query = Admin::find()->where(['is_sub'=>1])->andWhere([
|
||||
'role'=>\Yii::$app->user->identity->role,
|
||||
'mall_id'=>\Yii::$app->user->identity->mall_id,
|
||||
'is_delete'=>0
|
||||
]);
|
||||
|
||||
$this->field = [
|
||||
Admin::class => [
|
||||
'uid','username','mobile','last_login_time','last_login_ip'=>function($m){
|
||||
return $m->last_login_ip ? long2ip($m->last_login_ip) : '';
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort'=>[
|
||||
'defaultOrder'=>['uid'=>SORT_DESC]
|
||||
],
|
||||
'pagination'=>[
|
||||
'defaultPageSize'=>$m->pageSize,
|
||||
'params'=>['page'=>$m->page]
|
||||
]
|
||||
]);
|
||||
// add conditions that should always apply here
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
public function actionSave(){
|
||||
$id = (int)$this->get('id');
|
||||
$model = $this->findModel($id);
|
||||
$data = $this->post();
|
||||
$data['password'] = \Yii::$app->security->generatePasswordHash($data['password']);
|
||||
$data['role'] = \Yii::$app->user->identity->role;
|
||||
$data['mall_id'] = \Yii::$app->user->identity->mall_id;
|
||||
$data['is_sub'] = 1;
|
||||
$data['last_login_ip'] = isset($data['last_login_ip']) && $data['last_login_ip'] ? ip2long($data['last_login_ip']) : 0;
|
||||
if($model->load($data,'') && $model->save()){
|
||||
return [];
|
||||
}else{
|
||||
throw new Exception("保存失败:".current($model->getFirstErrors()));
|
||||
}
|
||||
}
|
||||
|
||||
public function actionMenuByUid(){
|
||||
$params = $this->requestValidate($this->post(),[
|
||||
['admin_id','required'],
|
||||
]);
|
||||
$roleMenus = RoleMenu::findAll(['role_id' => \Yii::$app->user->identity->role]);
|
||||
$roleKeys = ArrayHelper::getColumn($roleMenus,'menuUrl');
|
||||
$menus = Menu::find()->where(['in','menuUrl',$roleKeys])->asArray()->all();
|
||||
$userMenus = SubAccountMenu::findAll(['admin_id'=>$params->admin_id]);
|
||||
$keys = ArrayHelper::getColumn($userMenus,'menuUrl');
|
||||
return[
|
||||
'menus'=>ArrayHelper::itemsMerge($menus,0,'menuUrl','parentPath','children'),
|
||||
'checked'=>$keys
|
||||
];
|
||||
}
|
||||
|
||||
public function actionDel(){
|
||||
$params = $this->requestValidate($this->post(),[
|
||||
['admin_id','required']
|
||||
]);
|
||||
$model = $this->findModel($params->admin_id);
|
||||
if(!$model || $model->is_sub!==1){
|
||||
throw new Exception("账号不存在");
|
||||
}
|
||||
$model->delete();
|
||||
// $model->updateAttributes(['is_delete'=>1]);
|
||||
return [];
|
||||
}
|
||||
public function actionSaveMenu(){
|
||||
$params = $this->requestValidate($this->post(),[
|
||||
['admin_id','required'],
|
||||
['admin_id','integer'],
|
||||
['ids','required']
|
||||
]);
|
||||
if(is_array($params->ids)){
|
||||
$insert = [];
|
||||
foreach ($params->ids as $id){
|
||||
$insert[] = [
|
||||
'admin_id'=>$params->admin_id,
|
||||
'menuUrl'=>$id,
|
||||
'created_at'=>time(),
|
||||
'updated_at'=>time()
|
||||
];
|
||||
}
|
||||
SubAccountMenu::deleteAll(['admin_id'=>$params->admin_id]);
|
||||
SubAccountMenu::getDb()->createCommand()->batchInsert(SubAccountMenu::tableName(),array_keys($insert[0]),$insert)->execute();
|
||||
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return ActiveRecord
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if ($id == 0) {
|
||||
return new $this->modelClass();
|
||||
}
|
||||
if (($model = $this->modelClass::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user