TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'], ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time'] ] ] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => 'Store ID', 'user_id' => 'User ID', 'status' => ' 0未领取1 已领取', 'remark' => 'remark', 'create_time' => 'Create Time', 'update_time' => '领取时间', ]; } public function sendNum($user_id) { $t = \Yii::$app->db->beginTransaction(); try { $time = time(); $user = User::findOne($user_id); if ($user && $user->parent_id) { $setting = PondSetting::find() ->where(['store_id' => $user->store_id]) ->andWhere(['<=', 'start_time', $time]) ->andWhere(['>', 'end_time', $time]) ->asArray()->one(); if ($setting) { $obj = new self(); $obj->store_id = $user->store_id; $obj->user_id = $user->parent_id; $obj->status = 0; $obj->remark = '下级用户下单赠送'; $obj->save(); } } $t->commit(); } catch (\Exception $e) { $t->rollBack(); \Yii::error($e->getMessage()); } } }