dever 3 lat temu
rodzic
commit
c47843d3bd

+ 1 - 1
app/mshop/src/Data.php

@@ -470,7 +470,7 @@ class Data extends Core
         );
 
         $this->data['price'] -= $cash;
-        $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
+        $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
         return $pay;
     }
 

+ 11 - 1
app/shop/database/info.php

@@ -20,7 +20,7 @@ $invoice = array
     2 => '不可以开发票',
 );
 
-$col = 'id,name,`desc`,ps_cash,truename,mobile,lng,lat,address,open,worktime,method,gotime,city,area,province,county,town,coupon_city,pdesc,license,food_license,jy_license,license_number,company_name,coord_address,invoice,type';
+$col = 'id,name,`desc`,ps_cash,truename,mobile,lng,lat,address,open,worktime,method,gotime,city,area,province,county,town,coupon_city,pdesc,license,food_license,jy_license,license_number,company_name,coord_address,invoice,type,mid';
 
 $act = function()
 {
@@ -521,6 +521,16 @@ return array
             'option'    => $act,
         ),
 
+        'mid'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '分账商户号',
+            'default'   => '',
+            'desc'      => '分账商户号',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'ps_cash'      => array
         (
             'type'      => 'varchar-50',

+ 11 - 0
app/shop/database/sell_order.php

@@ -187,6 +187,17 @@ return array
             'list'      => true,
         ),
 
+        'oprice'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '原价',
+            'default'   => '0',
+            'desc'      => '原价',
+            'match'     => 'option',
+            'update'    => 'text',
+            //'list'        => true,
+        ),
+
         'price'      => array
         (
             'type'      => 'varchar-50',

+ 23 - 4
app/shop/lib/Refund.php

@@ -267,7 +267,7 @@ class Refund
             if ($info['type'] == 2) {
                 $state = Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 3));
                 if ($state) {
-                    $this->notice($state, $order, $info['cash']);
+                    $this->notice($state, $order, $info);
                     # 检查这个订单下的商品是不是都退了
                     $total = Dever::db($this->goods_table)->getTotal(array('order_id' => $order['id'], 'status' => '1,2'));
 
@@ -294,7 +294,7 @@ class Refund
                 $update['status'] = 8;
                 $state = Dever::db($this->order_table)->update($update);
                 if ($state) {
-                    $this->notice($state, $order, $info['cash']);
+                    $this->notice($state, $order, $info);
                     if (isset($order['user_coupon_id']) && $order['user_coupon_id']) {
                         # 还原优惠券
                         Dever::db('shop/user_coupon')->update(array('where_id' => $order['user_coupon_id'], 'status' => 1));
@@ -346,9 +346,12 @@ class Refund
     }
 
     # 退款通知
-    public function notice($state, $data, $refund_cash)
+    public function notice($state, $data, $info)
     {
         if ($state && isset($data['uid']) && $data['uid'] > 0) {
+            $refund_cash = $info['cash'];
+            $refund_order_id = $info['id'];
+
             $shop = Dever::db('shop/info')->one($data['shop_id']);
             $msg_param['type'] = 1;//消息类型1是订单消息
             $msg_param['id'] = $data['id'];
@@ -358,7 +361,23 @@ class Refund
             Dever::load('message/lib/data')->push(-1, $data['uid'], '退款成功通知', $msg, 2, 1, false, $msg_param);
 
             # 退款到原支付账户 待处理
-
+            $param = array
+            (
+                'project_id' => 1,
+                'channel_id' => 1,
+                'system_source' => 5,
+                'order_id' => $data['order_num'],
+                'refund_cash' => $refund_cash,
+                'refund_order_id' => $refund_order_id
+            );
+
+            $result = Dever::load('pay/api.refund', $param);
+
+            if (!$result) {
+                # 退款失败,抛出错误
+                throw new \Exception('退款失败');
+                Dever::alert('退款失败');
+            }
 
             if (Dever::load('wechat_applet')) {
                 $config = Dever::db($this->order_table)->config;

+ 29 - 1
app/shop/lib/Sell.php

@@ -575,6 +575,9 @@ class Sell
             $num = explode(',', $num);
         }
 
+        # 原价
+        $data['oprice'] = 0;
+        # 现价
         $data['price'] = 0;
         $data['num'] = 0;
         $data['name'] = array();
@@ -618,11 +621,13 @@ class Sell
             $data['ps_cash'] = $data['shop']['ps_cash'];
         }
 
+        $data['oprice'] = $data['price'];
+
         return $data;
     }
 
     # 发起支付
-	public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $price, $cash, $address_id, $invoice_id, $info, $card, $coupon_id, $user_coupon_id, $coupon_cash, $cart = false, $system_source = 5, $refer = '')
+	public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $oprice, $price, $cash, $address_id, $invoice_id, $info, $card, $coupon_id, $user_coupon_id, $coupon_cash, $cart = false, $system_source = 5, $refer = '')
     {
         if (!$user) {
             Dever::alert('错误的用户信息');
@@ -630,6 +635,12 @@ class Sell
 
         $uid = $user['id'];
 
+        $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => 1));
+
+        if (!$wechat) {
+            Dever::alert('错误的用户信息');
+        }
+
         if ($method == 2) {
             $order_data['ps_cash'] = $shop['ps_cash'];
             $price += $order_data['ps_cash'];
@@ -643,6 +654,7 @@ class Sell
         $order_data['name'] = $name;
         $order_data['num'] = $num;
         $order_data['info'] = $info;
+        $order_data['oprice'] = $oprice;
         $order_data['price'] = $price;
         $order_data['kou_cash'] = $cash;
 
@@ -733,16 +745,32 @@ class Sell
             );
         }
 
