PaymentOrderService.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace App\Services;
  3. use App\Services\BaseService;
  4. use App\Models\PaymentOrder;
  5. use App\Models\Config;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Collection;
  8. use Illuminate\Support\Facades\Cache;
  9. use Illuminate\Support\Facades\Log;
  10. use App\Services\Payment\SanJinService;
  11. /**
  12. * 投注
  13. */
  14. class PaymentOrderService extends BaseService
  15. {
  16. const TYPE_PAY = 1; // 代收
  17. const TYPE_PAYOUT = 1; // 代付
  18. /**
  19. * @description: 模型
  20. * @return {string}
  21. */
  22. public static function model() :string
  23. {
  24. return PaymentOrder::class;
  25. }
  26. /**
  27. * @description: 枚举
  28. * @return {*}
  29. */
  30. public static function enum() :string
  31. {
  32. return '';
  33. }
  34. /**
  35. * @description: 获取查询条件
  36. * @param {array} $search 查询内容
  37. * @return {array}
  38. */
  39. public static function getWhere(array $search = []) :array
  40. {
  41. $where = [];
  42. if(isset($search['member_id']) && !empty($search['member_id'])){
  43. $where[] = ['member_id', '=', $search['member_id']];
  44. }
  45. if(isset($search['type']) && !empty($search['type'])){
  46. $where[] = ['type', '=', $search['type']];
  47. }
  48. if(isset($search['channel']) && !empty($search['channel'])){
  49. $where[] = ['channel', '=', $search['channel']];
  50. }
  51. if(isset($search['id']) && !empty($search['id'])){
  52. $where[] = ['id', '=', $search['id']];
  53. }
  54. if(isset($search['status']) && !empty($search['status'])){
  55. $where[] = ['status', '=', $search['status']];
  56. }
  57. return $where;
  58. }
  59. /**
  60. * @description: 查询单条数据
  61. * @param array $search
  62. * @return \App\Models\Coin|null
  63. */
  64. public static function findOne(array $search): ?PaymentOrder
  65. {
  66. return self::model()::where(self::getWhere($search))->first();
  67. }
  68. /**
  69. * @description: 查询所有数据
  70. * @param array $search
  71. * @return \Illuminate\Database\Eloquent\Collection
  72. */
  73. public static function findAll(array $search = [])
  74. {
  75. return self::model()::where(self::getWhere($search))->get();
  76. }
  77. /**
  78. * @description: 分页查询
  79. * @param array $search
  80. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  81. */
  82. public static function paginate(array $search = [])
  83. {
  84. $limit = isset($search['limit'])?$search['limit']:15;
  85. $paginator = self::model()::where(self::getWhere($search))->paginate($limit);
  86. return ['total' => $paginator->total(), 'data' => $paginator->items()];
  87. }
  88. /**
  89. * @description:
  90. * @param {*} $params
  91. * @return {*}
  92. */
  93. public static function submit($params = [])
  94. {
  95. $result = false;
  96. $msg['code'] = self::NOT;
  97. $msg['msg'] = '';
  98. // 2. 判断是否是更新
  99. if (!empty($params['id'])) {
  100. // 更新
  101. $info = self::findOne(['id'=>$params['id']] );
  102. if (!$info) {
  103. $msg['msg'] = '数据不存在!';
  104. }else{
  105. $result = $info->update($params);
  106. $id = $params['id'];
  107. }
  108. } else {
  109. // 创建
  110. $result = $info = self::model()::create($params);
  111. $id = $result->id;
  112. }
  113. if($result){
  114. $msg['code'] = self::YES;
  115. $msg['msg'] = '设置成功';
  116. $msg['key'] = $id;
  117. }else{
  118. $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
  119. }
  120. return $msg;
  121. }
  122. public static function createPayout($memberId ,$amount ,$channel ,$bank_name ,$account ,$card_no)
  123. {
  124. $data = [];
  125. $data['type'] = self::TYPE_PAYOUT;
  126. $order_no = self::createOrderNo('sj'.$data['type'].'_',$memberId);
  127. $data['order_no'] = $order_no;
  128. $data['member_id'] = $memberId;
  129. $amount = number_format($amount, 2, '.', '');
  130. $data['amount'] = $amount;
  131. $data['channel'] = $channel;
  132. $data['bank_name'] = $bank_name;
  133. $data['account'] = $account;
  134. $data['card_no'] = $card_no;
  135. $data['callback_url'] = SanJinService::getNotifyUrl();
  136. $ret = SanJinService::payout($amount,$order_no,$bank_name,$account,$card_no);
  137. return $ret;
  138. }
  139. }