瀏覽代碼

wes 多宝福袋
1)更新绿色积分支付
2)后台订单类型显示

wesmiler 2 年之前
父節點
當前提交
37a59f9ebf

+ 0 - 2
app/api/controller/v1/Box.php

@@ -175,7 +175,6 @@ class Box
         $pageSize = $request->post('limit',10);
         $result = ShopGoodsService::make()->getBoxGoodsListByType($boxType,$pageSize);
         return api_succ_return(['msg' => '成功', 'data' => isset($result['data'])? $result['data'] : []]);
-
     }
 
     /**
@@ -190,7 +189,6 @@ class Box
         }else{
             return api_error_return('福袋未开,请耐心等候');
         }
-
     }
 
     /**

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

@@ -121,7 +121,12 @@ class Pay
                 throw new Exception('支付类型错误或未开放');
             }
 
-            if ($post['order_type'] == 4) {
+            $orderType = isset($post['order_type'])? intval($post['order_type']) : 0;
+            if(!in_array($orderType, [4,6])){
+                throw new Exception('订单类型参数错误');
+            }
+
+            if ($orderType == 4) {
                 if (empty($post['order_id'])) {
                     throw new Exception('参数错误');
                 }
@@ -158,9 +163,16 @@ class Pay
                 case 3:
                     // 余额支付
                     getActionSecury($request->uid, $request->post('security_pass', ''));
-                    $ser = new \app\api\services\BalancePayServices();
-                    $ser->balanceToOrder($request->uid, $request->post('order_id', ''));
-                    $result = api_succ_return(['msg' => '余额支付调用成功', 'data' => []]);
+                    if(PaymentService::make()->AccountPayBack($request->uid, $request->post('order_id', ''), 3)){
+                        $result = api_succ_return(['msg' => '余额支付调用成功', 'data' => ['type'=> 'account']]);
+                    }
+                    break;
+                case 6:
+                    // 绿色积分支付
+                    getActionSecury($request->uid, $request->post('security_pass', ''));
+                    if(PaymentService::make()->AccountPayBack($request->uid, $request->post('order_id', ''), 6)){
+                        $result = api_succ_return(['msg' => '绿色积分支付调用成功', 'data' => ['type'=> 'account']]);
+                    }
                     break;
                 case 14:
                     // 第三方支付 汇付支付支付

+ 16 - 0
app/api/controller/v1/User.php

@@ -6,6 +6,7 @@ namespace app\api\controller\v1;
 use app\api\services\UserServices;
 use app\common\model\ActiveLogModel;
 use app\common\model\GoodsAttensionModel;
+use app\common\model\GreenScoreLogModel;
 use app\common\model\MoneyLogModel;
 use app\common\model\PaymentModel;
 use app\common\model\ScoreAwayLogModel;
@@ -262,6 +263,21 @@ class User
     }
 
     /**
+     * 绿色积分记录
+     * @param Request $request
+     * @param GreenScoreLogModel $model
+     * @return \think\Response
+     */
+    public function greenScoreLog (Request $request, GreenScoreLogModel $model)
+    {
+        try {
+            return api_succ_return(['msg'=>'成功', 'data'=>$model->getLog($request)]);
+        } catch (\Exception $e) {
+            return api_error_return('失败');
+        }
+    }
+
+    /**
      * 利润结算记录
      * @param Request $request
      * @return \think\Response

+ 1 - 0
app/api/route/v1.php

@@ -77,6 +77,7 @@ Route::group(function (){
 
     Route::post('moneyLog', 'v1.User/moneyLog'); // 余额记录
     Route::post('scoreLog', 'v1.User/scoreLog'); // 积分记录
+    Route::post('greenScoreLog', 'v1.User/greenScoreLog'); // 绿色积分记录
     Route::post('jhLog', 'v1.User/jhLog'); // 通证记录
     Route::post('messageList', 'v1.User/messageList'); // 用户通知列表
     Route::post('articleList', 'v1.Fragment/articleList'); // 文章列表

+ 1 - 1
app/common.php

@@ -2016,7 +2016,7 @@ function getServiceTop(){
 }
 
 function getActionSecury($uid, $security_pass){
-    $user = Db::name('user')->where('id', $uid)->field('id,pay_pass')->find();
+    $user = \app\common\model\UserModel::where('id', $uid)->field('id,pay_pass')->find();
     if ($user){
         if (empty($user['pay_pass'])){
             throw new \think\Exception('还未设置安全密码或安全密码错误', 500);

+ 23 - 6
app/common/model/GreenScoreLogModel.php

@@ -1,16 +1,33 @@
 <?php
+/**
+ * 绿色积分明细
+ */
 
 namespace app\common\model;
 
+
 use think\Model;
 
