afa 10 сар өмнө
parent
commit
9fabfc9e90

+ 6 - 6
application/admin/view/general/announcement/index.html

@@ -7,12 +7,12 @@
                 <div class="widget-body no-padding">
                     <div id="toolbar" class="toolbar">
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
-                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('general/banner/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
-                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('general/banner/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
-                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('general/banner/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('general/announcement/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('general/announcement/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('general/announcement/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
                         
 
-                        <div class="dropdown btn-group {:$auth->check('general/banner/multi')?'':'hide'}">
+                        <div class="dropdown btn-group {:$auth->check('general/announcement/multi')?'':'hide'}">
                             <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
                             <ul class="dropdown-menu text-left" role="menu">
                                 <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
@@ -23,8 +23,8 @@
                         
                     </div>
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
-                           data-operate-edit="{:$auth->check('general/banner/edit')}"
-                           data-operate-del="{:$auth->check('general/banner/del')}"
+                           data-operate-edit="{:$auth->check('general/announcement/edit')}"
+                           data-operate-del="{:$auth->check('general/announcement/del')}"
                            width="100%">
                     </table>
                 </div>

+ 3 - 1
application/api/command/SendBonusRewards.php

@@ -30,7 +30,9 @@ class SendBonusRewards extends Command
         /*** 发放团队算力奖励 ***/
         $output->writeln("开始发放团队算力奖励:");
 
-        $log_id = (new BonusRewards())->powerRewards();
+        $model = new BonusRewards();
+        
+        $model->allowanceRewards();
 
         $output->info("SendTeamRewards ok!");
     }

+ 0 - 2
application/api/config.php

@@ -3,6 +3,4 @@
 //配置文件
 return [
     'exception_handle'        => '\\app\\api\\library\\ExceptionHandle',
-
-    'transfes_txt' => '收取交易额的百分之一'
 ];

+ 3 - 7
application/api/controller/Home.php

@@ -72,13 +72,8 @@ class Home extends Api
         //更新库存
         $productPopular::setUpdateStatus();
         // 热销
-        $resp['product_list'] = $productPopular->alias('a')
-           ->join("product_list b", "a.product_id = b.id", "left")
-           ->field('a.id,'.'b.'.$this->lan.'_name as name,a.product_id,b.thum as img_url,price,cost_price,stock,num,start_time,end_time')
-           ->limit(2)
-           ->where('a.status', '<', $productPopular::STOP)
-           ->order('a.weigh desc')
-           ->select();
+        $resp['product_list']  = $productPopular->with('productsList')->where('product_popular.status', '<', $productPopular::STOP)->limit(2)
+           ->order('start_time asc,weigh desc')->select();
 
         // 转让 
         $resp['transfer_list'] = $productTransfer->alias('a')
@@ -106,6 +101,7 @@ class Home extends Api
     public function getPopularInfo(ProductPopular $productPopular, ProductOrder $productOrder)
     {
         try {
+            
             $ids = $this->request->post('ids/d', 0);
             $product_id = $this->request->post('product_id/d', 0);
             if(empty($ids)) throw new Exception(__("Parameter error"));

+ 21 - 47
application/api/controller/Order.php

@@ -49,18 +49,10 @@ class Order extends Api
             if($order_info->stock == 0 || time() >= $order_info->end_time) throw new Exception(__("抢购已结束"));
             //批量地区添加
             foreach ($areaArr as $item) {
-                       
-                $order_data['order_id']  = $params['order_id'];
-                $order_data['product_id']= $params['product_id'];
-                $order_data['price']     = $order_info['price'];
-                $order_data['type_id']   = $productOrder::Popular;
-                $order_data['area_id']   = $item;
-                $order_data['order_no']  = getOrderSN('R');
-                $order_data['user_id']   = $this->auth->id;
-                $order_data['status']    = $productOrder::Paid;
-                $order_data['num']       = 1;
                 // 生成订单
-                $productOrder->create($order_data);
+                $order_info['product_id']= $params['product_id'];
+                $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Popular, $this->auth->id, 0, getOrderSN('R'), 0);
+
                 //修改区域状态
                 $productArea->where('id', $item)->setField('status', ProductLists::STOP);
             }
@@ -69,9 +61,13 @@ class Order extends Api
 
             //直推收益: pv* ×10%
             if($order_info['pv'] > 0 && $this->auth->parent_id > 0 && $userModel::getUserRwaNum($this->auth->parent_id) > 0){
-                $pv = bcmul($order_info['pv'], getConfig('pv_rate'), 2);
+                $pv = bcmul(($order_info['pv'] * $areaNum), getConfig('pv_rate'), 2);
                 $ledgerWalletModel->changeWalletAccount($this->auth->parent_id, Asset::TOKEN, $pv, $ledgerWalletModel::Direct, $this->auth->id);
+                //社区奖励
+                $pvs = bcmul(($order_info['pv'] * $areaNum), config('community_ratio'), 2);
+                $userModel::setCommunityRewards($this->auth->id, $pvs, Asset::TOKEN);
             }
+
             //更新Rwa持有数量
             $userModel->updateForRwaNum($this->auth->id, $areaNum, '+');
             //扣除库存
@@ -99,15 +95,13 @@ class Order extends Api
         if(!$validate->scene('pick')->check($params)) $this->error($validate->getError());
         $order_info = $productOrder->where('id', $params['order_id'])->find();
         if(empty($order_info)) $this->error( __("参数有误,无可用产品"));
-        $order_data['name']     = $params['name'];
-        $order_data['phone']    = $params['phone'];
-        $order_data['address']  = $params['address'];
-        $order_data['order_id'] = $params['order_id'];
+
         // 启动事务
         Db::startTrans();
         try {
             // 生成订单
-            $userArea->create($order_data);
+            $userArea->create(['name'=>$params['name'], 'phone'=>$params['phone'],'address'=>$params['address'],'order_id'=>$params['order_id']]);
+
             //扣除Rwa数量
             $userModel->updateForRwaNum($order_info->user_id, 1, '-');
 
@@ -145,9 +139,6 @@ class Order extends Api
             $feeAmount = bcmul($params['price'], $fee, 2) ;
             $productTransfer::setTransferOrder($this->auth->id, $order_info['product_id'], $order_info['area_id'], $feeAmount, $params);
 
-            //扣除Rwa有效
-            $userModel->updateForRwaNum($order_info['user_id'], 1, '-');
-
             //修改状态
             $order_info->status = $productOrder::Transferred;
             $order_info->save();
@@ -177,22 +168,14 @@ class Order extends Api
             $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
             if(bccomp($order_info['price'], $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
 
-            $order_data['order_id']  = $params['order_id'];
-            $order_data['product_id']= $order_info['product_id'];
-            $order_data['type_id']   = $productOrder::Transfer;
-            $order_data['status']    = $productOrder::Paid;
-            $order_data['area_id']   = $order_info['area_id'];
-            $order_data['order_no']  = getOrderSN('Z');
-            $order_data['user_id']   = $this->auth->id;
-            $order_data['from_user'] = $order_info['user_id'];
-            $order_data['price']     = $order_info['price'];
-            $order_data['fees']      = $order_info['fees'];
-            $order_data['num']       = 1;
-            
             // 生成订单
-            $productOrder->create($order_data);
+            $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Transfer, $this->auth->id, $order_info['user_id'], getOrderSN('Z'), $order_info['fees']);
+           
             //扣除余额记录 
             $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Payment, $order_info['user_id']);
+            
+            //扣除Rwa有效
+            $userModel->updateForRwaNum($order_info['user_id'], 1, '-');
           
             //增加转让人余额
             $amount = bcsub($order_info['price'], $order_info['fees'], 2);
@@ -236,24 +219,15 @@ class Order extends Api
             if(bccomp($fees, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
      
             //添加记录
-            $order_data['order_id']  = $params['order_id'];
-            $order_data['product_id']= $order_info['product_id'];
-            $order_data['type_id']   = $productOrder::Giveaway;
-            $order_data['status']    = $productOrder::Paid;
-            $order_data['area_id']   = $order_info['area_id'];
-            $order_data['order_no']  = getOrderSN('G');
-            $order_data['user_id']   = $user['id'];
-            $order_data['from_user'] = $this->auth->id;
-            $order_data['price']     = $order_info['price'];
-            $order_data['fees']      = $fees;
-            $order_data['num']       = 1;
-
-            $productOrder::create($order_data);
+            $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Giveaway, $user['id'], $this->auth->id, getOrderSN('G'), $fees);
+
+            //对方Rwa+1
+            $userModel->updateForRwaNum($user['id'], 1, '+');
 
             //扣除手续费
             $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$fees, $ledgerWalletModel::Giveaway, $user['id']);
 
-            //扣除Rwa有效
+            //扣除Rwa有效-1
             $userModel->updateForRwaNum($this->auth->id, 1, '-');
 
             $order_info->status= $productOrder::Closure; 

+ 5 - 8
application/api/controller/Product.php

@@ -2,7 +2,9 @@
 
 namespace app\api\controller;
 
+use think\Db;
 use app\common\controller\Api;
+use app\common\model\ProductLists;
 use app\common\model\ProductsModel;
 use app\common\model\ProductPopular;
 use app\common\model\ProductTransfer;
@@ -22,18 +24,13 @@ class Product extends Api
     /**
      * 热销列表   
      */
-    public function getPopularList(ProductsModel $productsModel, ProductPopular $productPopular)
+    public function getPopularList(ProductsModel $productsModel, ProductPopular $productPopular, ProductLists $productLists)
     {
         $list = $productsModel->where('status', 1)->column('id,'.$this->lan.'_title as title');
         $resp = array();
         foreach ($list as $kk =>$val) {
-            $pro = $productPopular->alias('a')
-                ->join("product_list b", "a.product_id = b.id", "left")
-                ->field('a.id,'.'b.'.$this->lan.'_name as name,a.product_id,b.thum as img_url,price,cost_price,stock,num,start_time,end_time')
-                ->where('a.status', '<', $productPopular::STOP)
-                ->where('b.type_id', $kk)
-                ->order('a.weigh desc')
-                ->select();
+            $pro = $productLists->with('productpopular')->where('productpopular.status', '<', $productPopular::STOP)->where('product_lists.type_id', $kk)
+            ->order('productpopular.start_time', 'asc')->select();
             $resp[] = ['type_id'=>$kk,'title'=>$val, 'product'=>$pro];
         }
         $this->success('', $resp);

+ 4 - 1
application/api/lang/en.php

@@ -18,7 +18,10 @@ return [
     '分享'                                   => 'Share',
     '退回'                                   => 'Return',
     '赠送'                                   => 'Gift fee',
-    '直推收益'                               => 'Direct income',
+    '布道津贴'                               => 'Preaching allowance',
+    '社区津贴'                               => 'Community allowance',
+    '服务津贴'                               => 'Service allowance',
+    '共创津贴'                               => 'Co creation allowance',
     '系统调整'                               => 'System Adjustments',
     '赠送支出'                               => 'Gift Expenses',
     '赠送收款'                                                                    => 'Gift Receipt',

+ 4 - 1
application/api/lang/zh-cn.php

@@ -111,6 +111,9 @@ return [
     '赠送支出'                                                                    => '赠送支出',
     '赠送收款'                                                                    => '赠送收款',
     '抢购未开始'                                                                  => '抢购未开始',
-
+    '布道津贴'                                                                    => '布道津贴',
+    '社区津贴'                                                                    => '社区津贴',
+    '服务津贴'                                                                    => '服务津贴',
+    '共创津贴'                                                                    => '共创津贴',
 
 ];

+ 40 - 250
application/common/logic/BonusRewards.php

@@ -5,8 +5,8 @@ namespace app\common\logic;
 
 use app\common\model\EtcWithdrawRecordModel;
 use app\common\model\LedgerWalletModel;
-use app\common\model\OfflineRechargeRecordModel;
-use app\common\model\ParametersModel;
+use app\common\model\ProductOrder;
+use app\common\model\UserModel;
 use app\common\model\TimedTaskLogModel;
 use app\common\model\UserPathModel;
 use fast\Action;
@@ -30,105 +30,63 @@ class BonusRewards
      * @var array
      */
     private array $rewards_type = [
-        'community' => [
-            'type_id' => 1,
-            'type_name' => "社区建设津贴"
-        ],
         'service' => [
-            'type_id' => 2,
-            'type_name' => "服务津贴"
+            'type_id' => 1,
+            'type_name' => "服务共创津贴"
         ],
         'together' => [
-            'type_id' => 3,
+            'type_id' => 2,
             'type_name' => "共创津贴"
         ]
     ];
 
     /**
-     * 发放团队算力奖励
-     * 1.先判断最后一次发放时间,把该时间至当前时间的所有日期内的数据都发放了
-     * 2.从算力明细表,取当日算力租赁数据,写入团队统计表,统计每人当日团队新增算力
-     * 3.遍历当日统计表,计算每人理论应得算力奖励
-     * 4.发放奖励,理论奖励-团队已发放=自身奖励金额
+     * 社区建设津贴
+     * 1.直推几个有效用户,拿几层,最高10层;每次收益3.5%
+     * 2.举例:会员A直推了三个有效用户,则会员A下三代内,每个用户购买RWA茶时,A都会收益对应PV的3.5%;
      */
-    public function powerRewards()
+    public function allowanceRewards()
     {
-        $date = $this->getExeDate($this->rewards_type['community']['type_id']);
+        $date = $this->getExeDate($this->rewards_type['service']['type_id']);
         if(empty($date))  return "本次没有可用时间";
         
-
+      
         //创建定时任务执行日志
         $TimedTaskLog = new TimedTaskLogModel();
         $log_id = $TimedTaskLog->insertGetId([
-            'type_id'       => $this->rewards_type['community']['type_id'],
-            'type_name'     => $this->rewards_type['community']['type_name'],
+            'type_id'       => $this->rewards_type['service']['type_id'],
+            'type_name'     => $this->rewards_type['service']['type_name'],
             'date_time'     => $date,
             'create_time'   => date('Y-m-d H:i:s'),
 
         ]);
 
-        $between_time = [strtotime($date), strtotime($date) + 86400];
-
-        //读取当日新增数据,按用户分组统计
-        $recharge_record = DB::table('offline_recharge_record')
-            ->field('user_id, SUM(amount) as amount')
-            ->whereBetween('create_time', $between_time)
-            ->where('order_type', 1)
-            ->where('status', 1)
-            ->group('user_id')
-            ->select();
-
-        if(empty($recharge_record)){
+        //读取当日新增数据
+        $bonus = self::getDayEarnings($date);
+        if(empty($bonus)){
             (new Output())->writeln("本次没有可用新增数据:" . $date);
-
             return $log_id;
         }
-
-        //1.统计团队新增业绩
+        $ledgerWalletModel = new LedgerWalletModel();
+        //1.服务津贴
+        $recharge_record = UserModel::alias('a')
+        ->join('user b', 'a.parent_id = b.id', 'left')
+        ->field('a.id,sum(a.rwa_num) as total_amount')->having('total_amount >= 10')->group("a.id")
+        ->select();
+        $recharge_count  = count($recharge_record);//总人数
+        $pv = bcdiv(bcmul($bonus, config('service_ratio')), $recharge_count, 2); //收益
         foreach ($recharge_record as $info) {
-            $path = (new UserPathModel())
-                ->where('user_id', $info['user_id'])
-                ->column('parent_id');
-            $path[] = $info['user_id'];
-
-            $this->createData($path, $info['amount'], $date);
+            $ledgerWalletModel->changeWalletAccount($info->id, Asset::TOKEN, $pv, $ledgerWalletModel::Service, 0);
         }
-
-        //2.计算每人理论收益
-        $team_level_config = DB::table('team_level')
-            ->field('level_id, compute_require, compute_incentive')
-            ->select();
-
-        $rewards_record = DB::table('team_rewards')
-            ->field('id, user_id, today_power, date_time')
-            ->where('date_time', $date)
-            ->where('status', 0)
-            ->select();
-
-        foreach ($rewards_record as $info) {
-            $this->calculateRewards($info, $team_level_config);
-        }
-
-        //3.发放收益
-        $rewards_send = DB::table('team_rewards')
-            ->field('id, user_id, commission, team_commission, date_time')
-            ->where('date_time', $date)
-            ->where('status', 0)
-            ->select();
-        foreach ($rewards_send as $info) {
-            $amount = $info['commission'] - $info['team_commission'];
-            if($amount > 0){
-                (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::POWER, $amount / 8, Action::PowerProfit);
+        //2.共享津贴收益
+        $rewards_record = UserModel::where('rwa_num', '>', 4)->column('id');
+        if(!empty($rewards_record )){
+            $rewards_count  = count($rewards_record);//总人数
+            $pvs = bcdiv(bcmul($bonus, config('together_ratio')), $rewards_count, 2); //收益
+            foreach ($rewards_record as $info) {
+                $ledgerWalletModel->changeWalletAccount($info, Asset::TOKEN, $pvs, $ledgerWalletModel::Together, 0);
             }
-            DB::table('team_rewards')
-                ->where('id', $info['id'])
-                ->update([
-                    'send_commission' => $amount,
-                    'status' => 1,
-                    'update_time'   => date('Y-m-d H:i:s')
-                ]);
         }
-
         return $log_id;
     }
 
@@ -336,187 +294,20 @@ class BonusRewards
         return $log_id;
     }
 
-    /**
-     * 团队业绩分红
-     * 1.提取社区长等级的会员列表
-     * 2.再计算当日新增业绩 * 0.08
-     * 3.取20%发放算力,剩余发放U
-     */
-    public function teamRewards()
-    {
-        $date = $this->getExeDate($this->rewards_type['team']['type_id']);
-
-        if(empty($date)){
-            return "本次没有可用时间";
-        }
-
-        //创建定时任务执行日志
-        $TimedTaskLog = new TimedTaskLogModel();
-        $log_id = $TimedTaskLog->insertGetId([
-            'type_id'       => $this->rewards_type['team']['type_id'],
-            'type_name'     => $this->rewards_type['team']['type_name'],
-            'date_time'     => $date,
-            'create_time'   => date('Y-m-d H:i:s'),
-        ]);
-
-        $between_time = [strtotime($date), strtotime($date) + 86400];
-
-        //查找有团队长等级的会员
-        $community_user_list = DB::table('user')
-            ->field('id,market_level_id')
-            ->where('market_level_id', MembershipLevel::CommunityLeader)
-            ->select();
-
-        if(empty($community_user_list)){
-            (new Output())->writeln("本次没有可用会员数据:" . $date);
-            return $log_id;
-        }
-
-        $market_level_arr = [];//所有社区长,以user_id 为键名的数组
-        $market_user_id_arr = [];//所有社区长,user_id 数组
-        foreach ($community_user_list as $info) {
-            $market_level_arr[$info['id']] = [
-                'user_id'    => $info['id'],//自身ID
-                'today_usdt' => 0,//当日团队新增业绩USDT
-                'user_power' => 0,//自身收益
-                'user_usdt'  => 0,//自身收益
-                'team_power' => 0,//下级团队收益
-                'team_usdt'  => 0,//下级团队收益
-                'same_power' => 0,//同级奖收益
-                'same_usdt'  => 0,//同级奖收益
-            ];
-            $market_user_id_arr[] = $info['id'];
-        }
-
-        $community_rewards = (new ParametersModel())->getValue('communityTeamRewards'); //社区长分红参数 数据格式为:0.08:0.2:0.8
-        $community_rewards_arr = explode(':', $community_rewards);
-        dump('团队分红参数配置');
-        dump($community_rewards_arr);
-
-        $performance_list = (new \app\admin\model\TeamRewards())
-            ->where('user_id', 'in', $market_user_id_arr)
-            ->where('date_time', $date)
-            ->select();
-        foreach ($performance_list as $item){
-            if($item['today_power'] > 0){
-                $amount = $community_rewards_arr[0] * $item['today_power'];//取新增业绩的8%
-                if($amount < 1){
-                    dump("会员:" . $item['user_id'] . ",本次没有可用新增数据:" . $date);
-                    continue;
-                }
-
-                $market_level_arr[$item['user_id']]['today_usdt'] = $item['today_power'];//u折成算力
-                $market_level_arr[$item['user_id']]['user_power'] = $amount * $community_rewards_arr[1] / 8;//u折成算力
-                $market_level_arr[$item['user_id']]['user_usdt']  = $amount * $community_rewards_arr[2];
-
-                $parent_ids = (new UserPathModel())
-                    ->where('user_id', $item['user_id'])
-                    ->order('distance')
-                    ->select();
-                $i = 0;
-                dump($item['user_id'] . '的上级');
-                foreach ($parent_ids as $uid){
-                    if(isset($market_level_arr[$uid['parent_id']])){//向上级的团队收益中累计本次收益,方便后面对应的上级减掉
-                        dump($uid['parent_id']);
-
-                        if($i == 0){//只累计给首个上级
-                            dump($uid['parent_id'] . '累计上级');
-
-                            $market_level_arr[$uid['parent_id']]['team_power'] += $market_level_arr[$item['user_id']]['user_power'];
-                            $market_level_arr[$uid['parent_id']]['team_usdt']  += $market_level_arr[$item['user_id']]['user_usdt'];
-                            $i++;
-                        }
-                        dump($uid['parent_id'] . '累计平级');
-                        //每个同级上级都有平级奖
-                        $market_level_arr[$uid['parent_id']]['same_power'] += $market_level_arr[$item['user_id']]['user_power'] * 0.05;//5%的平级奖
-                        $market_level_arr[$uid['parent_id']]['same_usdt']  += $market_level_arr[$item['user_id']]['user_usdt'] * 0.05;//5%的平级奖
-                    }
-                }
-
-                dump($market_level_arr[$item['user_id']]);
-                //dump(['用户ID:' . $info['id'],'新增业绩:' . $recharge_power, '算力收益:' . $reward_power, 'U收益:' . $reward_usdt]);
-            }
-        }
-
-        dump('进展过半');
-        Log::info($date . ' - 社区长分红');
-        foreach ($market_level_arr as $info) {
-            Log::info(json_encode($info));
-            $power = $info['user_power'] - $info['team_power'];
-            $usdt  = $info['user_usdt'] - $info['team_usdt'];
-            //社区长团队分红
-            if($power > 0){
-                (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::POWER, $power, Action::PowerCommunityBonusAward);
-            }
-            if($usdt > 0){
-                (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::USDT, $usdt, Action::UsdtCmmunityBonus);
-            }
-            //平级奖励
-            if($info['same_power'] > 0){
-                (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::POWER, $info['same_power'], Action::PowerSameBonus);
-            }
-            if($info['same_usdt'] > 0){
-                (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::USDT, $info['same_usdt'], Action::UsdtSameBonus);
-            }
-        }
-
-        return $log_id;
-    }
 
     /**
-     * 拨币
-     * 向会员发放ETC
-     * 每8000算力每天收益93,即每算力每天收益 93/8000=0.011625人民币
-     * 实际发放的时候,发放ETH,根据当日价格,折算相应ETH,比如1ETH=12300RMB,则每算力为:0.011625/12300=0.000000945122ETH
+     * 获取当日收益 Daily earnings
      */
-    public function AllocateEtc()
-    {
-        $date = $this->getExeDate($this->rewards_type['allocate']['type_id']);
-
-        if(empty($date)){
-            return "本次没有可用时间";
-        }
-
-        //创建定时任务执行日志
-        $TimedTaskLog = new TimedTaskLogModel();
-        $log_id = $TimedTaskLog->insertGetId([
-            'type_id'       => $this->rewards_type['allocate']['type_id'],
-            'type_name'     => $this->rewards_type['allocate']['type_name'],
-            'date_time'     => $date,
-            'create_time'   => date('Y-m-d H:i:s'),
-        ]);
-
+    private static function getDayEarnings(string $date)
+    {   
         $between_time = [strtotime($date), strtotime($date) + 86400];
+        //读取当日新增数据
+        return ProductOrder::where('type_id', ProductOrder::Popular)->where('status', ProductOrder::Paid)->whereBetween('create_time', $between_time)->sum('price');
+    }
 
-        //查找会员资产列表
-        $info_list = DB::table('ledger_wallet')
-            ->alias('w')
-            ->join('user u','u.id = w.user_id')
-            ->field('user_id,power,server_power')
-            ->where('power', '>', 0)
-            ->where('effective_time', '<', strtotime($date) - 1209600) //报单十五天后才有收益
-            ->select();
-
-        if(empty($info_list)){
-            (new Output())->writeln("本次没有可用会员数据:" . $date);
-            return $log_id;
-        }
-
-        $etc_usdt_price = (new EtcWithdrawRecordModel)->getEtcPrice();
-
-        $power_usdt_price = 0.0038;//每算力每日获得Usdt的数量 没8000算力13U除过来的
-        $power_etc_price = round($power_usdt_price / $etc_usdt_price, 6);//每算力每日获得ETC的数量
-
-        foreach ($info_list as $info) {
-            $amount = ($info['power'] + $info['server_power']) * $power_etc_price;
-            dump(['用户ID:' . $info['user_id'],'拨币量为:' . $amount]);
-
-            //发放
-            (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::TOKEN, $amount, Action::TokenAllocateEtc);
-        }
+  
 
-        return $log_id;
-    }
+  
 
     /**
      * 获取可用日期
@@ -525,7 +316,6 @@ class BonusRewards
     protected function getExeDate($type_id = 1)
     {
         $today = date('Y-m-d',strtotime("-1day"));//当前时间减一天为最后一次可用时间
-
         $dateInfo = DB::table('timed_task_log')
             ->where('type_id' ,$type_id)
             ->where('status', 1)

+ 10 - 4
application/common/model/LedgerWalletModel.php

@@ -35,8 +35,11 @@ class LedgerWalletModel extends Model
     const Giveaway          = 7;
     const Direct            = 8;
     const System            = 9;
-    const GiftPay           = 10; //Gift Expenses
+    const GiftPay           = 10; //赠送支出
     const GiftReceipt       = 11;
+    const Community         = 12; //社区津贴
+    const Service           = 13; //服务津贴
+    const Together          = 14; //共创津贴
     /*
      * 支付状态
      * 0未支付 100支付中 200支付成功 400支付失败
@@ -51,10 +54,13 @@ class LedgerWalletModel extends Model
         self::Share             => '分享',
         self::Return            => '退回',
         self::Giveaway          => '赠送手续费',
-        self::Direct            => '直推收益',
+        self::Direct            => '布道津贴', //直推
         self::System            => '系统调整',
         self::GiftPay           => '赠送支出',
         self::GiftReceipt       => '赠送收款',
+        self::Community         => '社区津贴',
+        self::Service           => '服务津贴',
+        self::Together          => '共创津贴',
     ];
 
     public static function getWalletChaBao($userID)
@@ -82,8 +88,8 @@ class LedgerWalletModel extends Model
     public static function getStatusList()
     {
         return [self::Popular => __('热销支付'), self::Payment  => __('转让支付'), self::Receive => __('转让收款'), self::Recharge => __('充值'), 
-        self::Withdraw  => __('提现'), self::Share => __('分享'), self::Return => __('退回'), self::Giveaway => __('赠送'), self::Direct => __('直推收益'),
-        self::System => __('系统调整'),self::GiftPay => __('赠送支出'),self::GiftReceipt => __('赠送收款')];
+        self::Withdraw  => __('提现'), self::Share => __('分享'), self::Return => __('退回'), self::Giveaway => __('赠送'), self::Direct => __('布道津贴'),
+        self::System => __('系统调整'),self::GiftPay => __('赠送支出'),self::GiftReceipt => __('赠送收款'), self::Community => __('社区津贴'), self::Service => __('服务津贴'), self::Together => __('共创津贴')];
     }
 
     /**

+ 7 - 0
application/common/model/ProductLists.php

@@ -43,6 +43,13 @@ class ProductLists extends Model
         return $this->hasOne('ProductsModel', 'id', 'type_id', [], 'LEFT')->setEagerlyType(0);
     }
 
+    //抢购 ProductPopular
+    public function productpopular()
+    {
+        return $this->hasOne('ProductPopular', 'product_id', 'id', [], 'LEFT')->order('start_time')->setEagerlyType(0);
+    }
+
+        
 
     protected static function init()
     {

+ 24 - 0
application/common/model/ProductOrder.php

@@ -49,6 +49,30 @@ class ProductOrder extends Model
         self::Closure           => '关闭',
     ];
 
+    /**
+     * @param int $orderId 订单id
+     * @param array $orderInfo 订单详情
+     * @param int   $typeId    订单类型
+     * @param int   $userId    用户id
+     * @param int   $fromUser  来源id
+     * @param float $fees      手续费
+     */
+    public static function setCreateOrder(int $orderId, $orderInfo, $typeId, $userId, $fromUser, string $orderNo, float $fees): object
+    {
+        return self::create([
+                'order_id'   => $orderId,
+                'product_id' => $orderInfo['product_id'],
+                'type_id'    => $typeId,
+                'status'     => self::Paid,
+                'area_id'    => $orderInfo['area_id'],
+                'order_no'   => $orderNo,
+                'user_id'    => $userId,
+                'from_user'  => $fromUser,
+                'price'      => $orderInfo['price'],
+                'fees'       => $fees,
+                'num'        => 1
+        ]);
+    }
 
 
 

+ 21 - 2
application/common/model/UserModel.php

@@ -4,8 +4,9 @@ namespace app\common\model;
 
 use think\db\exception\DataNotFoundException;
 use think\db\exception\ModelNotFoundException;
+use app\common\model\UserPathModel;
 use think\Exception;
-use think\exception\DbException;
+use app\common\model\LedgerWalletModel;
 use think\Model;
 
 /**
@@ -91,5 +92,23 @@ class UserModel extends Model
         }
     }
 
-   
+
+    //社区向上发放奖励津贴
+    public static function setCommunityRewards($uid, $pv, $token)
+    {
+        $paths  = UserPathModel::where('user_id', $uid)->where('distance', '<', 11)->order('distance', 'asc')->column('distance,parent_id');
+        if (!empty($paths)) {
+            $model = new LedgerWalletModel();
+            foreach ($paths as $kk=>$item) {
+                if($kk== 1){
+                    $model->changeWalletAccount($item, $token, $pv, $model::Community, $uid);
+                }else{
+                    //间接推荐有效会员大于层级
+                    if(self::where('parent_id', $item)->where('rwa_num','>', 0)->count() >= $kk){
+                        $model->changeWalletAccount($item, $token, $pv, $model::Community, $uid);
+                    }
+                }
+            }
+        }
+    }
 }

+ 4 - 0
application/config.php

@@ -314,4 +314,8 @@ return [
     'rental'                 => [
         'invite_domain' => Env::get('rental.invitedomain', 'dapp.uaddev.tk'),
     ],
+    'transfes_txt'    => '收取交易额的百分之一',
+    'community_ratio' => 0.035,
+    'service_ratio'   => 0.05, //服务津贴
+    'together_ratio'  => 0.05, //共创津贴
 ];

+ 5 - 2
public/assets/js/backend/ledger/ledger_token_change.js

@@ -42,10 +42,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 5: '分享',
                                 6: '提现退回',
                                 7: '赠送手续费',
-                                8: '直推收益',
+                                8: '布道津贴',
                                 9: '系统赠送',
                                 10: '赠送支出',
-                                11: '赠送收款'
+                                11: '赠送收款',
+                                12: '社区津贴',
+                                13: '服务津贴',
+                                14: '共创津贴',
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },
                     ]