request->get('promotion_code'); // 推广码 $profit = $this->request->get('profit'); // 订单金额 // 推广人 $userSelf = UserLogic::getUserByInviteCode($inviteCode); if (empty($userSelf)) { return $this->fail('推广人不存在'); } // 推广人用户角色 // 小队/小区队长 if (in_array($userSelf['group_id'] , [2, 18])) { //村/社区合伙人 $where = ['group_id' => 3, 'village'=>$userSelf['village']]; $villageUser = UserLogic::getUser($where); //镇/街道合伙人 $where1 = ['group_id' => 15, 'street'=>$userSelf['street']]; $streetUser = UserLogic::getUser($where1); // 计算分润 UserLogic::shareProfit($userSelf, $villageUser, $streetUser, $profit); return $this->success('成功', [ ['user_id' => $userSelf['id'], 'mobile' => $userSelf['account'], 'user_profit' => bcmul($profit, 0.03, 2)], ['user_id' => $villageUser['id'], 'mobile' => $villageUser['account'], 'user_profit' => bcmul($profit, 0.03, 2)], ['user_id' => $streetUser['id'], 'mobile' => $streetUser['account'], 'user_profit' => bcmul($profit, 0.01, 2)], ]); } // 村/社区合伙人 if ($userSelf['group_id'] == 3) { // 查下级 小队 $where = ['group_id' => [2, 18], 'village'=>$userSelf['village']]; $bridgeUser = UserLogic::getUser($where); //镇/街道合伙人 $where = ['group_id' => 15, 'village'=>$userSelf['village']]; $streetUser = UserLogic::getUser($where); // 计算分润 UserLogic::shareProfit($bridgeUser, $userSelf, $streetUser, $profit); return $this->success('成功', [ ['user_id' => $bridgeUser['id'], 'mobile' => $bridgeUser['account'], 'user_profit' => bcmul($profit, 0.03, 2)], ['user_id' => $userSelf['id'], 'mobile' => $userSelf['account'], 'user_profit' => bcmul($profit, 0.03, 2)], ['user_id' => $streetUser['id'], 'mobile' => $streetUser['account'], 'user_profit' => bcmul($profit, 0.01, 2)], ]); } // 镇/街道合伙人 if ($userSelf['group_id'] == 15) { // 查下级村 $where = ['group_id' => 3, 'village'=>$userSelf['village']]; $villageUser = UserLogic::getUser($where); //和小队 $where = ['group_id' => [2, 18], 'village'=>$userSelf['village']]; $bridgeUser = UserLogic::getUser($where); // 计算分润 UserLogic::shareProfit($bridgeUser, $villageUser, $userSelf, $profit); return $this->success('成功', [ ['user_id' => $bridgeUser['id'], 'mobile' => $bridgeUser['account'], 'user_profit' => bcmul($profit, 0.03, 2)], ['user_id' => $villageUser['id'], 'mobile' => $villageUser['account'], 'user_profit' => bcmul($profit, 0.03, 2)], ['user_id' => $userSelf['id'], 'mobile' => $userSelf['account'], 'user_profit' => bcmul($profit, 0.01, 2)], ]); } } /** * 用户订单分润 * 镇合伙人 */ public function user_order_share_profit() { $inviteCode = $this->request->get('promotion_code'); // 推广码 $profit = $this->request->get('profit'); // 订单金额 // 推广人 $userSelf = UserLogic::getUserByInviteCode($inviteCode); if (empty($userSelf)) { return $this->fail('推广人不存在'); } $proportion = 0.01; // 比例 // 镇/街道合伙人 if ($userSelf['group_id'] == 15) { // 计算分润 UserLogic::userProfit($userSelf, $profit, $proportion); } // 小队/小区队长 if (in_array($userSelf['group_id'] , [2, 18])) { //镇/街道合伙人 $where1 = ['group_id' => 15, 'street'=>$userSelf['street']]; $streetUser = UserLogic::getUser($where1); // 计算分润 UserLogic::userProfit($streetUser, $profit, 0.01); } // 村/社区合伙人 if ($userSelf['group_id'] == 3) { //镇/街道合伙人 $where = ['group_id' => 15, 'village'=>$userSelf['village']]; $streetUser = UserLogic::getUser($where); // 计算分润 UserLogic::userProfit($streetUser, $profit, 0.01); } return $this->success('成功', ['user_id' => $userSelf['id'], 'mobile' => $userSelf['account'], 'user_profit' => bcmul($profit, $proportion, 2)]); } }