123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- namespace App\Services\Pair;
- use App\Http\Controllers\Core\Ding;
- use App\Models\Fpdx\ActivityModel;
- use App\Models\Fpdx\PairModel;
- use App\Services\Service;
- class MatchService extends Service
- {
- // 加载重新匹配队列
- public function rematch()
- {
- $ings = ActivityModel::getActivitys();
- $stage_id = $ings['ing'];
- $pairModel = new PairModel();
- if (app()->environment() == 'production') {
- $number = $pairModel->where('stage_id', $stage_id)->where('rematch', 1)->count();
- Ding::robot([
- 'title' => '[分配对象]重新匹配|开始',
- 'text' => "选择重匹人数{$number}",
- ]);
- }
- // 匹配数据初始化
- $this->initReMatchQueue($stage_id);
- $cronpair = new \App\Http\Controllers\Crontab\Pair();
- // $cronpair->pipei(array($pairModel, 'getRematchPair'), [$stage_id, '72h', '浙江-杭州']);
- // $cronpair->pipei(array($pairModel, 'getRematchPair'), [$stage_id, 'qbj']);
- $cronpair->pipei(array($pairModel, 'getRematchPair'), [$stage_id, '72h']);
- if (app()->environment() == 'production') {
- $number = $pairModel->where('stage_id', $stage_id)->where('rematch', 1)->whereNotNull('assoc_id')->count();
- Ding::robot([
- 'title' => "[分配对象]重新匹配|完成",
- 'text' => "重配成功人数{$number}",
- ]);
- }
- $check = new CheckService();
- $check->baocun($stage_id);
- $check->check($stage_id);
- }
- // 重新匹配
- public function initReMatchQueue(int $stage_id)
- {
- if (app()->environment() == 'production') {
- Ding::robot([
- 'title' => '[分配对象]重新匹配|数据初始化|开始',
- 'text' => "数据初始化|开始",
- ]);
- }
- $pairs = PairModel::where([
- ['stage_id', $stage_id],
- ['partner', 1],
- ['room_id', 0],
- ])->whereBetween('state', [400, 499])->whereNotNull('assoc_id')->get();
- foreach ($pairs as $pair) {
- try {
- $other = PairModel::findOrFail($pair->assoc_id);
- /**
- * pair同意 + other同意
- */
- if (0 < $pair->confirm && 0 < $other->confirm) {
- continue;
- }
- /**
- * pair不操作 + other不操作
- */
- if (0 < $pair->confirm && 0 < $other->confirm) {
- continue;
- }
- /**
- * pair不同意 + other不同意
- * exitGroup
- * pair.last_assoc = pair.assoc_id;
- * other.last_assoc = other.assoc_id
- * pair.assoc_id = other.assoc_id = null;
- * pair.rematch = other.rematch = 1;
- * pair.partner = other.partner = 0;
- */
- if (0 > $pair->confirm && 0 > $other->confirm) {
- $gs = new GroupService();
- $gs->exitGroup($pair);
- $pair->last_assoc = $pair->assoc_id;
- $other->last_assoc = $other->assoc_id;
- $pair->assoc_id = $other->assoc_id = null;
- $pair->rematch = $other->rematch = 1;
- $pair->partner = $other->partner = 0;
- $pair->save() && $other->save();
- continue;
- }
- /**
- * pair同意 + other不同意
- * exitGroup
- * pair.last_assoc = pair.assoc_id;
- * other.last_assoc = other.assoc_id
- * pair.assoc_id = other.assoc_id = null;
- * pair.rematch = other.rematch = 1;
- * pair.partner = other.partner = 0;
- */
- if (0 < $pair->confirm && 0 > $other->confirm) {
- $gs = new GroupService();
- $gs->exitGroup($pair);
- $pair->last_assoc = $pair->assoc_id;
- $other->last_assoc = $other->assoc_id;
- $pair->assoc_id = $other->assoc_id = null;
- $pair->rematch = $other->rematch = 1;
- $pair->partner = $other->partner = 0;
- $pair->save() && $other->save();
- continue;
- }
- /**
- * pair不同意 + other同意
- * exitGroup
- * pair.last_assoc = pair.assoc_id;
- * other.last_assoc = other.assoc_id
- * pair.assoc_id = other.assoc_id = null;
- * pair.rematch = other.rematch = 1;
- * pair.partner = other.partner = 0;
- */
- if (0 > $pair->confirm && 0 < $other->confirm) {
- $gs = new GroupService();
- $gs->exitGroup($pair);
- $pair->last_assoc = $pair->assoc_id;
- $other->last_assoc = $other->assoc_id;
- $pair->assoc_id = $other->assoc_id = null;
- $pair->rematch = $other->rematch = 1;
- $pair->partner = $other->partner = 0;
- $pair->save() && $other->save();
- continue;
- }
- /**
- * pair同意 + other不操作 :
- * exitGroup
- * pair.last_assoc = pair.assoc_id;
- * other.last_assoc = other.assoc_id
- * pair.assoc_id = other.assoc_id = null;
- * pair.rematch = 1;
- * pair.partner = other.partner = 0;
- * other.state = other.state + 400;
- *
- */
- if (0 < $pair->confirm && 0 == $other->confirm) {
- $gs = new GroupService();
- $gs->exitGroup($pair);
- $pair->last_assoc = $pair->assoc_id;
- $other->last_assoc = $other->assoc_id;
- $pair->assoc_id = $other->assoc_id = null;
- $pair->rematch = 1;
- $pair->partner = $other->partner = 0;
- $other->state = $other->state + 400;
- $pair->save() && $other->save();
- continue;
- }
- /**
- * pair不操作 + other同意 :
- * exitGroup
- * pair.last_assoc = pair.assoc_id;
- * other.last_assoc = other.assoc_id
- * pair.assoc_id = other.assoc_id = null;
- * other.rematch = 1;
- * pair.partner = other.partner = 0;
- * pair.state = pair.state + 400;
- *
- */
- if (0 == $pair->confirm && 0 < $other->confirm) {
- $gs = new GroupService();
- $gs->exitGroup($pair);
- $pair->last_assoc = $pair->assoc_id;
- $other->last_assoc = $other->assoc_id;
- $pair->assoc_id = $other->assoc_id = null;
- $other->rematch = 1;
- $pair->partner = $other->partner = 0;
- $pair->state = $pair->state + 400;
- $pair->save() && $other->save();
- continue;
- }
- /**
- * pair不同意 + other不操作 :
- * exitGroup
- * pair.last_assoc = pair.assoc_id;
- * other.last_assoc = other.assoc_id
- * pair.assoc_id = other.assoc_id = null;
- * pair.rematch = 1;
- * pair.partner = other.partner = 0;
- * other.state = other.state + 400;
- */
- if (0 > $pair->confirm && 0 == $other->confirm) {
- $gs = new GroupService();
- $gs->exitGroup($pair);
- $pair->last_assoc = $pair->assoc_id;
- $other->last_assoc = $other->assoc_id;
- $pair->assoc_id = $other->assoc_id = null;
- $pair->rematch = 1;
- $pair->partner = $other->partner = 0;
- $other->state = $other->state + 400;
- $pair->save() && $other->save();
- continue;
- }
- /**
- * pair不操作 + other不同意 :
- * exitGroup
- * pair.last_assoc = pair.assoc_id;
- * other.last_assoc = other.assoc_id
- * pair.assoc_id = other.assoc_id = null;
- * other.rematch = 1;
- * pair.partner = other.partner = 0;
- * pair.state = pair.state + 400;
- *
- */
- if ($pair->confirm == 0 && 0 > $other->confirm) {
- $gs = new GroupService();
- $gs->exitGroup($pair);
- $pair->last_assoc = $pair->assoc_id;
- $other->last_assoc = $other->assoc_id;
- $pair->assoc_id = $other->assoc_id = null;
- $other->rematch = 1;
- $pair->partner = $other->partner = 0;
- $pair->state = $pair->state + 400;
- $pair->save() && $other->save();
- continue;
- }
- } catch (\Exception $e) {
- continue;
- }
- }
- if (app()->environment() == 'production') {
- Ding::robot([
- 'title' => '[分配对象]重新匹配|数据初始化|完成',
- 'text' => "数据初始化|完成",
- ]);
- }
- }
- }
|