Explorar o código

三方定时拉取订单赠送养老金,积分,贡献值

hehaiqiang hai 1 ano
pai
achega
4edb9f7649

+ 54 - 0
app/common/repositories/store/order/StoreOrderRepository.php

@@ -3127,6 +3127,60 @@ class StoreOrderRepository extends BaseRepository
3127
     }
3127
     }
3128
 
3128
 
3129
 
3129
 
3130
+    public function yugu_rebate_gong_fu($order){
3131
+
3132
+        $order_sn = $order["order_sn"];
3133
+        $tongji=Db::name("user_bill")->where("order_sn",$order_sn)->count();
3134
+        if($tongji){
3135
+            //第三方订单状态修改
3136
+            try {
3137
+                if(isset($order['table']) && !empty($order['table'])){
3138
+                    $table = $order['table'];
3139
+                    $bill_status = Db::name("$table")->where('order_sn',$order_sn) -> value('bill_status');
3140
+                    if($bill_status == 2){
3141
+                        Db::name("user_bill") -> where("order_sn",$order_sn) -> update(["status"=>-1]);
3142
+                    }
3143
+                }
3144
+            }catch (Exception $exception){
3145
+                Db::name("log")->insert(array('data'=>'第三方订单状态修改:'.$exception->getMessage()));//日志记录
3146
+            }
3147
+            return true;
3148
+        }
3149
+
3150
+        $order_id = $order["order_id"];
3151
+
3152
+
3153
+        /***************可以返的佣金*****************/
3154
+        //商户养老金比例
3155
+        $yanglao= systemConfig('yanglaojin_admin');
3156
+        //平台若有养老金配置 则开始分配养老金
3157
+        if ($yanglao){
3158
+            //养老金
3159
+//            $oldagefee=$this->decimal2($order["extension_one"]* $yanglao * 0.01);
3160
+            //y养老金最新调整 =佣金的*50%*5%
3161
+            $oldagefee=$this ->decimal2($order['total_price']*0.5*0.05);
3162
+
3163
+            //当前已扣会费总额
3164
+//            $oldagefee = $oldagefee-$dues;
3165
+            $mark = "消费获得养老金".$oldagefee;
3166
+
3167
+            //end会费
3168
+            //sat存养老金
3169
+            $title = "养老金 ";
3170
+            $commission_type = 5;
3171
+            if ($oldagefee >= 0.01) {
3172
+                $this->add_bill($title, $oldagefee, $order["uid"], $mark, $commission_type, $order_sn, $order_id, $order["mer_id"], 0, 0, $order["type_shop"]);
3173
+            }else {
3174
+                Db::name('log')->insert(['data'=>'订单号:'.$order_sn.'付款额度较低或 商家、平台设置的返佣比例较低,养老金低于0.01无法入库 特此记录!']);
3175
+            }
3176
+            //end存养老金
3177
+        }
3178
+
3179
+//
3180
+    }
3181
+
3182
+
3183
+
3130
     public function yugu_rebate($order)
3184
     public function yugu_rebate($order)
3131
     {
3185
     {
3132
 
3186
 

+ 36 - 14
app/common/repositories/user/UserThirdRepository.php

@@ -232,9 +232,9 @@ class UserThirdRepository extends BaseRepository
232
             ];
232
             ];
233
             return $order;
233
             return $order;
234
 //            var_dump($order,$pid);exit;
234
 //            var_dump($order,$pid);exit;
235
-//            $StoreOrderRepository = app()->make(StoreOrderRepository::class);
235
+            $StoreOrderRepository = app()->make(StoreOrderRepository::class);
236
 //            $StoreOrderRepository->yugu_rebate($order);
236
 //            $StoreOrderRepository->yugu_rebate($order);
237
-//            $StoreOrderRepository->yugu_rebate_gong_fu($order);
237
+            $StoreOrderRepository->yugu_rebate_gong_fu($order);
238
 
238
 
239
 
239
 
240
 //            $money_hui = 0;
240
 //            $money_hui = 0;
@@ -596,45 +596,67 @@ class UserThirdRepository extends BaseRepository
596
         return $data;
596
         return $data;
597
     }
597
     }
598
     /**
598
     /**
599
-     * 预估积分
599
+     * 添加预估积分记录
600
      */
600
      */
601
+
601
 //预估养老金
602
 //预估养老金
