select(); // 计算总业绩 $totalPv = []; foreach ($user_team_amount as $order) { if (!isset($totalPv[$order['user_id']])) { $totalPv[$order['user_id']] = 0; } switch ($order['money']) { case 1180: $totalPv[$order['user_id']] += 700; break; case 11800: $totalPv[$order['user_id']] += 7000; break; case 10620: $totalPv[$order['user_id']] += 6300; break; case 2360: $totalPv[$order['user_id']] += 1400; break; case 9440: $totalPv[$order['user_id']] += 5600; break; default: if ($order['money'] == 2344.99) { break; } $totalPv[$order['user_id']] += round($order['money'] * 0.7,2); break; } } foreach ($totalPv as $uid => $pv) { Db::name("user")->where('is_old', 1)->where("uid", $uid)->update(['pv' => $pv]); } return; /** * 周金花200(13959100621) * 黄金花200(18603401312) * 徐立苹100(13521438652) * 李素红200(13701061395) * 周行体200(13231658486) * 刘银霞100(13161909228) * 李卫东100(13911601230) * 金 波100(13801358713) * 王 玲 150(15810064711) * 侯玉兰150(15232797965) * 吕丽娣100(15960349667) * 张传莲100(15332507711) * 刘春梅100(18760167163) * 付天如100(18863873000) * 付绍先100(15324059286) * 黄桂林100(15960196876) * 温 煌100(18350134089) * 谭英先100(13978627072) * 陈玉珍100(19858353660) * 黄雪云100(18650055445) * 黄 玲100(13877193411) * 邱佳珍100(13960379098) * 隋彩云100(13601071082) */ $data = [ '13959100621' => 200, '18603401312' => 200, '13521438652' => 100, '13701061395' => 200, '13231658486' => 200, '13161909228' => 100, '13911601230' => 100, '13801358713' => 100, '15810064711' => 150, '15232797965' => 150, '15960349667' => 100, '15332507711' => 100, '18760167163' => 100, '18863873000' => 100, '15324059286' => 100, '15960196876' => 100, '18350134089' => 100, '13978627072' => 100, '19858353660' => 100, '18650055445' => 100, '13877193411' => 100, '13960379098' => 100, '13601071082' => 100, ]; $result = Db::name("user") ->whereIn("account", array_keys($data)) ->where('is_del', 0) ->field('uid, brokerage_price, account, nickname') ->select(); $res = []; foreach ($result as $v) { Db::name("user")->where("uid", $v['uid'])->inc("brokerage_price", $data[$v['account']])->save(); $this->bill_user_log111111($v['uid'], "佣金补贴", $data[$v['account']], "佣金补贴", 8);//股权分佣明细2.0系统 $res[] = [ 'uid' => $v['uid'], 'account' => $v['account'], 'brokerage_price_pre' => $v['brokerage_price'], 'brokerage_price' => $data[$v['account']], 'nickname' => $v['nickname'] ]; } return json($res); } public function lst6() { $startTime = '2025-03-10'; $endTime = '2025-03-30'; // 查询测试人员账号信息 //18973958920 //15186694339 //18833633835 //19525470098 //17756507016 //18226705337 $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337']; $removeUserList = Db::name("user") ->whereIn('account', $testAccount) ->where("status", "<>", 0) ->where('is_del', '<>', 1) ->select() ->toArray(); $removeUserIdList = array_column($removeUserList, 'uid'); if (empty($startTime) || empty($endTime)) { $timeMap = $this->getTime('last_week'); $startTime = $timeMap['startTime'] . ' 00:00:00'; $endTime = $timeMap['endTime'] . ' 23:59:59'; } // 定义分红金额 $weekRecord = $this->getTeamPvByTime($startTime, $endTime, $removeUserIdList); // 分红金额 - 红包金额 $redEnvelope = $this->getRedEnvelopeByTime($startTime, $endTime, $removeUserIdList); $weekRecord -= $redEnvelope; if ($weekRecord <= 0) { return json('无效分红金额'); } // $stock_comm = round($weekRecord * 0.05 ,2); $stock_comm = floor(($weekRecord * 0.05) * 100) / 100; //获取股权分红的人 $GetAllUserPackNum = db::name("old_user_stock")->sum("pack");//计算所有用户的份数总和 $stockuserdatas = db::name("old_user_stock")->select();//获取所有用户 $salesArr = []; if (count($stockuserdatas) > 0) { // $one_pack_comm_data = round($stock_comm / $GetAllUserPackNum,2);//获取每份的单佣金 $one_pack_comm_data = floor(($stock_comm / $GetAllUserPackNum) * 100) / 100; foreach ($stockuserdatas as &$v) { $salesArr[] = [ 'stock_comm' => $stock_comm, 'GetAllUserPackNum' => $GetAllUserPackNum, 'uid' => $v['user_id'], 'pack' => $v['pack'], 'one_pack_comm_data' => $one_pack_comm_data, 'getcomm' => floor(($v['pack'] * $one_pack_comm_data) * 100) / 100 ]; $v['getcomm'] = floor(($v['pack'] * $one_pack_comm_data) * 100) / 100; $v['allgetcomm'] = $v['allgetcomm'] + $v['getcomm']; $v['update_time'] = time(); $yj_90 = $v['getcomm'] * 0.9; $fg_10 = $v['getcomm'] * 0.1; // // 更新 user_stock 表中的记录 $res = db::name("old_user_stock")->where("id", $v['id'])->update([ 'getcomm' => $v['getcomm'], 'allgetcomm' => $v['allgetcomm'], 'update_time' => $v['update_time'] ]); Db::name("user")->where("uid", $v['user_id'])->inc("brokerage_price", $yj_90)->save(); $res1 = Db::name("user")->where("uid", $v['user_id'])->inc("total_amount_old", $yj_90)->save(); $res2 = Db::name("user")->where("uid", $v['user_id'])->inc("amount_old", $yj_90)->save(); $res3 = Db::name("user")->where("uid", $v['user_id'])->inc("fugou", $fg_10)->save(); $res = true; if ($res) { $das = $this->change_user_log($v['user_id'], 'amount_old', 1, $yj_90, "member_award_stock", "股权分红入账" . "-" . $v['pack']);//释放佣金 //入账星级分红记录表 $week_data = []; $week_data['user_id'] = $v['user_id']; $week_data['user_star_id'] = 0; $week_data['award_num'] = 0; $week_data['award_num_sm'] = 0; $week_data['remark'] = "股权分红主动执行" . $yj_90; $week_data['week_record'] = $weekRecord; $week_data['all_amount'] = $stock_comm; $week_data['radio'] = 2; $week_data['owner_bill'] = 0; //总流水金额 $week_data['my_bill'] = 0; //我的流水 $week_data['create_time'] = time(); Db::name("old_user_weekaward")->insert($week_data); $userdatassss = db::name("old_user_jbp")->where("id", $v['user_id'])->find(); $datas_log = [ 'note' => "名称:" . $userdatassss['nick_name'] . " 用户:" . $v['user_id'] . " 新增股权佣金:" . $yj_90, 'create_time' => date('Y-m-d H:i:s') ]; $con_data = Db::name('test_log')->insert($datas_log); //数据存到2.0数据表中 $this->bill_user_log111111($v['user_id'], "股权分佣", $yj_90, "股权明细入账", 13);//股权分佣明细2.0系统 $this->fugou_user_log($v['user_id'], $fg_10, 16, 1, 1);//复购金明细入账 } } } return json($salesArr); //股权分红 end } //添加复购金 public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1) { $fugou_data = Db::name('user')->where("uid", $uid)->find(); $bill = [ 'uid' => $uid, 'number' => $num,//数量 'status' => $status,//复购金状态1-有效 0-失效 -1待确认 'mark' => "复购金",//备注 'desc' => "10%作为复购金",//描述 'order_id' => $order_id,//订单id 'surplus' => 0,//剩余 'order_type' => 11,//关联订单ID 'type' => $type_inc_des,//复购金类型 :1赠送,2消耗 'settlement_time' => date('Y-m-d H:i:s'),//添加时间, 'addtime' => time(), ]; Db::name('user_sign_fugou')->insert($bill); } //添加平台分佣2.0系统收益明细日志(养老金金额) public function bill_user_log111111($uid, $name, $num, $mark, $comm) { $con_data = Db::name('user')->where("uid", $uid)->find(); //如果是会员专区就即刻到账 // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]); $bill = [ 'uid' => $uid, 'link_id' => 0,//关联订单id 'pm' => 1,//0:支出,1:获得 'title' => $name,//账单标题 'category' => 'now_money',//明细种类 'type' => 'commission',//明细类型 'number' => $num,//明细数字 'balance' => 0,//剩余 'mark' => $mark,//备注 'create_time' => date('Y-m-d H:i:s'),//添加时间 'status' => 1,//0待确定,1有效,-1无效 'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费 //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金 //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’ 'order_sn' => 0,//订单号 'tripartite' => 0,// 'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上 'mer_id' => 0,//商户id 'source' => 0,//1线下 0线上 'order_type' => 1,//1自营 2 第三方 订单类型 'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金 'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入 'take_time' => '',//结算时间 'district_id' => '',// 'street_id' => '',// 'month' => '',//月份 ]; Db::name('user_bill')->insert($bill); } //发放佣金 示例: $this->change_user_log($v,'amount',1,$all_award,"member_award","星级分红入账"."-".$value['title']);//释放佣金 function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0) { $transition = [ 'pv' => 1, "gb" => 2, "df" => 3, "vr" => 4, "bt" => 5, "withdraw_quota_old" => 6,//提现 "unsettled_pension" => 7, "amount_old" => 8//发放佣金 ]; $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find(); if (empty($routineInfo)) { return false; } $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0; if ($appoint_money > 0) { $alter_money = $appoint_money; } else { //再去查询变更前的 金额 $alter_money = Db::name("user")->where('uid', $user_id)->value($type); } if ($change_status == 1) { //新增前 $alter_money = $alter_money - $money; } else if ($change_status == 2) { //减少前 $alter_money = $alter_money + $money; } if ($alter_money < 0) { $alter_money = 0; } $inser_data = []; $inser_data['user_id'] = $user_id; $inser_data['type'] = $transition[$type]; $inser_data['change_status'] = $change_status; $inser_data['money'] = $money; $inser_data['routine_log_of_key_id'] = $key_id; $inser_data['remark'] = $remark; $inser_data['is_admin'] = $is_admin; $inser_data['create_time'] = time(); $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0; Db::name("old_user_log")->insert($inser_data); } public function getTime($timePeriod) { // 定义时间区间 $now = time(); $startTime = ''; $endTime = ''; if ($timePeriod == 'last_week') { // 上周的时间区间 $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间 $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间 } elseif ($timePeriod == 'this_week') { // 这周的时间区间 $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间 $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间 } // return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23']; return ['startTime' => $startTime, 'endTime' => $endTime]; } public function getTeamPvByTime($startTime, $endTime, $removeUserIdList = []) { // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单 $orders = Db::name("store_order") ->where('mer_id', 496) ->whereNotIn('uid', $removeUserIdList) ->whereIn('status', [0, 1, 2, 3]) ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440]) ->whereBetween("pay_time", [$startTime, $endTime]) ->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单 ->select(); // 计算总业绩 $totalPv = 0; foreach ($orders as $order) { switch ($order['total_price']) { case 1180: $totalPv += 700; break; case 11800: $totalPv += 7000; break; case 10620: $totalPv += 6300; break; case 2360: $totalPv += 1400; break; case 9440: $totalPv += 5600; break; } } return $totalPv; } public function getRedEnvelopeByTime($startTime, $endTime, $removeUserIdList = []) { // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单 $redEnvelopeList = Db::name("user_sign_hongbao") ->whereNotIn('uid', $removeUserIdList) ->where('status', 1) ->whereBetween("settlement_time", [$startTime, $endTime]) ->select() ->toArray(); return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100; } }