12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2020/6/2
- * Time: 上午10:44
- */
- namespace app\main\service;
- use app\admin\library\Auth;
- use app\main\constants\AdminConstants;
- use app\main\constants\ApiConstants;
- /**
- * Class BookListChService
- * @package app\main\service
- */
- class BookListChService extends BaseService
- {
- /**
- * @var BookListChService
- */
- protected static $self = null;
- /**
- * @return $this
- */
- public static function instance()
- {
- if (self::$self == null) {
- self::$self = new self();
- }
- return self::$self;
- }
- public function getCollectList($ids, $admin_id)
- {
- $bookListItem = model('book_list_ch')
- ->alias('c')
- ->where('c.id', $ids)
- ->field('c.id,c.admin_id,c.title,c.createtime')
- ->find();
- $admin_ids = (array)AdminService::instance()->getAdminId($admin_id)->data;
- $bookListItem['uv'] = $bookListItem['orders_num'] = $bookListItem['recharge_money'] = 0;
- $resultList = [];
- if (VisitLimitService::instance()->checkMigratedV2()) {
- if (count($admin_ids) == 1) {
- $where = ['ids' => [$ids]];
- } else {
- $where = ['ids' => [$ids], 'admin_id' => $admin_ids[0]];
- }
- $result = ApiService::instance()->getCollectFromApi(ApiConstants::API_BOOK_LIST, $where)->data;
- if ($result) {
- foreach ($result as $index => $item) {
- if (in_array($item['adminId'], $admin_ids)) {
- $tmp = $bookListItem->getData();
- $tmp['admin_id'] = $item['adminId']??'';
- $tmp['booklistId'] = $item['booklistId'];
- $tmp['idx'] = $item['idx'];
- $tmp['uv'] = $item['uv'];
- $tmp['orders_num'] = $item['orders'];
- $tmp['recharge_money'] = $item['money'];
- $resultList[] = $tmp;
- }
- }
- }
- } else {
- $customCollect = model('booklist_collect')
- ->alias('bc')
- ->where('bc.booklist_id', $ids)
- ->whereIn('bc.admin_id', (array)$admin_ids)
- ->order('recharge_money', 'desc')
- ->field(['bc.admin_id','bc.booklist_id'=>'id','bc.idx','bc.uv','bc.orders_num','bc.recharge_money'])
- ->select();
- if ($customCollect) {
- foreach ($customCollect as $item) {
- $tmp = array_merge($bookListItem->getData(), $item->getData());
- $resultList[] = $tmp;
- }
- }
- }
- if ($resultList) {
- $bookIds = array_column($resultList, 'idx');
- $booksInfo = BookService::instance()->getBookModel()->getBooksInfo($bookIds);
- foreach ($resultList as $index => $item) {
- $resultList[$index]['book_name'] = $booksInfo[$item['idx']]['name'];
- $resultList[$index]['book_id'] = $item['idx'];
- }
- }
- return $this->setData($resultList)->getReturn();
- }
- }
|