浏览代码

wes 多宝福袋

wesmiler 2 年之前
父节点
当前提交
b8a3a87423

+ 23 - 53
app/api/controller/v1/Pay.php

@@ -9,6 +9,7 @@ use app\common\model\ShopGoodsModel;
 use app\common\model\ShopOrderGoodsModel as OrderGoods;
 use app\common\model\ShopOrderModel;
 use app\common\model\UserModel;
+use app\common\service\PayConfigService;
 use app\common\service\PaymentService;
 use app\common\service\SystemConfigService;
 use app\common\service\UserBankSignService;
@@ -39,58 +40,14 @@ class Pay
      */
     public function payconfig(Request $request)
     {
-        $setting = [];
-        $appresource = $request->post('app_sources', '');
-        $order_type = $request->post('order_type');
-        if (empty($order_type)) {
+        $paySource = $request->post('app_sources', '');
+        $orderType = $request->post('order_type');
+        if (empty($orderType)) {
             return api_error_return('参数错误');
         }
 
-
-        // 石区支付宝支付
-        array_push($setting, ['is_open' => 1, 'channel' => 22, 'title' => '支付宝支付', 'icon' => getWebUrl() . '/static/img/payconfig/ic_zhifubao.png']);
-
-        // 商城购买
-        if ($order_type == 4) {
-
-
-            if ($appresource == 'android') {
-
-                // 石学长 银联支付
-                array_push($setting, ['is_open' => 1, 'channel' => 15, 'title' => '银联(协议绑卡)', 'icon' => getWebUrl() . '/static/img/payconfig/ic_yinlian_pay.png']);
-
-
-            }
-
-            if ($appresource == 'ios') {
-                // 石学长 银联支付
-                array_push($setting, ['is_open' => 1, 'channel' => 15, 'title' => '银联', 'icon' => getWebUrl() . '/static/img/payconfig/ic_yinlian_pay.png']);
-
-            }
-
-        }
-
-
-        // 购买服务商
-        if ($order_type == 6) {
-
-            if ($appresource == 'android') {
-
-                // 石学长 银联支付
-                array_push($setting, ['is_open' => 1, 'channel' => 15, 'title' => '银联(协议绑卡)', 'icon' => getWebUrl() . '/static/img/payconfig/ic_yinlian_pay.png']);
-
-            }
-
-            if ($appresource == 'ios') {
-
-                // 石学长 银联支付
-                array_push($setting, ['is_open' => 1, 'channel' => 15, 'title' => '银联(协议绑卡)', 'icon' => getWebUrl() . '/static/img/payconfig/ic_yinlian_pay.png']);
-
-            }
-
-        }
-
-        return api_succ_return(['msg' => '成功', 'data' => ['setting' => $setting]]);
+        $channelList = PayConfigService::make()->getChannelList($orderType, $paySource);
+        return api_succ_return(['msg' => '成功', 'data' => ['setting' => array_values($channelList)]]);
     }
 
     /**
@@ -141,6 +98,7 @@ class Pay
         }
 
         // 加锁
+        $result = false;
         RedisCache::setnx($cacheKeyLock, 1, rand(2, 3));
         try {
 
@@ -153,12 +111,17 @@ class Pay
                 }
             }
 
-            if (!in_array($channel, [14, 15, 20, 22])) {
-                throw new Exception('支付类型错误');
+            $channelList = PayConfigService::make()->getChannelList($orderType, $app_sources);
+            if(empty($channelList)){
+                throw new Exception('支付渠道暂未开放,请先配置');
             }
 
-            if ($post['order_type'] == 4) {
+            $channels = $channelList? array_keys($channelList) : [15, 22, 66];
+            if (!in_array($channel, $channels)) {
+                throw new Exception('支付类型错误或未开放');
+            }
 
+            if ($post['order_type'] == 4) {
                 if (empty($post['order_id'])) {
                     throw new Exception('参数错误');
                 }
@@ -263,6 +226,13 @@ class Pay
                         $result = $pay->getYsfPayInfoTY($request->uid, $request->data);
                     }
                     break;
+                case 66:
+                    // 电科云闪付
+                    {
+                        $pay = new ThirdPayServices();
+                        $result = $pay->getPayInfoDiankeYsf($request->uid, $request->data);
+                    }
+                    break;
             }
 
         } catch (Exception $e) {
@@ -271,7 +241,7 @@ class Pay
         }
 
         RedisCache::keyDel("caches:paymentCall:u{$request->uid}_ot{$orderType}*");
-        return $result;
+        return $result? $result : api_error_return('支付请求错误或未开放,请联系客服');
 
     }
 

+ 82 - 0
app/api/services/ThirdPayServices.php

@@ -1483,6 +1483,88 @@ class ThirdPayServices extends BasePayServices
     }
 
     /**
+     * 电科云闪付
+     * @param $uid
+     * @param $params
+     * @return \think\Response
+     * @throws Exception
+     */
+    public function getPayInfoDiankeYsf($uid, $payData)
+    {
+        list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way, $voucher_img) = $this->_payConf($uid, $payData);
+
+        // 接口地址
+
+        $apiUrl = env('PAYDK.DKPAY_API_URL','http://1.14.197.47/proxy/pay/unifiedorder');
+
+        $date = date('Y-m-d H:i:s');
+        $out_trade_no = createdOrderSn();
+        $cacheKey = "caches:payment:dkpay:otn_{$out_trade_no}:{$uid}_{$remarks}_";
+        RedisCache::set($cacheKey.'payData', ['payData'=> $payData, 'date'=>$date], 2*86400);
+
+        // 测试金额
+        if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])) {
+            $total_amount = floatval('0' . '.' . mt_rand(1, 2) . mt_rand(1, 9));
+        }
+
+        if ($total_amount > 15000) {
+            $loData = ['payData'=> $payData,'error'=>'大额不能使用支付宝支付', 'date'=>$date];
+            RedisCache::set($cacheKey.'error', $loData, 2*86400);
+            sr_throw('大额不能使用支付宝支付');
+        }
+
+        $params = [
+            'appId' => 'dianke',
+            'version' => '1.0',
+            'nonceStr' => nonce_str(15),
+            'orderId' => $out_trade_no,
+            'amount' => intval($total_amount * 100),
+            'payChannel' => 'ALP',
+            'goodsName' => $body? $body : '牛仔裤',
+            'goodsDesc' => $body? $body : '牛仔裤',
+            'clientIp' => get_client_ip(),
+            'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_ZFB_NEWURL'),
+            'tradeType' => 'QRCODE'
+        ];
+
+        ksort($params);
+        $params['sign'] = $this->diankesign($params);
+
+        // 提交确定支付请求接口
+        $loData = ['url'=>$apiUrl,'payData'=> $payData,'params'=> $params, 'date'=>$date];
+        RedisCache::set($cacheKey.'request', $loData, 2*86400);
+        $result = curlPost($apiUrl, $params);
+        $result = $result? json_decode($result, true) : [];
+        $payUrl = isset($result['data'])? $result['data'] : '';
+
+
+        $loData['result'] = $result;
+        RedisCache::set($cacheKey.'result', $loData, 2*86400);
+        if ($payUrl) {
+            $payment = [
+                'total_fee' => $total_amount,
+                'trade_type' => $trade_type,
+                'body' => $body,
+                'state' => 7,
+                'out_trade_no' => $out_trade_no,
+                'pay_way' => $pay_way,
+                'remarks' => $remarks,
+                'order_type' => $order_type,
+                'uid' => $uid,
+                'voucher_img' => $voucher_img,
+                'out_trade_no1' => '',
+                'hy_token_id' => ''
+            ];
+            Db::name('payment')->insert($payment);
+
+            return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]);
+
+        } else {
+            return api_error_return('支付错误,请联系客服');
+        }
+    }
+
+    /**
      * 银盛-第三方快捷支付
      * @param $trade_no
      * @param $sms_code

+ 7 - 6
app/common/service/BoxRecordService.php

@@ -189,7 +189,7 @@ class BoxRecordService
         }
 
         if ($boxCount > 20) {
-            sr_throw('最多可预约20个');
+            sr_throw('每次最多可预约20个');
         }
 
         // 如果预约数量小于5
@@ -198,8 +198,9 @@ class BoxRecordService
         }
 
         // 预约数量限制
-        if ($this->model->where(['uid' => $uid, 'status' => 1])->sum('num') > 100) {
-            sr_throw('每一场最多可预约100次');
+        $applyCount = $this->model->where(['uid' => $uid, 'status' => 1])->sum('num');
+        if ($applyCount + $boxCount> 100) {
+            sr_throw("每一场最多可预约100个,您已预约".($applyCount)."个");
         }
 
         $lun = 1;
@@ -511,7 +512,7 @@ class BoxRecordService
                     foreach ($boxArr as $bk => $bName) {
                         $goodsArr = isset($boxGoods[$bk]) ? $boxGoods[$bk] : [];
                         $awardNum = isset($val['box' . $bk]) ? intval($val['box' . $bk]) : 0;
-                        $time = sr_getcurtime(time() + ($bk / 10));
+                        $time = sr_getcurtime(strtotime($openTime) + ($bk / 10));
 
                         // 有中奖
                         if ($awardNum > 0) {
@@ -537,7 +538,7 @@ class BoxRecordService
                                     'rid' => $rid,
                                     'status' => 2,
                                     'goods_id' => $goodsId,
-                                    'create_time' => $time,
+                                    'create_time' => $time<$openTime?$openTime:$time,
                                     'box_settle_time' => $openTime,
                                     'box_type' => $bk,
                                     'goods_price' => isset($goods['price']) ? $goods['price'] : 0,
@@ -552,7 +553,7 @@ class BoxRecordService
                                     'rid' => $rid,
                                     'handle_type' => 0,
                                     'goods_id' => $goodsId,
-                                    'create_time' => $time,
+                                    'create_time' => $time<$openTime?$openTime:$time,
                                     'open_time' => $openTime,
                                     'box_type' => $bk,
                                     'goods_price' => isset($goods['price']) ? $goods['price'] : 0

+ 36 - 3
app/common/service/PayConfigService.php

@@ -40,15 +40,15 @@ class PayConfigService
      * @param bool $cache
      * @return array|mixed
      */
