|
@@ -3,6 +3,9 @@
|
|
|
|
|
|
namespace app\models\user;
|
|
|
|
|
|
+use app\models\auction\AuctionBooking;
|
|
|
+use app\models\auction\AuctionOrder;
|
|
|
+use app\models\auction\AuctionReward;
|
|
|
use app\models\store\StoreOrder;
|
|
|
use app\models\store\StoreProduct;
|
|
|
use crmeb\services\SystemConfigService;
|
|
@@ -732,4 +735,228 @@ class User extends BaseModel
|
|
|
}
|
|
|
return $model->where('brokerage_price', '>', $brokerage_price)->count('uid');
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 直推奖励
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public static function direct_push()
|
|
|
+ {
|
|
|
+ if (!AuctionReward::where('create_time', strtotime(date('Y-m-d', time())))->find()){
|
|
|
+ // 查找到今天没有分发奖励
|
|
|
+ $time = strtotime(date('Y-m-d', strtotime('-1 day'))); // 昨天的时间
|
|
|
+ $timet = strtotime(date('Y-m-d', time())); // 今天时间
|
|
|
+ $order = AuctionOrder::where('status', '=',2)->where('create_time', '>=', $time)->where('create_time', '<=', $timet)->select();
|
|
|
+ if ($order){
|
|
|
+ foreach ($order as $k => $v) {
|
|
|
+ $user = User::where('uid', $v['uid'])->find();
|
|
|
+ if ($user['spread_uid']){
|
|
|
+ $spread = User::where('uid', $user['spread_uid'])->find();
|
|
|
+ $bo = AuctionBooking::where('uid', '=', $spread['uid'])->where('create_time', '>=', $time)->where('create_time', '<=', $timet)->find();
|
|
|
+ if ($bo){
|
|
|
+ $money = round($v['price'] * 0.03, 2);
|
|
|
+ $spread['sp_final'] += $money;
|
|
|
+ $spread->save();
|
|
|
+ UserBill::income('奖励购物积分', $spread['uid'], 'sp_final', 'add_sp_final', $money, $user['uid'], $spread['sp_final'], '奖励购物积分');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分红奖励
|
|
|
+ * @return void
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function bonus(){
|
|
|
+ if (!AuctionReward::where('create_time', strtotime(date('Y-m-d', time())))->find()){
|
|
|
+ $config = SystemConfigService::more(['bonus', 'bonus_standard']);
|
|
|
+ $user = self::field('uid,spread_uid, sp_final')->select();
|
|
|
+ $user = empty($user) ? [] : $user->toArray();
|
|
|
+ $time = strtotime(date('Y-m-d', strtotime('-1 day'))); // 昨天的时间
|
|
|
+ $timet = strtotime(date('Y-m-d', time())); // 今天时间
|
|
|
+ $orderMoney = AuctionOrder::where('status', '=',2)->where('create_time', '>=', $time)->where('create_time', '<=', $timet)->sum('price');// 找到昨天的总流水金额
|
|
|
+ $moneys = [];
|
|
|
+ foreach ($user as $k => $v){
|
|
|
+ $bo = AuctionBooking::where('uid', '=', $v['uid'])->where('create_time', '>=', $time)->where('create_time', '<=', $timet)->find(); // 查看昨天有预约记录
|
|
|
+ if ($bo){
|
|
|
+ $dow = User::where('spread_uid', $v['uid'])->select()->toArray(); // 是否有下级
|
|
|
+ if (!empty($dow)){
|
|
|
+ foreach ($dow as $key => $value){
|
|
|
+ $userDow[$value['uid']] = get_downline($user,$value['uid']);
|
|
|
+ }
|
|
|
+ foreach ($userDow as $dk => $dv){
|
|
|
+ //查询出下级每个分支昨天流水多少
|
|
|
+ $money = AuctionOrder::where('uid', $dk)->where('status',2)->sum('price');
|
|
|
+ if ($dv){
|
|
|
+ $money += AuctionOrder::where('uid', 'in', $dv)->where('status', '=', 2)->sum('price');
|
|
|
+ }
|
|
|
+ $moneys[] = $money;
|
|
|
+ }
|
|
|
+ sort($moneys); // 排序
|
|
|
+ array_pop($moneys); // 删除最大的流水
|
|
|
+ $sum = array_sum($moneys);
|
|
|
+ if ($sum > (float)$config['bonus_standard']){
|
|
|
+ $reward = round($orderMoney * ($config['bonus']/100), 2); // 奖励分红额度
|
|
|
+ $v['sp_final'] += $reward;
|
|
|
+ User::where('uid', $v['uid'])
|
|
|
+ ->update(['sp_final' => $v['sp_final']]);
|
|
|
+ UserBill::income('分红奖励', $v['uid'], 'sp_final', 'add_sp_final', $reward, 0, $v['sp_final'], '分红奖励');
|
|
|
+
|
|
|
+ }
|
|
|
+ unset($moneys);
|
|
|
+ unset($userDow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * KPI奖励
|
|
|
+ * @return void
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function kpi()
|
|
|
+ {
|
|
|
+ if (!AuctionReward::where('create_time', strtotime(date('Y-m-d', time())))->find()){
|
|
|
+ $user = self::field('uid,spread_uid, sp_final')->select();
|
|
|
+ $user = empty($user) ? [] : $user->toArray();
|
|
|
+ $moneys = [];
|
|
|
+ $time = strtotime(date('Y-m-d', strtotime('-1 day'))); // 昨天的时间
|
|
|
+ $timet = strtotime(date('Y-m-d', time())); // 今天时间
|
|
|
+ $userl = [];
|
|
|
+ foreach ($user as $k => $v){
|
|
|
+ $bo = AuctionBooking::where('uid', '=', $v['uid'])->where('create_time', '>=', $time)->where('create_time', '<=', $timet)->find(); // 查看昨天有预约记录
|
|
|
+ if ($bo){
|
|
|
+ $dow = User::where('spread_uid', $v['uid'])->select()->toArray(); // 是否有下级
|
|
|
+ if (!empty($dow)){
|
|
|
+ foreach ($dow as $key => $value){
|
|
|
+ $userDow[$value['uid']] = get_downline($user,$value['uid']); // 获取到下级
|
|
|
+ }
|
|
|
+ foreach ($userDow as $dk => $dv){
|
|
|
+ //查询出下级每个分支昨天流水多少
|
|
|
+ $money = AuctionOrder::where('uid', $dk)->where('status',2)->sum('price');
|
|
|
+ if ($dv){
|
|
|
+ $money += AuctionOrder::where('uid', 'in', $dv)->where('status', '=', 2)->sum('price');
|
|
|
+ }
|
|
|
+ $moneys[$dk] = $money; // 查询到支线下级总额度
|
|
|
+ }
|
|
|
+ $userl = $moneys;
|
|
|
+ sort($moneys); // 排序
|
|
|
+ array_pop($moneys); // 删除最大的流水
|
|
|
+ $sum = array_sum($moneys);
|
|
|
+ $level = self::con($sum);
|
|
|
+ if ($level > 0){
|
|
|
+ if (empty($v['spread_uid'])){
|
|
|
+ // 没有上级
|
|
|
+ foreach ($userl as $uk => $uv){
|
|
|
+ $towdow = self::dow($uk);
|
|
|
+ if ($level > $towdow){
|
|
|
+ $reward = ($level - $towdow)/100; // 减掉下级获得的倍率
|
|
|
+ $userl[$uk] = $uv * $reward;
|
|
|
+ }elseif ($level == $towdow){
|
|
|
+ $reward = $level/100; // 如果等级相同就只拿百分之十
|
|
|
+ $userl[$uk] = ($uv * $reward) * 0.1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $userMoney = array_sum($userl);
|
|
|
+ $v['sp_final'] += $userMoney;
|
|
|
+ User::where('uid', $v['uid'])
|
|
|
+ ->update(['sp_final' => $v['sp_final']]);
|
|
|
+ UserBill::income('KPI奖励', $v['uid'], 'sp_final', 'add_sp_final', $userMoney, 0, $v['sp_final'], 'KPI奖励');
|
|
|
+ }else{
|
|
|
+ //有上级
|
|
|
+ foreach ($userl as $uk => $uv){
|
|
|
+ $towdow = self::dow($uk);
|
|
|
+ if ($level > $towdow){
|
|
|
+ $reward = $level/100; // 减掉下级获得的倍率
|
|
|
+ }elseif ($level == $towdow){
|
|
|
+ $reward = ($level* 0.1)/100; // 如果下级等级相同就只拿百分之十
|
|
|
+ }
|
|
|
+ $userl[$uk] = $uv * $reward;
|
|
|
+ }
|
|
|
+ $plevel = self::dow($v['spread_uid']);
|
|
|
+ $userMoney = array_sum($userl);
|
|
|
+ if ($plevel == $level) {
|
|
|
+ $userMoney = $userMoney * 0.9; // 如果和上级相同等级只拿百分之九十
|
|
|
+ }
|
|
|
+ $v['sp_final'] += $userMoney;
|
|
|
+ User::where('uid', $v['uid'])
|
|
|
+ ->update(['sp_final' => $v['sp_final']]);
|
|
|
+ UserBill::income('KPI奖励', $v['uid'], 'sp_final', 'add_sp_final', $userMoney, 0, $v['sp_final'], 'KPI奖励');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ unset($userl);
|
|
|
+ unset($moneys);
|
|
|
+ unset($userDow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static function dow($id)
|
|
|
+ {
|
|
|
+ $user = self::field('uid,spread_uid, sp_final')->select();
|
|
|
+ $dow = User::where('spread_uid', $id)->select()->toArray(); // 是否有下级
|
|
|
+ if (!empty($dow)) {
|
|
|
+ foreach ($dow as $key => $value) {
|
|
|
+ $userDow[$value['uid']] = get_downline($user, $value['uid']);
|
|
|
+ }
|
|
|
+ foreach ($userDow as $dk => $dv) {
|
|
|
+ //查询出下级每个分支昨天流水多少
|
|
|
+ $money = AuctionOrder::where('uid', $dk)->where('status', 2)->sum('price');
|
|
|
+ if ($dv) {
|
|
|
+ $money += AuctionOrder::where('uid', 'in', $dv)->where('status', '=', 2)->sum('price');
|
|
|
+ }
|
|
|
+ $moneys[$dk] = $money;
|
|
|
+ }
|
|
|
+ sort($moneys); // 排序
|
|
|
+ array_pop($moneys); // 删除最大的流水
|
|
|
+ $sum = array_sum($moneys);
|
|
|
+ $level = self::con($sum);
|
|
|
+ return $level;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function con($sum){
|
|
|
+ $config = SystemConfigService::more([
|
|
|
+ 'level_one','one_standard','level_two','two_standard','level_three','three_standard','level_four','four_standard','level_five','five_standard'
|
|
|
+ ]);
|
|
|
+ $status = '';
|
|
|
+ if ($sum < $config['one_standard']) $status = 0;
|
|
|
+ if ($sum >= $config['one_standard'] and $sum < $config['two_standard']) $status = $config['level_one']; // 达标1级
|
|
|
+ if ($sum >= $config['two_standard'] and $sum < $config['three_standard']) $status = $config['level_two'];// 达标2级
|
|
|
+ if ($sum >= $config['three_standard'] and $sum < $config['four_standard']) $status = $config['level_three'];// 达标3级
|
|
|
+ if ($sum >= $config['four_standard'] and $sum < $config['five_standard']) $status = $config['level_four'];// 达标4级
|
|
|
+ if ($sum >= $config['five_standard']) $status = $config['level_five'];// 达标5级
|
|
|
+
|
|
|
+ return $status;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static function up_time()
|
|
|
+ {
|
|
|
+ if (!AuctionReward::where('create_time', strtotime(date('Y-m-d', time())))->find()){
|
|
|
+ AuctionReward::create([
|
|
|
+ 'create_time' => strtotime(date('Y-m-d', time()))
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|