AdvertService.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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\Common;
  12. use App\Models\AdvertModel;
  13. use App\Models\UserModel;
  14. use App\Services\BaseService;
  15. use App\Services\RedisService;
  16. /**
  17. * 用户挂单广告-服务类
  18. * Class AdvertService
  19. * @package App\Services\Common
  20. */
  21. class AdvertService extends BaseService
  22. {
  23. // 静态对象
  24. protected static $instance = null;
  25. /**
  26. * 构造函数
  27. * @since 2020/11/10
  28. * AdvertService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new AdvertModel();
  33. $this->userModel = new UserModel();
  34. }
  35. /**
  36. * 静态入口
  37. * @return static|null
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = (new static());
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * 获取挂单广告列表
  48. * @param $params 参数
  49. * @param int $pageSize 分页大小:默认 15
  50. * @return array
  51. */
  52. public function getDataList($params, $pageSize = 15)
  53. {
  54. $where = ['a.mark' => 1];
  55. $type = isset($params['type'])? $params['type'] : 1;
  56. $businessId = isset($params['business_id'])? $params['business_id'] : 0;
  57. if($type>0){
  58. $where['a.type'] = $type;
  59. }
  60. if($businessId>0){
  61. $where['a.business_id'] = $businessId;
  62. }
  63. $list = $this->model->from('advert as a')
  64. ->leftJoin('member as m', 'm.id', '=', 'a.business_id')
  65. ->where($where)
  66. ->where('a.expired_at', '>', date('Y-m-d H:i:s'))
  67. ->select(['a.*', 'm.username','m.realname'])
  68. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  69. $list = $list? $list->toArray() :[];
  70. if($list){
  71. $field = $type == 1? 'usdt_buy_price' : 'usdt_sell_price';
  72. $marketPrice = \App\Services\ConfigService::make()->getConfigByCode($field);
  73. foreach($list['data'] as &$item){
  74. $expiredAt = isset($item['expired_at']) && $item['expired_at']? strtotime($item['expired_at']) : 0;
  75. $item['expired'] = max(0,$expiredAt-time());
  76. $item['expired_text'] = $expiredAt>0? formatTime($expiredAt - time()) : '已过期';
  77. // 固定价格和市场浮动价格处理
  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['create_time_text'] = $item['create_time']? datetime($item['create_time']):'';
  82. $item['limit_min'] = moneyFormat($item['limit_min'], 2);
  83. $item['limit_max'] = moneyFormat($item['limit_max'], 2);
  84. $priceType = isset($item['price_type'])? intval($item['price_type']) : 0;
  85. $item['real_price'] = $priceType==2? moneyFormat($item['price']+$marketPrice, 2) : $item['price'];
  86. }
  87. }
  88. return [
  89. 'pageSize'=> $pageSize,
  90. 'total'=>isset($list['total'])? $list['total'] : 0,
  91. 'list'=> isset($list['data'])? $list['data'] : []
  92. ];
  93. }
  94. /**
  95. * 获取资料详情
  96. * @param $where
  97. * @param array $field
  98. */
  99. public function getInfo($where, array $field = [])
  100. {
  101. $field = $field ? $field : ['*'];
  102. if (is_array($where)) {
  103. $info = $this->model->where($where)->select($field)->first();
  104. } else {
  105. $info = $this->model->where(['id' => (int)$where])->select($field)->first();
  106. }
  107. $info = $info ? $info->toArray() : [];
  108. return $info;
  109. }
  110. /**
  111. * @param $userId
  112. * @param $data
  113. * @return array
  114. */
  115. public function saveData($userId, $data){
  116. $memberInfo = MemberService::make()->getInfo($userId);
  117. $tradePassword = isset($memberInfo['trade_password'])? $memberInfo['trade_password'] : '';
  118. $password = isset($data['trade_password'])?$data['trade_password']: '';
  119. // 交易密码
  120. if (empty($tradePassword)) {
  121. return message(2015, false);
  122. }
  123. if(get_password($password.md5($password.'otc')) != $tradePassword){
  124. return message(2016, false);
  125. }
  126. // 开始时间
  127. if ($data['pay_type']) {
  128. $data['pay_type'] = implode(',', $data['pay_type']);
  129. }
  130. $data['business_id'] = $userId;
  131. return parent::edit($data); // TODO: Change the autogenerated stub
  132. }
  133. }