123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace App\Http\Services\V1_1;
- use App\Generated\V1_1\DTOs\AdminPartnerDTO;
- use App\Generated\V1_1\DTOs\PageDTO;
- use App\Generated\V1_1\Messages\AdminPartner\UnSelectPartnerMessage;
- use App\Generated\V1_1\Messages\AdminPartner\Change2NewMessage;
- use App\Generated\V1_1\Messages\AdminPartner\LowListMessage;
- use App\Generated\V1_1\Messages\AdminPartner\IsSelectedListMessage;
- use App\Models\PartnerModel;
- use Illuminate\Database\Eloquent\Builder;
- class AdminPartnerService
- {
- public function isSelectedList(IsSelectedListMessage $message)
- {
- $isFeedPush = $message->getIsFeedPush();
- $sex = $message->getSex();
- $page = $message->getPages();
- $limit = 20;
- if (1 == $page) {
- $total = PartnerModel::where('is_select', 1)
- ->when($isFeedPush, function (/** @var Builder $query */ $query) {
- return $query->where('is_sell', 1)->where('score', '>=', 0);
- })
- ->when($sex, function (/** @var Builder $query */ $query) use ($sex) {
- return $query->where('sex', $sex);
- })
- ->where(function (/** @var Builder $query */ $query) {
- return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
- ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
- ->orWhere('photo_4_check', 1);
- })->count();
- } else {
- $total = 10000;
- }
- $datas = PartnerModel::where('is_select', 1)
- ->when($isFeedPush, function (/** @var Builder $query */ $query) {
- return $query->where('is_sell', 1)->where('score', '>=', 0);
- })
- ->when($sex, function (/** @var Builder $query */ $query) use ($sex) {
- return $query->where('sex', $sex);
- })
- ->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
- return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
- ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
- ->orWhere('photo_4_check', 1);
- })->orderByDesc('select_at')->skip(($page - 1) * $limit)->take($limit)->get();
- foreach ($datas as &$data) {
- /** @var PartnerModel $data */
- if ($data->check_photo == 1) {
- $data->photo_src = "http://oss.pocketuniversity.cn{$data->photo_src}";
- } else {
- unset($data->photo_src);
- }
- if ($data->photo_1_check == 1) {
- $data->photo_1 = "http://oss.pocketuniversity.cn{$data->photo_1}";
- } else {
- unset($data->photo_1);
- }
- if ($data->photo_2_check == 1) {
- $data->photo_2 = "http://oss.pocketuniversity.cn{$data->photo_2}";
- } else {
- unset($data->photo_2);
- }
- if ($data->photo_3_check == 1) {
- $data->photo_3 = "http://oss.pocketuniversity.cn{$data->photo_3}";
- } else {
- unset($data->photo_3);
- }
- if ($data->photo_4_check == 1) {
- $data->photo_4 = "http://oss.pocketuniversity.cn{$data->photo_4}";
- } else {
- unset($data->photo_4);
- }
- }
- $message->setResponse(PageDTO::initFromEloquent([
- 'page' => (int)$page,
- 'limit' => $limit,
- 'total' => $total
- ]), AdminPartnerDTO::initFromEloquents($datas));
- }
- public function lowList(LowListMessage $message)
- {
- $page = $message->getPages();
- $limit = 20;
- if (1 == $page) {
- $total = PartnerModel::where([
- ['feed_pool_level', 'low'],
- ['wait_low_pool', '!=', 2]
- ])->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
- return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
- ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
- ->orWhere('photo_4_check', 1);
- })->count();
- } else {
- $total = 10000;
- }
- $datas = PartnerModel::where([
- ['feed_pool_level', 'low'],
- ['wait_low_pool', '!=', 2]
- ])->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
- return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
- ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
- ->orWhere('photo_4_check', 1);
- })->orderByDesc('select_at')->skip(($page - 1) * $limit)->take($limit)->get();
- foreach ($datas as &$data) {
- /** @var PartnerModel $data */
- if ($data->check_photo == 1) {
- $data->photo_src = "http://oss.pocketuniversity.cn{$data->photo_src}";
- } else {
- unset($data->photo_src);
- }
- if ($data->photo_1_check == 1) {
- $data->photo_1 = "http://oss.pocketuniversity.cn{$data->photo_1}";
- } else {
- unset($data->photo_1);
- }
- if ($data->photo_2_check == 1) {
- $data->photo_2 = "http://oss.pocketuniversity.cn{$data->photo_2}";
- } else {
- unset($data->photo_2);
- }
- if ($data->photo_3_check == 1) {
- $data->photo_3 = "http://oss.pocketuniversity.cn{$data->photo_3}";
- } else {
- unset($data->photo_3);
- }
- if ($data->photo_4_check == 1) {
- $data->photo_4 = "http://oss.pocketuniversity.cn{$data->photo_4}";
- } else {
- unset($data->photo_4);
- }
- }
- $message->setResponse(PageDTO::initFromEloquent([
- 'page' => (int)$page,
- 'limit' => $limit,
- 'total' => $total
- ]), AdminPartnerDTO::initFromEloquents($datas));
- }
- public function change2New(Change2NewMessage $message)
- {
- $reqs = $message->getReq();
- foreach ($reqs as $req) {
- if ($req->getToType()) {
- PartnerModel::where('id', $req->getPartnerId())->update([
- 'feed_tag_cnt' => 0,
- 'feed_tag_like' => 0,
- 'feed_pool_level' => 'new',
- 'wait_low_pool' => 0
- ]);
- } else {
- PartnerModel::where('id', $req->getPartnerId())->update([
- 'wait_low_pool' => 2
- ]);
- }
- }
- }
- public function unSelectPartner(UnSelectPartnerMessage $message)
- {
- $partnerId = $message->getPartnerId();
- PartnerModel::where('id', $partnerId)->update(['is_select' => 0]);
- }
- }
|