| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace addons\CloudStockTwo\common\logic\reward;
- use addons\CloudStockTwo\common\models\CloudStockTwoFillOrder;
- use common\enums\AddonsEnum;
- use common\models\order\Order;
- abstract class Reward
- {
- protected $bonus_agent; //分得奖励的代理商模型
- protected $stock_goods; //库存商品模型
- protected $after_distribution_unit_goods_price; //扣分润后的商品单价,(货款单价)
- public $reward_unit_price = 0; //商品奖励单价
- protected $after_count_unit_goods_price; //分配奖励后的货款单价
- protected $order_id; //订单id;
- protected $goods_num; //商城数量;
- protected $is_frozen; //是否结算
- protected $change_type; //资金变动类型
- protected $change_desc; //资金变动描述
- protected $mall_id;
- protected $is_job;
- protected $order_type;
- public function __construct($bonus_agent,
- $stock_goods,
- $after_distribution_unit_goods_price,
- $order_id,
- $goods_num,
- $is_frozen,
- $order_type,
- $change_desc, $is_job = 0)
- {
- $this->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;
- }
- }
|