123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- namespace App\Services\Appearance;
- use App\Models\Appearance\AppearanceModel;
- use App\Models\Appearance\AppearanceVoteModel;
- use App\Models\Appearance\PartnerRankModel;
- use App\Models\Appearance\SchoolRankModel;
- use App\Models\SchoolModel;
- class VoteService
- {
- public $pick_partner = false;
- public $pick_school = false;
- /**
- * 投票卡片
- * @param $uid
- * @param $partnerId
- * @param $mediaId
- */
- public function votePartner($uid, $partnerId, $mediaId)
- {
- if (
- !AppearanceVoteModel::where('uid', $uid)
- ->where('type', '2')
- ->where('partner_id', $partnerId)
- ->today()
- ->first()
- ) {
- $appearance = AppearanceModel::where('partner_id', $partnerId)->firstOrFail();
- AppearanceVoteModel::create([
- 'uid' => $uid,
- 'type' => '2',
- 'partner_id' => $partnerId,
- 'media_id' => $mediaId,
- ]);
- // 月榜
- $type = 'monthly';
- $date = date("Y-m-01");
- if (
- $partnerRank = PartnerRankModel::where('partner_id', $partnerId)
- ->where('date', $date)
- ->where('type', $type)
- ->first()
- ) {
- $partnerRank->increment('count');
- } else {
- PartnerRankModel::create([
- 'type' => $type,
- 'sex' => $appearance->sex,
- 'partner_id' => $partnerId,
- 'count' => 1,
- 'date' => $date,
- 'school' => $appearance->school,
- ]);
- }
- // 周榜
- $type = 'weekly';
- $date = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
- if (
- $partnerRank = PartnerRankModel::where('partner_id', $partnerId)
- ->where('date', $date)
- ->where('type', $type)
- ->first()
- ) {
- $partnerRank->increment('count');
- } else {
- PartnerRankModel::create([
- 'type' => $type,
- 'sex' => $appearance->sex,
- 'partner_id' => $partnerId,
- 'count' => 1,
- 'date' => $date,
- 'school' => $appearance->school,
- ]);
- }
- $this->pick_partner = true;
- $this->voteSchool($uid, $appearance->school, $mediaId);
- }
- }
- /**
- * 投票学校
- * @param $uid
- * @param $school
- * @param $mediaId
- */
- public function voteSchool($uid, $school, $mediaId)
- {
- if (
- !AppearanceVoteModel::where('uid', $uid)
- ->where('type', '1')
- ->where('school', $school)
- ->today()
- ->first()
- ) {
- $schoolModel = SchoolModel::where('school', $school)->firstOrFail();
- AppearanceVoteModel::create([
- 'uid' => $uid,
- 'type' => '1',
- 'school' => $schoolModel->school,
- 'media_id' => $mediaId,
- ]);
- // 月榜
- $type = 'monthly';
- $date = date("Y-m-01");
- if (
- $schoolRank = SchoolRankModel::where('school', $schoolModel->school)
- ->where('date', $date)
- ->where('type', $type)
- ->first()
- ) {
- $schoolRank->increment('count');
- } else {
- SchoolRankModel::create([
- 'type' => $type,
- 'province' => $schoolModel->province,
- 'city' => $schoolModel->city,
- 'count' => 1,
- 'date' => $date,
- 'school' => $schoolModel->school,
- ]);
- }
- // 周榜
- $type = 'weekly';
- $date = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
- if (
- $partnerRank = SchoolRankModel::where('school', $schoolModel->school)
- ->where('date', $date)
- ->where('type', $type)
- ->first()
- ) {
- $partnerRank->increment('count');
- } else {
- SchoolRankModel::create([
- 'type' => $type,
- 'province' => $schoolModel->province,
- 'city' => $schoolModel->city,
- 'count' => 1,
- 'date' => $date,
- 'school' => $schoolModel->school,
- ]);
- }
- $this->pick_school = true;
- }
- }
- /**
- * 取消上架卡片
- * @param $uid
- */
- public function unApply($uid)
- {
- $appearance = AppearanceModel::where('uid', $uid)->firstOrFail();
- if ($appearance->state == 2) {
- $appearance->state = 1;
- $appearance->save();
- }
- }
- }
|