瀏覽代碼

wes 多宝福袋

wesmiler 2 年之前
父節點
當前提交
c3fdeac5b6

+ 1 - 1
app/admin/controller/Ajax.php

@@ -64,7 +64,7 @@ class Ajax extends AdminController
         RedisCache::keyDel("caches:goods*");
 
         // 其他临时缓存
-        RedisCache::keyDel("caches:temp*");
+        RedisCache::keyDel("caches:tem*");
         Cache::clear();
         $this->success('清理缓存成功');
     }

+ 17 - 1
app/admin/view/system/config/site.html

@@ -28,8 +28,24 @@
     </div>
 
     <div class="layui-form-item">
+        <label class="layui-form-label">安卓APP地址</label>
+        <div class="layui-input-block">
+            <input type="text" name="site_android_url" class="layui-input" placeholder="请输入安卓APP下载地址" value="{:sysconfig('site','site_android_url')}">
+            <tip>填写安卓APP下载地址。</tip>
+        </div>
+    </div>
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">苹果APP地址</label>
+        <div class="layui-input-block">
+            <input type="text" name="site_ios_url" class="layui-input"  placeholder="请输入平果APP下载地址" value="{:sysconfig('site','site_ios_url')}">
+            <tip>填写苹果APP下载地址。</tip>
+        </div>
+    </div>
+
+    <div class="layui-form-item">
         <label class="layui-form-label">站点名称</label>
-        <div class="layui-input-block">app/admin/view/system/config/index.html
+        <div class="layui-input-block">
             <input type="text" name="site_name" class="layui-input" lay-verify="required" placeholder="请输入站点名称" value="{:sysconfig('site','site_name')}">
             <tip>填写站点名称。</tip>
         </div>

+ 5 - 5
app/api/command/SettleTeamAward.php

@@ -138,7 +138,7 @@ class SettleTeamAward extends Command
                         'from_id'=> $boxId,
                         'uid2'=> $uid,
                         'free_type'=> 0,
-                        'remark'=> '直推1个福袋奖金'.($todayZtMoney>0? ',有今日奖金':'')
+                        'remark'=> "V{$pLevel}直推1个福袋奖金".($todayZtMoney>0? ",有今日奖金{$todayZtMoney}":'')
                     ];
                     $moneyLogs[] = $log;
                     if(!UserModel::where('id', $pid)->inc('money', $ztAward)->inc('today_money', $todayZtMoney)->update()){
@@ -211,7 +211,7 @@ class SettleTeamAward extends Command
                         if($tLevel == $tLastLevel){
                             $sameAward = isset($teamMoneys[$tLastId])? floatval($teamMoneys[$tLastId]) : 0;
                             $sameTeamAward = round($sameAward * 0.1, 2);
-                            $sameTeamAward = $sameTeamAward>0.1? $sameTeamAward : 0;
+                            $sameTeamAward = $sameTeamAward>=0.1? $sameTeamAward : 0;
                             if($sameTeamAward>0){
                                 $teamMoneys[$tId] = $sameTeamAward;
                             }
@@ -234,9 +234,9 @@ class SettleTeamAward extends Command
                             'before_money'=> $tMoney,
                             'after_money'=> floatval($tMoney + $endTeamAward),
                             'from_id'=> $boxId,
-                            'uid2'=> $sameTeamAward? $tLastId : 0,
-                            'free_type'=> 0,
-                            'remark'=> ($sameTeamAward? '1个福袋平级奖':'1个福袋团队奖').($tTodayAward>0? ',有今日奖金':'')
+                            'uid2'=> $sameTeamAward? $tLastId : $uid,
+                            'free_type'=> $sameTeamAward? 0 : 1,
+                            'remark'=> ($sameTeamAward? "V{$tLevel}得[ID:{$tLastId}]1个福袋平级奖":"V{$tLevel}得[ID:{$uid}]1个福袋团队奖").($tTodayAward>0? ",有今日奖金{$tTodayAward}":'')
                         ];
                         $moneyLogs[] = $log;
                         if(!UserModel::where('id', $tId)->inc('money', $endTeamAward)->inc('today_money', $tTodayAward)->update()){

+ 32 - 30
app/api/controller/h5/DownApp.php

@@ -5,6 +5,7 @@ namespace app\api\controller\h5;
 use app\api\services\UserServices;
 use app\api\validate\UserValidate;
 use app\common\model\SystemArticleModel;
+use app\common\service\SystemConfigService;
 use app\Request;
 use think\Exception;
 use think\exception\ValidateException;
@@ -21,70 +22,71 @@ class DownApp
         $this->service = $services;
     }
 
-    // 下载app
+    /**
+     * 下载app
+     * @param Request $request
+     * @return string
+     */
     public function downapp (Request $request)
     {
-//        // 这是测试 上线要干掉
-//            echo '网站正在升级中';
-//            die();
 
+        $config = SystemConfigService::make()->getConfigByNames(['site_android_url','site_ios_url'],1,'site');
+        $androidUrl = isset($config['site_android_url'])?$config['site_android_url'] : env('app.DOWN_ANDROID_URL_GENERAL');
+        $iosdUrl = isset($config['site_ios_url'])?$config['site_ios_url'] : env('app.DOWN_IOS_URL');
 
-        $a_url = env('app.DOWN_ANDROID_URL_GENERAL');
-        $i_url = env('app.DOWN_IOS_URL');
-
-        $is_fair = false; // 是否是浏览器
+        $isFair = false; // 是否是浏览器
         if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === !1) {
-            $is_fair = true;
+            $isFair = true;
         }
         View::assign([
-            'is_fair' => $is_fair,
+            'is_fair' => $isFair,
             'k' => $request->param('k', ''),
             'v' => $request->param('v', ''),
         ]);
 
-        View::assign('aurl', $a_url);
-        View::assign('iurl', $i_url);
+        View::assign('aurl', $androidUrl);
+        View::assign('iurl', $iosdUrl);
         $info = [
           'name'=>env('app.name')
         ];
         View::assign('info', $info);
-
         return View::fetch();
     }
 
 
