agent = $agent; $this->order = $order; $this->order_goods = $order_goods; $this->set = $set; $this->team_goods = $team_goods; $this->finish_ratio = $finish_ratio; $this->finish_price = $finish_price; } /** * @name 商品独立设置-比例-解序列化 * @author * @return mixed */ private function getDividendRates() { return unserialize($this->team_goods->has_dividend_rates); } /** * @name 商品独立设置-固定金额-解序列化 * @author * @return mixed */ private function getDividendPrices() { return unserialize($this->team_goods->has_dividend_prices); } /** * @name 商品独立设置-额外分红-解序列化 * @author * @return mixed */ public function getDividendExtra() { return unserialize($this->team_goods->has_dividend_extra); } /** * @name 商品是否启用独立设置 * @author * @return mixed */ private function hasDividend() { return $this->team_goods->has_dividend; } /** * @name 收银台商品与存在独立奖励设置 * @author * @return bool */ private function hasDividendRate() { return $this->order->plugin_id == 31 && $this->team_goods->has_dividend_rate; } /** * @name 商城商品设置奖励比例 * @author * @return bool */ private function hasDividendRates() { return !empty($this->team_goods->has_dividend_rates); } /** * @name 商城商品设置奖励固定金额 * @author * @return bool */ private function hasDividendPrices() { return !empty($this->team_goods->has_dividend_prices); } /** * @name 商品是否开启平级奖独立设置 * @author * @return mixed */ private function hasPeers() { return $this->team_goods->has_peers; } /** * @name 平级奖等级设置 * @author * @return mixed */ private function getHierarchys() { return unserialize($this->team_goods->has_hierarchys); } /** * @name 获取平级奖奖励层级 * @author * @return mixed */ public function getAwardHierarchy() { $award_hierarchy = $this->agent['has_one_level']['award_hierarchy']; if ($this->hasPeers()) { $hierarchys = $this->getHierarchys(); $hierarchy_level = $hierarchys[$this->agent['level']]; if ($hierarchy_level && $hierarchy_level['hierarchy'] > 0) { $award_hierarchy = $hierarchy_level['hierarchy']; } } return $award_hierarchy; } /** * @name 获取平级奖奖励比例 * @author * @return mixed */ public function getAwardHierarchyRatio() { $ratio = $this->agent['has_one_level']['award_ratio']; if ($this->hasPeers()) { $hierarchys = $this->getHierarchys(); $hierarchy_level = $hierarchys[$this->agent['level']]; if ($hierarchy_level && $hierarchy_level['ratio'] > 0) { $ratio = $hierarchy_level['ratio']; } } return $ratio; } public function getAwardHierarchyAmount() { // 基础设置 $amount = OrderCreatedService::getAmount($this->order_goods, $this->set, $this->team_goods); // 商品独立设置 if ($this->hasDividend()) { $amount = $this->order_goods->payment_amount; // 商城商品设置奖励固定金额 if ($this->hasDividendPrices()) { $dividend_prices = $this->getDividendPrices(); // 提成结算金额 $amount = $this->order_goods->total * $dividend_prices['level_' . $this->agent['level']]; } } // 奖励金额 return $amount; } /** * @name 获取奖励金额 * @author * @param $ratio * @return float|int */ // 传入 比例 是防止重复调用getRatio 造成finish_ratio重新赋值,结果计算错误 public function getDividendAmount($ratio) { // 商品独立设置 if ($this->hasDividend()) { // 收银台商品 if ($this->hasDividendRate()) { // 提成结算金额 $this->amount = $this->order_goods->payment_amount * $this->team_goods->has_dividend_rate / 100; // 奖励金额 return $this->amount * $ratio / 100; } // 存在独立奖励设置 // 商城商品设置奖励比例 if ($this->hasDividendRates()) { // $dividend_rates = $this->getDividendRates(); // $ratio = $dividend_rates['level_' . $this->agent['level']]; if (isset($ratio) && $ratio >= 0) { // 提成结算金额 $this->amount = $this->order_goods->payment_amount; // 奖励金额 return $this->amount * $ratio / 100; } } // 商城商品设置奖励固定金额 if ($this->hasDividendPrices()) { $dividend_prices = $this->getDividendPrices(); // 提成结算金额 $this->amount = $this->order_goods->total * $dividend_prices['level_' . $this->agent['level']]; $this->fixed = 1; $this->ratio = 0; // 奖励金额 return $this->amount - $this->finish_price; } } // 基础设置 $this->amount = OrderCreatedService::getAmount($this->order_goods, $this->set, $this->team_goods); // 门店设置 if ($this->order->plugin_id == 32) { if ($this->set['has_dividend_rate']) { $this->amount = $this->amount * $this->set['has_dividend_rate'] / 100; } } // 奖励金额 return $this->amount * $ratio / 100; } /** * @name 获取奖励比例 * @author * @return int */ public function getRatio() { // 商品独立设置 else 基础设置 if ($this->hasDividend()) { // 收银台商品 与 存在独立奖励设置 else 商城 if ($this->hasDividendRate()) { // 经销商奖励比例 - 下级经销商奖励比例 = 奖励比例 $ratio = $this->agent['has_one_level']['dividend_ratio'] - $this->finish_ratio; $this->finish_ratio = $this->agent['has_one_level']['dividend_ratio']; return $ratio; } else { // 商城商品设置奖励比例 else 商城商品设置奖励固定金额 if ($this->hasDividendRates()) { $dividend_rates = $this->getDividendRates(); $ratio = $dividend_rates['level_' . $this->agent['level']] - $this->finish_ratio; $this->finish_ratio = $dividend_rates['level_' . $this->agent['level']]; return $ratio; } } } else { $ratio = $this->agent['has_one_level']['dividend_ratio'] - $this->finish_ratio; $this->finish_ratio = $this->agent['has_one_level']['dividend_ratio']; return $ratio; } } /** * 获取最大奖励 */ public function getTotalDividend() { $maxRatio = max(TeamDividendLevelModel::uniacid()->select('dividend_ratio')->get()->toArray()); if ($this->hasDividend()) { if ($this->hasDividendRate()) { $amount = $this->order_goods->payment_amount * $this->team_goods->has_dividend_rate / 100; return $amount * $maxRatio['dividend_ratio'] / 100;; } else { if ($this->hasDividendRates()) { $dividend_rates = $this->getDividendRates(); $amount = $this->order_goods->payment_amount; return $amount * max($dividend_rates) / 100; } if ($this->hasDividendPrices()) { $dividend_prices = $this->getDividendPrices(); // 提成结算金额 $amount = $this->order_goods->total * max($dividend_prices);; // 奖励金额 return $amount; } } } else { $amount = OrderCreatedService::getAmount($this->order_goods, $this->set, $this->team_goods); if ($this->order->plugin_id == 32) { if ($this->set['has_dividend_rate']) { $amount = $amount * $this->set['has_dividend_rate'] / 100; } } return $amount * $maxRatio['dividend_ratio'] / 100; } } }