| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\AdvertModel;
- use App\Models\UserModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 用户挂单广告-服务类
- * Class AdvertService
- * @package App\Services\Common
- */
- class AdvertService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @since 2020/11/10
- * AdvertService constructor.
- */
- public function __construct()
- {
- $this->model = new AdvertModel();
- $this->userModel = new UserModel();
- }
- /**
- * 静态入口
- * @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];
- $type = isset($params['type'])? $params['type'] : 1;
- $businessId = isset($params['business_id'])? $params['business_id'] : 0;
- if($type>0){
- $where['a.type'] = $type;
- }
- if($businessId>0){
- $where['a.business_id'] = $businessId;
- }
- $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','m.realname'])
- ->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['logo_index'] = intval($item['business_id']%5);
- $item['username_text'] = $item['username']? mb_substr($item['username'], 0,1, 'utf-8'):'';
- $item['username_hidden'] = $item['username']? format_account($item['username']):'';
- $item['create_time_text'] = $item['create_time']? datetime($item['create_time']):'';
- $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['real_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'] : []
- ];
- }
- /**
- * 获取资料详情
- * @param $where
- * @param array $field
- */
- public function getInfo($where, array $field = [])
- {
- $field = $field ? $field : ['*'];
- if (is_array($where)) {
- $info = $this->model->where($where)->select($field)->first();
- } else {
- $info = $this->model->where(['id' => (int)$where])->select($field)->first();
- }
- $info = $info ? $info->toArray() : [];
- return $info;
- }
- /**
- * @param $userId
- * @param $data
- * @return array
- */
- public function saveData($userId, $data){
- $memberInfo = MemberService::make()->getInfo($userId);
- $tradePassword = isset($memberInfo['trade_password'])? $memberInfo['trade_password'] : '';
- $password = isset($data['trade_password'])?$data['trade_password']: '';
- // 交易密码
- if (empty($tradePassword)) {
- return message(2015, false);
- }
- if(get_password($password.md5($password.'otc')) != $tradePassword){
- return message(2016, false);
- }
- // 开始时间
- if ($data['pay_type']) {
- $data['pay_type'] = implode(',', $data['pay_type']);
- }
- $data['business_id'] = $userId;
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- }
|