| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace addons\LuckyGroup\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_lucky_group_win_log".
- *
- * @property int $id 表id
- * @property int $mall_id 商城ID
- * @property int $activity_id 活动id
- * @property int $user_id 用户id
- * @property int $win_num 累计拼中次数
- * @property int $loss_num 连续拼不中次数
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class LuckyGroupWinLog extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_lucky_group_win_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'activity_id', 'user_id', 'win_num', 'loss_num', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '表id',
- 'mall_id' => '商城ID',
- 'activity_id' => '活动id',
- 'user_id' => '用户id',
- 'win_num' => '累计拼中次数',
- 'loss_num' => '连续拼不中次数',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- public static function setData($params)
- {
- try {
- if (empty($params['mall_id']) || empty($params['activity_id']) || empty($params['user_id'])) return;
- $model = self::findOne([
- 'mall_id' => $params['mall_id'],
- 'user_id' => $params['user_id'],
- 'activity_id' => $params['activity_id'],
- 'status' => [StatusEnum::ENABLED],
- ]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- $model->activity_id = $params['activity_id'];
- $model->user_id = $params['user_id'];
- }
- if (!empty($params['win_num'])) {
- $model->win_num += $params['win_num'];
- $model->loss_num = 0;
- }else{
- $model->loss_num += 1;
- }
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- var_dump( $e->getMessage());
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|