GoodsBrandSubscribeLog.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\models;
  8. use app\models\common\admin\log\CommonActionLog;
  9. use Yii;
  10. use yii\behaviors\TimestampBehavior;
  11. /**
  12. * This is the model class for table "{{%goods_cat}}".
  13. *
  14. * @property integer $id
  15. * @property integer $user_id
  16. * @property string $goods_brand_id
  17. * @property string $created_at
  18. * @property string $updated_at
  19. */
  20. class GoodsBrandSubscribeLog extends \yii\db\ActiveRecord
  21. {
  22. /**
  23. * @inheritdoc
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%goods_brand_subscribe_log}}';
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['id', 'user_id', 'goods_brand_id'], 'integer'],
  36. [['created_at', 'updated_at'], 'string'],
  37. ];
  38. }
  39. public function behaviors()
  40. {
  41. return [
  42. [
  43. 'class' => TimestampBehavior::class,
  44. ]
  45. ];
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'id' => '主键',
  54. 'user_id' => '用户ID',
  55. 'goods_brand_id' => '品牌ID',
  56. 'created_at' => '添加时间',
  57. 'updated_at' => '',
  58. ];
  59. }
  60. // public function afterSave($insert, $changedAttributes)
  61. // {
  62. /*$data = $insert ? json_encode($this->attributes) : json_encode($changedAttributes);
  63. CommonActionLog::storeActionLog('', $insert, $this->is_delete, $data, $this->id);*/
  64. // }
  65. public static function getUserSubscribeLog($user_id) {
  66. return self::find()->alias('s')->leftJoin(['b' => GoodsBrand::tableName()], 's.goods_brand_id = b.id')
  67. ->where(['s.user_id' => $user_id, 'b.is_delete' => 0, 'b.is_show' => 1])->select('s.goods_brand_id')
  68. ->orderBy('s.id DESC')->column();
  69. }
  70. public static function getBrandList($brand_id) {
  71. return self::find()->where(['goods_brand_id' => $brand_id])->select('id')->column();
  72. }
  73. public static function isSubscribe($user_id, $brand_id) {
  74. return self::findOne(['goods_brand_id' => $brand_id, 'user_id' => $user_id]);
  75. }
  76. }