Live.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace addons\WechatMini\common\models\live;
  3. use common\behaviors\MerchantBehavior;
  4. use common\helpers\StringHelper;
  5. use common\models\base\BaseModel;
  6. /**
  7. * This is the model class for table "rf_addon_wechat_mini_live".
  8. *
  9. * @property int $id 组合商品id
  10. * @property int|null $merchant_id 商户id
  11. * @property int|null $store_id 店铺ID
  12. * @property string|null $name 直播间名称
  13. * @property int|null $roomid 直播间ID
  14. * @property string|null $cover_img 直播封面
  15. * @property string|null $share_img 直播间分享图链接
  16. * @property int|null $live_status 直播间状态
  17. * @property int|null $start_time 开始时间
  18. * @property int|null $end_time 结束时间
  19. * @property string|null $anchor_name 主播名
  20. * @property string|null $anchor_wechat 主播微信
  21. * @property string|null $sub_anchor_wechat 主播副号微信号
  22. * @property int|null $live_type 直播类型,1 推流 0 手机直播
  23. * @property string|null $creater_openid 创建者openid
  24. * @property string|null $creater_wechat 创建者微信号
  25. * @property int|null $close_like 是否关闭点赞[0:开启;1:关闭]
  26. * @property int|null $close_goods 是否关闭货架[0:开启;1:关闭]
  27. * @property int|null $close_comment 是否关闭评论[0:开启;1:关闭]
  28. * @property int|null $close_share 是否关闭分享[0:开启;1:关闭]
  29. * @property int|null $close_kf 是否关闭客服[0:开启;1:关闭]
  30. * @property int|null $close_replay 是否关闭回放[0:开启;1:关闭]
  31. * @property int|null $is_feeds_public 是否开启官方收录[1:开启;0:关闭]
  32. * @property string|null $feeds_img 官方收录封面
  33. * @property int|null $total 拉取房间总数
  34. * @property string|null $playback 回放视频
  35. * @property string|null $push_addr 直播间推流地址
  36. * @property string|null $assistant 小助手
  37. * @property string|null $cover_media 直播封面资源ID
  38. * @property string|null $share_media 直播间分享图资源ID
  39. * @property string|null $feeds_media 官方收录封面资源ID
  40. * @property string|null $share_path 分享
  41. * @property string|null $qrcode_url 二维码地址
  42. * @property int|null $is_recommend 是否推荐
  43. * @property int|null $is_stick 是否置顶
  44. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  45. * @property int|null $created_at 创建时间
  46. * @property int|null $updated_at 修改时间
  47. */
  48. class Live extends BaseModel
  49. {
  50. use MerchantBehavior;
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public static function tableName()
  55. {
  56. return '{{%addon_wechat_mini_live}}';
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function rules()
  62. {
  63. return [
  64. [
  65. [
  66. 'merchant_id',
  67. 'store_id',
  68. 'roomid',
  69. 'live_status',
  70. 'live_type',
  71. 'close_like',
  72. 'close_goods',
  73. 'close_comment',
  74. 'close_share',
  75. 'close_kf',
  76. 'close_replay',
  77. 'is_feeds_public',
  78. 'total',
  79. 'is_recommend',
  80. 'is_stick',
  81. 'status',
  82. 'created_at',
  83. 'updated_at',
  84. ],
  85. 'integer',
  86. ],
  87. [['playback', 'assistant', 'share_path'], 'safe'],
  88. [
  89. [
  90. 'name',
  91. 'cover_img',
  92. 'share_img',
  93. 'anchor_name',
  94. 'feeds_img',
  95. 'cover_media',
  96. 'share_media',
  97. 'feeds_media',
  98. ],
  99. 'string',
  100. 'max' => 200,
  101. ],
  102. [['anchor_wechat', 'sub_anchor_wechat', 'creater_openid', 'creater_wechat'], 'string', 'max' => 50],
  103. [['push_addr'], 'string', 'max' => 500],
  104. [['qrcode_url'], 'string', 'max' => 255],
  105. // 自定义
  106. [['name', 'anchor_name', 'anchor_wechat', 'cover_img', 'share_img', 'feeds_img'], 'required'],
  107. [['name'], 'string', 'min' => 3, 'max' => 17],
  108. [['anchor_name'], 'string', 'min' => 2, 'max' => 15],
  109. [['start_time', 'end_time'], 'required'],
  110. [['end_time'], 'comparisonEndTime'],
  111. ];
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public function attributeLabels()
  117. {
  118. return [
  119. 'id' => '组合商品id',
  120. 'merchant_id' => '商户id',
  121. 'store_id' => '店铺ID',
  122. 'name' => '直播间名称',
  123. 'roomid' => '直播间ID',
  124. 'cover_img' => '直播封面',
  125. 'share_img' => '直播间分享图',
  126. 'live_status' => '直播间状态',
  127. 'start_time' => '开始时间',
  128. 'end_time' => '结束时间',
  129. 'anchor_name' => '主播名',
  130. 'anchor_wechat' => '主播微信号',
  131. 'sub_anchor_wechat' => '主播副号微信号',
  132. 'creater_wechat' => '创建者微信号',
  133. 'live_type' => '直播类型', // 1:推流;0:手机直播
  134. 'creater_openid' => '创建者openid',
  135. 'close_like' => '点赞', // 0:开启;1:关闭
  136. 'close_goods' => '货架', // 0:开启;1:关闭
  137. 'close_comment' => '评论', // 0:开启;1:关闭
  138. 'close_share' => '分享', // 0:开启;1:关闭
  139. 'close_kf' => '客服', // 0:开启;1:关闭
  140. 'close_replay' => '直播回放', // 0:开启;1:关闭
  141. 'is_feeds_public' => '官方收录', // 1:开启;0:关闭
  142. 'feeds_img' => '官方收录封面',
  143. 'total' => '拉取房间总数',
  144. 'playback' => '回放视频',
  145. 'push_addr' => '直播间推流地址',
  146. 'share_link' => '直播间分享二维码',
  147. 'assistant' => '小助手',
  148. 'is_stick' => '是否置顶',
  149. 'is_recommend' => '是否推荐',
  150. 'status' => '状态', // [-1:删除;0:禁用;1启用]
  151. 'created_at' => '创建时间',
  152. 'updated_at' => '修改时间',
  153. ];
  154. }
  155. /**
  156. * @param $attribute
  157. */
  158. public function comparisonEndTime($attribute)
  159. {
  160. $start_time = StringHelper::dateToInt($this->start_time);
  161. $end_time = StringHelper::dateToInt($this->end_time);
  162. if ($start_time >= $end_time) {
  163. $this->addError($attribute, '结束时间必须大于开始时间');
  164. }
  165. }
  166. /**
  167. * @return \yii\db\ActiveQuery
  168. */
  169. public function getGoodsMap()
  170. {
  171. return $this->hasMany(GoodsMap::class, ['roomid' => 'roomid']);
  172. }
  173. /**
  174. * @param bool $insert
  175. * @return bool
  176. */
  177. public function beforeSave($insert)
  178. {
  179. $this->start_time = StringHelper::dateToInt($this->start_time);
  180. $this->end_time = StringHelper::dateToInt($this->end_time);
  181. return parent::beforeSave($insert);
  182. }
  183. }
粤ICP备19079148号