+        $sell_config = Dever::db('main/sell_config')->one();
+
+        # 分账
+        $other = false;
+        if (isset($shop['mid']) && $shop['mid']) {
+            $other = array
+            (
+                'mid' => $shop['mid'],
+                'order_id' => $order_data['order_num'] . '_' . $shop['id'],
+                'per' => $sell_config['per'],
+                'oprice' => $oprice,
+            );
+        }
+
         $param = array
         (
             'project_id' => 1,
             'channel_id' => 1,
             'system_source' => $system_source,
             'uid' => $uid,
+            'openid' => $wechat['openid'],
             'name' => $order_data['name'],
             'cash' => $price,
             'product_id' => $id,
             'order_id' => $order_data['order_num'],
+            'other' => $other,
             'refer' => $refer,
         );
 

+ 1 - 1
app/shop/src/Buy.php

@@ -244,7 +244,7 @@ class Buy extends Core
 			$this->data['card'] = false;
 		}
 
-		$pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], 1, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], 0, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 5, $refer);
+		$pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], 1, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], 0, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 5, $refer);
 		return $pay;
 	}
 

+ 15 - 0
app/shop/src/Main.php

@@ -15,6 +15,21 @@ class Main extends Core
 
     public function test()
     {
+        # 退款到原支付账户 待处理
+        $param = array
+        (
+            'project_id' => 1,
+            'channel_id' => 1,
+            'system_source' => 5,
+            'order_id' => 'G202112296076319846598914',
+            'refund_cash' => 1,
+            'refund_order_id' => 1
+        );
+
+        $result = Dever::load('pay/api.refund', $param);
+
+        print_r($result);die;
+
         $data = array
         (
             'character_string6' => array

+ 10 - 0
main/database/sell_config.php

@@ -81,6 +81,16 @@ return array
             'place'     => '150*150',
         ),
 
+        'per'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '平台佣金比例-输入1就是百分之1,分账时,平台自动从支付的金额里抽取1%的手续费',
+            'default'   => '1',
+            'desc'      => '平台佣金比例',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'phone'      => array
         (
             'type'      => 'varchar-100',