602
-    public static function yuguJifen($price, $user_id, $table, $table_id, $type_shop, $order_sn)
603
+    public static function yuguJifen($price,$user_id,$order_sn,$type_shop)
603
     {
604
     {
604
         if (empty($user_id)) {
605
         if (empty($user_id)) {
605
-            Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $table_id, 赠送积分, 不存在用户ID"]);
606
+            Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $order_sn, 赠送积分, 不存在用户ID"]);
606
             return false;
607
             return false;
607
         }
608
         }
608
         //查询用户是否已经存在该订单
609
         //查询用户是否已经存在该订单
609
         $user_sign_score_list = Db::name('user_sign_score')
610
         $user_sign_score_list = Db::name('user_sign_score')
610
             ->where('uid', $user_id)
611
             ->where('uid', $user_id)
611
-            ->where('order_type', $table)
612
-            ->where('order_id', $table_id)
612
+            ->where('order_type', $type_shop)
613
+            ->where('order_id', $order_sn)
613
             ->find();
614
             ->find();
614
         if (!empty($user_sign_score_list)) {
615
         if (!empty($user_sign_score_list)) {
615
-            Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $table_id, 赠送积分, 订单已存在积分发放记录"]);
616
+            Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $order_sn, 赠送积分, 订单已存在积分发放记录"]);
616
             return false;
617
             return false;
617
         }
618
         }
618
-        Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $table_id, 赠送积分, $price"]);
619
+        Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $order_sn, 赠送积分, $price"]);
619
         Db::startTrans();
620
         Db::startTrans();
620
         try {
621
         try {
621
             //更新用户积分
622
             //更新用户积分
622
             $user = Db::name('user')->where('uid', $user_id)->find();
623
             $user = Db::name('user')->where('uid', $user_id)->find();
623
-            $inc_score = $price;
624
+            $inc_score = decimal2($price*0.5);//pv=佣金的50%=积分=贡献值
624
             $user_score = $user['score'];
625
             $user_score = $user['score'];
625
             $ins_data['uid'] = $user_id;
626
             $ins_data['uid'] = $user_id;
626
             $ins_data['reward_socre'] = $inc_score;
627
             $ins_data['reward_socre'] = $inc_score;
627
             $ins_data['addtime'] = time();
628
             $ins_data['addtime'] = time();
628
             $ins_data['status'] = -1;
629
             $ins_data['status'] = -1;
629
-            $ins_data['order_type'] = $table;
630
-            $ins_data['order_id'] = $table_id;
630
+            $ins_data['order_type'] = $type_shop;
631
+            $ins_data['order_id'] = $order_sn;
631
             $ins_data['mark'] = "购买三方商品赠送积分";
632
             $ins_data['mark'] = "购买三方商品赠送积分";
632
             $ins_data['desc'] = '';
633
             $ins_data['desc'] = '';
633
             $ins_data['surplus'] = $user_score + $inc_score;
634
             $ins_data['surplus'] = $user_score + $inc_score;
634
             $ins_data['type'] = 1;
635
             $ins_data['type'] = 1;
635
             $ins_data['pm'] = 1;
636
             $ins_data['pm'] = 1;
636
-            Db::name('user_sign_score')->insertGetId($ins_data);
637
-            Db::name('user')->where('uid', $user_id)->inc('score', $inc_score)->update();
637
+            $ins_data['source_type'] =3;
638
+
639
+
640
+            //更新贡献值
641
+            $gongxian_data['uid'] = $user_id;
642
+            $gongxian_data['number'] = $inc_score;
643
+            $gongxian_data['addtime'] = time();
644
+            $gongxian_data['status'] = -1;
645
+            $gongxian_data['order_type'] = $type_shop;
646
+            $gongxian_data['order_id'] = $order_sn;
647
+            $gongxian_data['mark'] = "购买三方商品赠送贡献值";
648
+            $gongxian_data['desc'] = '';
649
+            $gongxian_data['surplus'] = $user_score + $inc_score;
650
+            $gongxian_data['type'] = 1;
651
+            $gongxian_data['pm'] = 1;
652
+            $gongxian_data['source_type'] =3;
653
+
654
+            Db::name('user_sign_score')->insertGetId($ins_data);//添加积分记录
655
+            Db::name('user_sign_gongxian')->insertGetId($gongxian_data);//添加贡献记录
656
+
657
+//
658
+//            Db::name('user')->where('uid', $user_id)->inc('score', $inc_score)->update();
659
+//            Db::name('user')->where('uid', $user_id)->inc('contribute', $inc_score)->update();
638
             Db::commit();
660
             Db::commit();
639
 
661
 
640
 //            $now_score= Db::name('user')->where('uid',$user_id)->value('now_score_estimate');
662
 //            $now_score= Db::name('user')->where('uid',$user_id)->value('now_score_estimate');

+ 1 - 1
app/controller/api/store/product/DaTaoKe.php

@@ -386,7 +386,7 @@ class DaTaoKe
386
                 'order_tb');
386
                 'order_tb');
387
             //预估积分
387
             //预估积分
388
             $orderThird->yuguJifen(
388
             $orderThird->yuguJifen(
389
-                $localOrder['pay_amount'],
389
+                $localOrder['commission'],
390
                 $localOrder['uid'],
390
                 $localOrder['uid'],
391
                 $localOrder['order_sn'],
391
                 $localOrder['order_sn'],
392
                 5
392
                 5

+ 1 - 1
app/controller/api/store/product/Jd.php

@@ -628,7 +628,7 @@ class Jd extends BaseController
628
                 'order_jd');
628
                 'order_jd');
629
             //预估积分
629
             //预估积分
630
             $orderThird->yuguJifen(
630
             $orderThird->yuguJifen(
631
-                $order['price'],
631
+                $order['commission'],
632
                 $order['uid'],
632
                 $order['uid'],
633
                 $order['order_sn'],
633
                 $order['order_sn'],
634
                 6
634
                 6

+ 11 - 13
app/controller/api/store/product/Jt.php

@@ -802,21 +802,19 @@ class Jt extends BaseController
802
             $yanglaojin = $yanglaojin_order['extension_one'] ?? 0;
802
             $yanglaojin = $yanglaojin_order['extension_one'] ?? 0;
803
             //预估积分
803
             //预估积分
804
             $orderThird->yuguJifen(
804
             $orderThird->yuguJifen(
805
-                $localOrder['price'] + $yanglaojin,
806
-                $localOrder['uid'],
807
-                'order_jd',
808
-                $localOrder['order_jd_id'],
809
-                $type_shop,
810
-                $localOrder['order_sn']
805
+                $order['commission'],
806
+                $order['uid'],
807
+                $order['order_sn'],
808
+                6
811
             );
809
             );
812
             //直推奖处理
810
             //直推奖处理
813
-            $orderThird->yuguZhitui(
814
-                $localOrder['commission'],
815
-                $localOrder['uid'],
816
-                $type_shop,
817
-                $localOrder['order_sn'],
818
-                $localOrder['order_jd_id']
819
-            );
811
+//            $orderThird->yuguZhitui(
812
+//                $localOrder['commission'],
813
+//                $localOrder['uid'],
814
+//                $type_shop,
815
+//                $localOrder['order_sn'],
816
+//                $localOrder['order_jd_id']
817
+//            );
820
         }
818
         }
821
     }
819
     }
