OverReward.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace addons\CloudStockTwo\common\logic\reward;
  3. use addons\CloudStockTwo\common\models\CloudStockTwoAgent;
  4. use addons\CloudStockTwo\common\models\CloudStockTwoLevel;
  5. use common\enums\StatusEnum;
  6. use common\enums\UserWalletEnum;
  7. class OverReward extends Reward
  8. {
  9. public $over_level = 0;
  10. /**
  11. * 记录奖励
  12. */
  13. protected function addRewardLog()
  14. {
  15. $this->getRewardUnitPrice();
  16. //没有设置奖励金额
  17. if (empty($this->reward_unit_price)) return false;
  18. //扣库存数量为0;没有奖励
  19. if (empty($this->goods_num)) return false;
  20. if ($this->is_job) return true;
  21. $insert_wallet = $this->getInsertWallet(UserWalletEnum::OVER);
  22. if ($insert_wallet) CloudStockTwoAgent::sendUserWalletQueue($insert_wallet);
  23. }
  24. public function getRewardUnitPrice()
  25. {
  26. $level = CloudStockTwoLevel::findOne(['mall_id' => $this->mall_id, 'level' => $this->bonus_agent['level'], 'status' => StatusEnum::ENABLED]);
  27. switch ($this->over_level) {
  28. case 1:
  29. $over_level_list = json_decode($this->stock_goods['over_level_list'], true);
  30. $this->reward_unit_price = 0;
  31. break;
  32. case 2:
  33. if(!empty($this->stock_goods['over_level_list_2'])){
  34. $over_level_list_2 = json_decode($this->stock_goods['over_level_list_2'], true);
  35. $over_level_list = $over_level_list_2;
  36. }
  37. break;
  38. default:
  39. $this->reward_unit_price = 0;
  40. return;
  41. }
  42. if (!empty($level) && !empty($over_level_list)) {
  43. foreach ($over_level_list as $value) {
  44. if ($value['level'] == $this->bonus_agent->level) {
  45. $this->reward_unit_price = $value['price'];
  46. return;
  47. }
  48. }
  49. }
  50. $this->reward_unit_price = 0;
  51. }
  52. }