CloudStockTwoSms.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace addons\CloudStockTwo\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_cloud_stock_sms".
  8. *
  9. * @property int $id 自增id
  10. * @property string $temp_id 模板id
  11. * @property string $temp_content 模板内容
  12. * @property int $mall_id 商城id
  13. * @property string $sms_key 键值
  14. * @property string $temp_name 模板名称
  15. * @property int $status 状态[-1:删除;0:禁用;1启用]
  16. * @property int $created_at
  17. * @property int $updated_at
  18. */
  19. class CloudStockTwoSms extends BaseActiveRecord
  20. {
  21. public static $sms_data = [
  22. 'fill' => ['sms_key' => 'fill', 'temp_name' => '补货通知', 'temp_id' => '', 'temp_content' => '你有下级订单,请${hour}小时内补货。'],
  23. 'upgrade' => ['sms_key' => 'upgrade', 'temp_name' => '升级通知', 'temp_id' => '', 'temp_content' => '恭喜你,你的云库存代理商等级升到了${level_name}。'],
  24. 'bonus' => ['sms_key' => 'bonus', 'temp_name' => '收益通知', 'temp_id' => '', 'temp_content' => '恭喜你,获得了${money}元云库存收益。请注意查看']
  25. ];
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%addons_cloud_stock_two_sms}}';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['temp_id', 'temp_content', 'sms_key', 'temp_name'], 'required'],
  40. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  41. [['temp_id', 'sms_key'], 'string', 'max' => 255],
  42. [['temp_content', 'temp_name'], 'string', 'max' => 1024],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => '自增id',
  52. 'temp_id' => '模板id',
  53. 'temp_content' => '模板内容',
  54. 'mall_id' => '商城id',
  55. 'sms_key' => '键值',
  56. 'temp_name' => '模板名称',
  57. 'status' => '状态[-1:删除;0:禁用;1启用]',
  58. 'created_at' => 'Created At',
  59. 'updated_at' => 'Updated At',
  60. ];
  61. }
  62. public static function setData(array $params)
  63. {
  64. try {
  65. if(!empty($params['id'])){
  66. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED]]);
  67. if (empty($model)) throw new \Exception('服务不存在或已删除');
  68. }else{
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. }
  72. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  73. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  74. return $model;
  75. } catch (\Exception $e) {
  76. self::$static_error = $e->getMessage();
  77. return false;
  78. }
  79. }
  80. }