Browse Source

线下支付返佣调整

xialei 1 year ago
parent
commit
b095cbaa74
1 changed files with 98 additions and 18 deletions
  1. 98 18
      app/common/repositories/merchant/order/OrderMerchantRepository.php

+ 98 - 18
app/common/repositories/merchant/order/OrderMerchantRepository.php

@@ -596,7 +596,6 @@ class OrderMerchantRepository extends BaseRepository
596 596
 //                    $this->feidacang_fenyong($order_data, 0);
597 597
 //                }
598 598
                 $flag = 1;
599
-//                $this->feidacang_fenyong($order_data, 0);
600 599
                 $this->offLineOrder($order['id']);
601 600
                 if ($order['mer_id'] == 496) {
602 601
                     //一壶茶电子商务
@@ -641,7 +640,8 @@ class OrderMerchantRepository extends BaseRepository
641 640
                 //                ->update();
642 641
                 $user = $userRepository->getOne($where);
643 642
                 $order = (object)$order;
644
-                $this->doBind($user, $order, $flag);
643
+                $this->feidacang_fenyong($user, $order_data, 0);
644
+                $this->doBind($user, $order, $flag);//锁客
645 645
                 Db::name("log")->insert(['data' => '绑定用户完成']);//日志记录
646 646
                 $this->doBroadcast($actuallyPaid, $mer_id);
647 647
 
@@ -851,9 +851,41 @@ class OrderMerchantRepository extends BaseRepository
851 851
             if (!$user->mer_id) {
852 852
                 $user->mer_id = $order->mer_id;
853 853
                 $user->save();
854
-                $mer_uid = Db::name('merchant')->where('mer_id', $order->mer_id)->value('uid');
854
+                
855
+                $mer_fanyongbili = merchantConfig($order['mer_id'], 'base_commission');
856
+                //如果商户返佣比例设置的是0怎查系统设设置的分佣比例
857
+                if ($mer_fanyongbili == 0) {
858
+                    $mer_fanyongbili = merchantConfig(0, 'extension_one_rate');
859
+                }
860
+                //如果系统设置的是0就不执行!
861
+                if ($mer_fanyongbili == 0) {
862
+                    Db::name('log')->insert(['data' => '订单号:' . $order['order_sn'] . ' 订单因商家、平台没有设置返佣比例无任何奖励特此记录!']);
863
+                    return '';
864
+                }
865
+                $order_sn = $order['order_sn'] ?? '';
866
+                $order_id = $order['order_id'] ?? '';
867
+                //可分总佣金
868
+                $divisible_commission = bcmul($order['pay_price'], bcdiv($mer_fanyongbili, '100', 2), 2);//让利部分
869
+                $pv = bcmul($divisible_commission, '0.7', 2);//商家让利部分30%给消费者做养老金,70%做业绩PV
870
+
871
+                //商户锁客收益:PV的5%==14元X5%=0.7元 (加入到用户佣金,可以从用户佣金中提现,商户显示锁客收益总额)
872
+                $suo_commission = bcmul($pv, '0.5', 2);
873
+                if ($suo_commission >= 0.01) {
874
+                    $mark = "用户获得商户锁客收益" . $suo_commission . '佣金';
875
+                    $title = "佣金";
876
+                    $source = 1;
877
+                    $commission_type = 3;
878
+                    $this->add_bill($title, $suo_commission, $user->uid, $mark, $commission_type, $order_sn, $order_id, $order["mer_id"], $source, 1);
879
+                } else {
880
+                    Db::name('log')->insert(['data' => '订单号:' . $order['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,佣金低于0.01无法入库 特此记录!']);
881
+                }
882
+        
883
+
884
+    
885
+
886
+                // $mer_uid = Db::name('merchant')->where('mer_id', $order->mer_id)->value('uid');
855 887
                 //商户每锁定一个顾客获得300积分
856
-                $userRepository->sign_add($mer_uid, systemConfig('mer_score'), 1, '到店锁定一个顾客赠送积分', '', '', $order->id,1,'order_merchant');
888
+                // $userRepository->sign_add($mer_uid, systemConfig('mer_score'), 1, '到店锁定一个顾客赠送积分', '', '', $order->id,1,'order_merchant');
857 889
 //                Db::name('user')->where('uid',$mer_uid)->inc('score', systemConfig('mer_score'))->update();
858 890
 //                $ins_data['uid'] = $mer_uid;
859 891
 //                $ins_data['reward_socre'] = systemConfig('mer_score');
@@ -1222,12 +1254,13 @@ class OrderMerchantRepository extends BaseRepository
1222 1254
         }
1223 1255
     }
1224 1256
 
1225
-    public function feidacang_fenyong($order, $pay_status)
1257
+    //商户二维码收款返佣
1258
+    public function feidacang_fenyong($user, $order, $pay_status)
1226 1259
     {
1260
+        $userRepository = app()->make(UserRepository::class);
1227 1261
         if ($pay_status == 1) {
1228 1262
             return '';
1229 1263
         }
1230
-//        Db::name('log')->insert(['data' => '订单号:' . $order['order_sn'] . ' 非大仓订单进来了!']);
1231 1264
         $top_data = Db::name('user')->where('uid', $order['uid'])->field('spread_uid,mer_id')->find();
1232 1265
         $mer_fanyongbili = merchantConfig($order['mer_id'], 'base_commission');
1233 1266
         //如果商户返佣比例设置的是0怎查系统设设置的分佣比例
@@ -1242,15 +1275,22 @@ class OrderMerchantRepository extends BaseRepository
1242 1275
         $order_sn = $order['order_sn'] ?? '';
1243 1276
         $order_id = $order['order_id'] ?? '';
1244 1277
         //可分总佣金
1245
-        $divisible_commission = bcmul($order['pay_price'], bcdiv($mer_fanyongbili, '100', 2), 2);
1278
+        $divisible_commission = bcmul($order['pay_price'], bcdiv($mer_fanyongbili, '100', 2), 2);//让利部分
1279
+        $pv = bcmul($divisible_commission, '0.7', 2);//商家让利部分30%给消费者做养老金,70%做业绩PV
1246 1280
 
1247 1281
         /**
1248 1282
          * 各自的比例开始
1249 1283
          */
1250 1284
         //用户养老金比例
1251
-        $yonghu_bili = '0.5';
1252
-        //用户推荐人,消费者的推荐人
1253
-        $yonghu_tuijian = '0.15';
1285
+        $yonghu_bili = '0.3';
1286
+        //用户红包比例
1287
+        $yonghu_hongbao = '0.45';
1288
+        //用户推荐人养老金比例
1289
+        $yonghu_bili_tuijian = '0.05';
1290
+        //用户推荐人,消费者的推荐人佣金
1291
+        $yonghu_tuijian = '0.03';
1292
+
1293
+
1254 1294
         //商家流水分佣
1255 1295
 //        $mer_luishui_fenyong = '0.25';
1256 1296
         //跨店分佣
@@ -1258,13 +1298,7 @@ class OrderMerchantRepository extends BaseRepository
1258 1298
         /**
1259 1299
          * 各自的比例结束
1260 1300
          */
1261
-        //判断用户是否交了年费
1262
-//        $check_user_pension_account = Db::name("user_pension_account") -> where("uid",$order["uid"]) -> find();
1263
-//        if (!$check_user_pension_account || $check_user_pension_account["status"] == 0 || strtotime($check_user_pension_account['end_time']) < time()) {
1264
-//            $status = 0;
1265
-//        }else{
1266
-            $status = 1;
1267
-//        }
1301
+
1268 1302
         //用户可拿的养老金
1269 1303
         $user_yanglaojin = bcmul($divisible_commission, $yonghu_bili, 2);
1270 1304
         if ($user_yanglaojin >= 0.01) {
@@ -1272,10 +1306,51 @@ class OrderMerchantRepository extends BaseRepository
1272 1306
             $title = "养老金";
1273 1307
             $source = 1;
1274 1308
             $commission_type = 5;
1275
-            $this->add_bill($title, $user_yanglaojin, $order["uid"], $mark, $commission_type, $order_sn, $order_id, $order["mer_id"], $source, $status);
1309
+            $this->add_bill($title, $user_yanglaojin, $order["uid"], $mark, $commission_type, $order_sn, $order_id, $order["mer_id"], $source, 1);
1276 1310
         } else {
1277 1311
             Db::name('log')->insert(['data' => '订单号:' . $order['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,养老金低于0.01无法入库 特此记录!']);
1278 1312
         }
1313
+
1314
+        //用户可以拿到的红包 红包:如果是1.0的老用户 pv的45%放到红包里面。14*45%=6.3元。直至金额满足1.0平台当前用户身份为止就不在反红包了
1315
+        // if($user["is_old"]==1){
1316
+        //     //添加红包
1317
+        //     $hongbao=round($inc_score*0.45,2);
1318
+        //     $hongbao_data = [
1319
+        //         "uid"           =>$user_id,
1320
+        //         "number"  =>    $hongbao,
1321
+        //         "addtime"       =>time(),
1322
+        //         "status"        =>-1,
1323
+        //         "order_type"    =>$type_shop,
1324
+        //         "order_id"      =>$order_sn,
1325
+        //         "mark"          =>"购买{$make}商品赠送红包",
1326
+        //         "desc"          =>'',
1327
+        //         "surplus"       =>$hongbao,
1328
+        //         "type"          =>1
1329
+        //     ];
1330
+        //     Db::name("user_sign_hongbao")->insert($hongbao_data);//添加记录
1331
+        // }
1332
+
1333
+
1334
+
1335
+        ///用户可以拿到PV等值的积分和贡献值
1336
+        if ($pv >= 0.01) {
1337
+            $userRepository->sign_add($order["uid"], $pv, 1, '消费获得赠送积分', '', '', $order['id'], 1, 'order_merchant');
1338
+        } else {
1339
+            Db::name('log')->insert(['data' => '订单号:' . $order['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,积分和贡献值低于0.01无法入库 特此记录!']);
1340
+        }
1341
+
1342
+        //用户推荐人可拿的养老金
1343
+        $user_yanglaojin = bcmul($divisible_commission, $yonghu_bili, 2);
1344
+        if ($user_yanglaojin >= 0.01) {
1345
+            $mark = "消费获得养老金" . $user_yanglaojin;
1346
+            $title = "养老金";
1347
+            $source = 1;
1348
+            $commission_type = 5;
1349
+            $this->add_bill($title, $user_yanglaojin, $order["uid"], $mark, $commission_type, $order_sn, $order_id, $order["mer_id"], $source, 1);
1350
+        } else {
1351
+            Db::name('log')->insert(['data' => '订单号:' . $order['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,养老金低于0.01无法入库 特此记录!']);
1352
+        }
1353
+
1279 1354
         //用户推荐人佣金
1280 1355
         $tuijian_yongjin = bcmul($divisible_commission, $yonghu_tuijian, 2);
1281 1356
         if ($tuijian_yongjin >= 0.01) {
@@ -1287,6 +1362,11 @@ class OrderMerchantRepository extends BaseRepository
1287 1362
         } else {
1288 1363
             Db::name('log')->insert(['data' => '订单号:' . $order['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,佣金低于0.01无法入库 特此记录!']);
1289 1364
         }
1365
+
1366
+
1367
+        //商户得到的(京豆和贡献值奖励的倍,后台设置)
1368
+
1369
+
1290 1370
         //推荐商家流水返佣
1291 1371
 //        $mer_tuijian_yongjin = bcmul($divisible_commission, $mer_luishui_fenyong, 2);
1292 1372
 //        if ($mer_tuijian_yongjin > 0.01) {