CloudStockSms.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace addons\CloudStock\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 CloudStockSms 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. 'early_warning' => ['sms_key' => 'early_warning', 'temp_name' => '库存预警通知', 'temp_id' => '', 'temp_content' => '您的${goods_name}库存不足,请及时进行补货'],
  26. ];
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return '{{%addons_cloud_stock_sms}}';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['temp_id', 'temp_content', 'sms_key', 'temp_name'], 'required'],
  41. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  42. [['temp_id', 'sms_key'], 'string', 'max' => 255],
  43. [['temp_content', 'temp_name'], 'string', 'max' => 1024],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => '自增id',
  53. 'temp_id' => '模板id',
  54. 'temp_content' => '模板内容',
  55. 'mall_id' => '商城id',
  56. 'sms_key' => '键值',
  57. 'temp_name' => '模板名称',
  58. 'status' => '状态[-1:删除;0:禁用;1启用]',
  59. 'created_at' => 'Created At',
  60. 'updated_at' => 'Updated At',
  61. ];
  62. }
  63. public static function setData(array $params)
  64. {
  65. try {
  66. if(!empty($params['id'])){
  67. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED]]);
  68. if (empty($model)) throw new \Exception('服务不存在或已删除');
  69. }else{
  70. $model = new self();
  71. $model->loadDefaultValues();
  72. }
  73. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  74. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  75. return $model;
  76. } catch (\Exception $e) {
  77. self::$static_error = $e->getMessage();
  78. return false;
  79. }
  80. }
  81. }