MemberEditForm.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace addons\Member\merchant\forms;
  3. use Yii;
  4. use common\helpers\ArrayHelper;
  5. use common\forms\MemberForm;
  6. /**
  7. * Class MemberEditForm
  8. * @package addons\Member\merchant\forms
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class MemberEditForm extends MemberForm
  12. {
  13. public $tags = [];
  14. /**
  15. * @return array|array[]
  16. */
  17. public function rules()
  18. {
  19. return ArrayHelper::merge(parent::rules(), [
  20. ['tags', 'safe'],
  21. ]);
  22. }
  23. /**
  24. * @return array|string[]
  25. */
  26. public function attributeLabels()
  27. {
  28. return ArrayHelper::merge(parent::attributeLabels(), [
  29. 'tags' => '标签'
  30. ]);
  31. }
  32. public function afterFind()
  33. {
  34. $this->tags = Yii::$app->services->memberTagMap->findIdsByMemberId($this->id);
  35. parent::afterFind();
  36. }
  37. /**
  38. * @param bool $insert
  39. * @param array $changedAttributes
  40. * @throws \yii\db\Exception
  41. */
  42. public function afterSave($insert, $changedAttributes)
  43. {
  44. Yii::$app->services->memberTagMap->addTags($this->id, $this->tags);
  45. parent::afterSave($insert, $changedAttributes);
  46. }
  47. }
粤ICP备19079148号