OverReward.php 2.3 KB

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