| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\MemberModel;
- use App\Models\MemberSettingModel;
- use App\Services\BaseService;
- use App\Services\ConfigService;
- /**
- * 用户交易设置参数-服务类
- * Class MemberSettingService
- * @package App\Services\Common
- */
- class MemberSettingService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @since 2020/11/10
- * MemberSettingService constructor.
- */
- public function __construct()
- {
- $this->model = new MemberSettingModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 更新设置
- * @param $id
- * @param $status
- * @param $userId
- * @return mixed
- */
- public function setData($userId, $data)
- {
- if ($this->model->where(['user_id' => $userId])->value('id')) {
- return $this->model->where(['user_id' => $userId])->update($data);
- } else {
- $data['user_id'] = $userId;
- return $this->model->insert($data);
- }
- }
- /**
- * 详情
- * @param $id
- * @return mixed
- */
- public function getInfo($userId)
- {
- $info = $this->model->where(['user_id' => $userId])->first();
- if ($info['advert_online_time']) {
- $info['advert_online_time'] = max(0, intval($info['advert_online_time']) - time());
- $info['advert_online_time_text'] = $info['advert_online_time']? date('H:i:s', $info['advert_online_time']) : '00:00:00';
- $info['advert_online'] = $info['advert_online_time']>0? $info['advert_online'] : 0;
- }
- if ($info['buy_online_time']) {
- $info['buy_online_time'] = max(0, intval($info['buy_online_time']) - time());
- $info['buy_online_time_text'] = $info['buy_online_time']? date('H:i:s', $info['buy_online_time']) : '00:00:00';
- $info['buy_online'] = $info['buy_online_time']>0? $info['buy_online'] : 0;
- }
- if ($info['sell_online_time']) {
- $info['sell_online_time'] = max(0, intval($info['sell_online_time']) - time());
- $info['sell_online_time_text'] = $info['sell_online_time']? date('H:i:s', $info['sell_online_time']) : '00:00:00';
- $info['sell_online'] = $info['sell_online_time']>0? $info['sell_online'] : 0;
- }
- if (empty($info)) {
- $tradeSellQuota = ConfigService::make()->getConfigByCode('trade_sell_quota');
- $tradeSellQuota = $tradeSellQuota>0? $tradeSellQuota : 50000;
- $tradeOutlineTime = ConfigService::make()->getConfigByCode('trade_outline_time');
- $tradeOutlineTime = $tradeOutlineTime>0? $tradeOutlineTime*3600 : 8*3600;
- $data = [
- 'user_id'=> $userId,
- 'advert_online'=>1,
- 'advert_online_time'=> time()+ $tradeOutlineTime,
- 'buy_online'=>1,
- 'buy_online_time'=> time() + $tradeOutlineTime,
- 'sell_online'=>1,
- 'sell_online_time'=> time() + $tradeOutlineTime,
- 'day_sell_quota'=> $tradeSellQuota,
- 'update_time'=> time(),
- ];
- $this->model->insert($data);
- return $this->getInfo($userId);
- }
- return $info;
- }
- /**
- * 编辑
- * @param $id
- * @param $params
- * @return mixed
- */
- public function saveData($userId, $params)
- {
- $this->getInfo($userId);
- $tradeOutlineTime = ConfigService::make()->getConfigByCode('trade_outline_time');
- $tradeOutlineTime = $tradeOutlineTime>0? $tradeOutlineTime : 8;
- $data = [];
- $online = 0;
- if (isset($params['advert_online'])) {
- $data['advert_online'] = intval($params['advert_online']);
- if ($params['advert_online'] <= 0) {
- $data['advert_online_time'] = time();
- } else {
- $online = 1;
- $data['advert_online_time'] = time() + $tradeOutlineTime*3600;
- }
- }
- if (isset($params['buy_online'])) {
- $data['buy_online'] = intval($params['buy_online']);
- if ($params['buy_online'] <= 0) {
- $data['buy_online_time'] = time();
- } else {
- $online = 1;
- $data['buy_online_time'] = time() + $tradeOutlineTime*3600;
- }
- }
- if (isset($params['sell_online'])) {
- $data['sell_online'] = intval($params['sell_online']);
- if ($params['sell_online'] <= 0) {
- $data['sell_online_time'] = time();
- } else {
- $online = 1;
- $data['sell_online_time'] = time() + $tradeOutlineTime*3600;
- }
- }
- if (isset($params['day_sell_quota'])) {
- $data['day_sell_quota'] = floatval($params['day_sell_quota']);
- }
- if($online == 1){
- MemberModel::where(['id'=> $userId])->update(['is_online'=> 1,'login_time'=> time()]);
- }
- if($data){
- return $this->model->where(['user_id'=> $userId])->update($data);
- }else{
- return false;
- }
- }
- }
|