Files
xk-api-yii/admin/controllers/base/SetController.php

140 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2024-09-19 11:32:39 +08:00
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use admin\models\forms\drug\AgreeForm;
2024-12-19 19:20:27 +08:00
use common\models\oldDb\BaseConfig;
use common\models\oldDb\SystemConfig;
2024-09-19 11:32:39 +08:00
use yii\db\Exception;
/**
* @doc-module 设置
*/
class SetController extends BaseAdminController
{
/**
* @doc-name 协议列表
* @doc-return mixed @List{id,end-int-1用户端2服务端 ,type-int-类型1服务协议2隐私政策3其他,desc-string-描述,content-string-内容,change_at-string-变更时间,status-int-是否删除0否1是,created_at-int-创建时间} 协议列表
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
*/
public function actionAgreeList()
{
$get= \Yii::$app->request->get();
$query=BaseConfig::find()->where([
'status'=>0
]);
$this->field=[
BaseConfig::class=>[
'id','type','desc','content','change_at'=>function($m){
return date('Y-m-d H:i:s',$m->change_at);
},
'status','end',
'created_at'=>function($model){
return date('Y-m-d H:i:s',$model->created_at);
}
]
];
return $this->create($query,$get);
}
/**
* @doc-name 删除协议
* @doc-param int id 协议ID
*/
public function actionAgreeDel()
{
$get= \Yii::$app->request->get();
$this->requestValidate($get,[
['id','required']
]);
$AgreeForm=new AgreeForm();
$AgreeForm->attributes=$get;
return $AgreeForm->del();
}
/**
* @doc-name 编译协议及新增协议
* @doc-desc 传id即为编辑
* @doc-param int id 协议ID / optional
* @doc-param string type 类型1服务协议2隐私政策3其他
* @doc-param string desc 描述 / optional
* @doc-param string content 内容
*/
public function actionAgreeSave()
{
$post = \Yii::$app->request->post();
$AgreeForm=new AgreeForm();
$AgreeForm->attributes=$post;
return $AgreeForm->save();
}
/**
* @doc-name 西药包邮
* @doc-desc 传id即为编辑
* @doc-param string name name
* @doc-param string rule 规则
* @doc-param string value
*/
public function actionFreeShip()
{
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['name','required'],
['rule','required'],
['value','required'],
]);
$SystemConfig=SystemConfig::find()->where([
'config_type'=>2,
'type'=>2
])->one();
if (!$SystemConfig){
throw new Exception('西药包邮配置不存在');
}
$SystemConfig->name=$post['name'];
$SystemConfig->rule=$post['rule'];
$SystemConfig->value=$post['value'];
$SystemConfig->saveOrFail();
return ['设置成功'];
}
/**
* 小程序版本
*/
public function actionXcxVersion(){
$SystemConfig=SystemConfig::find()->where([
'config_type'=>3,
])->one();
if (!$SystemConfig){
throw new Exception('小程序版本配置不存在');
}
return $SystemConfig;
}
/**
* 小程序版本设置
*/
public function actionXcxVersionSet(){
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['value','required'],
]);
$SystemConfig=SystemConfig::find()->where([
'config_type'=>3,
])->one();
if (!$SystemConfig){
throw new Exception('小程序版本配置不存在');
}
$SystemConfig->value=$post['value'];
$SystemConfig->saveOrFail();
return ['设置成功'];
}
}