ShortVideoBrowseNum.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace addons\ShortVideo\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_short_video_browse_num}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id
  11. * @property int|null $look_num 观看次数
  12. * @property int $status 状态[-1:删除;0:禁用;1启用]
  13. * @property int $created_at
  14. * @property int $updated_at
  15. */
  16. class ShortVideoBrowseNum extends \common\models\base\BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_short_video_browse_num}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'user_id'], 'required'],
  32. [['mall_id', 'user_id', 'look_num', 'status', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'user_id' => 'User ID',
  44. 'look_num' => 'Look Num',
  45. 'status' => 'Status',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. ];
  49. }
  50. public static function setData(int $mall_id, array $data)
  51. {
  52. $model = self::findOne(['mall_id' => $mall_id, 'user_id' => $data['user_id'], 'status' => StatusEnum::ENABLED]);
  53. if (empty($model)) {
  54. $model = new self();
  55. $model->loadDefaultValues();
  56. $model->mall_id = $mall_id;
  57. }
  58. foreach ($data as $key => $val) {
  59. $model->$key = $val;
  60. }
  61. // dd($model);
  62. if (!$model->save()) {
  63. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  64. return false;
  65. }
  66. return $model;
  67. }
  68. }