| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace addons\Certificate\common\models;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_certificate}}".
- *
- * @property int $id
- * @property int|null $mall_id 商城ID
- * @property string|null $name 证书名称
- * @property int|null $download_num 下载次数
- * @property string|null $content 证书设置 json形式保存
- * @property string|null $bg 证书背景
- * @property string|null $status 状态(-1是已删除,0是禁用,1是正常)
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class Certificate extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_certificate}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'status', 'download_num', 'created_at', 'updated_at'], 'integer'],
- [['content', 'member_level'], 'string'],
- [['name', 'bg'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'name' => '证书名称',
- 'download_num' => '下载次数',
- 'content' => '证书设置 json形式保存',
- 'member_level' => '允许查看及保存的会员等级',
- 'bg' => '证书背景',
- 'status' => '状态(-1是已删除,0是禁用,1是正常)',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/5/8 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return string
- */
- public static function setData(array $params){
- try{
- if (isset($params['member_level']) && is_array($params['member_level'])) {
- $params['member_level'] = array_filter($params['member_level'], function ($item) {
- return trim($item) !== '';
- });
- $params['member_level'] = implode(',', $params['member_level']);
- }
- if (!empty($params['id'])) {
- $model = self::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
- if (empty($model)) throw new Exception('记录不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- $model->mall_id = $params['mall_id'];
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|