| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace addons\CloudStockTwo\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "{{%addons_cloud_stock_sms".
- *
- * @property int $id 自增id
- * @property string $temp_id 模板id
- * @property string $temp_content 模板内容
- * @property int $mall_id 商城id
- * @property string $sms_key 键值
- * @property string $temp_name 模板名称
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class CloudStockTwoSms extends BaseActiveRecord
- {
- public static $sms_data = [
- 'fill' => ['sms_key' => 'fill', 'temp_name' => '补货通知', 'temp_id' => '', 'temp_content' => '你有下级订单,请${hour}小时内补货。'],
- 'upgrade' => ['sms_key' => 'upgrade', 'temp_name' => '升级通知', 'temp_id' => '', 'temp_content' => '恭喜你,你的云库存代理商等级升到了${level_name}。'],
- 'bonus' => ['sms_key' => 'bonus', 'temp_name' => '收益通知', 'temp_id' => '', 'temp_content' => '恭喜你,获得了${money}元云库存收益。请注意查看']
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_two_sms}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['temp_id', 'temp_content', 'sms_key', 'temp_name'], 'required'],
- [['mall_id', 'status', 'created_at', 'updated_at'], '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' => '模板内容',
- 'mall_id' => '商城id',
- 'sms_key' => '键值',
- 'temp_name' => '模板名称',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if(!empty($params['id'])){
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|