UserLabelRelation.php 749 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\models\user;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. class UserLabelRelation extends BaseModel
  6. {
  7. /**
  8. * 模型名称
  9. * @var string
  10. */
  11. protected $name = 'user_label_relation';
  12. use ModelTrait;
  13. public static function saveUserLabel($uids, $labels)
  14. {
  15. self::whereIn('uid', $uids)->delete();
  16. $data = [];
  17. foreach ($uids as $uid) {
  18. foreach ($labels as $label) {
  19. $data[] = ['uid' => $uid, 'label_id' => $label];
  20. }
  21. }
  22. $res = true;
  23. if(!empty($data))
  24. $res = self::insertAll($data);
  25. if ($res) {
  26. return true;
  27. } else {
  28. return false;
  29. }
  30. }
  31. }