MemberPaymentService.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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\Api;
  12. use App\Models\MemberPaymentModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 会员收款方式-服务类
  16. * Class MemberPaymentService
  17. * @package App\Services\Api
  18. */
  19. class MemberPaymentService extends BaseService
  20. {
  21. // 静态对象
  22. protected static $instance = null;
  23. /**
  24. * 构造函数
  25. * @since 2020/11/10
  26. * LoginService constructor.
  27. */
  28. public function __construct()
  29. {
  30. $this->model = new MemberPaymentModel();
  31. }
  32. /**
  33. * 静态入口
  34. * @return static|null
  35. */
  36. public static function make()
  37. {
  38. if (!self::$instance) {
  39. self::$instance = (new static());
  40. }
  41. return self::$instance;
  42. }
  43. /**
  44. * 获取选项列表
  45. * @param $userId
  46. * @return mixed
  47. */
  48. public function getOptionList($userId, $type = 1, $pageSize = 15)
  49. {
  50. $pageSize = $type==1? 0 : $pageSize;
  51. $list = $this->model->where(function ($query) use ($userId, $type) {
  52. if ($type == 1) {
  53. $query->where(['user_id' => $userId, 'status' => 1,'mark'=>1])->whereRaw('(trade_num<=0 or trade_quota <= 0 or (trade_num-used_num>0 and trade_quota-used_quota>0))');
  54. } else {
  55. $query->where(['user_id' => $userId,'mark'=>1])->where('status','>',0);
  56. }
  57. })
  58. ->selectRaw('id,type,real_name,logo,bank_name,branch_name,account,bank_card,trade_num,used_num,trade_quota,used_quota,(trade_quota - used_quota) as credit,status')
  59. ->paginate($pageSize>0? $pageSize : 9999999);
  60. $list = $list? $list->toArray() :[];
  61. if($list){
  62. foreach($list['data'] as &$item){
  63. $item['logo'] = $item['logo'] ? get_image_url($item['logo']) : '';
  64. $item['realname_text'] = $item['real_name'] ? format_realname($item['real_name']) : '';
  65. $item['account_text'] = $item['account'] ? format_account($item['account']) : '';
  66. $item['status'] = $item['status'] ==1? true : false;
  67. $item['bank_card_text'] = $item['bank_card'] ? '*' . substr($item['bank_card'], -4, 4) : '';
  68. if ($item['type'] == 1) {
  69. $item['show_text'] = $item['bank_name'] . ' ' . $item['realname_text'] . ' ' . $item['bank_card_text'];
  70. } else {
  71. $item['show_text'] = $item['realname_text'] . ' ' . $item['account_text'];
  72. }
  73. }
  74. }
  75. return [
  76. 'pageSize'=> $pageSize,
  77. 'total'=>isset($list['total'])? $list['total'] : 0,
  78. 'list'=> isset($list['data'])? $list['data'] : []
  79. ];
  80. }
  81. /**
  82. * 是否已经设置了收款方式
  83. * @param $userId
  84. * @return mixed
  85. */
  86. public function checkHasByUser($userId)
  87. {
  88. return $this->model->where(['user_id' => $userId, 'status' => 1,'mark'=>1])->count('id');
  89. }
  90. /**
  91. * 更新状态
  92. * @param $id
  93. * @param $status
  94. * @param $userId
  95. * @return mixed
  96. */
  97. public function setPayment($id, $status, $userId){
  98. $status = $status? 1 : 2;
  99. return $this->model->where(['user_id' => $userId, 'id' => $id,'mark'=>1])->update(['status'=> $status]);
  100. }
  101. /**
  102. * 删除
  103. * @param $id
  104. * @param $userId
  105. * @return mixed
  106. */
  107. public function delPayment($id, $userId){
  108. // 永久删除
  109. $this->model->where(['user_id' => $userId, 'id' => $id,'status'=> 0,'mark'=>1])
  110. ->where('update_time','<', time() - 2 * 86400)
  111. ->delete();
  112. return $this->model->where(['user_id' => $userId, 'id' => $id])->update(['status'=> 0,'mark'=>1]);
  113. }
  114. /**
  115. * 详情
  116. * @param $id
  117. * @return mixed
  118. */
  119. public function getInfo($id)
  120. {
  121. $info = $this->model->where(['id' => $id,'mark'=>1])->where('status','>', 0)->first();
  122. if($info){
  123. $info['logo'] = $info['logo']? get_image_url($info['logo']) : '';
  124. $info['status'] = $info['status']==1? true : false;
  125. }
  126. return $info;
  127. }
  128. /**
  129. * 编辑或新增
  130. * @param $id
  131. * @param $params
  132. * @return mixed
  133. */
  134. public function saveData($id, $params)
  135. {
  136. $data = [
  137. 'user_id'=> isset($params['user_id'])? $params['user_id'] : 0,
  138. 'real_name'=> isset($params['real_name'])? $params['real_name'] : '',
  139. 'bank_name'=> isset($params['bank_name'])? $params['bank_name'] : '',
  140. 'branch_name'=> isset($params['branch_name'])? $params['branch_name'] : '',
  141. 'bank_card'=> isset($params['bank_card'])? $params['bank_card'] : '',
  142. 'trade_quota'=> isset($params['trade_quota'])? intval($params['trade_quota']) : 0,
  143. 'trade_num'=> isset($params['trade_num'])? intval($params['trade_num']) : 0,
  144. 'status'=> isset($params['status']) && $params['status'] == 1? intval($params['status']) : 2,
  145. 'mark'=> 1,
  146. ];
  147. if(isset($params['logo']) && strpos($params['logo'],'http')===false){
  148. $data['logo'] = $params['logo'];
  149. }
  150. if($id>0 && $this->model->where(['id'=> $id,'mark'=>1])->value('id')){
  151. return $this->model->where(['id'=> $id])->update($data);
  152. }else{
  153. return $this->model->insert($data);
  154. }
  155. }
  156. }