AdminPartnerService.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace App\Http\Services\V1;
  3. use App\Generated\V1\DTOs\AdminPartnerDTO;
  4. use App\Generated\V1\DTOs\PageDTO;
  5. use App\Generated\V1\Messages\AdminPartner\UnSelectPartnerMessage;
  6. use App\Generated\V1\Messages\AdminPartner\Change2NewMessage;
  7. use App\Generated\V1\Messages\AdminPartner\LowListMessage;
  8. use App\Generated\V1\Messages\AdminPartner\IsSelectedListMessage;
  9. use App\Models\PartnerModel;
  10. use Illuminate\Database\Eloquent\Builder;
  11. class AdminPartnerService
  12. {
  13. public function isSelectedList(IsSelectedListMessage $message)
  14. {
  15. $isFeedPush = $message->getIsFeedPush();
  16. $sex = $message->getSex();
  17. $page = $message->getPages();
  18. $limit = 20;
  19. if (1 == $page) {
  20. $total = PartnerModel::where('is_select', 1)
  21. ->when($isFeedPush, function (/** @var Builder $query */ $query) {
  22. return $query->where('is_sell', 1)->where('score', '>=', 0);
  23. })
  24. ->when($sex, function (/** @var Builder $query */ $query) use ($sex) {
  25. return $query->where('sex', $sex);
  26. })
  27. ->where(function (/** @var Builder $query */ $query) {
  28. return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
  29. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
  30. ->orWhere('photo_4_check', 1);
  31. })->count();
  32. } else {
  33. $total = 10000;
  34. }
  35. $datas = PartnerModel::where('is_select', 1)
  36. ->when($isFeedPush, function (/** @var Builder $query */ $query) {
  37. return $query->where('is_sell', 1)->where('score', '>=', 0);
  38. })
  39. ->when($sex, function (/** @var Builder $query */ $query) use ($sex) {
  40. return $query->where('sex', $sex);
  41. })
  42. ->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
  43. return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
  44. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
  45. ->orWhere('photo_4_check', 1);
  46. })->orderByDesc('select_at')->skip(($page - 1) * $limit)->take($limit)->get();
  47. foreach ($datas as &$data) {
  48. /** @var PartnerModel $data */
  49. if ($data->check_photo == 1) {
  50. $data->photo_src = "http://oss.pocketuniversity.cn{$data->photo_src}";
  51. } else {
  52. unset($data->photo_src);
  53. }
  54. if ($data->photo_1_check == 1) {
  55. $data->photo_1 = "http://oss.pocketuniversity.cn{$data->photo_1}";
  56. } else {
  57. unset($data->photo_1);
  58. }
  59. if ($data->photo_2_check == 1) {
  60. $data->photo_2 = "http://oss.pocketuniversity.cn{$data->photo_2}";
  61. } else {
  62. unset($data->photo_2);
  63. }
  64. if ($data->photo_3_check == 1) {
  65. $data->photo_3 = "http://oss.pocketuniversity.cn{$data->photo_3}";
  66. } else {
  67. unset($data->photo_3);
  68. }
  69. if ($data->photo_4_check == 1) {
  70. $data->photo_4 = "http://oss.pocketuniversity.cn{$data->photo_4}";
  71. } else {
  72. unset($data->photo_4);
  73. }
  74. }
  75. $message->setResponse(PageDTO::initFromEloquent([
  76. 'page' => (int)$page,
  77. 'limit' => $limit,
  78. 'total' => $total
  79. ]), AdminPartnerDTO::initFromEloquents($datas));
  80. }
  81. public function lowList(LowListMessage $message)
  82. {
  83. $page = $message->getPages();
  84. $limit = 20;
  85. if (1 == $page) {
  86. $total = PartnerModel::where([
  87. ['feed_pool_level', 'low'],
  88. ['wait_low_pool', '!=', 2]
  89. ])->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
  90. return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
  91. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
  92. ->orWhere('photo_4_check', 1);
  93. })->count();
  94. } else {
  95. $total = 10000;
  96. }
  97. $datas = PartnerModel::where([
  98. ['feed_pool_level', 'low'],
  99. ['wait_low_pool', '!=', 2]
  100. ])->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
  101. return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
  102. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
  103. ->orWhere('photo_4_check', 1);
  104. })->orderByDesc('select_at')->skip(($page - 1) * $limit)->take($limit)->get();
  105. foreach ($datas as &$data) {
  106. /** @var PartnerModel $data */
  107. if ($data->check_photo == 1) {
  108. $data->photo_src = "http://oss.pocketuniversity.cn{$data->photo_src}";
  109. } else {
  110. unset($data->photo_src);
  111. }
  112. if ($data->photo_1_check == 1) {
  113. $data->photo_1 = "http://oss.pocketuniversity.cn{$data->photo_1}";
  114. } else {
  115. unset($data->photo_1);
  116. }
  117. if ($data->photo_2_check == 1) {
  118. $data->photo_2 = "http://oss.pocketuniversity.cn{$data->photo_2}";
  119. } else {
  120. unset($data->photo_2);
  121. }
  122. if ($data->photo_3_check == 1) {
  123. $data->photo_3 = "http://oss.pocketuniversity.cn{$data->photo_3}";
  124. } else {
  125. unset($data->photo_3);
  126. }
  127. if ($data->photo_4_check == 1) {
  128. $data->photo_4 = "http://oss.pocketuniversity.cn{$data->photo_4}";
  129. } else {
  130. unset($data->photo_4);
  131. }
  132. }
  133. $message->setResponse(PageDTO::initFromEloquent([
  134. 'page' => (int)$page,
  135. 'limit' => $limit,
  136. 'total' => $total
  137. ]), AdminPartnerDTO::initFromEloquents($datas));
  138. }
  139. public function change2New(Change2NewMessage $message)
  140. {
  141. $reqs = $message->getReq();
  142. foreach ($reqs as $req) {
  143. if ($req->getToType()) {
  144. PartnerModel::where('id', $req->getPartnerId())->update([
  145. 'feed_tag_cnt' => 0,
  146. 'feed_tag_like' => 0,
  147. 'feed_pool_level' => 'new',
  148. 'wait_low_pool' => 0
  149. ]);
  150. } else {
  151. PartnerModel::where('id', $req->getPartnerId())->update([
  152. 'wait_low_pool' => 2
  153. ]);
  154. }
  155. }
  156. }
  157. public function unSelectPartner(UnSelectPartnerMessage $message)
  158. {
  159. $partnerId = $message->getPartnerId();
  160. PartnerModel::where('id', $partnerId)->update(['is_select' => 0]);
  161. }
  162. }