MemberSettingService.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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\MemberSettingModel;
  13. use App\Services\BaseService;
  14. use App\Services\ConfigService;
  15. /**
  16. * 用户交易设置参数-服务类
  17. * Class MemberSettingService
  18. * @package App\Services\Common
  19. */
  20. class MemberSettingService extends BaseService
  21. {
  22. // 静态对象
  23. protected static $instance = null;
  24. /**
  25. * 构造函数
  26. * @since 2020/11/10
  27. * MemberSettingService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new MemberSettingModel();
  32. }
  33. /**
  34. * 静态入口
  35. * @return static|null
  36. */
  37. public static function make()
  38. {
  39. if (!self::$instance) {
  40. self::$instance = (new static());
  41. }
  42. return self::$instance;
  43. }
  44. /**
  45. * 更新设置
  46. * @param $id
  47. * @param $status
  48. * @param $userId
  49. * @return mixed
  50. */
  51. public function setData($userId, $data)
  52. {
  53. if ($this->model->where(['user_id' => $userId])->value('id')) {
  54. return $this->model->where(['user_id' => $userId])->update($data);
  55. } else {
  56. $data['user_id'] = $userId;
  57. return $this->model->insert($data);
  58. }
  59. }
  60. /**
  61. * 详情
  62. * @param $id
  63. * @return mixed
  64. */
  65. public function getInfo($userId)
  66. {
  67. $info = $this->model->where(['user_id' => $userId])->first();
  68. if ($info['advert_online_time']) {
  69. $info['advert_online_time'] = max(0, intval($info['advert_online_time']) - time());
  70. $info['advert_online_time_text'] = $info['advert_online_time']? date('H:i:s', $info['advert_online_time']) : '00:00:00';
  71. $info['advert_online'] = $info['advert_online_time']>0? $info['advert_online'] : 0;
  72. }
  73. if ($info['buy_online_time']) {
  74. $info['buy_online_time'] = max(0, intval($info['buy_online_time']) - time());
  75. $info['buy_online_time_text'] = $info['buy_online_time']? date('H:i:s', $info['buy_online_time']) : '00:00:00';
  76. $info['buy_online'] = $info['buy_online_time']>0? $info['buy_online'] : 0;
  77. }
  78. if ($info['sell_online_time']) {
  79. $info['sell_online_time'] = max(0, intval($info['sell_online_time']) - time());
  80. $info['sell_online_time_text'] = $info['sell_online_time']? date('H:i:s', $info['sell_online_time']) : '00:00:00';
  81. $info['sell_online'] = $info['sell_online_time']>0? $info['sell_online'] : 0;
  82. }
  83. if (empty($info)) {
  84. $tradeSellQuota = ConfigService::make()->getConfigByCode('trade_sell_quota');
  85. $tradeSellQuota = $tradeSellQuota>0? $tradeSellQuota : 50000;
  86. $tradeOutlineTime = ConfigService::make()->getConfigByCode('trade_outline_time');
  87. $tradeOutlineTime = $tradeOutlineTime>0? $tradeOutlineTime*3600 : 8*3600;
  88. $data = [
  89. 'user_id'=> $userId,
  90. 'advert_online'=>1,
  91. 'advert_online_time'=> time()+ $tradeOutlineTime,
  92. 'buy_online'=>1,
  93. 'buy_online_time'=> time() + $tradeOutlineTime,
  94. 'sell_online'=>1,
  95. 'sell_online_time'=> time() + $tradeOutlineTime,
  96. 'day_sell_quota'=> $tradeSellQuota,
  97. 'update_time'=> time(),
  98. ];
  99. $this->model->insert($data);
  100. return $this->getInfo($userId);
  101. }
  102. return $info;
  103. }
  104. /**
  105. * 编辑
  106. * @param $id
  107. * @param $params
  108. * @return mixed
  109. */
  110. public function saveData($userId, $params)
  111. {
  112. $this->getInfo($userId);
  113. $tradeOutlineTime = ConfigService::make()->getConfigByCode('trade_outline_time');
  114. $tradeOutlineTime = $tradeOutlineTime>0? $tradeOutlineTime : 8;
  115. $data = [];
  116. if (isset($params['advert_online'])) {
  117. $data['advert_online'] = intval($params['advert_online']);
  118. if ($params['advert_online'] <= 0) {
  119. $data['advert_online_time'] = time();
  120. } else {
  121. $data['advert_online_time'] = time() + $tradeOutlineTime*3600;
  122. }
  123. }
  124. if (isset($params['buy_online'])) {
  125. $data['buy_online'] = intval($params['buy_online']);
  126. if ($params['buy_online'] <= 0) {
  127. $data['buy_online_time'] = time();
  128. } else {
  129. $data['buy_online_time'] = time() + $tradeOutlineTime*3600;
  130. }
  131. }
  132. if (isset($params['sell_online'])) {
  133. $data['sell_online'] = intval($params['sell_online']);
  134. if ($params['sell_online'] <= 0) {
  135. $data['sell_online_time'] = time();
  136. } else {
  137. $data['sell_online_time'] = time() + $tradeOutlineTime*3600;
  138. }
  139. }
  140. if (isset($params['day_sell_quota'])) {
  141. $data['day_sell_quota'] = floatval($params['day_sell_quota']);
  142. }
  143. if($data){
  144. return $this->model->where(['user_id'=> $userId])->update($data);
  145. }else{
  146. return false;
  147. }
  148. }
  149. }