HappinessLockUser.php 2.2 KB

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