-/**
- * 绿色积分记录
- * Class GreenScoreLogModel
- * @package app\common\model
- */
 class GreenScoreLogModel extends Model
 {
+    protected $name = "green_score_log";
 
-    protected $name = 'green_score_log';
+    /**
+     * 记录
+     * @param $param
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
+    public function getLog ($param)
+    {
+        $type_conf = config('type.green_score');
+        $list = self::where('uid', $param->uid)
+            ->withAttr('type', function ($value, $data) use ($type_conf) {
+                return isset($type_conf[$value]) ? $type_conf[$value] : '未知类型';
+            })
+            ->order('id', 'desc')
+            ->paginate($param->data['limit'])
+            ->toArray();
+        return $list['data'];
+    }
 }

+ 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,api_url,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,check_password,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,api_url,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,check_password,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');

+ 348 - 111
app/common/service/PaymentService.php

@@ -2,6 +2,7 @@
 
 namespace app\common\service;
 
+use app\common\model\GreenScoreLogModel;
 use app\common\model\PaymentModel;
 use app\common\model\ScoreLogModel;
 use app\common\model\ServicesOrderModel;
@@ -23,19 +24,20 @@ class PaymentService
     protected static $instance = null;
     protected $cacheTime = 7200;
     protected $payWayArr = [
-        1=>'wxpay',
-        2=>'alipay',
-        3=>'balancePay',
-        14=>'huifuPay',
-        15=>'sqzpay',
-        16=>'sqzAliPay',
-        17=>'sqzWxPay',
-        18=>'sqzYljk',
-        19=>'usdtPay',
-        20=>'yswkPay',
-        22=>'dkpay',
-        56=>'ysftyPay',
-        66=>'dkysf',
+        1 => 'wxpay',
+        2 => 'alipay',
+        3 => 'balancePay',
+        6 => 'greenScorePay',
+        14 => 'huifuPay',
+        15 => 'sqzpay',
+        16 => 'sqzAliPay',
+        17 => 'sqzWxPay',
+        18 => 'sqzYljk',
+        19 => 'usdtPay',
+        20 => 'yswkPay',
+        22 => 'dkpay',
+        56 => 'ysftyPay',
+        66 => 'dkysf',
     ];
     protected $model = null;
 
@@ -50,7 +52,7 @@ class PaymentService
      */
     public static function make()
     {
-        if(!self::$instance){
+        if (!self::$instance) {
             self::$instance = new static();
         }
 
@@ -64,7 +66,7 @@ class PaymentService
      */
     public function getPayCode($payType)
     {
-        return isset($this->payWayArr[$payType])? $this->payWayArr[$payType] : 'defpay';
+        return isset($this->payWayArr[$payType]) ? $this->payWayArr[$payType] : 'defpay';
     }
 
     /**
@@ -78,32 +80,32 @@ class PaymentService
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function getPaymentCountByState($uid, $orderSn='', $orderType, $state, $time = 2)
+    public function getPaymentCountByState($uid, $orderSn = '', $orderType, $state, $time = 2)
     {
         $cacheKey = "caches:paymentCall:u{$uid}_ot{$orderType}_s{$state}_{$time}_{$orderSn}";
         $data = RedisCache::get($cacheKey);
-        if($data){
+        if ($data) {
             return $data;
         }
         $where = [];
-        if($orderType){
+        if ($orderType) {
             $where['order_type'] = $orderType;
         }
 
-        if($state){
+        if ($state) {
             $where['state'] = $state;
         }
 
-        $data = $this->model->where($where)->where(function ($query) use($time,$orderSn){
-            if($time>0){
-                $query->where('creat_at','>=', time() - $time * 3600);
+        $data = $this->model->where($where)->where(function ($query) use ($time, $orderSn) {
+            if ($time > 0) {
+                $query->where('creat_at', '>=', time() - $time * 3600);
             }
-            if($orderSn){
-                $query->where('remarks',$orderSn);
+            if ($orderSn) {
+                $query->where('remarks', $orderSn);
             }
         })->count('id');
-        if($data){
-            RedisCache::set($cacheKey, $data, rand(3,5));
+        if ($data) {
+            RedisCache::set($cacheKey, $data, rand(3, 5));
         }
 
         return $data;
@@ -122,16 +124,16 @@ class PaymentService
     {
         $cacheKey = "caches:paymentState:u{$uid}_sn{$orderSn}";
         $data = RedisCache::get($cacheKey);
-        if($data){
+        if ($data) {
             return $data;
         }
-        $data = $this->model->where(['state'=> 6])->where(function ($query) use($orderSn){
-            if($orderSn){
+        $data = $this->model->where(['state' => 6])->where(function ($query) use ($orderSn) {
+            if ($orderSn) {
                 $query->where('remarks', $orderSn);
             }
         })->value('id');
-        if($data){
-            RedisCache::set($cacheKey, $data, rand(2,3));
+        if ($data) {
+            RedisCache::set($cacheKey, $data, rand(2, 3));
         }
 
         return $data;
@@ -145,24 +147,24 @@ class PaymentService
      * @param false $cache
      * @return array|mixed
      */
-    public function getCacheInfo($outTradeNo, $state=7, $field='', $cache = false)
+    public function getCacheInfo($outTradeNo, $state = 7, $field = '', $cache = false)
     {
-        $cacheKey = "caches:payment:info:otn{$outTradeNo}_{$state}".($field? '_'.md5($field):'');
+        $cacheKey = "caches:payment:info:otn{$outTradeNo}_{$state}" . ($field ? '_' . md5($field) : '');
         $data = RedisCache::get($cacheKey);
-        if($data && $cache){
+        if ($data && $cache) {
             return $data;
         }
-        $where = ['out_trade_no'=> $outTradeNo];
-        if($state){
+        $where = ['out_trade_no' => $outTradeNo];
+        if ($state) {
             $where['state'] = $state;
         }
-        $field = $field? $field : 'id,out_trade_no,uid,total_fee,state,trade_type,out_trade_no1,hy_token_id,syl_sureorderid,hy_bill_no,is_retreat,pay_way,order_type,sid,remarks,trade_no';
+        $field = $field ? $field : 'id,out_trade_no,uid,total_fee,state,trade_type,out_trade_no1,hy_token_id,syl_sureorderid,hy_bill_no,is_retreat,pay_way,order_type,sid,remarks,trade_no';
         $data = $this->model->where($where)
             ->field($field)
             ->order('creat_at desc')
             ->findOrEmpty();
-        if($data && $cache){
-            RedisCache::set($cacheKey, $data, rand(5,10));
+        if ($data && $cache) {
+            RedisCache::set($cacheKey, $data, rand(5, 10));
         }
 
         return $data;
@@ -170,7 +172,7 @@ class PaymentService
 
 
     /**
-     * 支付回调处理
+     * 线上支付回调处理
      * @param $outTradeNo
      * @param $payMoney
      * @param $payType
@@ -183,37 +185,42 @@ class PaymentService
     public function payBack($outTradeNo, $payMoney, $payType, $content)
     {
         $nowTime = date('Y-m-d H:i:s');
-        $params = $content? json_decode($content, true):[];
-        $payCode = PaymentService::make()->getPayCode($payType);
+        $params = $content ? json_decode($content, true) : [];
+        $payConfig = PayConfigService::make()->getInfoByChannel($payType, 1, 1);
+        $payCode = isset($payConfig['pay_code']) && $payConfig['pay_code']? $payConfig['pay_code'] : '';
+        if(empty($payConfig) || empty($payCode)){
+            sr_throw('该支付暂未开放');
+        }
+
         $cacheKey = "caches:payNotify:{$payCode}:otn_{$outTradeNo}:";
-        RedisCache::set($cacheKey.'catch', ['params'=>$params,'date'=> $nowTime], $this->cacheTime);
+        RedisCache::set($cacheKey . 'catch', ['params' => $params, 'date' => $nowTime], $this->cacheTime);
 
         // 验证支付请求信息
         $payInfo = PaymentService::make()->getCacheInfo($outTradeNo, 0);
-        $payId = isset($payInfo['id'])? $payInfo['id']:0;
-        $payUid = isset($payInfo['uid'])? $payInfo['uid']:0;
-        $payState = isset($payInfo['state'])? intval($payInfo['state']):0;
-        $totalFee = isset($payInfo['total_fee'])? floatval($payInfo['total_fee']):0;
-        $orderSn = isset($payInfo['remarks'])? trim($payInfo['remarks']):'';
-        $orderType = isset($payInfo['order_type'])? intval($payInfo['order_type']) : 0;
-        if (!$payInfo || $payUid<=0 || empty($orderSn) || $payState!= 7) {
-            $error = empty($payInfo) || !$payId || empty($orderSn)? "单号{$orderSn}支付信息不存在或参数错误":"单号{$orderSn}已经回调支付";
-            $logData = ['params'=>$params,'payInfo'=>$payInfo,'msg'=> $error,'date'=> $nowTime];
-            RedisCache::set($cacheKey.'error', $logData, $this->cacheTime);
+        $payId = isset($payInfo['id']) ? $payInfo['id'] : 0;
+        $payUid = isset($payInfo['uid']) ? $payInfo['uid'] : 0;
+        $payState = isset($payInfo['state']) ? intval($payInfo['state']) : 0;
+        $totalFee = isset($payInfo['total_fee']) ? floatval($payInfo['total_fee']) : 0;
+        $orderSn = isset($payInfo['remarks']) ? trim($payInfo['remarks']) : '';
+        $orderType = isset($payInfo['order_type']) ? intval($payInfo['order_type']) : 0;
+        if (!$payInfo || $payUid <= 0 || empty($orderSn) || $payState != 7) {
+            $error = empty($payInfo) || !$payId || empty($orderSn) ? "单号{$orderSn}支付信息不存在或参数错误" : "单号{$orderSn}已经回调支付";
+            $logData = ['params' => $params, 'payInfo' => $payInfo, 'msg' => $error, 'date' => $nowTime];
+            RedisCache::set($cacheKey . 'error', $logData, $this->cacheTime);
             sr_throw($error);
         }
 
         // 验证支付金额
-        if($payMoney < $totalFee || $totalFee<=0){
-            $logData = ['params'=>$params,'payInfo'=>$payInfo,'msg'=> "单号{$orderSn}支付金额错误",'date'=> $nowTime];
-            RedisCache::set($cacheKey.'error', $logData, $this->cacheTime);
+        if ($payMoney < $totalFee || $totalFee <= 0) {
+            $logData = ['params' => $params, 'payInfo' => $payInfo, 'msg' => "单号{$orderSn}支付金额错误", 'date' => $nowTime];
+            RedisCache::set($cacheKey . 'error', $logData, $this->cacheTime);
             sr_throw("单号{$orderSn}支付金额错误");
         }
 
         // 更新支付状态
-        if(!PaymentModel::where('id', $payId)->update(['state' => 6, 'pay_at' => $nowTime])){
-            $logData = ['params'=>$params,'payInfo'=>$payInfo,'msg'=> "单号{$orderSn}更新支付状态失败",'date'=> $nowTime];
-            RedisCache::set($cacheKey.'_error', $logData, $this->cacheTime);
+        if (!PaymentModel::where('id', $payId)->update(['state' => 6, 'pay_at' => $nowTime])) {
+            $logData = ['params' => $params, 'payInfo' => $payInfo, 'msg' => "单号{$orderSn}更新支付状态失败", 'date' => $nowTime];
+            RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
             sr_throw("单号{$orderSn}更新支付状态失败");
         }
 
@@ -226,9 +233,9 @@ class PaymentService
             'uid' => $payUid,
             'money' => $payMoney
         ];
-        if(!ThirdpayBackModel::insertGetid($data)){
-            $logData = ['params'=>$params,'payInfo'=>$payInfo,'third'=>$data,'msg'=> "单号{$orderSn}处理第三方回调数据错误",'date'=> $nowTime];
-            RedisCache::set($cacheKey.'_error', $logData, $this->cacheTime);
+        if (!ThirdpayBackModel::insertGetid($data)) {
+            $logData = ['params' => $params, 'payInfo' => $payInfo, 'third' => $data, 'msg' => "单号{$orderSn}处理第三方回调数据错误", 'date' => $nowTime];
+            RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
             sr_throw("单号{$orderSn}处理第三方回调数据错误");
         }
 
@@ -236,67 +243,65 @@ class PaymentService
         if ($orderType == 6) {
             // 获取验证订单信息
             $orderInfo = ServiceOrderService::make()->getInfoBySn($orderSn, $payUid);
-            $orderId = isset($orderInfo['order_id'])? $orderInfo['order_id'] : 0;
-            $orderMoney = isset($orderInfo['payment'])? floatval($orderInfo['payment']) : 0;
-            $orderStatus = isset($orderInfo['status'])? intval($orderInfo['status']) : 0;
-            if(empty($orderInfo) || $orderId<=0 || $orderMoney<=0){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'msg'=> "服务商订单{$orderSn}不存在或参数错误",'date'=> $nowTime];
-                RedisCache::set($cacheKey.'_error', $logData, $this->cacheTime);
+            $orderId = isset($orderInfo['order_id']) ? $orderInfo['order_id'] : 0;
+            $orderMoney = isset($orderInfo['payment']) ? floatval($orderInfo['payment']) : 0;
+            $orderStatus = isset($orderInfo['status']) ? intval($orderInfo['status']) : 0;
+            if (empty($orderInfo) || $orderId <= 0 || $orderMoney <= 0) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'msg' => "服务商订单{$orderSn}不存在或参数错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
                 sr_throw("服务商订单{$orderSn}不存在或参数错误");
             }
 
             // 验证订单状态
-            if($orderStatus != 1){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'msg'=> "服务商订单{$orderSn}订单已处理",'date'=> $nowTime];
-                RedisCache::set($cacheKey.'_error', $logData, $this->cacheTime);
+            if ($orderStatus != 1) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'msg' => "服务商订单{$orderSn}订单已处理", 'date' => $nowTime];
+                RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
                 sr_throw("服务商订单{$orderSn}订单已处理");
             }
 
             // 更新订单状态
-            if(!ServicesOrderModel::where('order_id', $orderId)->update(['status' => 2, 'pay_type' => $payType, 'updated_time' => $nowTime])){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'msg'=> "服务商订单{$orderSn}更新状态错误",'date'=> $nowTime];
-                RedisCache::set($cacheKey.'_error', $logData, $this->cacheTime);
+            if (!ServicesOrderModel::where('order_id', $orderId)->update(['status' => 2, 'pay_type' => $payType, 'updated_time' => $nowTime])) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'msg' => "服务商订单{$orderSn}更新状态错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
                 sr_throw("服务商订单{$orderSn}更新状态错误");
             }
 
             // 更新用户服务商有效期
             $date = sr_getcurtime(time(), 'Y-m-d');
             $expireDay = date('Y-m-d', strtotime("$date +1 month"));
-            if(!UserModel::where('id', $payUid)->update(['store_type' => 1,'store_expire_time' => $expireDay,'update_time'=>time()])){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'storeExpire'=>$expireDay,'msg'=> "服务商订单{$orderSn}更新用户服务商有效期错误",'date'=> $nowTime];
-                RedisCache::set($cacheKey.'_error', $logData, $this->cacheTime);
+            if (!UserModel::where('id', $payUid)->update(['store_type' => 1, 'store_expire_time' => $expireDay, 'update_time' => time()])) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'storeExpire' => $expireDay, 'msg' => "服务商订单{$orderSn}更新用户服务商有效期错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
                 sr_throw("服务商订单{$orderSn}更新用户服务商有效期错误");
             }
 
-            $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'storeExpire'=>$expireDay,'msg'=> "服务商订单{$orderSn}支付回调处理成功",'date'=> $nowTime];
-            RedisCache::set($cacheKey."success_{$orderSn}", $logData, $this->cacheTime);
+            $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'storeExpire' => $expireDay, 'msg' => "服务商订单{$orderSn}支付回调处理成功", 'date' => $nowTime];
+            RedisCache::set($cacheKey . "success_{$orderSn}", $logData, $this->cacheTime);
 
-        }
-
-        /** TODO 商城订单处理 **/
+        } /** TODO 商城订单处理 **/
         elseif ($orderType == 4) {
             // 获取验证订单信息
             $orderInfo = ShopOrderService::make()->getInfoBySn($orderSn, $payUid);
-            $orderId = isset($orderInfo['order_id'])? $orderInfo['order_id'] : 0;
-            $orderMoney = isset($orderInfo['payment'])? floatval($orderInfo['payment']) : 0;
-            $orderStatus = isset($orderInfo['status'])? intval($orderInfo['status']) : -1;
-            if(empty($orderInfo) || $orderId<=0 || $orderMoney<=0){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'msg'=> "商城订单{$orderSn}不存在或参数错误",'date'=> $nowTime];
-                RedisCache::set($cacheKey."error_{$orderSn}", $logData, $this->cacheTime);
+            $orderId = isset($orderInfo['order_id']) ? $orderInfo['order_id'] : 0;
+            $orderMoney = isset($orderInfo['payment']) ? floatval($orderInfo['payment']) : 0;
+            $orderStatus = isset($orderInfo['status']) ? intval($orderInfo['status']) : -1;
+            if (empty($orderInfo) || $orderId <= 0 || $orderMoney <= 0) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}不存在或参数错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
                 sr_throw("商城订单{$orderSn}不存在或参数错误");
             }
 
             // 验证订单状态
-            if($orderStatus != 0){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'msg'=> "商城订单{$orderSn}订单已处理",'date'=> $nowTime];
-                RedisCache::set($cacheKey."error_{$orderSn}", $logData, $this->cacheTime);
+            if ($orderStatus != 0) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}订单已处理", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
                 sr_throw("商城订单{$orderSn}订单已处理");
             }
 
             // 更新订单状态
-            if(!ShopOrderModel::where('order_id', $orderId)->update(['status' => 1, 'pay_type' => $payType, 'updated_time' => $nowTime])){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'order'=>$orderInfo,'msg'=> "服务商订单{$orderSn}更新状态错误",'date'=> $nowTime];
-                RedisCache::set($cacheKey.'_error', $logData, $this->cacheTime);
+            if (!ShopOrderModel::where('order_id', $orderId)->update(['status' => 1, 'pay_type' => $payType, 'updated_time' => $nowTime])) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'order' => $orderInfo, 'msg' => "服务商订单{$orderSn}更新状态错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
                 sr_throw("服务商订单{$orderSn}更新状态错误");
             }
 
@@ -310,25 +315,24 @@ class PaymentService
                     'g.real_sales_volume' => Db::raw('g.real_sales_volume + og.num'),
                 ]);
             if (!$updateSale) {
-                Db::rollback();
-                $logData = ['params' => $params, 'orderInfo' => $orderInfo, 'payInfo' => $payInfo, 'error' => "商城订单{$orderSn}更新商品销量失败", 'date' => $date];
+                $logData = ['params' => $params, 'orderInfo' => $orderInfo, 'payInfo' => $payInfo, 'error' => "商城订单{$orderSn}更新商品销量失败", 'date' => $nowTime];
                 RedisCache::set($cacheKey . "error_{$orderSn}", $logData, 7200);
                 sr_throw("商城订单{$orderSn}更新商品销量失败");
             }
 
             // 更新用户交易额(消费)
