MessageHistory.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace addons\Wechat\common\models;
  3. use common\models\member\Auth;
  4. /**
  5. * This is the model class for table "rf_addon_wechat_message_history".
  6. *
  7. * @property int $id
  8. * @property int|null $merchant_id 商户id
  9. * @property int|null $store_id 店铺ID
  10. * @property int|null $rule_id 规则id
  11. * @property int|null $keyword_id 关键字id
  12. * @property string|null $openid
  13. * @property string|null $module 触发模块
  14. * @property int|null $is_addon 是否插件
  15. * @property string $addon_name 插件名称
  16. * @property string|null $message 微信消息
  17. * @property string|null $type
  18. * @property string|null $event 详细事件
  19. * @property int $status 状态[-1:删除;0:禁用;1启用]
  20. * @property int|null $created_at 创建时间
  21. * @property int $updated_at 修改时间
  22. */
  23. class MessageHistory extends \common\models\base\BaseModel
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addon_wechat_message_history}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['merchant_id', 'store_id', 'rule_id', 'keyword_id', 'is_addon', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['openid', 'module'], 'string', 'max' => 50],
  40. [['addon_name'], 'string', 'max' => 100],
  41. [['message'], 'string', 'max' => 1000],
  42. [['type', 'event'], 'string', 'max' => 20],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'ID',
  52. 'merchant_id' => '商户id',
  53. 'store_id' => '店铺ID',
  54. 'rule_id' => '规则id',
  55. 'keyword_id' => '关键字id',
  56. 'openid' => 'openId',
  57. 'module' => '触发模块',
  58. 'is_addon' => '是否插件',
  59. 'addon_name' => '插件名称',
  60. 'message' => '微信消息',
  61. 'type' => 'Type',
  62. 'event' => '详细事件',
  63. 'status' => '状态',
  64. 'created_at' => '创建时间',
  65. 'updated_at' => '修改时间',
  66. ];
  67. }
  68. /**
  69. * 关联粉丝
  70. *
  71. * @return \yii\db\ActiveQuery
  72. */
  73. public function getFans()
  74. {
  75. return $this->hasOne(Fans::class, ['openid' => 'openid']);
  76. }
  77. /**
  78. * 关联授权
  79. */
  80. public function getAuth()
  81. {
  82. return $this->hasOne(Auth::class, ['oauth_client_user_id' => 'openid']);
  83. }
  84. /**
  85. * 关联规则
  86. *
  87. * @return \yii\db\ActiveQuery
  88. */
  89. public function getRule()
  90. {
  91. return $this->hasOne(Rule::class, ['id' => 'rule_id']);
  92. }
  93. /**
  94. * @param bool $insert
  95. * @return bool
  96. */
  97. public function beforeSave($insert)
  98. {
  99. if ($this->isNewRecord) {
  100. !empty($this->addon_name) && $this->is_addon = 1;
  101. }
  102. return parent::beforeSave($insert);
  103. }
  104. }
粤ICP备19079148号