bonus_agent = $bonus_agent; $this->mall_id = $bonus_agent->mall_id; $this->stock_goods = $stock_goods; $this->after_distribution_unit_goods_price = $after_distribution_unit_goods_price; $this->order_id = $order_id; $this->goods_num = $goods_num; $this->is_frozen = $is_frozen; $this->order_type = $order_type; $this->change_desc = $change_desc; $this->is_job = $is_job; } /** * 记录奖励 */ abstract protected function addRewardLog(); /** * 获取对应等级商品奖励金额单价 */ abstract protected function getRewardUnitPrice(); protected function countAfterCountUnitGoodsPrice() { $this->getRewardUnitPrice(); $configs = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_CLOUD_STOCK_TWO, 'basic'); //平级奖扣除来源,平台还是货款 switch ($configs['bonus']) { case 'payment': $money = $this->after_count_unit_goods_price = $this->after_distribution_unit_goods_price - $this->reward_unit_price; break; case 'platform': $money = $this->after_count_unit_goods_price = $this->after_distribution_unit_goods_price; break; default: $money = $this->after_count_unit_goods_price = $this->after_distribution_unit_goods_price - $this->reward_unit_price; } return $money; } /** * 获取分配奖励后的货款总价 * @return mixed */ protected function getAfterCountTotalGoodsPrice() { $this->countAfterCountUnitGoodsPrice(); return $this->after_count_unit_goods_price * $this->goods_num; } /** * 计算并记录奖励,返回分配奖励后的货款总价 * @return float|int|mixed */ public function sendReward() { if ($this->after_distribution_unit_goods_price > 0) { $this->addRewardLog(); return $this->getAfterCountTotalGoodsPrice(); } return 0; } public function getInsertWallet($capital_type) { $insert_wallet = []; $commission_num = $this->reward_unit_price * $this->goods_num; if(empty($commission_num)) return $insert_wallet; if ($this->order_type == 'buying') { $source_table = Order::tableName(); } else { $source_table = CloudStockTwoFillOrder::tableName(); } $insert_wallet[] = [ 'mall_id' => $this->mall_id, 'user_id' => $this->bonus_agent->user_id, 'is_frozen' => $this->is_frozen, 'wallet_type' => 'commission', 'money' => $commission_num, 'desc' => $this->change_desc, 'source_table' => $source_table, 'source_table_id' => $this->order_id, 'from_type' => AddonsEnum::ADDONS_NAME_CLOUD_STOCK_TWO, 'capital_type' => $capital_type, ]; return $insert_wallet; } }