HappinessPvWallet.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_happiness_pv_wallet}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id 商城id
  9. * @property int $user_id 用户id
  10. * @property float $score_value 累加积分
  11. * @property float $freeze_score_value 冻结积分
  12. * @property float $active_score_value 释放的积分
  13. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class HappinessPvWallet extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_happiness_pv_wallet}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id', 'score_value', 'freeze_score_value'], 'required'],
  33. [['mall_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['score_value', 'freeze_score_value', 'active_score_value', 'total_score_value'], 'number'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => 'Mall ID',
  45. 'user_id' => 'User ID',
  46. 'score_value' => 'Score Value',
  47. 'freeze_score_value' => 'Freeze Score Value',
  48. 'total_score_value' => 'Total Score Value',
  49. 'active_score_value' => 'Active Score Value',
  50. 'status' => 'Status',
  51. 'created_at' => 'Created At',
  52. 'updated_at' => 'Updated At',
  53. ];
  54. }
  55. public static function setData($params)
  56. {
  57. try {
  58. $model = self::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id']]);
  59. if (!$model) {
  60. $model = new self();
  61. $model->loadDefaultValues();
  62. }
  63. if (!$model->load($params, '') || !$model->save()) {
  64. throw new \Exception($model->getErrorMessage());
  65. }
  66. return $model;
  67. } catch (\Exception $e) {
  68. self::$static_error = $e->getMessage();
  69. return false;
  70. }
  71. }
  72. }