Просмотр исходного кода

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

hehaiqiang 1 год назад
Родитель
Сommit
d65bb939f0

+ 41 - 34
app/common/repositories/store/order/StoreOrderRepository.php

@@ -3129,10 +3129,13 @@ class StoreOrderRepository extends BaseRepository
3129 3129
 
3130 3130
     public function yugu_rebate_gong_fu($order){
3131 3131
 
3132
+
3132 3133
         $order_sn = $order["order_sn"];
3134
+        log::info("进入添加养老金{$order['order_sn']}");
3133 3135
         $tongji=Db::name("user_bill")->where("order_sn",$order_sn)->count();
3134 3136
         if($tongji){
3135 3137
             //第三方订单状态修改
3138
+            log::info("tongji");
3136 3139
             try {
3137 3140
                 if(isset($order['table']) && !empty($order['table'])){
3138 3141
                     $table = $order['table'];
@@ -3152,29 +3155,31 @@ class StoreOrderRepository extends BaseRepository
3152 3155
 
3153 3156
         /***************可以返的佣金*****************/
3154 3157
         //商户养老金比例
3155
-        $yanglao= systemConfig('yanglaojin_admin');
3158
+//        $yanglao= systemConfig('yanglaojin_admin');
3156 3159
         //平台若有养老金配置 则开始分配养老金
3157
-        if ($yanglao){
3158
-            //养老金
3160
+//        if ($yanglao){
3161
+//
3162
+//        }
3163
+        //养老金
3159 3164
 //            $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 3165
 
3163
-            //当前已扣会费总额
3166
+        //y养老金最新调整 =佣金的*50%*5%
3167
+        $oldagefee=decimal2($order['total_price']*0.5*0.05);
3168
+        log::info("++{$order['total_price']}+养老金===={$oldagefee}");
3169
+        //当前已扣会费总额
3164 3170
 //            $oldagefee = $oldagefee-$dues;
3165
-            $mark = "消费获得养老金".$oldagefee;
3171
+        $mark = "消费获得养老金".$oldagefee;
3166 3172
 
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存养老金
3173
+        //end会费
3174
+        //sat存养老金
3175
+        $title = "养老金 ";
3176
+        $commission_type = 5;
3177
+        if ($oldagefee >= 0.01) {
3178
+            $this->add_bill($title, $oldagefee, $order["uid"], $mark, $commission_type, $order_sn, $order_id, $order["mer_id"], 0, 0, $order["type_shop"]);
3179
+        }else {
3180
+            Db::name('log')->insert(['data'=>'订单号:'.$order_sn.'付款额度较低或 商家、平台设置的返佣比例较低,养老金低于0.01无法入库 特此记录!']);
3177 3181
         }
3182
+        //end存养老金
3178 3183
 
3179 3184
 //
3180 3185
     }
@@ -3679,19 +3684,20 @@ class StoreOrderRepository extends BaseRepository
3679 3684
      */
3680 3685
     public function add_bill($title, $number, $uid, $mark, $commission_type, $order_sn, $order_id = 0, $mer_id = 0, $source = 0, $status = 1, $type_shop = 0)
3681 3686
     {
3687
+        log::info("====进入add——bill");
3682 3688
 //        $old_number=Db::name("user")->where("uid",$uid)->value("brokerage_price");
3683 3689
         if ($uid == 0 || $number == 0) {
3684 3690
             return;
3685 3691
         }
3686 3692
 //        Log::info("user_bill_log");
3687
-        if ($commission_type != 5) {
3688
-            $promoter_rate_technology = systemConfig('promoter_rate_technology');
3689
-            if (floatval($promoter_rate_technology)) {
3690
-                $number = $number - ($number * $promoter_rate_technology / 100);
3691
-                // var_dump(=$number-$number*$promoter_rate_technology)
3692
-                $mark .= ",扣除技术服务费" . $promoter_rate_technology . "%";
3693
-            }
3694
-        }
3693
+//        if ($commission_type != 5) {
3694
+//            $promoter_rate_technology = systemConfig('promoter_rate_technology');
3695
+//            if (floatval($promoter_rate_technology)) {
3696
+//                $number = $number - ($number * $promoter_rate_technology / 100);
3697
+//                // var_dump(=$number-$number*$promoter_rate_technology)
3698
+//                $mark .= ",扣除技术服务费" . $promoter_rate_technology . "%";
3699
+//            }
3700
+//        }
3695 3701
 
3696 3702
 
3697 3703
 //        $number=round($number,2);
@@ -3715,17 +3721,18 @@ class StoreOrderRepository extends BaseRepository
3715 3721
             "source"          => $source,
3716 3722
             "type_shop"       => $type_shop
3717 3723
         ];
3724
+        log::info("开始添加user——bills");
3718 3725
         Db::name("user_bill")->insert($data);
3719 3726
 
3720
-        if ($type_shop == 0) {
3721
-            if ($commission_type == 5) {
3722
-                Db::name("user")->where("uid", $uid)->inc('annuity', $number)->update();
3723
-                Db::name("user")->where("uid", $uid)->inc('annuity_num', 1)->update();
3724
-            } else {
3725
-                Db::name("user")->where("uid", $uid)->inc('brokerage_price', $number)->update();
3726
-
3727
-            }
3728
-        }
3727
+//        if ($type_shop == 0) {
3728
+//            if ($commission_type == 5) {
3729
+//                Db::name("user")->where("uid", $uid)->inc('annuity', $number)->update();
3730
+//                Db::name("user")->where("uid", $uid)->inc('annuity_num', 1)->update();
3731
+//            } else {
3732
+//                Db::name("user")->where("uid", $uid)->inc('brokerage_price', $number)->update();
3733
+//
3734
+//            }
3735
+//        }
3729 3736
 
3730 3737
     }
3731 3738
 

+ 69 - 34
app/common/repositories/user/UserThirdRepository.php

@@ -19,6 +19,7 @@ use app\common\repositories\store\product\ProductRepository;
19 19
 use app\model\common\TbOrderModel;
20 20
 use think\exception\ValidateException;
21 21
 use think\facade\Log;
22
+use think\test\queue\LoopBreakerException;
22 23
 use function GuzzleHttp\Psr7\str;
23 24
 
24 25
 use think\facade\Db;
@@ -196,7 +197,7 @@ class UserThirdRepository extends BaseRepository
196 197
     public function yuguOrder($order_id, $commission, $pid, $order_sn, $type, $table)
197 198
     {
198 199
         //配置信息
199
-        $config = $this->config();
200
+//        $config = $this->config();
200 201
         //用户pid信息
201 202
 //        if ($type == 6) {//京东联盟改成京推推
202 203
 //            $user['uid'] = intval($pid - pow(10, 5));
@@ -230,10 +231,10 @@ class UserThirdRepository extends BaseRepository
230 231
                 "type_shop"=>$type,
231 232
                 "table"=>$table
232 233
             ];
233
-            return $order;
234
-//            var_dump($order,$pid);exit;
234
+
235 235
             $StoreOrderRepository = app()->make(StoreOrderRepository::class);
236 236
 //            $StoreOrderRepository->yugu_rebate($order);
237
+            log::info("===待进入养老金22222222222");
237 238
             $StoreOrderRepository->yugu_rebate_gong_fu($order);
238 239
 
239 240
 
@@ -617,47 +618,82 @@ class UserThirdRepository extends BaseRepository
617 618
             return false;
618 619
         }
619 620
         Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $order_sn, 赠送积分, $price"]);
620
-        Db::startTrans();
621
+
621 622
         try {
622 623
             //更新用户积分
624
+
623 625
             $user = Db::name('user')->where('uid', $user_id)->find();
624 626
             $inc_score = decimal2($price*0.5);//pv=佣金的50%=积分=贡献值
625 627
             $user_score = $user['score'];
626
-            $ins_data['uid'] = $user_id;
627
-            $ins_data['reward_socre'] = $inc_score;
628
-            $ins_data['addtime'] = time();
629
-            $ins_data['status'] = -1;
630
-            $ins_data['order_type'] = $type_shop;
631
-            $ins_data['order_id'] = $order_sn;
632
-            $ins_data['mark'] = "购买三方商品赠送积分";
633
-            $ins_data['desc'] = '';
634
-            $ins_data['surplus'] = $user_score + $inc_score;
635
-            $ins_data['type'] = 1;
636
-            $ins_data['pm'] = 1;
637
-            $ins_data['source_type'] =3;
628
+            $surplus=$user_score + $inc_score;
629
+            $surplusgongxian=$user['contribute'] + $inc_score;
630
+
631
+            $data = [
632
+                "uid"           =>  $user_id,
633
+                "reward_socre"  =>  $inc_score,
634
+                "addtime"       =>  time(),
635
+                "status"        =>  -1,
636
+                "order_type"    =>  $type_shop,
637
+                "order_id"      =>  $order_sn,
638
+                "mark"          =>  "购买三方商品赠送积分",
639
+                "surplus"       =>  $surplus,
640
+                "pm"            =>  1,
641
+                "source_type"   =>  3
642
+                ];
643
+            log::info("准备开始添加积分,贡献");
644
+            Db::name("user_sign_score")->insert($data);//添加积分记录
645
+
646
+            log::info("准备开始添加积分");
647
+//            $ins_data['uid'] = $user_id;
648
+//            $ins_data['reward_socre'] = $inc_score;
649
+//            $ins_data['addtime'] = time();
650
+//            $ins_data['status'] = -1;
651
+//            $ins_data['order_type'] = $type_shop;
652
+//            $ins_data['order_id'] = $order_sn;
653
+//            $ins_data['mark'] = "购买三方商品赠送积分";
654
+//            $ins_data['desc'] = '';
655
+//            $ins_data['surplus'] = $user_score + $inc_score;
656
+//            $ins_data['type'] = 1;
657
+//            $ins_data['pm'] = 1;
658
+//            $ins_data['source_type'] =3;
638 659
 
639 660
 
640 661
             //更新贡献值
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);//添加贡献记录
662
+            $gongxian_data = [
663
+                "uid"           =>$user_id,
664
+                "number"  =>    $inc_score,
665
+                "addtime"       =>time(),
666
+                "status"        =>-1,
667
+                "order_type"    =>$type_shop,
668
+                "order_id"      =>$order_sn,
669
+                "mark"          =>"购买三方商品赠送贡献值",
670
+                "desc"          =>'',
671
+                "surplus"       =>$surplusgongxian,
672
+                "type"          =>1
673
+            ];
674
+
675
+//            $gongxian_data['uid'] = $user_id;
676
+//            $gongxian_data['number'] = $inc_score;
677
+//            $gongxian_data['addtime'] = time();
678
+//            $gongxian_data['status'] = -1;
679
+//            $gongxian_data['order_type'] = $type_shop;
680
+//            $gongxian_data['order_id'] = $order_sn;
681
+//            $gongxian_data['mark'] = "购买三方商品赠送贡献值";
682
+//            $gongxian_data['desc'] = '';
683
+//            $gongxian_data['surplus'] = $user_score + $inc_score;
684
+//            $gongxian_data['type'] = 1;
685
+//            $gongxian_data['pm'] = 1;
686
+//            $gongxian_data['source_type'] =3;
687
+
688
+
689
+            Db::name("user_sign_gongxian")->insert($gongxian_data);//添加贡献记录
690
+            log::info("===添加完积分和养老金");
691
+
656 692
 
657 693
 //
658 694
 //            Db::name('user')->where('uid', $user_id)->inc('score', $inc_score)->update();
659 695
 //            Db::name('user')->where('uid', $user_id)->inc('contribute', $inc_score)->update();
660
-            Db::commit();
696
+
661 697
 
662 698
 //            $now_score= Db::name('user')->where('uid',$user_id)->value('now_score_estimate');
663 699
 //            $now_score_no= Db::name('user')->where('uid',$user_id)->value('now_score');
@@ -693,8 +729,7 @@ class UserThirdRepository extends BaseRepository
693 729
 //            Db::name('integral_log')->insert($insertDta);
694 730
 //            Db::name('user_bill')->insert($billData);
695 731
 
696
-        }  catch (\Exception $e) {
697
-            Db::rollback();
732
+        }  catch (Exception $e) {
698 733
             return app("json")->fail($e->getMessage());
699 734
         }
700 735
     }

