MemberSettingService.php 5.8 KB

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