Jelajahi Sumber

会员升级

Kirin 11 bulan lalu
induk
melakukan
9abc43ec43

+ 55 - 19
app/jobs/integral/IntegralJob.php

@@ -6,6 +6,7 @@ use app\services\user\level\UserLevelServices;
 use app\services\user\UserAwardIntegralServices;
 use app\services\user\UserBillServices;
 use app\services\user\UserBrokerageServices;
+use app\services\user\UserMoneyServices;
 use app\services\user\UserServices;
 use crmeb\basic\BaseJobs;
 use crmeb\traits\QueueTrait;
@@ -58,6 +59,9 @@ class IntegralJob extends BaseJobs
                 if ($spread) {
                     if ($awardIntegralService->getPaySum($spread['uid']) >= 1000 || $awardIntegralService->getHourExtractPaySum($spread['uid'], 24) >= 1000) {
                         $award_ratio = sys_config('recommend_integral', 0);
+                        if ($awardIntegralService->reOrder($user['uid'], $order['id'])) {
+                            $award_ratio = sys_config('reorder_recommend_integral', 0);
+                        }
                         $give_action_integral = bcdiv(bcmul($total_price, $award_ratio), 100, 2);
                         if ($give_action_integral > 0) {
                             $extract_sum = bcmul($give_action_integral, $rate, 2);
@@ -177,6 +181,8 @@ class IntegralJob extends BaseJobs
         $awardIntegralService = app()->make(UserAwardIntegralServices::class);
         /** @var UserBrokerageServices $brokerageService */
         $brokerageService = app()->make(UserBrokerageServices::class);
+        /** @var UserMoneyServices $moneyService */
+        $moneyService = app()->make(UserMoneyServices::class);
         /** @var UserBillServices $billService */
         $billService = app()->make(UserBillServices::class);
         /** @var UserServices $userService */
@@ -212,28 +218,58 @@ class IntegralJob extends BaseJobs
                 $mark = '用户积分出局,出局时价格' . $price;
                 $res = $res && $awardIntegralService->addLake(-$real_out, $info['id'], $mark);
 
+                $to_now_money = 0;
+                $starts_return_time = sys_config('starts_return_time', 0);
+                if ($starts_return_time > 0) {
+                    $count = $awardIntegralService->search(['uid' => $user['uid'], 'type' => 0, 'status' => 1])->count();
+                    if ($count < $starts_return_time) {
+                        $to_now_money = $info['order_price'];
+                        if ($to_now_money > $real_out) {
+                            $to_now_money = $real_out;
+                        }
+                        $real_out = bcsub($real_out, $to_now_money, 2);
+                    }
+                }
+
+                if ($to_now_money > 0) {
+                    $balance = bcadd($user['now_money'], $to_now_money, 2);
+                    $res = $res && $moneyService->income('extract_integral', $info['uid'], [
+                            'type' => $info['type'] ? '贡献分' : '消费分',
+                            'price' => round($price, 2),
+                            'integral_num' => $info['num'],
+                            'number' => floatval($to_now_money),
+                            'frozen_time' => 0
+                        ], $balance, $info['id']);
+                    // 添加用户佣金
+                    $res = $res && $userService->bcInc($info['uid'], 'now_money', $to_now_money, 'uid');
+                }
+
                 $to_brokerage = bcdiv(bcmul($real_out, sys_config('extract_brokerage_ratio', 0)), 100, 2);
-                $balance = bcadd($user['brokerage_price'], $to_brokerage, 2);
-                $res = $res && $brokerageService->income('extract_integral', $info['uid'], [
-                        'type' => $info['type'] ? '贡献分' : '消费分',
-                        'price' => round($price, 2),
-                        'integral_num' => $info['num'],
-                        'number' => floatval($to_brokerage),
-                        'frozen_time' => 0
-                    ], $balance, $info['id']);
-                // 添加用户佣金
-                $res = $res && $userService->bcInc($info['uid'], 'brokerage_price', $to_brokerage, 'uid');
+                if ($to_brokerage > 0) {
+                    $balance = bcadd($user['brokerage_price'], $to_brokerage, 2);
+                    $res = $res && $brokerageService->income('extract_integral', $info['uid'], [
+                            'type' => $info['type'] ? '贡献分' : '消费分',
+                            'price' => round($price, 2),
+                            'integral_num' => $info['num'],
+                            'number' => floatval($to_brokerage),
+                            'frozen_time' => 0
+                        ], $balance, $info['id']);
+                    // 添加用户佣金
+                    $res = $res && $userService->bcInc($info['uid'], 'brokerage_price', $to_brokerage, 'uid');
+                }
 
                 $to_energy = bcsub($real_out, $to_brokerage, 2);
-                $balance = bcadd($user['energy'], $to_energy, 2);
-                $res = $res && $billService->income('extract_integral', $info['uid'], [
-                        'type' => $info['type'] ? '贡献分' : '消费分',
-                        'price' => round($price, 2),
-                        'integral_num' => $info['num'],
-                        'number' => floatval($to_energy),
-                    ], $balance, $info['id']);
-                // 添加用户佣金
-                $res = $res && $userService->bcInc($info['uid'], 'energy', $to_energy, 'uid');
+                if ($to_energy > 0) {
+                    $balance = bcadd($user['energy'], $to_energy, 2);
+                    $res = $res && $billService->income('extract_integral', $info['uid'], [
+                            'type' => $info['type'] ? '贡献分' : '消费分',
+                            'price' => round($price, 2),
+                            'integral_num' => $info['num'],
+                            'number' => floatval($to_energy),
+                        ], $balance, $info['id']);
+                    // 添加用户佣金
+                    $res = $res && $userService->bcInc($info['uid'], 'energy', $to_energy, 'uid');
+                }
                 $res = $res && $awardIntegralService->update($info['id'], ['handle' => 0, 'extract_sum_real' => $sum, 'status' => 1, 'extract_time' => time()]);
             }
             if ($to_top > 0) {

+ 6 - 1
app/model/user/UserIntegral.php

@@ -129,6 +129,11 @@ class UserIntegral extends BaseModel
         $query->where('link_id', $value);
     }
 
+    public function searchOrderIdNotAttr($query, $value)
+    {
+        $query->where('link_id', '<>', $value);
+    }
+
 
     /**
      * 订单号
@@ -137,6 +142,6 @@ class UserIntegral extends BaseModel
      */
     public function searchExtractPriceAttr($query, $value)
     {
-        $query->where('(num *'.$value.')>=extract_sum');
+        $query->where('(num *' . $value . ')>=extract_sum');
     }
 }

+ 2 - 0
app/services/system/config/SystemConfigServices.php

@@ -1518,6 +1518,7 @@ WSS;
                 Build::inputNum('static_integral_ratio', $data['static_integral_ratio']['info'], $data['static_integral_ratio']['value'])->min(0)->info($data['static_integral_ratio']['desc']),
                 Build::inputNum('lake_ratio', $data['lake_ratio']['info'], $data['lake_ratio']['value'])->min(0)->info($data['lake_ratio']['desc']),
                 Build::inputNum('recommend_integral', $data['recommend_integral']['info'], $data['recommend_integral']['value'])->min(0)->info($data['recommend_integral']['desc']),
+                Build::inputNum('reorder_recommend_integral', $data['reorder_recommend_integral']['info'], $data['reorder_recommend_integral']['value'])->min(0)->info($data['reorder_recommend_integral']['desc']),
                 Build::inputNum('recommend_speed_integral', $data['recommend_speed_integral']['info'], $data['recommend_speed_integral']['value'])->min(0)->info($data['recommend_speed_integral']['desc']),
                 Build::inputNum('static_integral_rate', $data['static_integral_rate']['info'], $data['static_integral_rate']['value'])->min(0)->info($data['static_integral_rate']['desc']),
                 Build::inputNum('action_integral_rate', $data['action_integral_rate']['info'], $data['action_integral_rate']['value'])->min(0)->info($data['action_integral_rate']['desc']),
@@ -1531,6 +1532,7 @@ WSS;
                 Build::inputNum('city_award', $data['city_award']['info'], $data['city_award']['value'])->min(0)->info($data['city_award']['desc']),
                 Build::inputNum('district_award', $data['district_award']['info'], $data['district_award']['value'])->min(0)->info($data['district_award']['desc']),
                 Build::inputNum('area_award_time', $data['area_award_time']['info'], $data['area_award_time']['value'])->min(0)->info($data['area_award_time']['desc']),
+                Build::inputNum('starts_return_time', $data['starts_return_time']['info'], $data['starts_return_time']['value'])->min(0)->info($data['starts_return_time']['desc']),
             ])->option('提现设置', [
                 Build::alert('微信提现到零钱为自动到账(需要开通微信:企业付款到零钱(商家转账到零钱),并确保配置微信支付证书正确,特别注意:需要配置场景、开启API发起转账),其他方式均需要手动转账', Alert::WARNING)->showIcon(true),
                 Build::radio('brokerage_type', $data['brokerage_type']['info'], $data['brokerage_type']['value'])->options($this->getOptions($data['brokerage_type']['parameter']))->control(1, [

+ 10 - 0
app/services/user/UserAwardIntegralServices.php

@@ -157,6 +157,16 @@ class UserAwardIntegralServices extends BaseServices
         return $this->dao->sum($where, 'order_price', true);
     }
 
+    /**
+     * 获取单条数据
+     * @return float
+     */
+    public function reOrder($uid, $exceptId = 0)
+    {
+        $where = ['uid' => $uid, 'type' => 0, 'order_id_not' => $exceptId];
+        return $this->dao->search($where)->count() > 0;
+    }
+
 
     /**
      * 获取用户业绩

+ 89 - 82
app/services/user/UserMoneyServices.php

@@ -116,25 +116,32 @@ class UserMoneyServices extends BaseServices
             'status' => 1,
             'pm' => 0
         ],
+        'extract_integral' => [
+            'title' => '积分出局',
+            'type' => 'extract_integral',
+            'mark' => '用户{%type%}出局,出局时积分价格{%price%},共出局{%integral_num%}积分,获得余额{%number%}元',
+            'status' => 1,
+            'pm' => 1
+        ],
     ];
 
-	/**
- 	* 类型名称
-	* @var string[]
- 	*/
-	protected $typeName = [
-		'pay_product' => '商城购物',
+    /**
+     * 类型名称
+     * @var string[]
+     */
+    protected $typeName = [
+        'pay_product' => '商城购物',
         'pay_product_refund' => '商城购物退款',
-		'system_add' => '系统充值',
-		'system_sub' => '系统扣除',
-		'recharge' => '用户充值',
-		'recharge_refund' => '用户充值退款',
-		'extract' => '佣金提现充值',
-		'lottery_use' => '抽奖使用',
-		'lottery_add' => '抽奖中奖充值',
-		'newcomer_add' => '新人礼赠送充值',
-		'level_add' => '会员卡激活赠送充值'
-	];
+        'system_add' => '系统充值',
+        'system_sub' => '系统扣除',
+        'recharge' => '用户充值',
+        'recharge_refund' => '用户充值退款',
+        'extract' => '佣金提现充值',
+        'lottery_use' => '抽奖使用',
+        'lottery_add' => '抽奖中奖充值',
+        'newcomer_add' => '新人礼赠送充值',
+        'level_add' => '会员卡激活赠送充值'
+    ];
 
     /**
      * UserMoneyServices constructor.
@@ -239,7 +246,7 @@ class UserMoneyServices extends BaseServices
     public function getRechargeList(int $uid = 0, $where_time = [], string $field = '*')
     {
         [$page, $limit] = $this->getPageValue();
-		$where = [];
+        $where = [];
         if ($uid) $where['uid'] = $uid;
         if ($where_time) $where['add_time'] = $where_time;
         $list = $this->dao->getList($where, $field, $page, $limit);
@@ -278,9 +285,9 @@ class UserMoneyServices extends BaseServices
             $data['mark'] = str_replace(['{%num%}'], $number, $data['mark']);
         }
         $data['add_time'] = time();
-		if ((float)$data['number']) {
-			return $this->dao->save($data);
-		}
+        if ((float)$data['number']) {
+            return $this->dao->save($data);
+        }
         return true;
     }
 
@@ -325,12 +332,12 @@ class UserMoneyServices extends BaseServices
         $count = $this->dao->count($where);
         $times = [];
         if ($list) {
-			$typeName = $this->typeName;
+            $typeName = $this->typeName;
             foreach ($list as &$item) {
                 $item['time_key'] = $item['time'] = $item['add_time'] ? date('Y-m', (int)$item['add_time']) : '';
-				$item['day'] = $item['add_time'] ? date('Y-m-d', (int)$item['add_time']) : '';
+                $item['day'] = $item['add_time'] ? date('Y-m-d', (int)$item['add_time']) : '';
                 $item['add_time'] = $item['add_time'] ? date('Y-m-d H:i', (int)$item['add_time']) : '';
-				$item['type_name'] = $typeName[$item['type'] ?? ''] ?? '未知类型';
+                $item['type_name'] = $typeName[$item['type'] ?? ''] ?? '未知类型';
             }
             $times = array_merge(array_unique(array_column($list, 'time_key')));
         }
@@ -357,66 +364,66 @@ class UserMoneyServices extends BaseServices
     }
 
 
-	/**
- 	* 新人礼赠送余额
-	* @param int $uid
-	* @return bool
-	 */
-	public function newcomerGiveMoney(int $uid)
-	{
-		if (!sys_config('newcomer_status')) {
-			return false;
-		}
-		$status = sys_config('register_money_status');
-		if (!$status) {//未开启
-			return true;
-		}
-		$money = (int)sys_config('register_give_money', []);
-		if (!$money) {
-			return true;
-		}
-		/** @var UserServices $userServices */
-		$userServices = app()->make(UserServices::class);
-		$userInfo = $userServices->getUserInfo($uid);
-		if (!$userInfo) {
-			return true;
-		}
-		$balance = bcadd((string)$userInfo['now_money'], (string)$money);
-		$this->income('newcomer_give_money', $uid, $money, $balance);
-		$userServices->update($uid, ['now_money' => $balance]);
-		return true;
-	}
+    /**
+     * 新人礼赠送余额
+     * @param int $uid
+     * @return bool
+     */
+    public function newcomerGiveMoney(int $uid)
+    {
+        if (!sys_config('newcomer_status')) {
+            return false;
+        }
+        $status = sys_config('register_money_status');
+        if (!$status) {//未开启
+            return true;
+        }
+        $money = (int)sys_config('register_give_money', []);
+        if (!$money) {
+            return true;
+        }
+        /** @var UserServices $userServices */
+        $userServices = app()->make(UserServices::class);
+        $userInfo = $userServices->getUserInfo($uid);
+        if (!$userInfo) {
+            return true;
+        }
+        $balance = bcadd((string)$userInfo['now_money'], (string)$money);
+        $this->income('newcomer_give_money', $uid, $money, $balance);
+        $userServices->update($uid, ['now_money' => $balance]);
+        return true;
+    }
 
-	/**
- 	* 会员卡激活赠送余额
-	* @param int $uid
-	* @return bool
-	 */
-	public function levelGiveMoney(int $uid)
-	{
-		$status = sys_config('level_activate_status');
-		if (!$status) {//是否需要激活
-			return true;
-		}
-		$status = sys_config('level_money_status');
-		if (!$status) {//未开启
-			return true;
-		}
-		$money = (int)sys_config('level_give_money', []);
-		if (!$money) {
-			return true;
-		}
-		/** @var UserServices $userServices */
-		$userServices = app()->make(UserServices::class);
-		$userInfo = $userServices->getUserInfo($uid);
-		if (!$userInfo) {
-			return true;
-		}
-		$balance = bcadd((string)$userInfo['now_money'], (string)$money);
-		$this->income('level_give_money', $uid, $money, $balance);
-		$userServices->update($uid, ['now_money' => $balance]);
-		return true;
-	}
+    /**
+     * 会员卡激活赠送余额
+     * @param int $uid
+     * @return bool
+     */
+    public function levelGiveMoney(int $uid)
+    {
+        $status = sys_config('level_activate_status');
+        if (!$status) {//是否需要激活
+            return true;
+        }
+        $status = sys_config('level_money_status');
+        if (!$status) {//未开启
+            return true;
+        }
+        $money = (int)sys_config('level_give_money', []);
+        if (!$money) {
+            return true;
+        }
+        /** @var UserServices $userServices */
+        $userServices = app()->make(UserServices::class);
+        $userInfo = $userServices->getUserInfo($uid);
+        if (!$userInfo) {
+            return true;
+        }
+        $balance = bcadd((string)$userInfo['now_money'], (string)$money);
+        $this->income('level_give_money', $uid, $money, $balance);
+        $userServices->update($uid, ['now_money' => $balance]);
+        return true;
+    }
 
     /**
      * 余额统计基础