-    public function getInfoByChannel($channel, $field='', $cache=true)
+    public function getInfoByChannel($channel, $scene=1, $paySource=1, $cache=true)
     {
-        $cacheKey = "caches:temp:payConfig:channel_{$channel}".($field? '_'.md5($field):'');
+        $cacheKey = "caches:temp:payConfig:info:c_{$channel}_{$scene}_{$paySource}";
         $data = RedisCache::get($cacheKey);
         if($data && $cache){
             return $data;
         }
 
-        $field = $field? $field : 'app_id,private_key,public_key,app_cert_path,pay_root_cert,pay_cert_path,mchid';
+        $field = 'app_id,title,pay_code,sign_key,scene,pay_source,private_key,public_key,app_cert_path,pay_root_cert,pay_cert_path,mchid';
         $data = $this->model->where(['channel'=> $channel,'status'=>1])->field($field)->findOrEmpty();
         $data = $data? $data->toArray() : [];
         if($data && $cache){
@@ -57,4 +57,37 @@ class PayConfigService
 
         return $data;
     }
+
+    /**
+     * 获取开启的支付渠道配置
+     * @param int $scene 支付场景:1-所有,4-商城,6-服务商
+     * @param int $paySource 支付来源:1-所有,2-安卓,3-苹果
+     * @param bool $cache
+     * @return array|mixed
+     */
+    public function getChannelList($scene=1, $paySource=1, $cache=true)
+    {
+        $cacheKey = "caches:temp:payConfig:channelList:s_{$scene}_{$paySource}";
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+        $where = ['status'=>1];
+        if($scene>0){
+            $where['scene'] = $scene;
+        }
+        if($paySource>0){
+            $where['pay_source'] = $paySource;
+        }
+        $field = 'app_id,title,pay_code,sign_key,scene,pay_source,private_key,icon,public_key,app_cert_path,pay_root_cert,pay_cert_path,mchid';
+        $data = $this->model->where($where)->withAttr('icon',function($value){
+            return getWebUrl().$value;
+        })->order('sort asc,id asc')->column($field,'channel');
+        if($data && $cache){
+
+            RedisCache::set($cacheKey, $data, 7200);
+        }
+
+        return $data;
+    }
 }

