StoreUserEnterQualification.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_store_user_enter_qualification}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id
  11. * @property int $enter_mode 入驻模式,1:免费入驻,2:购买指定商品入驻
  12. * @property int $goods_id 已经购买的商品 id
  13. * @property int $status 状态,-1:已删除;0:禁用;1:正常
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class StoreUserEnterQualification extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_store_user_enter_qualification}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id'], 'required'],
  33. [['mall_id', 'user_id', 'enter_mode', 'goods_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => 'Mall ID',
  44. 'user_id' => 'User ID',
  45. 'enter_mode' => '入驻模式,1:免费入驻,2:购买指定商品入驻',
  46. 'goods_id' => '已经购买的商品 id',
  47. 'status' => '状态,-1:已删除;0:禁用;1:正常',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. ];
  51. }
  52. public static function setData(int $mall_id, array $data)
  53. {
  54. if (!empty($data['id'])) {
  55. $model = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]);
  56. if (empty($model)) {
  57. self::$static_error = '数据异常';
  58. return false;
  59. }
  60. } else {
  61. $model = new self();
  62. $model->loadDefaultValues();
  63. $model->mall_id = $mall_id;
  64. $model->status = 1;
  65. unset($data['id']);
  66. }
  67. foreach ($data as $key => $val) {
  68. $model->$key = $val;
  69. }
  70. $res = $model->save();
  71. if (!$res) {
  72. self::$static_error = $model->getErrorMessage();
  73. return false;
  74. }
  75. return $model;
  76. }
  77. }