+ 20 - 16
app/controller/api/store/product/DaTaoKe.php

@@ -215,7 +215,7 @@ class DaTaoKe
215 215
     public function getOrder()
216 216
     {
217 217
         try {
218
-            $startTime = date("Y-m-d H:i:00", strtotime("-20 minutes"));
218
+            $startTime = date("Y-m-d H:i:00", strtotime("-50 minutes"));
219 219
             $endTime = date("Y-m-d H:i:00");
220 220
             $url = 'https://openapi.dataoke.com/api/tb-service/get-order-details';
221 221
             $queryTypes = [1, 2, 3];//1:按照订单淘客创建时间查询,2:按照订单淘客付款时间查询,3:按照订单淘客结算时间查询
@@ -367,30 +367,34 @@ class DaTaoKe
367 367
     {
368 368
         $orderThird = app()->make(UserThirdRepository::class);
369 369
         foreach ($formatLists as $k => $order) {
370
+            log::info("=++++==taobaoorder=====+++");
370 371
             if (empty($order)) continue;
371 372
             //判断数据库有无此订单
372 373
             $localOrder = TbOrderModel::getInstance()->getOne(['order_sn' => $order['order_sn']]);
373 374
             if (empty($localOrder)) {
374 375
                 //订单写入数据库,bill_end_time再格式化订单的时候已经加入,所以写入订单的时候就不需要在计算了
375 376
                 $localOrder = TbOrderModel::create($order);
377
+                    //预估养老金
378
+                log::info("===待进入养老金");
379
+                $orderThird->yuguOrder(
380
+                    $localOrder['order_tb_id'],
381
+                    $localOrder['commission'],
382
+                    $localOrder['uid'],
383
+                    $localOrder['order_sn'],
384
+                    5,
385
+                    'order_tb');
386
+                //预估积分
387
+                log::info("===待进入积分");
388
+                $orderThird->yuguJifen(
389
+                    $localOrder['commission'],
390
+                    $localOrder['uid'],
391
+                    $localOrder['order_sn'],
392
+                    5
393
+                );
376 394
             } else {
377 395
                 $localOrder->save($order);//更新订单信息
378 396
             }
379
-            //预估养老金
380
-            $orderThird->yuguOrder(
381
-                $localOrder['order_tb_id'],
382
-                $localOrder['commission'],
383
-                $localOrder['uid'],
384
-                $localOrder['order_sn'],
385
-                5,
386
-                'order_tb');
387
-            //预估积分
388
-            $orderThird->yuguJifen(
389
-                $localOrder['commission'],
390
-                $localOrder['uid'],
391
-                $localOrder['order_sn'],
392
-                5
393
-            );
397
+
394 398
         }
395 399
 
396 400
     }

+ 4 - 2
app/controller/api/store/product/TaoKe.php

@@ -30,8 +30,10 @@ class TaoKe extends BaseController
30 30
     public function __construct(App $app)
31 31
     {
32 32
         parent::__construct($app);
33
-        $this->clientId = '37d1fa73af80497ba17bc39ed832310d';
34
-        $this->clientSecret = '0654e9101c6cb9d1cd7379e91f596027b3d4d5d7';
33
+//        $this->clientId = '37d1fa73af80497ba17bc39ed832310d';
34
+//        $this->clientSecret = '0654e9101c6cb9d1cd7379e91f596027b3d4d5d7';
35
+        $this->clientId = 'e87a7f3bea3d4866be1ebcd6297c236f';
36
+        $this->clientSecret = 'bc906432b1db7f2c417fa4e7f258d3b29374d464';
35 37
         $this->userThird = app()->make(UserThirdRepository::class);
36 38
     }
37 39