Kirin 3 年之前
父節點
當前提交
4717921095

+ 12 - 0
app/admin/model/order/StoreOrder.php

@@ -133,6 +133,9 @@ class StoreOrder extends BaseModel
                     case 'yue':
                         $item['pay_type_name'] = '余额支付';
                         break;
+                    case 'cash':
+                        $item['pay_type_name'] = '现金支付';
+                        break;
                     case 'offline':
                         $item['pay_type_name'] = '线下支付';
                         break;
@@ -587,6 +590,13 @@ HTML;
                 'background_color' => 'layui-bg-blue',
                 'col' => 2
             ],
+            [
+                'name' => '现金支付金额',
+                'field' => '元',
+                'count' => $price['pay_price_cash'],
+                'background_color' => 'layui-bg-blue',
+                'col' => 2
+            ],
             [
                 'name' => '运费金额',
                 'field' => '元',
@@ -682,6 +692,8 @@ HTML;
                 $price['pay_price_wx'] = $v['sum_pay_price'];
             } elseif ($v['pay_type'] == 'yue') {
                 $price['pay_price_yue'] = $v['sum_pay_price'];
+            } elseif ($v['pay_type'] == 'cash') {
+                $price['pay_price_cash'] = $v['sum_pay_price'];
             } elseif ($v['pay_type'] == 'offline') {
                 $price['pay_price_offline'] = $v['sum_pay_price'];
             } else {

+ 11 - 0
app/api/controller/order/StoreOrderController.php

@@ -244,6 +244,17 @@ class StoreOrderController
                             return app('json')->status('pay_error', $errorinfo);
                     }
                     break;
+                case 'cash':
+                    if (StoreOrder::cashPay($orderId, $request->uid(), $formId))
+                        return app('json')->status('success', '现金支付成功', $info);
+                    else {
+                        $errorinfo = StoreOrder::getErrorInfo();
+                        if (is_array($errorinfo))
+                            return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
+                        else
+                            return app('json')->status('pay_error', $errorinfo);
+                    }
+                    break;
                 case 'pink_integral':
                     if (StoreOrder::pinkPay($orderId, $request->uid(), $formId))
                         return app('json')->status('success', '拼团积分支付成功', $info);

+ 38 - 1
app/models/store/StoreOrder.php

@@ -57,7 +57,7 @@ class StoreOrder extends BaseModel
 
     protected $insert = ['add_time'];
 
-    protected static $payType = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'pink_integral' => '拼团积分支付'];
+    protected static $payType = ['cash' => '现金支付', 'weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'pink_integral' => '拼团积分支付'];
 
     protected static $deliveryType = ['send' => '商家配送', 'express' => '快递配送'];
 
@@ -709,6 +709,43 @@ class StoreOrder extends BaseModel
         return $res;
     }
 
+    /**
+     * 余额支付
+     * @param $order_id
+     * @param $uid
+     * @param string $formId
+     * @return bool
+     * @throws \think\Exception
+     * @throws DataNotFoundException
+     * @throws ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function cashPay($order_id, $uid, $formId = '')
+    {
+        $orderInfo = self::where('uid', $uid)->where('order_id', $order_id)->where('is_del', 0)->find();
+        if (!$orderInfo) return self::setErrorInfo('订单不存在!');
+        if ($orderInfo['paid']) return self::setErrorInfo('该订单已支付!');
+//        if($orderInfo['pay_type'] != 'yue') return self::setErrorInfo('该订单不能使用余额支付!');
+        $userInfo = User::getUserInfo($uid);
+        if ($userInfo['cash'] < $orderInfo['pay_price'])
+            return self::setErrorInfo(['status' => 'pay_deficiency', 'msg' => '现金不足' . floatval($orderInfo['pay_price'])]);
+        self::beginTrans();
+
+        $res1 = false !== User::bcDec($uid, 'cash', $orderInfo['pay_price'], 'uid');
+        $res2 = UserBill::expend('购买商品', $uid, 'cash', 'cash_pay_product', $orderInfo['pay_price'], $orderInfo['id'], $userInfo['cash'], '现金支付' . floatval($orderInfo['pay_price']) . '元购买商品');
+        $res3 = self::paySuccess($order_id, 'cash', $formId);//余额支付成功
+        try {
+            PaymentRepositories::yuePayProduct($userInfo, $orderInfo);
+        } catch (\Exception $e) {
+            self::rollbackTrans();
+            return self::setErrorInfo($e->getMessage());
+        }
+        $res = $res1 && $res2 && $res3;
+        self::checkTrans($res);
+        return $res;
+    }
+
+
     public static function pinkPay($order_id, $uid, $formId = '')
     {
         $orderInfo = self::where('uid', $uid)->where('order_id', $order_id)->where('is_del', 0)->find();