| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace addons\CloudStock\common\logic\deduction;
- use addons\CloudStock\common\enums\CloudStockEnum;
- use addons\CloudStock\common\logic\reward\FillRewardLogic;
- use addons\CloudStock\common\models\CloudStockAgent;
- use addons\CloudStock\common\models\CloudStockGoods;
- use addons\CloudStock\common\models\CloudStockLevel;
- use common\models\user\UserPartitionRelationship;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\helpers\BcHelper;
- class FillDeductionLogic extends DeductionLogic
- {
- public function getUnitGoodsPrice()
- {
- if ($this->order->pay_money <= 0) return 0;
- $this->unit_goods_price = $this->getOrderGoodsUnitPrice();
- $setting = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_CLOUD_STOCK, 'basic');
- //队列触发的,不用再计算平级、越级奖
- //平级奖、越级奖扣除
- //获取补货者代理商数据
- $agent = CloudStockAgent::findOne(['user_id' => $this->user_id, 'mall_id' => $this->mall_id,'status'=>StatusEnum::ENABLED]);
- $stock_good = CloudStockGoods::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'goods_id' => $this->order['goods_id']]);
- //紧凑平级奖
- if(!empty($stock_good['is_find_equal'])){
- $parent_id_arr = UserPartitionRelationship::getParentIdArr($this->user_id);
- $parent_id_arr = array_reverse($parent_id_arr);
- $reward_list = [];
- $is_find_equal = false;
- foreach ($parent_id_arr as $parent_id) {
- $parent_agent = CloudStockAgent::findOne(['user_id' => $parent_id, 'mall_id' => $this->mall_id,'status'=>StatusEnum::ENABLED]);
- //找平级
- if(!empty($parent_agent)){
- if($parent_agent['level'] < $agent['level']) {
- if (!empty($this->user['parent_id']) && $parent_id == $this->user['parent_id']) {
- $reward_list[] = [
- 'level' => 1,
- 'agent' => $parent_agent,
- ];
- }
- if (!empty($this->user['second_parent_id']) && $parent_id == $this->user['second_parent_id']) {
- $reward_list[] = [
- 'level' => 2,
- 'agent' => $parent_agent,
- ];
- }
- }elseif($parent_agent['level'] == $agent['level']){
- if(!$is_find_equal){
- $reward_list[] = [
- 'level' => 1,
- 'agent' => $parent_agent,
- ];
- $is_find_equal = true;
- }else{
- $reward_list[] = [
- 'level' => 2,
- 'agent' => $parent_agent,
- ];
- break;
- }
- }
- }
- }
- if(!empty($reward_list)){
- foreach($reward_list as $reward){
- if($reward['agent']['level'] < $agent['level']){
- $over_desc = "补货越级奖发放,越级层数".$reward['level'];
- $stock_level = CloudStockLevel::findOne(['mall_id' => $this->mall_id, 'level' => $reward['agent']['level'], 'status' => StatusEnum::ENABLED]);
- $this->sendOverReward($reward['agent'], $stock_level, $reward['level'], $over_desc, $this->order['num'], !empty($setting['is_by_buy_agent_level']), $agent['level']);
- }
- // 此处需要判断云库存用户是否开启了平级奖限制
- if($reward['agent']['level'] == $agent['level'] && empty($reward['agent']['is_equal_award_restriction'])){
- $equal_desc = "补货平级奖发放,平级层数".$reward['level'];
- $stock_level = CloudStockLevel::findOne(['mall_id' => $this->mall_id, 'level' => $reward['agent']['level'], 'status' => StatusEnum::ENABLED]);
- $this->sendEqualReward($reward['agent'], $stock_level, $reward['level'], $equal_desc, $this->order['num']);
- }
- }
- }
-
- }else{
- //发放平一级对象,直推
- if (!empty($this->user['parent_id'])) {
- $direct_agent = CloudStockAgent::findOne(['user_id' => $this->user['parent_id'], 'mall_id' => $this->mall_id,'status'=>StatusEnum::ENABLED]);
- //获取平一级代理商数据
- if ($direct_agent && empty($direct_agent['is_equal_award_restriction'])) {
- $stock_level = CloudStockLevel::findOne(['mall_id' => $this->mall_id, 'level' => $direct_agent['level'], 'status' => StatusEnum::ENABLED]);
- //发放平一级奖励
- $over_desc = "补货越级奖发放,越级层数1";
- $equal_desc = "补货平级奖发放,平级层数1";
- $this->equalOne($agent, $direct_agent, $stock_level, $over_desc, $equal_desc, $this->order['num'], $setting);
- }
- //发放平二级用户,间推
- if (!empty($this->user['second_parent_id'])) {
- //获取平二级代理商数据
- $second_parent_agent = CloudStockAgent::findOne(['user_id' => $this->user['second_parent_id'],'status'=>StatusEnum::ENABLED, 'mall_id' => $this->mall_id]);
- if($second_parent_agent){
- switch (true) {
- case $agent['level'] > $second_parent_agent['level']:
- $over_level = 2;
- $over_desc = "补货越级奖发放,越级层数" . $over_level;
- $stock_level = CloudStockLevel::findOne(['mall_id' => $this->mall_id, 'level' => $second_parent_agent['level'], 'status' => StatusEnum::ENABLED]);
- $this->sendOverReward($second_parent_agent, $stock_level, $over_level, $over_desc, $this->order['num'], !empty($setting['is_by_buy_agent_level']), $agent['level']);
- break;
- case $agent['level'] == $second_parent_agent['level']:
- if (empty($second_parent_agent['is_equal_award_restriction'])) {
- $equal_level = 2;
- $equal_desc = "补货平级奖发放,平级层数" . $equal_level;
- $stock_level = CloudStockLevel::findOne(['mall_id' => $this->mall_id, 'level' => $second_parent_agent['level'], 'status' => StatusEnum::ENABLED]);
- $this->sendEqualReward($second_parent_agent, $stock_level, $equal_level, $equal_desc, $this->order['num']);
- }
- break;
- }
- }
- }
- }
- }
- //补货奖励
- $level = CloudStockLevel::findOne(['mall_id' => $this->mall_id, 'level' => $agent->level, 'status' => StatusEnum::ENABLED]);
- if (!empty($level['is_fill'])) {
- //补货奖发放
- $stock_goods = CloudStockGoods::findOne(['mall_id' => $this->mall_id, 'goods_id' => $this->goods_id]);
- $fill_reward_logic = new FillRewardLogic($agent, $stock_goods, 0, $this->order['id'], $this->order['num'], 0,
- CloudStockEnum::CHANGE_TYPE_INCREASE_FILL_EXTRA_BONUS,
- '补货奖发放',
- 0
- );
- $reward_unit_price = $fill_reward_logic->addRewardLog();
- $configs = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_CLOUD_STOCK, 'basic');
- if(!empty($configs['fill_bonus'])){
- $this->unit_goods_price = $this->unit_goods_price-$reward_unit_price;
- if($this->unit_goods_price<0) $this->unit_goods_price = 0;
- }
- }
- return $this->unit_goods_price;
- }
- /**
- * 货款单价
- * @return float|int
- */
- public function getOrderGoodsUnitPrice()
- {
- return $this->order->pay_money / $this->order->num;
- }
- }
|