BookListChService.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2020/6/2
  6. * Time: 上午10:44
  7. */
  8. namespace app\main\service;
  9. use app\admin\library\Auth;
  10. use app\main\constants\AdminConstants;
  11. use app\main\constants\ApiConstants;
  12. /**
  13. * Class BookListChService
  14. * @package app\main\service
  15. */
  16. class BookListChService extends BaseService
  17. {
  18. /**
  19. * @var BookListChService
  20. */
  21. protected static $self = null;
  22. /**
  23. * @return $this
  24. */
  25. public static function instance()
  26. {
  27. if (self::$self == null) {
  28. self::$self = new self();
  29. }
  30. return self::$self;
  31. }
  32. public function getCollectList($ids, $admin_id)
  33. {
  34. $bookListItem = model('book_list_ch')
  35. ->alias('c')
  36. ->where('c.id', $ids)
  37. ->field('c.id,c.admin_id,c.title,c.createtime')
  38. ->find();
  39. $admin_ids = (array)AdminService::instance()->getAdminId($admin_id)->data;
  40. $bookListItem['uv'] = $bookListItem['orders_num'] = $bookListItem['recharge_money'] = 0;
  41. $resultList = [];
  42. if (VisitLimitService::instance()->checkMigratedV2()) {
  43. if (count($admin_ids) == 1) {
  44. $where = ['ids' => [$ids]];
  45. } else {
  46. $where = ['ids' => [$ids], 'admin_id' => $admin_ids[0]];
  47. }
  48. $result = ApiService::instance()->getCollectFromApi(ApiConstants::API_BOOK_LIST, $where)->data;
  49. if ($result) {
  50. foreach ($result as $index => $item) {
  51. if (in_array($item['adminId'], $admin_ids)) {
  52. $tmp = $bookListItem->getData();
  53. $tmp['admin_id'] = $item['adminId']??'';
  54. $tmp['booklistId'] = $item['booklistId'];
  55. $tmp['idx'] = $item['idx'];
  56. $tmp['uv'] = $item['uv'];
  57. $tmp['orders_num'] = $item['orders'];
  58. $tmp['recharge_money'] = $item['money'];
  59. $resultList[] = $tmp;
  60. }
  61. }
  62. }
  63. } else {
  64. $customCollect = model('booklist_collect')
  65. ->alias('bc')
  66. ->where('bc.booklist_id', $ids)
  67. ->whereIn('bc.admin_id', (array)$admin_ids)
  68. ->order('recharge_money', 'desc')
  69. ->field(['bc.admin_id','bc.booklist_id'=>'id','bc.idx','bc.uv','bc.orders_num','bc.recharge_money'])
  70. ->select();
  71. if ($customCollect) {
  72. foreach ($customCollect as $item) {
  73. $tmp = array_merge($bookListItem->getData(), $item->getData());
  74. $resultList[] = $tmp;
  75. }
  76. }
  77. }
  78. if ($resultList) {
  79. $bookIds = array_column($resultList, 'idx');
  80. $booksInfo = BookService::instance()->getBookModel()->getBooksInfo($bookIds);
  81. foreach ($resultList as $index => $item) {
  82. $resultList[$index]['book_name'] = $booksInfo[$item['idx']]['name'];
  83. $resultList[$index]['book_id'] = $item['idx'];
  84. }
  85. }
  86. return $this->setData($resultList)->getReturn();
  87. }
  88. }