LuckyGroupWinLog.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\LuckyGroup\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "qimall_addons_lucky_group_win_log".
  9. *
  10. * @property int $id 表id
  11. * @property int $mall_id 商城ID
  12. * @property int $activity_id 活动id
  13. * @property int $user_id 用户id
  14. * @property int $win_num 累计拼中次数
  15. * @property int $loss_num 连续拼不中次数
  16. * @property int $status 状态[-1:删除;0:禁用;1启用]
  17. * @property int|null $created_at 创建时间
  18. * @property int|null $updated_at 更新时间
  19. */
  20. class LuckyGroupWinLog extends BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_lucky_group_win_log}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'activity_id', 'user_id', 'win_num', 'loss_num', 'status', 'created_at', 'updated_at'], 'integer'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => '表id',
  45. 'mall_id' => '商城ID',
  46. 'activity_id' => '活动id',
  47. 'user_id' => '用户id',
  48. 'win_num' => '累计拼中次数',
  49. 'loss_num' => '连续拼不中次数',
  50. 'status' => '状态[-1:删除;0:禁用;1启用]',
  51. 'created_at' => '创建时间',
  52. 'updated_at' => '更新时间',
  53. ];
  54. }
  55. public static function setData($params)
  56. {
  57. try {
  58. if (empty($params['mall_id']) || empty($params['activity_id']) || empty($params['user_id'])) return;
  59. $model = self::findOne([
  60. 'mall_id' => $params['mall_id'],
  61. 'user_id' => $params['user_id'],
  62. 'activity_id' => $params['activity_id'],
  63. 'status' => [StatusEnum::ENABLED],
  64. ]);
  65. if (empty($model)) {
  66. $model = new self();
  67. $model->loadDefaultValues();
  68. $model->mall_id = $params['mall_id'];
  69. $model->activity_id = $params['activity_id'];
  70. $model->user_id = $params['user_id'];
  71. }
  72. if (!empty($params['win_num'])) {
  73. $model->win_num += $params['win_num'];
  74. $model->loss_num = 0;
  75. }else{
  76. $model->loss_num += 1;
  77. }
  78. if (!$model->save()) throw new Exception($model->getErrorMessage());
  79. return $model;
  80. } catch (\Exception $e) {
  81. var_dump( $e->getMessage());
  82. self::$static_error = $e->getMessage();
  83. return false;
  84. }
  85. }
  86. }