-            $userInfo = UserService::make()->getCacheInfo($payUid,'id,mobile,score,money,path', false);
-            $upperPath = isset($userInfo['path'])? $userInfo['path'] : '';
-            if($userInfo && !UserModel::where('id', $payUid)->inc('total_income', $totalFee)->inc('total_team_income',$totalFee)->update()){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'user'=>$userInfo,'order'=>$orderInfo,'msg'=> "商城订单{$orderSn}更新用户交易数据错误",'date'=> $nowTime];
-                RedisCache::set($cacheKey."error_{$orderSn}", $logData, $this->cacheTime);
+            $userInfo = UserService::make()->getCacheInfo($payUid, 'id,mobile,score,money,path', false);
+            $upperPath = isset($userInfo['path']) ? $userInfo['path'] : '';
+            if ($userInfo && !UserModel::where('id', $payUid)->inc('total_income', $totalFee)->inc('total_team_income', $totalFee)->update()) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}更新用户交易数据错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
                 sr_throw("商城订单{$orderSn}更新用户交易数据错误");
             }
 
             // 更新团队交易额数据
-            if($upperPath && !UserModel::whereIn('id', explode(',', $upperPath))->inc('total_team_income',$totalFee)->update()){
-                $logData = ['params'=>$params,'payInfo'=>$payInfo,'user'=>$userInfo,'order'=>$orderInfo,'msg'=> "商城订单{$orderSn}更新用户上级交易数据错误",'date'=> $nowTime];
-                RedisCache::set($cacheKey."error_{$orderSn}", $logData, $this->cacheTime);
+            if ($upperPath && !UserModel::whereIn('id', explode(',', $upperPath))->inc('total_team_income', $totalFee)->update()) {
+                $logData = ['params' => $params, 'payInfo' => $payInfo, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}更新用户上级交易数据错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
                 sr_throw("商城订单{$orderSn}更新用户上级交易数据错误");
             }
 
@@ -338,8 +342,8 @@ class PaymentService
             if ($rebateScore > 0 && $userInfo) {
                 // 更新用户账户积分
                 if (!UserModel::where('id', $payUid)->inc('score', $rebateScore)->update()) {
-                    $logData = ['params'=>$params,'payInfo'=>$payInfo,'user'=>$userInfo,'order'=>$orderInfo,'msg'=> "商城订单{$orderSn}赠送积分处理错误",'date'=> $nowTime];
-                    RedisCache::set($cacheKey."error_{$orderSn}", $logData, $this->cacheTime);
+                    $logData = ['params' => $params, 'payInfo' => $payInfo, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}赠送积分处理错误", 'date' => $nowTime];
+                    RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
                     sr_throw("商城订单{$orderSn}赠送积分处理错误");
                 }
 
@@ -350,22 +354,22 @@ class PaymentService
                     'type' => 3,
                     'score' => $rebateScore,
                     'create_at' => sr_getcurtime(time()),
-                    'state' => 12,
+                    'state' => 1,
                     'before_score' => $userScore,
                     'after_score' => floatval($userScore + $rebateScore),
                     'from_id' => $payId,
                     'uid2' => 0
                 ];
                 if (!ScoreLogModel::insertGetId($data)) {
-                    $logData = ['params'=>$params,'payInfo'=>$payInfo,'user'=>$userInfo,'order'=>$orderInfo,'msg'=> "商城订单{$orderSn}赠送积分明细处理错误",'date'=> $nowTime];
-                    RedisCache::set($cacheKey."error_{$orderSn}", $logData, $this->cacheTime);
+                    $logData = ['params' => $params, 'payInfo' => $payInfo, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}赠送积分明细处理错误", 'date' => $nowTime];
+                    RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
                     sr_throw("商城订单{$orderSn}赠送积分明细处理错误");
                 }
 
             }
 
