BuyGoodsLog.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * BuyGoodsLog.php
  4. * todo 文件描述
  5. * Created on 2024/4/15 13:55
  6. * @author: hankaige
  7. */
  8. namespace app\models;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%card}}".
  13. * @property int $id
  14. * @property int|null $store_id
  15. * @property string $goods_id 卡券名称
  16. * @property string $nickname
  17. * @property string|null $avatar_url 卡券描述
  18. * @property int $status
  19. * @property int|null $updated_at
  20. * @property int|null $created_at
  21. */
  22. class BuyGoodsLog extends \yii\db\ActiveRecord
  23. {
  24. const STATUS_TRUE = 1;
  25. const STATUS_FALSE = 0;
  26. public static function tableName()
  27. {
  28. return "{{%buy_goods_log}}";
  29. }
  30. public function behaviors()
  31. {
  32. return [
  33. [
  34. 'class' => TimestampBehavior::class,
  35. 'attributes' => [
  36. ActiveRecord::EVENT_BEFORE_INSERT => [
  37. 'updated_at',
  38. 'created_at'
  39. ],
  40. ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
  41. ]
  42. ]
  43. ];
  44. }
  45. public function rules()
  46. {
  47. return [
  48. [
  49. [
  50. 'store_id',
  51. 'goods_id',
  52. 'status',
  53. 'updated_at',
  54. 'created_at'
  55. ],
  56. 'integer'
  57. ],
  58. [
  59. [
  60. 'nickname',
  61. 'avatar_url'
  62. ],
  63. 'string'
  64. ],
  65. [
  66. [
  67. 'store_id',
  68. 'goods_id',
  69. 'nickname',
  70. 'avatar_url'
  71. ],
  72. 'required'
  73. ]
  74. ];
  75. }
  76. public function attributeLabels()
  77. {
  78. return [
  79. 'id' => 'ID',
  80. 'store_id' => 'Store ID',
  81. 'goods_id' => '卡券名称',
  82. 'nickname' => '昵称',
  83. 'avatar_url' => '头像',
  84. 'status' => '状态',
  85. 'updated_at' => 'Update Time',
  86. 'created_at' => 'Add Time',
  87. ];
  88. }
  89. public static function set($goodsId,$nickname,$avatarUrl){
  90. $goods = Goods::findOne($goodsId);
  91. $model = new self();
  92. $model->store_id = $goods->store_id ?? 0;
  93. $model->goods_id = $goodsId;
  94. $model->nickname = $nickname;
  95. $model->avatar_url = $avatarUrl;
  96. $model->status = 0;
  97. $model->save();
  98. }
  99. }