DoubleCopyChangeTopid.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace addons\DoubleCopy\common\models;
  3. use common\models\user\User;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%addons_double_copy_change_topid}}".
  8. *
  9. * @property int $id
  10. * @property int $change_pos_id qimall_addons_double_copy_change_pos.id
  11. * @property int $mall_id 商城ID
  12. * @property int|null $user_id 用户ID
  13. * @property int|null $old_topid 原topid
  14. * @property int|null $now_topid 现topid
  15. * @property int $status 状态[-1:删除;0:禁用;1启用]
  16. * @property int|null $created_at 创建时间
  17. * @property int|null $updated_at 更新时间
  18. */
  19. class DoubleCopyChangeTopid extends \common\models\base\BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_double_copy_change_topid}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['change_pos_id', 'mall_id', 'user_id', 'old_topid', 'now_topid', 'status', 'created_at', 'updated_at'], 'integer'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'change_pos_id' => 'qimall_addons_double_copy_change_pos.id',
  45. 'mall_id' => '商城ID',
  46. 'user_id' => '用户ID',
  47. 'old_topid' => '原topid',
  48. 'now_topid' => '现topid',
  49. 'status' => '状态[-1:删除;0:禁用;1启用]',
  50. 'created_at' => '创建时间',
  51. 'updated_at' => '更新时间',
  52. ];
  53. }
  54. /**
  55. * 关联用户
  56. * @Author: lun
  57. * @DateTime: 2023/6/3 0003 15:51
  58. * @Copyright: copyright (c) 2021 广东七件事集团
  59. * @return \yii\db\ActiveQuery
  60. */
  61. public function getUser()
  62. {
  63. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,mobile,avatar_url,parent_id');
  64. }
  65. /**
  66. * 换位前用户
  67. * @Author: lun
  68. * @DateTime: 2023/6/3 0003 15:51
  69. * @Copyright: copyright (c) 2021 广东七件事集团
  70. * @return \yii\db\ActiveQuery
  71. */
  72. public function getOldTop()
  73. {
  74. return $this->hasOne(User::class, ['id' => 'old_topid'])->select('id,nickname,mobile,avatar_url,parent_id');
  75. }
  76. /**
  77. * 换位后用户
  78. * @Author: lun
  79. * @DateTime: 2023/6/3 0003 15:52
  80. * @Copyright: copyright (c) 2021 广东七件事集团
  81. * @return \yii\db\ActiveQuery
  82. */
  83. public function getNowTop()
  84. {
  85. return $this->hasOne(User::class, ['id' => 'now_topid'])->select('id,nickname,mobile,avatar_url,parent_id');
  86. }
  87. /**
  88. * 保存数据
  89. * @Author: lun
  90. * @DateTime: 2023/6/2 0002 15:53
  91. * @Copyright: copyright (c) 2021 广东七件事集团
  92. * @param $params
  93. * @return bool
  94. */
  95. public static function setData($params)
  96. {
  97. try {
  98. $model = new self();
  99. $model->loadDefaultValues();
  100. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  101. return true;
  102. } catch (\Exception $e) {
  103. self::setStaticError($e->getMessage());
  104. return false;
  105. }
  106. }
  107. }