| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace addons\Pk\common\models;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_pk_sms}}".
- *
- * @property int $id 自增id
- * @property string $temp_id 模板id
- * @property string $temp_content 模板内容
- * @property int $created_at
- * @property int $updated_at
- * @property int $mall_id
- * @property string $sms_key 键值
- * @property string $temp_name 模板名称
- * @property int $is_enable 是否开启通知;
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- */
- class PkSms extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_pk_sms}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['temp_id', 'temp_content', 'sms_key', 'temp_name'], 'required'],
- [['created_at', 'updated_at', 'mall_id', 'is_enable', 'status'], 'integer'],
- [['temp_id', 'sms_key'], 'string', 'max' => 255],
- [['temp_content', 'temp_name'], 'string', 'max' => 1024],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '自增id',
- 'temp_id' => '模板id',
- 'temp_content' => '模板内容',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'mall_id' => 'Mall ID',
- 'sms_key' => '键值',
- 'temp_name' => '模板名称',
- 'is_enable' => '是否开启通知;',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/6/8 0015 9:26
- * @Copyright: copyright (c) 2021
- * @param $mall_id
- * @param array $params
- * @return Rebate|bool
- */
- public static function setData(array $params){
- try{
- $mall_id = $params['mall_id'];
- if(!empty($params['id'])){
- $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', -1]]);
- if(empty($model)) throw new \Exception('活动不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- // 将内容转为json字符串
- if(!empty($params['reward_info'])) $params['recommen_reward'] = json_encode($params['reward_info']);
- if(!empty($params['be_reward_info'])) $params['be_recommen_reward'] = json_encode($params['be_reward_info']);
- if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|