GroupService.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Services\Pair;
  3. use App\Models\Fpdx\GroupMemberModel;
  4. use App\Models\Fpdx\GroupModel;
  5. use App\Models\Fpdx\PairModel;
  6. class GroupService
  7. {
  8. public function exitGroup(PairModel $pair)
  9. {
  10. try {
  11. \DB::beginTransaction();
  12. $other = PairModel::find($pair->assoc_id);
  13. if ($other) {
  14. if ($other->group_id > 0) {
  15. GroupMemberModel::where('uid', $other->uid)->where('stage_id', $other->stage_id)->where(
  16. 'type',
  17. 'pair'
  18. )->delete();
  19. GroupModel::where('id', $other->group_id)->decrement('total_number');
  20. $other->group_id = 0;
  21. $other->save();
  22. }
  23. }
  24. $pair = PairModel::find($pair->id);
  25. if ($pair) {
  26. if ($pair->group_id > 0) {
  27. GroupMemberModel::where('uid', $pair->uid)->where('stage_id', $pair->stage_id)->where(
  28. 'type',
  29. 'pair'
  30. )->delete();
  31. GroupModel::where('id', $pair->group_id)->decrement('total_number');
  32. $pair->group_id = 0;
  33. $pair->save();
  34. }
  35. }
  36. \DB::commit();
  37. return true;
  38. } catch (\Exception $e) {
  39. \DB::rollBack();
  40. return false;
  41. }
  42. }
  43. }