PkSms.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace addons\Pk\common\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "{{%addons_pk_sms}}".
  7. *
  8. * @property int $id 自增id
  9. * @property string $temp_id 模板id
  10. * @property string $temp_content 模板内容
  11. * @property int $created_at
  12. * @property int $updated_at
  13. * @property int $mall_id
  14. * @property string $sms_key 键值
  15. * @property string $temp_name 模板名称
  16. * @property int $is_enable 是否开启通知;
  17. * @property int $status 状态[-1:删除;0:禁用;1启用]
  18. */
  19. class PkSms extends \common\models\base\BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_pk_sms}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['temp_id', 'temp_content', 'sms_key', 'temp_name'], 'required'],
  35. [['created_at', 'updated_at', 'mall_id', 'is_enable', 'status'], 'integer'],
  36. [['temp_id', 'sms_key'], 'string', 'max' => 255],
  37. [['temp_content', 'temp_name'], 'string', 'max' => 1024],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => '自增id',
  47. 'temp_id' => '模板id',
  48. 'temp_content' => '模板内容',
  49. 'created_at' => 'Created At',
  50. 'updated_at' => 'Updated At',
  51. 'mall_id' => 'Mall ID',
  52. 'sms_key' => '键值',
  53. 'temp_name' => '模板名称',
  54. 'is_enable' => '是否开启通知;',
  55. 'status' => '状态[-1:删除;0:禁用;1启用]',
  56. ];
  57. }
  58. /**
  59. * 保存数据
  60. * @Author: ltm
  61. * @DateTime: 2022/6/8 0015 9:26
  62. * @Copyright: copyright (c) 2021
  63. * @param $mall_id
  64. * @param array $params
  65. * @return Rebate|bool
  66. */
  67. public static function setData(array $params){
  68. try{
  69. $mall_id = $params['mall_id'];
  70. if(!empty($params['id'])){
  71. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', -1]]);
  72. if(empty($model)) throw new \Exception('活动不存在或已删除');
  73. }else{
  74. $model = new self();
  75. $model->loadDefaultValues();
  76. $model->mall_id = $mall_id;
  77. }
  78. // 将内容转为json字符串
  79. if(!empty($params['reward_info'])) $params['recommen_reward'] = json_encode($params['reward_info']);
  80. if(!empty($params['be_reward_info'])) $params['be_recommen_reward'] = json_encode($params['be_reward_info']);
  81. if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  82. return $model;
  83. }catch(\Exception $e){
  84. self::setStaticError($e->getMessage());
  85. return false;
  86. }
  87. }
  88. }