MemberPaymentService.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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)
  49. {
  50. $list = $this->model->where(['user_id'=> $userId,'status'=>1])
  51. ->whereRaw('(trade_num-used_num>0 and trade_quota-used_quota>0)')
  52. ->selectRaw('id,type,real_name,bank_name,account,bank_card,trade_quota,used_quota,(trade_quota - used_quota) as credit')
  53. ->get()
  54. ->each(function($item,$k){
  55. $item['realname_text'] = $item['real_name']? format_realname($item['real_name']) : '';
  56. $item['account_text'] = $item['account']? format_account($item['account']) : '';
  57. $item['bank_card_text'] = $item['bank_card']? '*'.substr($item['bank_card'], -4, 4) : '';
  58. if($item['type'] == 1){
  59. $item['show_text'] = $item['bank_name'].' '.$item['realname_text'].' '.$item['bank_card_text'];
  60. }else{
  61. $item['show_text'] = $item['realname_text'].' '.$item['account_text'];
  62. }
  63. });
  64. return $list? $list->toArray() : [];
  65. }
  66. /**
  67. * 是否已经设置了收款方式
  68. * @param $userId
  69. * @return mixed
  70. */
  71. public function checkHasByUser($userId){
  72. return $this->model->where(['user_id'=> $userId,'status'=>1])->count('id');
  73. }
  74. }