| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * BuyGoodsLog.php
- * todo 文件描述
- * Created on 2024/4/15 13:55
- * @author: hankaige
- */
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%card}}".
- * @property int $id
- * @property int|null $store_id
- * @property string $goods_id 卡券名称
- * @property string $nickname
- * @property string|null $avatar_url 卡券描述
- * @property int $status
- * @property int|null $updated_at
- * @property int|null $created_at
- */
- class BuyGoodsLog extends \yii\db\ActiveRecord
- {
- const STATUS_TRUE = 1;
- const STATUS_FALSE = 0;
- public static function tableName()
- {
- return "{{%buy_goods_log}}";
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => [
- 'updated_at',
- 'created_at'
- ],
- ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
- ]
- ]
- ];
- }
- public function rules()
- {
- return [
- [
- [
- 'store_id',
- 'goods_id',
- 'status',
- 'updated_at',
- 'created_at'
- ],
- 'integer'
- ],
- [
- [
- 'nickname',
- 'avatar_url'
- ],
- 'string'
- ],
- [
- [
- 'store_id',
- 'goods_id',
- 'nickname',
- 'avatar_url'
- ],
- 'required'
- ]
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => 'Store ID',
- 'goods_id' => '卡券名称',
- 'nickname' => '昵称',
- 'avatar_url' => '头像',
- 'status' => '状态',
- 'updated_at' => 'Update Time',
- 'created_at' => 'Add Time',
- ];
- }
- public static function set($goodsId,$nickname,$avatarUrl){
- $goods = Goods::findOne($goodsId);
- $model = new self();
- $model->store_id = $goods->store_id ?? 0;
- $model->goods_id = $goodsId;
- $model->nickname = $nickname;
- $model->avatar_url = $avatarUrl;
- $model->status = 0;
- $model->save();
- }
- }
|