Kirin 1 anno fa
parent
commit
1465619a20

+ 4 - 4
app/controller/api/v1/PublicController.php

@@ -62,16 +62,16 @@ class PublicController extends BaseController
     public function test()
     {
         $list = UserIntegral::where('add_time', 'between', [1705766400, 1705852800])->where('extract_sum_real', null)->where('type', 0)
-            ->group('link_id')->field('link_id,count(id),price,add_time')->select()->toArray();
+            ->select()->toArray();
 
         foreach ($list as $v) {
 
-            $this->dealOrderIntegral(StoreOrder::where('id', $v['link_id'])->find(), $v['price'], $v['add_time']);
+            $this->dealOrderIntegral(StoreOrder::where('id', $v['link_id'])->find(), $v['price'], $v['add_time'], $v['num'] < 0);
         }
 
     }
 
-    public function dealOrderIntegral($order, $price, $time)
+    public function dealOrderIntegral($order, $price, $time, $reCaculator)
     {
         /** @var UserAwardIntegralServices $awardIntegralService */
         $awardIntegralService = app()->make(UserAwardIntegralServices::class);
@@ -112,7 +112,7 @@ class PublicController extends BaseController
                 $send = 0;
                 while ($spread && !in_array($spread['uid'], $pass)) {
                     //先发奖,再结算等级
-                    $level = $levelServices->getUserLevel($spread['uid']);
+                    $level = $levelServices->getUserLevelBefore($spread['uid'], $time);
                     $ratio = $level['levelInfo']['group_award'] ?? 0;
                     $give_action_integral = bcdiv(bcmul($total_price, $ratio), 100, 2);
                     if ($give_action_integral > $send) {

+ 14 - 0
app/dao/user/level/UserLevelDao.php

@@ -46,6 +46,20 @@ class UserLevelDao extends BaseDao
         return $this->getModel()->where('uid', $uid)->where('is_del', 0)->where('status', 1)->field($field)->with(['levelInfo'])->order('grade desc,add_time desc')->find();
     }
 
+    /**
+     * 根据uid 获取用户会员等级详细信息
+     * @param int $uid
+     * @param string $field
+     * @return array|\think\Model|null
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getUserLevelBefore(int $uid, $addtime, string $field = '*')
+    {
+        return $this->getModel()->where('uid', $uid)->where('is_del', 0)->where('add_time', '<', $addtime)->where('status', 1)->field($field)->with(['levelInfo'])->order('grade desc,add_time desc')->find();
+    }
+
     /**
      * 获取用户等级折扣
      * @param int $uid

+ 1 - 1
app/services/user/UserAwardIntegralServices.php

@@ -221,7 +221,7 @@ class UserAwardIntegralServices extends BaseServices
     public function incIntegralAdmin(int $uid, string $price, string $total, float $order_price, int $type, string $extract_sum, int $link_id = 0, string $mark = '', $add_time = 0)
     {
         $inc_integral = bcdiv($total, $price, 5);
-        $old = UserIntegral::where('uid', $uid)->where('link_id', $link_id)->where('type', $type)->where('mark', $mark)->find();
+        $old = UserIntegral::where('uid', $uid)->where('link_id', $link_id)->where('type', $type)->whereLike('mark', '%$mark%')->find();
         if ($old) {
             $dump = '用户' . $uid . $mark . '补' . bcsub($inc_integral, $old['num'], 5);
         } else {