|
@@ -0,0 +1,159 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Services;
|
|
|
|
|
+
|
|
|
|
|
+use App\Services\BaseService;
|
|
|
|
|
+use App\Models\PaymentOrder;
|
|
|
|
|
+use App\Models\Config;
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
+use Illuminate\Support\Collection;
|
|
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
+
|
|
|
|
|
+use App\Services\Payment\SanJinService;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 投注
|
|
|
|
|
+*/
|
|
|
|
|
+class PaymentOrderService extends BaseService
|
|
|
|
|
+{
|
|
|
|
|
+ const TYPE_PAY = 1; // 代收
|
|
|
|
|
+ const TYPE_PAYOUT = 1; // 代付
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 模型
|
|
|
|
|
+ * @return {string}
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function model() :string
|
|
|
|
|
+ {
|
|
|
|
|
+ return PaymentOrder::class;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 枚举
|
|
|
|
|
+ * @return {*}
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function enum() :string
|
|
|
|
|
+ {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 获取查询条件
|
|
|
|
|
+ * @param {array} $search 查询内容
|
|
|
|
|
+ * @return {array}
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function getWhere(array $search = []) :array
|
|
|
|
|
+ {
|
|
|
|
|
+ $where = [];
|
|
|
|
|
+ if(isset($search['member_id']) && !empty($search['member_id'])){
|
|
|
|
|
+ $where[] = ['member_id', '=', $search['member_id']];
|
|
|
|
|
+ }
|
|
|
|
|
+ if(isset($search['type']) && !empty($search['type'])){
|
|
|
|
|
+ $where[] = ['type', '=', $search['type']];
|
|
|
|
|
+ }
|
|
|
|
|
+ if(isset($search['channel']) && !empty($search['channel'])){
|
|
|
|
|
+ $where[] = ['channel', '=', $search['channel']];
|
|
|
|
|
+ }
|
|
|
|
|
+ if(isset($search['id']) && !empty($search['id'])){
|
|
|
|
|
+ $where[] = ['id', '=', $search['id']];
|
|
|
|
|
+ }
|
|
|
|
|
+ if(isset($search['status']) && !empty($search['status'])){
|
|
|
|
|
+ $where[] = ['status', '=', $search['status']];
|
|
|
|
|
+ }
|
|
|
|
|
+ return $where;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 查询单条数据
|
|
|
|
|
+ * @param array $search
|
|
|
|
|
+ * @return \App\Models\Coin|null
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function findOne(array $search): ?PaymentOrder
|
|
|
|
|
+ {
|
|
|
|
|
+ return self::model()::where(self::getWhere($search))->first();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 查询所有数据
|
|
|
|
|
+ * @param array $search
|
|
|
|
|
+ * @return \Illuminate\Database\Eloquent\Collection
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function findAll(array $search = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ return self::model()::where(self::getWhere($search))->get();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 分页查询
|
|
|
|
|
+ * @param array $search
|
|
|
|
|
+ * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function paginate(array $search = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ $limit = isset($search['limit'])?$search['limit']:15;
|
|
|
|
|
+ $paginator = self::model()::where(self::getWhere($search))->paginate($limit);
|
|
|
|
|
+ return ['total' => $paginator->total(), 'data' => $paginator->items()];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description:
|
|
|
|
|
+ * @param {*} $params
|
|
|
|
|
+ * @return {*}
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function submit($params = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ $result = false;
|
|
|
|
|
+ $msg['code'] = self::NOT;
|
|
|
|
|
+ $msg['msg'] = '';
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 判断是否是更新
|
|
|
|
|
+ if (!empty($params['id'])) {
|
|
|
|
|
+ // 更新
|
|
|
|
|
+ $info = self::findOne(['id'=>$params['id']] );
|
|
|
|
|
+ if (!$info) {
|
|
|
|
|
+ $msg['msg'] = '数据不存在!';
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $result = $info->update($params);
|
|
|
|
|
+ $id = $params['id'];
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 创建
|
|
|
|
|
+ $result = $info = self::model()::create($params);
|
|
|
|
|
+ $id = $result->id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if($result){
|
|
|
|
|
+ $msg['code'] = self::YES;
|
|
|
|
|
+ $msg['msg'] = '设置成功';
|
|
|
|
|
+ $msg['key'] = $id;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $msg;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function createPayout($memberId ,$amount ,$channel ,$bank_name ,$account ,$card_no)
|
|
|
|
|
+ {
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ $data['type'] = self::TYPE_PAYOUT;
|
|
|
|
|
+ $order_no = self::createOrderNo('sj'.$data['type'].'_',$memberId);
|
|
|
|
|
+ $data['order_no'] = $order_no;
|
|
|
|
|
+ $data['member_id'] = $memberId;
|
|
|
|
|
+ $amount = number_format($amount, 2, '.', '');
|
|
|
|
|
+ $data['amount'] = $amount;
|
|
|
|
|
+ $data['channel'] = $channel;
|
|
|
|
|
+ $data['bank_name'] = $bank_name;
|
|
|
|
|
+ $data['account'] = $account;
|
|
|
|
|
+ $data['card_no'] = $card_no;
|
|
|
|
|
+ $data['callback_url'] = SanJinService::getNotifyUrl();
|
|
|
|
|
+
|
|
|
|
|
+ $ret = SanJinService::payout($amount,$order_no,$bank_name,$account,$card_no);
|
|
|
|
|
+
|
|
|
|
|
+ return $ret;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|