-    // 下载app 义礼德特
+    /**
+     * 下载app 义礼德特
+     * @param Request $request
+     * @return string
+     */
     public function downappyldt1 (Request $request)
     {
+        $config = SystemConfigService::make()->getConfigByNames(['site_android_cdn_url','site_ios_cdn_url'],1,'site');
+        $androidUrl = isset($config['site_android_cdn_url'])?$config['site_android_cdn_url'] : env('app.DOWN_ANDROID_URL_CDN');
+        $iosdUrl = isset($config['site_ios_cdn_url'])?$config['site_ios_cdn_url'] : env('app.DOWN_IOS_URL');
 
-
-        $a_url = env('app.DOWN_ANDROID_URL_CDN_TEST_YL');
-        $i_url = env('app.DOWN_IOS_URL');
-
-        $is_fair = false; // 是否是浏览器
+        $isFair = false; // 是否是浏览器
         if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === !1) {
-            $is_fair = true;
+            $isFair = true;
         }
         View::assign([
-            'is_fair' => $is_fair,
+            'is_fair' => $isFair,
             'k' => $request->param('k', ''),
             'v' => $request->param('v', ''),
         ]);
 
-        View::assign('aurl', $a_url);
-        View::assign('iurl', $i_url);
-
+        View::assign('aurl', $androidUrl);
+        View::assign('iurl', $iosdUrl);
         return View::fetch();
     }
 
