Browse Source

代理奖

lizhen_gitee 2 weeks from now
parent
commit
bc0c9bb38b
1 changed files with 60 additions and 5 deletions
  1. 60 5
      application/api/controller/Demo.php

+ 60 - 5
application/api/controller/Demo.php

@@ -52,21 +52,21 @@ class Demo extends Api
      * 订单额,返利比例
      * $table : offline_shop ,
      * */
-    public function test1($order_amount,$rate,$user_id,$shop_id,$table)
+    public function test1($total_amount,$back_rate,$user_id,$shop_id,$table_name)
     {
         //3-20%
-        $amount = bcdiv(bcmul($order_amount,$rate,2),100,2);
+        $amount = bcdiv(bcmul($total_amount,$back_rate,2),100,2);
 
         //5倍
-        $back_double = config('site.back_double');
-        $amount = bcmul($amount,$back_double,2);
+//        $back_double = config('site.back_double');
+//        $amount = bcmul($amount,$back_double,2);
 
         //商务 + 锁客 + 网体 + 省代 + 市代 + 区代 = 40% (大约40%,具体看多少看各级配置)
 
         //商务 发给门店的上级  收益
         $shangwu_rate = config('site.back_shangwu');
         $shangwu_amount = bcdiv(bcmul($amount,$shangwu_rate,2),2);
-        $shangwu_invite_id = Db::name($table)->where('id',$shop_id)->value('invite_id');
+        $shangwu_invite_id = Db::name($table_name)->where('id',$shop_id)->value('invite_id');
 
         //发钱给 $shangwu_invite_id
         if($shangwu_invite_id && $shangwu_amount > 0){
@@ -92,6 +92,61 @@ class Demo extends Api
 
     }
 
+    //每月初执行,跑代理辅助表,把上个月的数据全部推送到 代理队列
+    public function task_agent(){
+        $last_month =  date('Ym',strtotime(date('Y-m-01')) - 86400); //上个月一号,202502
+
+        $agent_month = Db::name('agent_month')->where('month_date',$last_month)->where('status',0)->column('id');
+
+        //推送到代理job
+
+        //修改状态
+        Db::name('agent_month')->where('id','IN',$agent_month)->update([
+            'status'     => 1,
+            'updatetime' => time(),
+        ]);
+    }
+
+    //代理job,跑完代理队列里的每一条
+    public function job_agent($agent_month_id){
+
+        $agent_month = Db::name('agent_month')->where('id',$agent_month_id)->find();
+        if($agent_month['status'] != 1){
+            //结束
+            return;
+        }
+
+        $area = Db::name('shopro_data_area')
+            ->where('id','IN',[$agent_month['province_id'],$agent_month['city_id'],$agent_month['district_id']])
+            ->where('user_id','>',0)
+            ->where('back_rate','>',0)
+            ->select();
+
+        if(empty($area)){
+            //结束
+            return;
+        }
+
+        //省市县执行三次
+        foreach($area as $key => $agent){
+
+            $agent_money = bcdiv(bcmul($agent_month['back_amount'],$agent['back_rate'],2),100,2);
+
+            //发钱
+            if($agent_money > 0){
+                $agent['user_id'];
+            }
+        }
+
+        //状态改为已发放
+        Db::name('agent_month')->where('id',$agent_month_id)->update([
+            'status' => '2',
+            'exec_time' => time(),
+        ]);
+
+
+    }
+
     /**
      * 需要登录的接口
      *