| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\AdvertModel;
- use App\Services\BaseService;
- /**
- * 用户挂单广告-服务类
- * Class AdvertService
- * @package App\Services\Api
- */
- class AdvertService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @since 2020/11/10
- * AdvertService constructor.
- */
- public function __construct()
- {
- $this->model = new AdvertModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 获取挂单广告列表
- * @param $params 参数
- * @param int $pageSize 分页大小:默认 15
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['a.mark' => 1, 'a.status' => 1];
- $type = isset($params['type'])? $params['type'] : 1;
- if($type>0){
- $where['type'] = $type;
- }
- $list = $this->model->from('advert as a')
- ->leftJoin('member as m', 'm.id', '=', 'a.business_id')
- ->where($where)
- ->where('a.expired_at', '>', date('Y-m-d H:i:s'))
- ->select(['a.*', 'm.username'])
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list? $list->toArray() :[];
- if($list){
- $field = $type == 1? 'usdt_buy_price' : 'usdt_sell_price';
- $marketPrice = \App\Services\ConfigService::make()->getConfigByCode($field);
- foreach($list['data'] as &$item){
- $expiredAt = isset($item['expired_at']) && $item['expired_at']? strtotime($item['expired_at']) : 0;
- $item['expired'] = max(0,$expiredAt-time());
- $item['expired_text'] = $expiredAt>0? formatTime($expiredAt - time()) : '已过期';
- // 固定价格和市场浮动价格处理
- $item['source_price'] = $item['price'];
- $item['logo_index'] = intval($item['business_id']%5);
- $item['username_text'] = $item['username']? mb_substr($item['username'], 0,1, 'utf-8'):'';
- $item['limit_min'] = moneyFormat($item['limit_min'], 2);
- $item['limit_max'] = moneyFormat($item['limit_max'], 2);
- $priceType = isset($item['price_type'])? intval($item['price_type']) : 0;
- $item['price'] = $priceType==2? moneyFormat($item['price']+$marketPrice, 2) : $item['price'];
- }
- }
- return [
- 'pageSize'=> $pageSize,
- 'total'=>isset($list['total'])? $list['total'] : 0,
- 'list'=> isset($list['data'])? $list['data'] : []
- ];
- }
- }
|