wesmiler преди 2 месеца
родител
ревизия
fe9c1e96a6
променени са 4 файла, в които са добавени 46 реда и са изтрити 117 реда
  1. 1 1
      app/Models/OrderModel.php
  2. 0 5
      app/Services/Api/AccountService.php
  3. 27 32
      app/Services/Api/BalanceLogService.php
  4. 18 79
      app/Services/PaymentService.php

+ 1 - 1
app/Models/OrderModel.php

@@ -41,7 +41,7 @@ class OrderModel extends BaseModel
     public function user()
     {
         return $this->hasOne(MemberModel::class, 'id', 'user_id')
-            ->select(['id', 'mobile', 'nickname', 'realname', 'status']);
+            ->select(['id', 'mobile', 'nickname','balance', 'realname', 'status']);
     }
 
     /**

+ 0 - 5
app/Services/Api/AccountService.php

@@ -12,12 +12,7 @@
 namespace App\Services\Api;
 
 use App\Models\AccountLogModel;
-use App\Models\MemberModel;
 use App\Services\BaseService;
-use App\Services\ConfigService;
-use App\Services\PaymentService;
-use App\Services\RedisService;
-use Illuminate\Support\Facades\DB;
 
 /**
  * 交易管理-服务类

+ 27 - 32
app/Services/Api/BalanceLogService.php

@@ -13,8 +13,8 @@ namespace App\Services\Api;
 
 use App\Models\AccountLogModel;
 use App\Models\ActionLogModel;
-use App\Models\AgentModel;
 use App\Models\BalanceLogModel;
+use App\Models\MemberBankModel;
 use App\Models\MemberModel;
 use App\Services\BaseService;
 use App\Services\ConfigService;
@@ -151,17 +151,16 @@ class BalanceLogService extends BaseService
     public function withdraw($userId, $params)
     {
         // 参数验证
-        $accountType = isset($params['account_type']) && $params['account_type']? intval($params['account_type']) : 2;
+        $accountType = isset($params['account_type']) && $params['account_type']? intval($params['account_type']) : 1;
         $money = isset($params['money'])? floatval($params['money']) : 0;
-        $accountRemark = isset($params['account_remark'])? trim($params['account_remark']) : '';
-        $account = isset($params['account'])? trim($params['account']) : '';
-        $realname = isset($params['realname'])? trim($params['realname']) : '';
+        $accountId = isset($params['account_id'])? trim($params['account_id']) : 0;
         if($money<=0){
-            $this->error = 2301;
+            $this->error = '请输入提现金额';
             return false;
         }
-        if(empty($realname) || empty($account)){
-            $this->error = 2302;
+
+        if($accountId<=0){
+            $this->error = '请选择收款账户';
             return false;
         }
 
@@ -184,34 +183,33 @@ class BalanceLogService extends BaseService
             return false;
         }
 
+        $accountInfo = MemberBankModel::where(['id'=> $accountId,'user_id'=>$userId,'mark'=>1])->first();
+        $realname = isset($accountInfo['realname'])?$accountInfo['realname'] : '';
+        $account = isset($accountInfo['account'])?$accountInfo['account'] : '';
+        $accountName = isset($accountInfo['account_name'])?$accountInfo['account_name'] : '';
+        $accountRemark = isset($accountInfo['account_remark'])?$accountInfo['account_remark'] : '';
+        if(empty($accountInfo) || empty($realname) || empty($accountName) || empty($account)){
+            $this->error = '抱歉,当前收款账户错误请更换后重试';
+            return false;
+        }
+
         // 判断用户账号状态
         RedisService::set($cacheLockKey, ['user_id'=>$userId,'params'=>$params], rand(10,20));
         $userInfo = MemberService::make()->getInfo($userId,[], true);
         $status = isset($userInfo['status'])? $userInfo['status'] : 0;
         $balance = isset($userInfo['balance'])? $userInfo['balance'] : 0;
-        $agent = isset($userInfo['agent'])? $userInfo['agent'] : [];
-        $agentBalance = isset($agent['balance'])? $agent['balance'] : 0;
-        $nickname = isset($userInfo['nickname'])? $userInfo['nickname'] : '';
-        $balance = $accountType==2?$agentBalance:$balance;
         if(empty($userInfo) || $status != 1){
             $this->error = 1045;
             RedisService::clear($cacheLockKey);
             return false;
         }
 
-        if($accountType==2 && empty($agent)){
-            $this->error = '代理账号或已被冻结,请联系客服';
-            RedisService::clear($cacheLockKey);
-            return false;
-        }
-
         if($money > $balance){
             $this->error = '可提现金额不足';
             RedisService::clear($cacheLockKey);
             return false;
         }
 
-
         // 提现处理
         DB::beginTransaction();
         $updateData = ['balance'=>DB::raw("balance - {$money}"),'update_time'=>time()];
@@ -222,25 +220,21 @@ class BalanceLogService extends BaseService
             RedisService::clear($cacheLockKey);
             return false;
         }
-        // 代理账户
-        else if($accountType==2 && !AgentModel::where(['user_id'=> $userId])->update($updateData)){
-            DB::rollBack();
-            $this->error = '提现处理失败';
-            RedisService::clear($cacheLockKey);
-            return false;
-        }
 
-        $orderNo = get_order_num('LW');
+        $orderNo = get_order_num('JW');
         $order = [
             'user_id'=> $userId,
             'order_no'=> $orderNo,
             'money'=> $money,
+            'after_money'=> moneyFormat(max(0,$balance-$money), 2),
             'type'=>2,
             'account_type'=> $accountType,
-            'pay_type'=>0,
-            'account_remark'=> $accountRemark,
+            'pay_type'=> 50,
             'realname'=> $realname,
+            'account_name'=> $accountName,
             'account'=> $account,
+            'account_remark'=> $accountRemark,
+            'date'=> date('Y-m-d'),
             'create_time'=> time(),
             'status'=>1,
             'mark'=>1
@@ -257,10 +251,11 @@ class BalanceLogService extends BaseService
             'source_order_no' => $orderNo,
             'type' => 4,
             'money' => $money,
-            'before_money' => $balance,
+            'after_money' => moneyFormat(max(0,$balance-$money), 2),
             'date'=> date('Y-m-d'),
             'create_time' => time(),
-            'remark' => '收入提现',
+            'remark' => "余额转出-{$accountName}",
+            'remark1' => "{$account}".($accountRemark?'/'.$accountRemark:''),
             'status' => 1,
             'mark' => 1,
         ];
@@ -274,7 +269,7 @@ class BalanceLogService extends BaseService
         DB::commit();
 
         // 操作日志
-        ActionLogModel::setRecord($userId,['type'=>2,'title'=>'收入提现','content'=>"姓名:{$realname},账号:{$account},提现{$money}元,单号:{$orderNo}",'module'=>'balanceLog']);
+        ActionLogModel::setRecord($userId,['type'=>2,'title'=>'余额提现','content'=>"姓名:{$realname},账号:{$accountName}/{$account}/{$accountRemark},提现{$money}元,单号:{$orderNo}",'module'=>'balanceLog']);
         ActionLogModel::record();
 
         $this->error = '提现申请成功,请耐心等候审核~';

+ 18 - 79
app/Services/PaymentService.php

@@ -11,9 +11,9 @@
 
 namespace App\Services;
 
+use App\Models\AccountLogModel;
 use App\Models\OrderModel;
 use App\Models\PaymentModel;
-use App\Models\PayOrdersModel;
 use App\Services\Api\SettleService;
 use Illuminate\Support\Facades\DB;
 use Yansongda\Pay\Pay;
@@ -496,33 +496,6 @@ class PaymentService extends BaseService
                     return false;
                 }
             }
-            // 生活充值
-            else if ($scene == 'pay') {
-                $orderInfo = PayOrdersModel::where(['order_no' => $orderNo, 'mark' => 1])
-                    ->select(['id as order_id', 'user_id','meal_id','product_id', 'order_no','transaction_id','account', 'total as pay_money','area','ytype','city','id_card_no','pay_total', 'pay_at as pay_time', 'remark', 'status'])
-                    ->first();
-                $orderStatus = isset($orderInfo['status']) ? $orderInfo['status'] : 0;
-                // 验证订单
-                if (empty($orderInfo)) {
-                    DB::rollBack();
-                    $this->error = 2629;
-                    return false;
-                }
-
-                // 订单状态
-                if ($orderStatus != 1) {
-                    DB::rollBack();
-                    $this->error = 2630;
-                    return false;
-                }
-
-                $updateData = ['pay_at' => $payAt, 'transaction_id' => $transactionId, 'status' => 2, 'update_time' => time()];
-                if (!PayOrdersModel::where(['order_no' => $orderNo, 'mark' => 1])->update($updateData)) {
-                    $this->error = 2633;
-                    DB::rollBack();
-                    return false;
-                }
-            }
             // 退款
             else if ($scene == 'refund') {
                 $orderInfo = OrderModel::where(['order_no' => $orderNo, 'mark' => 1])
@@ -564,59 +537,25 @@ class PaymentService extends BaseService
             $this->saveLog("caches:payments:notify_{$scene}:catch_{$orderNo}_{$orderUserId}", ['order' => $orderInfo, 'notify' => $data]);
             switch ($scene) {
                 case 'store': //
-                    break;
-                case 'pay': //
-                    // 调起 接口充值
-                    $orderId = isset($orderInfo['order_id'])? $orderInfo['order_id'] : 0;
-                    $productId = isset($orderInfo['product_id'])? $orderInfo['product_id'] : '';
-                    $orderNo = isset($orderInfo['order_no'])? $orderInfo['order_no'] : '';
-                    $account = isset($orderInfo['account'])? $orderInfo['account'] : '';
-                    $total = isset($orderInfo['pay_money'])? $orderInfo['pay_money'] : 0;
-                    $payTotal = isset($orderInfo['pay_total'])? $orderInfo['pay_total'] : 0;
-                    $amount = $total;
-                    $params = [
-                        'price'=>$payTotal,
-                        'ytype'=>isset($orderInfo['ytype'])?$orderInfo['ytype']:0,
-                        'id_card_no'=>isset($orderInfo['id_card_no'])?$orderInfo['id_card_no']:'',
-                        'area'=>isset($orderInfo['area'])?$orderInfo['area']:'',
-                        'city'=>isset($orderInfo['city'])?$orderInfo['city']:'',
+                    $userInfo = isset($orderInfo['user'])?$orderInfo['user']:[];
+                    $balance = isset($userInfo['balance'])? $userInfo['balance'] : 0;
+                    $data = [
+                        'user_id'=>$orderUserId,
+                        'source_order_no'=>$orderNo,
+                        'type'=> 1,
+                        'money'=> $payTotal,
+                        'after_money'=>$balance,
+                        'date'=>date('Y-m-d'),
+                        'create_time'=>time(),
+                        'remark'=> '订单付款-商品',
+                        'status'=>1,
+                        'mark'=>1
                     ];
-
-                    $result = DyrPayService::make()->recharge($orderNo, $account, $productId, $amount, $params);
-                    $errno = isset($result['errno'])?$result['errno'] : -1;
-                    $errmsg = isset($result['errmsg'])?$result['errmsg'] : '';
-                    $res = isset($result['data'])?$result['data']:[];
-                    $order_number = isset($res['order_number'])?$res['order_number']:'';
-                    $total_price = isset($res['total_price'])?$res['total_price']:'';
-                    if(empty($result) || $errno != 0 || empty($order_number)){
-
-                        $this->error = '充值调用失败:'.$errmsg;
-
-                        // 退款
-                        $orderInfo['money'] = $payTotal;
-                        $orderInfo['remark'] = '充值失败退款';
-                        $refundStatus = PaymentService::make()->refund($orderInfo,'pay');
-                        $updateData = ['refund_status'=> $refundStatus?1:3,'status'=>5,'result'=>json_encode(['amount'=>$amount,'params'=>$params,'result'=>$result],256),'failed_remark'=> $errmsg,'refund_at'=>date('Y-m-d H:i:s'),'refund_money'=>$refundStatus?$payTotal:0,'update_time'=>time()];
-                        $this->saveLog("caches:payments:notify_{$scene}:pay_failed_{$orderNo}_{$orderUserId}", ['error'=>$this->error,'update'=>$updateData,'order' => $orderInfo,'result'=>$result, 'notify' => $data]);
-                        if(!PayOrdersModel::where(['id'=>$orderId])->update($updateData)){
-                            $this->error = '订单退款状态更新错误~';
-                        }
-
-                        DB::commit();
-                        return false;
+                    if(!AccountLogModel::insertGetId($data)){
+                        Db::rollBack();
+                        $this->error = '付款处理失败';
                     }
-
-                    $updateData = ['status'=>3,'result'=>json_encode(['amount'=>$amount,'params'=>$params,'result'=>$result],256),'out_trade_no'=>$order_number,'update_time'=>time()+1];
-                    $this->saveLog("caches:payments:notify_{$scene}:pay_success_{$orderNo}_{$orderUserId}", ['error'=> '充值调用成功','id'=>$orderId,'update'=>$updateData,'order' => $orderInfo,'result'=>$result, 'notify' => $data]);
-                    if(!PayOrdersModel::where(['id'=>$orderId])->update($updateData)){
-                        DB::commit();
-                        $this->error = '更新充值订单失败';
-                        $this->saveLog("caches:payments:notify_{$scene}:pay_failed_{$orderNo}_{$orderUserId}", ['error'=>$this->error,'update'=>$updateData,'order' => $orderInfo,'result'=>$result, 'notify' => $data]);
-                        return false;
-                    }
-
-                    DB::commit();
-                    return true;
+                    break;
                 default:
                     break;
             }