+ 2 - 1
app/common/service/PaymentService.php

@@ -34,7 +34,8 @@ class PaymentService
         19=>'usdtPay',
         20=>'yswkPay',
         22=>'dkpay',
-        56=>'ysftyPay'
+        56=>'ysftyPay',
+        66=>'dkysf',
     ];
     protected $model = null;
 

+ 2 - 0
config/type.php

@@ -19,6 +19,7 @@ return [
       ],
     // 余额
     'money'=>[
+        0=>'其他',
         1=>'预约福袋',
         2=>'回收商品',
         3=>'预约福袋空盒退回',
@@ -39,6 +40,7 @@ return [
     ],
     // 积分
     'score'=>[
+        0=>'其他',
         1=>'预约福袋',
         2=>'预约福袋空盒退回',
         3=>'买商品送积分',

+ 1 - 0
public/static/admin/js/user/user.js

@@ -46,6 +46,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
                     },
 
                     {field: 'pid', width: 100, title: '上级ID'},
+                    {field: 'code', width: 120, title: '邀请码'},
                     {field: 'is_px', width: 80, title: '来源', search: 'select', selectList: {0: '邀请码', 1: '排线码'}},
                     {field: 'is_auth', width: 100, title: '是否实名', search: 'select', selectList: {0: '未实名', 1: '已实名'}},
                     // {field: 'coin', width: 80, title: 'T币', searchOp: 'range'},

二进制
public/static/img/payconfig/ic_dianke_ysf.png