HappinessBusiness.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_happiness_business".
  8. *
  9. * @property int $id
  10. * @property int $user_id 用户ID
  11. * @property int $mall_id 商城ID
  12. * @property int $level 权重
  13. * @property int $status 状态
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class HappinessBusiness extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return 'qimall_addons_happiness_business';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['user_id', 'mall_id', 'level', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['level'], 'required'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'user_id' => 'User ID',
  44. 'mall_id' => 'Mall ID',
  45. 'level' => 'Level',
  46. 'status' => 'Status',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. public function getUser()
  52. {
  53. return $this->hasOne(User::class, ['id' => 'user_id']);
  54. }
  55. public static function setData($params)
  56. {
  57. try {
  58. if (isset($params['user_id']) && !empty($params['user_id'])) {
  59. $model = self::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  60. }
  61. else if(isset($params['id']) && !empty($params['id']))
  62. $model = self::findOne($params['id']);
  63. else {
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. }
  67. if(!$model)
  68. {
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. }
  72. if (!$model->load($params, '') || !$model->save()) {
  73. throw new \Exception($model->getErrorMessage());
  74. }
  75. return $model;
  76. } catch (\Exception $e) {
  77. self::$static_error = $e->getMessage();
  78. return false;
  79. }
  80. }
  81. }