-            $logData = ['params'=>$params,'payInfo'=>$payInfo,'user'=>$userInfo,'order'=>$orderInfo,'msg'=> "商城订单{$orderSn}回调处理成功",'date'=> $nowTime];
-            RedisCache::set($cacheKey."success_{$orderSn}", $logData, $this->cacheTime);
+            $logData = ['params' => $params, 'payInfo' => $payInfo, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}回调处理成功", 'date' => $nowTime];
+            RedisCache::set($cacheKey . "success_{$orderSn}", $logData, $this->cacheTime);
         }
 
 
@@ -373,8 +377,241 @@ class PaymentService
     }
 
 
+    /**
+     * 账户支付处理
+     * @param $payUid
+     * @param $orderSn
+     * @param $payType
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function accountPayBack($payUid, $orderSn, $payType = 6)
+    {
+        $nowTime = date('Y-m-d H:i:s');
+        $params = ['uid' => $payUid, 'order_sn' => $orderSn, 'pay_type' => $payType];
+        $payConfig = PayConfigService::make()->getInfoByChannel($payType, 1, 1);
+        $payCode = isset($payConfig['pay_code']) && $payConfig['pay_code']? $payConfig['pay_code'] : '';
+        if(empty($payConfig) || empty($payCode)){
+            sr_throw('该支付暂未开放');
+        }
+
+        $cacheKey = "caches:payNotify:{$payCode}:otn_{$orderSn}:";
+        RedisCache::set($cacheKey . 'catch', ['params' => $params, 'date' => $nowTime], $this->cacheTime);
+
+        // 获取验证订单信息
+        $orderInfo = ShopOrderService::make()->getInfoBySn($orderSn, $payUid);
+        $orderId = isset($orderInfo['order_id']) ? $orderInfo['order_id'] : 0;
+        $totalFee = isset($orderInfo['payment']) ? floatval($orderInfo['payment']) : 0;
+        $orderStatus = isset($orderInfo['status']) ? intval($orderInfo['status']) : -1;
+        if (empty($orderInfo) || $orderId <= 0 || $totalFee <= 0) {
+            $logData = ['params' => $params, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}不存在或参数错误", 'date' => $nowTime];
+            RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+            sr_throw("商城订单{$orderSn}不存在或参数错误");
+        }
+
+        // 验证订单状态
+        if ($orderStatus != 0) {
+            $logData = ['params' => $params, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}订单已处理", 'date' => $nowTime];
+            RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+            sr_throw("商城订单{$orderSn}订单已处理");
+        }
+
+        // 用户信息
+        $userInfo = UserService::make()->getCacheInfo($payUid, 'id,mobile,green_score,score,money,path', false);
+        if(empty($userInfo)){
+            $logData = ['params' => $params, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}账户信息不寻找或已被冻结", 'date' => $nowTime];
+            RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+            sr_throw('账户信息不寻找或已被冻结');
+        }
+
+        // 支付处理
+        Db::startTrans();
+        try {
+            switch ($payType) {
+                case 3: // 余额支付
+                    // 验证账户余额
+                    $userMoney = isset($userInfo['money']) ? floatval($userInfo['money']) : 0;
+                    if ($userMoney < $totalFee) {
+                        $logData = ['params' => $params, 'order' => $orderInfo, 'userInfo' => $userInfo, 'msg' => "服务商订单{$orderSn}账户余额不足", 'date' => $nowTime];
+                        RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
+                        sr_throw('账户余额不足');
+                    }
+
+                    // 扣款
+                    if (!UserModel::where('id', $payUid)->inc('money', $totalFee)->update()) {
+                        $logData = ['params' => $params, 'order' => $orderInfo, 'userInfo' => $userInfo, 'msg' => "服务商订单{$orderSn}余额支付失败", 'date' => $nowTime];
+                        RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
+                        sr_throw('余额支付失败');
+                    }
+
+                    // 流水
+                    $log = [
+                        'uid' => $payUid,
+                        'type' => 11,
+                        'score' => $totalFee,
+                        'create_at' => sr_getcurtime(time()),
+                        'state' => 2, // 1进账,2-出账
+                        'before_score' => $userMoney,
+                        'after_score' => max(0, $userMoney - $totalFee),
+                        'from_id' => $orderId,
+                        'uid2' => 0
+                    ];
+
+                    if (!GreenScoreLogModel::insertGetId($log)) {
+                        $logData = ['params' => $params, 'order' => $orderInfo, 'userInfo' => $userInfo,'log'=>$log, 'msg' => "服务商订单{$orderSn}账户余额支付处理失败", 'date' => $nowTime];
+                        RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
+                        sr_throw('账户余额支付处理失败');
+                    }
+
+                    break;
+                case 6: // 绿色积分
+                    // 验证账户
+                    $userGreenScore = isset($userInfo['green_score']) ? floatval($userInfo['green_score']) : 0;
+                    if ($userGreenScore < $totalFee) {
+                        $logData = ['params' => $params, 'order' => $orderInfo, 'userInfo' => $userInfo, 'msg' => "服务商订单{$orderSn}账户绿色积分不足", 'date' => $nowTime];
+                        RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
+                        sr_throw('账户绿色积分不足');
+                    }
+
+                    // 扣款
+                    if (!UserModel::where('id', $payUid)->inc('green_score', $totalFee)->update()) {
+                        $logData = ['params' => $params, 'order' => $orderInfo, 'userInfo' => $userInfo, 'msg' => "服务商订单{$orderSn}账户绿色积分支付失败", 'date' => $nowTime];
+                        RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
+                        sr_throw('绿色积分支付失败');
+                    }
+
+                    // 流水
+                    $log = [
+                        'uid' => $payUid,
+                        'type' => 4,
+                        'score' => $totalFee,
+                        'create_at' => sr_getcurtime(time()),
+                        'state' => 2, // 1进账,2-出账
+                        'before_score' => $userGreenScore,
+                        'after_score' => max(0, $userGreenScore - $totalFee),
+                        'from_id' => $orderId,
+                        'uid2' => 0
+                    ];
+
+                    if (!GreenScoreLogModel::insertGetId($log)) {
+                        $logData = ['params' => $params, 'order' => $orderInfo, 'userInfo' => $userInfo,'log'=>$log, 'msg' => "服务商订单{$orderSn}绿色积分支付处理失败", 'date' => $nowTime];
+                        RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
+                        sr_throw('绿色积分支付处理失败');
+                    }
+
+                    break;
+                default:
+                    sr_throw("该支付方式暂不支持");
+                    break;
+            }
+
+            // 更新订单状态
+            if (!ShopOrderModel::where('order_id', $orderId)->update(['status' => 1, 'pay_type' => $payType, 'updated_time' => $nowTime])) {
+                $logData = ['params' => $params, 'order' => $orderInfo, 'msg' => "服务商订单{$orderSn}更新状态错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . '_error', $logData, $this->cacheTime);
+                sr_throw("服务商订单{$orderSn}更新状态错误");
+            }
+
+            // 写入支付信息
+            $outTradeNo = 'BA' . createdOrderSn();
+            $log = [
+                'total_fee' => $totalFee,
+                'trade_type' => 'app',
+                'body' => '购买商品',
+                'state' => 6,
+                'out_trade_no' => $outTradeNo,
+                'pay_way' => 3,
+                'remarks' => $orderId,
+                'order_type' => 4,
+                'pay_at' => sr_getcurtime(time()),
+                'uid' => $payUid,
+                'voucher_img' => '',
+                'out_trade_no1' => ''
+            ];
+            if (!PaymentModel::insertGetId($log)) {
+                $logData = ['params' => $params, 'orderInfo' => $orderInfo,'payLog'=>$log, 'error' => "商城订单{$orderSn}更新商品销量失败", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, 7200);
+                sr_throw("商城订单{$orderSn}更新商品销量失败");
+            }
+
+            // 增加订单商品销量
+            $updateSale = ShopOrderModel::alias('a')
+                ->leftJoin('shop_order_goods og', 'og.order_id=a.order_id')
+                ->leftJoin('shop_goods g', 'g.goods_id=og.goods_id')
+                ->where(['a.order_id' => $orderId, 'a.user_id' => $payUid])
+                ->update([
+                    'g.sales_volume' => Db::raw('g.sales_volume + og.num'),
+                    'g.real_sales_volume' => Db::raw('g.real_sales_volume + og.num'),
+                ]);
+            if (!$updateSale) {
+                $logData = ['params' => $params, 'orderInfo' => $orderInfo, 'error' => "商城订单{$orderSn}更新商品销量失败", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, 7200);
+                sr_throw("商城订单{$orderSn}更新商品销量失败");
+            }
+
+            // 更新用户交易额(消费)
+            $upperPath = isset($userInfo['path']) ? $userInfo['path'] : '';
+            if ($userInfo && !UserModel::where('id', $payUid)->inc('total_income', $totalFee)->inc('total_team_income', $totalFee)->update()) {
+                $logData = ['params' => $params, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}更新用户交易数据错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+                sr_throw("商城订单{$orderSn}更新用户交易数据错误");
+            }
+
+            // 更新团队交易额数据
+            if ($upperPath && !UserModel::whereIn('id', explode(',', $upperPath))->inc('total_team_income', $totalFee)->update()) {
+                $logData = ['params' => $params, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}更新用户上级交易数据错误", 'date' => $nowTime];
+                RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+                sr_throw("商城订单{$orderSn}更新用户上级交易数据错误");
+            }
+
 
+            // 赠送积分处理
+            $rebateScore = isset($orderInfo['rebate_score']) ? floatval($orderInfo['rebate_score']) : 0;
+            if ($rebateScore > 0 && $userInfo) {
+                // 更新用户账户积分
+                if (!UserModel::where('id', $payUid)->inc('score', $rebateScore)->update()) {
+                    $logData = ['params' => $params, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}赠送积分处理错误", 'date' => $nowTime];
+                    RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+                    sr_throw("商城订单{$orderSn}赠送积分处理错误");
+                }
 
+                // 处理积分流水明细
+                $userScore = isset($userInfo['score']) ? floatval($userInfo['score']) : 0;
+                $data = [
+                    'uid' => $payUid,
+                    'type' => 3,
+                    'score' => $rebateScore,
+                    'create_at' => sr_getcurtime(time()),
+                    'state' => 1,
+                    'before_score' => $userScore,
+                    'after_score' => floatval($userScore + $rebateScore),
+                    'from_id' => $orderId,
+                    'uid2' => 0
+                ];
+                if (!ScoreLogModel::insertGetId($data)) {
+                    $logData = ['params' => $params, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}赠送积分明细处理错误", 'date' => $nowTime];
+                    RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+                    sr_throw("商城订单{$orderSn}赠送积分明细处理错误");
+                }
+
+            }
+
+            Db::commit();
+            $logData = ['params' => $params, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => "商城订单{$orderSn}回调处理成功", 'date' => $nowTime];
+            RedisCache::set($cacheKey . "success_{$orderSn}", $logData, $this->cacheTime);
+            return true;
+        }catch (\Exception $exception){
+            Db::rollback();
+            $msg = $exception->getMessage();
+            $logData = ['params' => $params, 'user' => $userInfo, 'order' => $orderInfo, 'msg' => $msg, 'trace'=>$exception->getTrace(), 'date' => $nowTime];
+            RedisCache::set($cacheKey . "error_{$orderSn}", $logData, $this->cacheTime);
+            sr_throw($msg? $msg:'支付失败');
+        }
+
+        return false;
+    }
 
 
 }

+ 10 - 1
config/type.php

@@ -43,9 +43,18 @@ return [
         0=>'其他',
         1=>'预约福袋',
         2=>'预约福袋空盒退回',
-        3=>'买商品送积分',
+        3=>'买商品送积分',
         4=>'提现多次返回'
     ],
+    // 积分
+    'green_score'=>[
+        1=>'积分兑换',
+        2=>'利润兑换',
+        3=>'余额兑换',
+        4=>'购买商品',
+        5=>'预约福袋',
+        99=>'其他'
+    ],
     'scoreAll'=>[
         1=>'预约福袋',
         2=>'预约福袋空盒退回',

+ 1 - 1
public/static/admin/js/mall/shop_order.js

@@ -48,7 +48,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
                         field: 'pay_type',
                         title: '支付类型',
                         width: 120,
-                        selectList: {0: '待支付', 1: '微信', 2: '支付宝', 3: '余额支付'}
+                        selectList: {0: '待支付', 1: '微信', 2: '支付宝', 3: '余额支付',6:'绿色积分',15:'银联绑卡',22:'电科支付宝',66:'电科云闪付',99:'未选'}
                     },
                     {
                         field: 'order_type',

二進制
public/static/img/payconfig/ic_green_score.png


二進制
public/static/img/payconfig/ic_huifubao_zfb.png


二進制
public/static/img/payconfig/ic_money.png


二進制
public/static/img/payconfig/ic_score.png