-    // 下载app yijiahui
+    /**
+     * 下载app yijiahui
+     * @param Request $request
+     * @return string
+     */
     public function downappyjh (Request $request)
     {
-//        // 这是测试 上线要干掉
-//            echo '网站正在升级中';
-//            die();
-
-
         $a_url = 'http://yijia.meikangjw.com/upload/yjhv1.0.apk';
         $i_url = 'https://lumayun-1305480448.file.myqcloud.com/efvsgp';
 

+ 9 - 18
app/api/controller/h5/User.php

@@ -20,7 +20,7 @@ class User
     {
         $this->service = $services;
     }
-    
+
     // 隐私政策
     public function privateInfo (Request $request)
     {
@@ -83,14 +83,14 @@ class User
 
     // 关于我们
     public function aboutUs (Request $request)
-     {
-         $id = $request->param('id/d', '');
-         $m_article = new SystemArticleModel();
-         $row = $m_article->where(['type' => 5])->findOrEmpty();
-         empty($row) && abort(403, '页面异常');
-         View::assign('row', $row);
-         return View::fetch();
-     }
+    {
+        $id = $request->param('id/d', '');
+        $m_article = new SystemArticleModel();
+        $row = $m_article->where(['type' => 5])->findOrEmpty();
+        empty($row) && abort(403, '页面异常');
+        View::assign('row', $row);
+        return View::fetch();
+    }
 
     /**
      * h5注册
@@ -99,9 +99,6 @@ class User
      */
     public function registerH5 (Request $request)
     {
-        // 这是测试 上线要干掉
-//        echo '网站正在更新';
-//        die();
         if ($request->isPost()) {
             $data = $request->post();
             try {
@@ -137,10 +134,6 @@ class User
 
         $code = $request->param('code');
         if ($code) {
-//            $code = decode($code);
-//            7H+6DCDrGMtrESqhogM
-//            $code = cryption($code, 'D', 'zy02022');
-//            return $code;
             !$code && abort(40003, '页面错误');
             $is_px = false;
             $invite = Db::name('user')->where('code', $code)->field('code,id')->find();
@@ -222,8 +215,6 @@ class User
      * @return string
      */
     public function aboutboxurl(Request $request){
-
-//        $id = $request->param('id/d', '');
         $m_article = new SystemArticleModel();
         $row = $m_article->where(['type' => 7])->findOrEmpty();
         empty($row) && abort(403, '页面异常');

+ 74 - 4
app/api/controller/v1/Pay.php

@@ -237,6 +237,7 @@ class Pay
 
         } catch (Exception $e) {
             RedisCache::clear($cacheKeyLock);
+            RedisCache::set("caches:payment:dkysf:otn_{$orderSn}:fail", ['msg'=>$e->getMessage(),'trace'=>$e->getTrace()], 7200);
             return api_error_return($e->getMessage());
         }
 
@@ -484,10 +485,10 @@ class Pay
         $amount = isset($params['amount'])? floatval($params['amount']) : 0;
         $paySign = isset($params['sign'])? trim($params['sign']) : '';
 
-        if(empty($paySign)){
-            unset($params['sign']);
-            return $service->diankesign($params);
-        }
+//        if(empty($paySign)){
+//            unset($params['sign']);
+//            return $service->diankesign($params);
+//        }
 
         // 加锁
         $key = $outTradeNo? $outTradeNo : date('YmdHis');
@@ -534,6 +535,75 @@ class Pay
         return 'fail';
     }
 
+    /**
+     * 电科支付回调处理
+     * @param Request $request
+     * @return string
+     */
+    public function thirdPayDkysfPayBack(Request $request)
+    {
+        $params = $request->param();
+        $service = new ThirdPayServices();
+        $date = date('Y-m-d H:i:s');
+        $outTradeNo = isset($params['orderId'])? trim($params['orderId']) : '';
+        $isPay = isset($params['pay'])? trim($params['pay']) : '';
+        $amount = isset($params['amount'])? floatval($params['amount']) : 0;
+        $paySign = isset($params['sign'])? trim($params['sign']) : '';
+
+        if(empty($paySign)){
+            unset($params['sign']);
+            return $service->makeSign($params);
+        }
+
+        // 加锁
+        $key = $outTradeNo? $outTradeNo : date('YmdHis');
+        $cacheKeyLock = "caches:payNotify:dkysf:locks:otn_{$key}";
+        $cacheKey = "caches:payNotify:dkysf:otn_{$key}:";
+        if(RedisCache::get($cacheKeyLock)){
+            return 'Frequent submission';
+        }
+
+        // 回调处理
+        RedisCache::setnx($cacheKeyLock, 1, rand(2,3));
+        RedisCache::set($cacheKey.'callback', ['params'=> $params,'date'=> $date], 7200);
+        if ($outTradeNo && $amount && $isPay == 'true') {
+            $payConfig = PayConfigService::make()->getInfoByChannel(66, 1);
+            $signKey = isset($payConfig['sign_key'])? $payConfig['sign_key'] : '';
+            if(empty($payConfig) || empty($signKey)){
+                return 'Payment config error';
+            }
+
+            // 校验签名
+            if ($paySign) {
+                $signData = $params;
+                unset($signData['sign']);
+                $sign = $service->makeSign($signData, $signKey);
+                if ($sign == $paySign) {
+                    Db::startTrans();
+                    try {
+                        PaymentService::make()->payBack($params['orderId'], $params['amount'], 66, json_encode($params));
+                        Db::commit();
+                        return 'success';
+                    } catch (\Exception $e) {
+                        Db::rollback();
+                        $error = [
+                            'msg'=> $e->getMessage(),
+                            'trace'=> $e->getTrace(),
+                        ];
+                        RedisCache::set($cacheKey.'fail', ['params'=> $params,'error'=> $error,'date'=> $date], 7200);
+                        RedisCache::clear($cacheKeyLock);
+                    }
+                } else {
+                    RedisCache::set($cacheKey.'error', ['params'=> $params,'error'=>'签名错误','date'=> $date], 7200);
+                }
+            }else{
+                RedisCache::set($cacheKey.'error', ['params'=> $params,'error'=>'缺少签名参数','date'=> $date], 7200);
+            }
+
+        }
+
+        return 'fail';
+    }
 
     /**
      * 支付宝支付回调

+ 55 - 11
app/api/services/ThirdPayServices.php

@@ -14,6 +14,7 @@ use app\common\model\ShopOrderModel as Order;
 use app\common\model\UserBankSignModel;
 use app\common\model\UserModel;
 use app\common\model\WithDrawLogModel;
+use app\common\service\PayConfigService;
 use app\common\service\PaymentService;
 use app\common\service\UserBankSignService;
 use app\common\service\UserService;
@@ -23,6 +24,19 @@ use utils\RedisCache;
 
 class ThirdPayServices extends BasePayServices
 {
+    protected $dkError = [
+        '40001'=>'请求参数有误(缺少或者格式有误)',
+        '40002'=>'尚未登录/回话超时',
+        '40500'=>'处理扫码付错误',
+        '40510'=>'不支持的通道',
+        '40511'=>'通道已失效',
+        '40513'=>'商户不合法',
+        '40520'=>'订单不存在',
+        '40521'=>'订单已存在',
+        '50001'=>'未授权',
+        '50002'=>'签名错误',
+    ];
+
 
     /**
      * 多乐宝支付宝支付
@@ -1457,6 +1471,8 @@ class ThirdPayServices extends BasePayServices
 
 
         $loData['result'] = $result;
+        $code = isset($result['code'])? $result['code'] : '';
+        $msg = isset($this->dkError[$code])? $this->dkError[$code] : '';
         RedisCache::set($cacheKey.'result', $loData, 2*86400);
         if ($payUrl) {
             $payment = [
@@ -1478,7 +1494,7 @@ class ThirdPayServices extends BasePayServices
             return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]);
 
         } else {
-            return api_error_return('支付错误,请联系客服');
+            return api_error_return($msg? '支付错误:'.$msg:'支付错误,请联系客服');
         }
     }
 
@@ -1494,12 +1510,18 @@ class ThirdPayServices extends BasePayServices
         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');
+        $payConfig = PayConfigService::make()->getInfoByChannel($pay_way, $order_type);
+        $apiUrl = isset($payConfig['api_url'])? trim($payConfig['api_url']) : '';
+        $apiUrl = $apiUrl? $apiUrl : 'http://1.14.197.47/proxy';
+        $appId = isset($payConfig['app_id'])? trim($payConfig['app_id']) : '';
+        $signKey = isset($payConfig['sign_key'])? trim($payConfig['sign_key']) : '';
+        if(empty($payConfig) || empty($appId) || empty($apiUrl) || empty($signKey)){
+            return api_error_return('支付配置错误,请先配置支付参数');
+        }
 
         $date = date('Y-m-d H:i:s');
         $out_trade_no = createdOrderSn();
-        $cacheKey = "caches:payment:dkpay:otn_{$out_trade_no}:{$uid}_{$remarks}_";
+        $cacheKey = "caches:payment:dkysf:otn_{$out_trade_no}:{$uid}_{$remarks}_";
         RedisCache::set($cacheKey.'payData', ['payData'=> $payData, 'date'=>$date], 2*86400);
 
         // 测试金额
@@ -1514,31 +1536,34 @@ class ThirdPayServices extends BasePayServices
         }
 
         $params = [
-            'appId' => 'dianke',
+            'appId' => $appId,
             'version' => '1.0',
             'nonceStr' => nonce_str(15),
             'orderId' => $out_trade_no,
             'amount' => intval($total_amount * 100),
-            'payChannel' => 'ALP',
+            'payChannel' => 'WXP',
             'goodsName' => $body? $body : '牛仔裤',
             'goodsDesc' => $body? $body : '牛仔裤',
             'clientIp' => get_client_ip(),
-            'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_ZFB_NEWURL'),
+            'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_YSF_URL'),
             'tradeType' => 'QRCODE'
         ];
 
         ksort($params);
-        $params['sign'] = $this->diankesign($params);
+        $params['sign'] = $this->makeSign($params, $signKey);
 
         // 提交确定支付请求接口
-        $loData = ['url'=>$apiUrl,'payData'=> $payData,'params'=> $params, 'date'=>$date];
+        $payApiUrl = $apiUrl.'/pay/unifiedorder';
+        $loData = ['url'=>$payApiUrl,'payData'=> $payData,'payconfig'=>$payConfig,'params'=> $params, 'date'=>$date];
         RedisCache::set($cacheKey.'request', $loData, 2*86400);
-        $result = curlPost($apiUrl, $params);
+        $result = curlPost($payApiUrl, $params);
         $result = $result? json_decode($result, true) : [];
         $payUrl = isset($result['data'])? $result['data'] : '';
 
 
         $loData['result'] = $result;
+        $code = isset($result['code'])? $result['code'] : '';
+        $msg = isset($this->dkError[$code])? $this->dkError[$code] : '';
         RedisCache::set($cacheKey.'result', $loData, 2*86400);
         if ($payUrl) {
             $payment = [
@@ -1560,7 +1585,7 @@ class ThirdPayServices extends BasePayServices
             return api_succ_return(['msg' => '成功', 'data' => ['pay_url' => $payUrl]]);
 
         } else {
-            return api_error_return('支付错误,请联系客服');
+            return api_error_return($msg? '支付错误:'.$msg:'支付错误,请联系客服');
         }
     }
 
@@ -1703,6 +1728,25 @@ class ThirdPayServices extends BasePayServices
     }
 
     /**
+     * 公共支付签名
+     * @param $data
+     * @return string
+     */
+    public function makeSign($data, $signKey='')
+    {
+        ksort($data);
+        $signStr = "";
+        foreach ($data as $key => $val) {
+            $signStr .= $key . '=' . $val . '&';
+        }
+        $stringSignTemp = $signStr . 'key='.$signKey;
+        $signtemp = md5($stringSignTemp);
+
+        return strtoupper($signtemp);
+
+    }
+
+    /**
      * 签名
      * @param $data
      * @return string

+ 9 - 5
app/common/model/MoneyLogModel.php

@@ -39,8 +39,16 @@ class MoneyLogModel extends Model
         return compact('list', 'history');
     }
 
+    /**
+     * 团队奖金
+     * @param $param
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
     public function getTeamMoneyLog($param){
         $type_conf = config('type.money');
+        $total = self::where('uid', $param->uid)
+            ->whereIn('type', [5,7])->sum('money');
         $list = self::where('uid', $param->uid)
             ->whereIn('type', [5,7])
             ->withAttr('type', function ($value, $data) use ($type_conf) {
@@ -49,10 +57,6 @@ class MoneyLogModel extends Model
             ->order('id', 'desc')
             ->paginate($param->data['limit'])
             ->toArray();
-//        $history = self::where([
-//            ['uid', '=', $param->uid],
-//            ['state', '=', 1]
-//        ])->sum('money');
-        return $list['data'];
+        return ['list'=>$list['data'],'total'=>$total,'count'=>$list['total']];
     }
 }

+ 2 - 2
app/common/service/PayConfigService.php

@@ -48,7 +48,7 @@ class PayConfigService
             return $data;
         }
 
-        $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';
+        $field = 'app_id,title,pay_code,sign_key,scene,pay_source,api_url,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){
@@ -79,7 +79,7 @@ class PayConfigService
         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';
+        $field = 'app_id,title,pay_code,sign_key,scene,pay_source,api_url,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');