WIN-2308041133\Administrator 5 月之前
父节点
当前提交
13a263dfc6

+ 25 - 6
app/common/model/user/AwardLake.php

@@ -4,12 +4,13 @@ namespace app\common\model\user;
 
 use app\common\model\BaseModel;
 use app\common\repositories\user\AwardIntegralPriceRepository;
+use app\common\repositories\user\UserBillRepository;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\Exception;
 
-class Awardlake extends BaseModel
+class AwardLake extends BaseModel
 {
     public static function tablePk(): ?string
     {
@@ -18,10 +19,11 @@ class Awardlake extends BaseModel
 
     public static function tableName(): string
     {
-        return 'award_integral_price';
+        return 'award_lake';
     }
 
     /**
+     * 奖池累加
      * @param int $lake_type 奖池类型 1:节能油,2:礼包
      * @param float $order_price 订单价格
      * @param int $order_id 订单ID
@@ -84,14 +86,20 @@ class Awardlake extends BaseModel
             case 1:
                 $model = new OilLevel();
                 $field = 'oil_level';
+                $name = '节能油';
+                $title = '节能油积分分红';
                 break;
             case 2:
                 $model = new GiftLevel();
                 $field = 'gift_level';
+                $name = '礼包';
+                $title = '礼包积分分红';
                 break;
             default :
                 $model = new OilLevel();
                 $field = 'oil_level';
+                $name = '节能油';
+                $title = '节能油积分分红';
         }
         $level = $model->where('id', $lake['level'])->find();
         $levels = $model->where('grade', '>=', $level['grade'])->column('id');
@@ -104,10 +112,21 @@ class Awardlake extends BaseModel
         $real_send = 0;
         $price = app()->make(AwardIntegralPriceRepository::class)->awardIntegralPrice();  //分红积分价格
         foreach ($users as $user) {
-            //todo 添加用户积分
-
-
-
+            //todo 添加用户积分  用户分的奖励除以积分价格就是积分数量
+            $integral = bcdiv($every, $price, 2);
+            $award_integral=User::where('uid', $user['uid'])->value('award_integral');
+            $after = bcadd($award_integral, $integral, 2);
+            // 创建用户账单仓库实例
+            $make = app()->make(UserBillRepository::class);
+            $make->incBill($user['uid'], 'award_integral', 'oil_integral', [
+                'number' => $award_integral,
+                'title' => $title,
+                'balance' => $after,
+                'status' => 1,
+                'link_id' => 0,
+                'mark' => $user['nickname'] . '获得' .$name.'分红积分'.$award_integral ,
+            ]);
+            User::where('uid', $user['uid'])->update(['award_integral' => $after]);
 
 
             //todo end

+ 1 - 1
app/common/model/user/AwardLakeLog.php

@@ -14,7 +14,7 @@ class AwardLakeLog extends BaseModel
 
     public static function tableName(): string
     {
-        return 'award_integral_price';
+        return 'award_lake_log';
     }
 
 

+ 8 - 5
app/common/repositories/store/order/StoreOrderRepository.php

@@ -13,6 +13,7 @@ namespace app\common\repositories\store\order;
 
 use app\common\model\store\order\StoreCart;
 use app\common\model\store\product\Product;
+use app\common\model\user\Awardlake;
 use app\common\model\user\GiftLevel;
 use app\common\model\user\OilLevel;
 use app\controller\api\server\StoreProduct;
@@ -1099,7 +1100,7 @@ class StoreOrderRepository extends BaseRepository
                 $order_award_range = bcmul($order['pay_price'], 3, 2);
                 $after = bcadd($award_range, $order_award_range, 2);
                 $make->incBill($order['uid'], 'award_range', 'energy_saving_oil', [
-                    'number' => $order['pay_price'],
+                    'number' => $order_award_range,
                     'title' => '下单节能油获得分红额度',
                     'balance' => $after,
                     'status' => 1,
@@ -1113,7 +1114,7 @@ class StoreOrderRepository extends BaseRepository
                 $order_award_range = bcmul($order['pay_price'], 3, 2);
                 $after = bcadd($award_range, $order_award_range, 2);
                 $make->incBill($order['uid'], 'award_range', 'award_gift_pack', [
-                    'number' => $order['pay_price'],
+                    'number' => $order_award_range,
                     'title' => '下单礼包获得分红额度',
                     'balance' => $after,
                     'status' => 1,
@@ -1130,7 +1131,7 @@ class StoreOrderRepository extends BaseRepository
                 $order_award_range = bcmul($order['pay_price'], 1, 2);
                 $after = bcadd($award_range, $order_award_range, 2);
                 $make->incBill($order['uid'], 'award_range', 'ordinary', [
-                    'number' => $order['pay_price'],
+                    'number' => $order_award_range,
                     'title' => '下单普通商品获得分红额度',
                     'balance' => $after,
                     'status' => 1,
@@ -1146,14 +1147,14 @@ class StoreOrderRepository extends BaseRepository
                 $order_award_range = bcmul($order['pay_price'], 0.2, 2);
                 $after2 = bcadd($award_integral, $order_award_range, 2);
                 $make->incBill($order['uid'], 'award_integral', 'ordinary_integral', [
-                    'number' => $order['pay_price'],
+                    'number' => $order_award_range,
                     'title' => '下单普通商品获得分红积分',
                     'balance' => $after2,
                     'status' => 1,
                     'link_id' => $order['order_id'],
                     'mark' => $user['nickname'] . '成功消费普通商品' . floatval($order['pay_price']) . '元,奖励分红积分' . $order_award_range,
                 ]);
-                User::where('uid', $order['uid'])->update(['award_integral' => $after]);
+                User::where('uid', $order['uid'])->update(['award_integral' => $after2]);
             }
         }
         //份额和积分变动时触发
@@ -1164,8 +1165,10 @@ class StoreOrderRepository extends BaseRepository
 //        检测节能油或者礼包升级
         if ($type==5){
             OilLevel::checkLevel($order['uid']);
+            AwardLake::addOrderLakes(1,$order['pay_price'],$order['order_id']);
         }elseif ($type==6){
             GiftLevel::checkLevel($order['uid']);
+            AwardLake::addOrderLakes(2,$order['pay_price'],$order['order_id']);
         }
     }
 

+ 3 - 1
app/common/repositories/user/UserBillRepository.php

@@ -96,7 +96,9 @@ class UserBillRepository extends BaseRepository
         'award_integral' =>[
             'award/spread_oil_integral' =>'下级节能油订单获得分红积分',
             'award/spread_pack_integral' =>'下级礼包订单获得分红积分',
-            'award/ordinary_integral' =>'下单普通商品获得分红积分'
+            'award/ordinary_integral' =>'下单普通商品获得分红积分',
+            'award/oil_integral' =>'节能油分红积分',
+            'award/pack_integral' =>'礼包分红积分',
         ]
     ];
 

+ 6 - 0
app/controller/api/user/User.php

@@ -14,6 +14,7 @@
 namespace app\controller\api\user;
 
 
+use app\common\model\user\AwardLake;
 use app\common\repositories\store\IntegralRepository;
 use app\common\repositories\store\service\StoreServiceRepository;
 use app\common\repositories\system\CacheRepository;
@@ -745,5 +746,10 @@ class User extends BaseController
         $this->repository->updateBaseInfo($data,$user);
         return app('json')->success('修改成功');
     }
+    public function autoSend(){
+        var_dump(123456);die();
+        AwardLake::autoSend();
+        return app('json')->success('发送成功');
+    }
 
 }

+ 1 - 0
route/api.php

@@ -21,6 +21,7 @@ use think\facade\Route;
 
 Route::group('api/', function () {
     Route::any('test', 'api.Auth/test');
+    Route::get('autoSend', 'api.User/autoSend');
     //强制登录
     Route::group(function () {
         Route::get('pay/config', 'api.store.order.StoreOrder/payConfig');