AdvertService.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\AdvertModel;
  13. use App\Models\CapitalLogModel;
  14. use App\Models\MemberModel;
  15. use App\Services\BaseService;
  16. use App\Services\ConfigService;
  17. use App\Services\RedisService;
  18. /**
  19. * 用户挂单广告-服务类
  20. * Class AdvertService
  21. * @package App\Services\Api
  22. */
  23. class AdvertService extends BaseService
  24. {
  25. // 静态对象
  26. protected static $instance = null;
  27. /**
  28. * 构造函数
  29. * @since 2020/11/10
  30. * AdvertService constructor.
  31. */
  32. public function __construct()
  33. {
  34. $this->model = new AdvertModel();
  35. $this->memberModel = new MemberModel();
  36. $this->capitalModel = new CapitalLogModel();
  37. }
  38. /**
  39. * 静态入口
  40. * @return static|null
  41. */
  42. public static function make()
  43. {
  44. if (!self::$instance) {
  45. self::$instance = (new static());
  46. }
  47. return self::$instance;
  48. }
  49. /**
  50. * 获取挂单广告列表
  51. * @param $params 参数
  52. * @param int $pageSize 分页大小:默认 15
  53. * @return array
  54. */
  55. public function getDataList($params, $pageSize = 15)
  56. {
  57. $where = ['a.mark' => 1, 'a.status' => 1];
  58. $type = isset($params['type'])? $params['type'] : 1;
  59. if($type>0){
  60. $where['type'] = $type;
  61. }
  62. $list = $this->model->from('advert as a')
  63. ->leftJoin('member as m', 'm.id', '=', 'a.business_id')
  64. ->where($where)
  65. ->where('a.expired_at', '>', date('Y-m-d H:i:s'))
  66. ->select(['a.*', 'm.username'])
  67. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  68. $list = $list? $list->toArray() :[];
  69. if($list){
  70. $field = $type == 1? 'usdt_buy_price' : 'usdt_sell_price';
  71. $marketPrice = \App\Services\ConfigService::make()->getConfigByCode($field);
  72. foreach($list['data'] as &$item){
  73. $expiredAt = isset($item['expired_at']) && $item['expired_at']? strtotime($item['expired_at']) : 0;
  74. $item['expired'] = max(0,$expiredAt-time());
  75. $item['expired_text'] = $expiredAt>0? formatTime($expiredAt - time()) : '已过期';
  76. // 固定价格和市场浮动价格处理
  77. $item['source_price'] = $item['price'];
  78. $item['logo_index'] = intval($item['business_id']%5);
  79. $item['username_text'] = $item['username']? mb_substr($item['username'], 0,1, 'utf-8'):'';
  80. $item['username_hidden'] = $item['username']? format_account($item['username']):'';
  81. $item['limit_min'] = moneyFormat($item['limit_min'], 2);
  82. $item['limit_max'] = moneyFormat($item['limit_max'], 2);
  83. $priceType = isset($item['price_type'])? intval($item['price_type']) : 0;
  84. $item['price'] = $priceType==2? moneyFormat($item['price']+$marketPrice, 2) : $item['price'];
  85. }
  86. }
  87. return [
  88. 'pageSize'=> $pageSize,
  89. 'total'=>isset($list['total'])? $list['total'] : 0,
  90. 'list'=> isset($list['data'])? $list['data'] : []
  91. ];
  92. }
  93. }