822
 
820
 

+ 4 - 4
app/controller/api/store/product/Su.php

@@ -759,10 +759,10 @@ class Su extends BaseController
759
                 3,
759
                 3,
760
                 'order_su');
760
                 'order_su');
761
             //预估积分
761
             //预估积分
762
-            $orderThird->yuguJifen($localOrder['pay_amount'],
763
-                $localOrder['uid'],
764
-                $localOrder['order_sn'],
765
-                $localOrder['bill_end_time'],
762
+            $orderThird->yuguJifen(
763
+                $order['commission'],
764
+                $order['uid'],
765
+                $order['order_sn'],
766
                 3
766
                 3
767
             );
767
             );
768
         }
768
         }

+ 2 - 1
app/controller/api/store/product/Vip.php

@@ -880,7 +880,8 @@ class Vip extends BaseController
880
                     2,
880
                     2,
881
                     'order_vip');
881
                     'order_vip');
882
                 //预估积分
882
                 //预估积分
883
-                $orderThird->yuguJifen($localOrder['pay_amount'],
883
+                $orderThird->yuguJifen(
884
+                    $localOrder['commission'],
884
                     $localOrder['uid'],
885
                     $localOrder['uid'],
885
                     $localOrder['order_sn'],
886
                     $localOrder['order_sn'],
886
                     $localOrder['bill_end_time'],
887
                     $localOrder['bill_end_time'],