CommissionRateService.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/12/4
  6. * Time: 上午9:56
  7. */
  8. namespace App\Modules\Finance\Services;
  9. use App\Modules\Finance\Models\Bill;
  10. use App\Modules\Finance\Models\CommissionRate;
  11. class CommissionRateService
  12. {
  13. /**
  14. *
  15. * @param $id
  16. * @return mixed
  17. */
  18. public static function getCommissionRateSingle($id) {
  19. $result = CommissionRate::where('id', $id)->first();
  20. return $result;
  21. }
  22. /**
  23. * 获取佣金结算比例列表
  24. * @param $channelId
  25. * @return mixed
  26. */
  27. public static function getCommissionRateList($channelId) {
  28. $result = CommissionRate::getListByDistributionChannel($channelId);
  29. return $result;
  30. }
  31. /**
  32. * 创建佣金结算
  33. * @param $channelId
  34. * @param $begin_amount 起始金额
  35. * @param $end_amount 结束金额
  36. * @param $rate 比例
  37. * @return mixed
  38. */
  39. public static function addCommissionRate($channelId, $begin_amount, $end_amount, $rate) {
  40. if(is_numeric($rate) && $rate >= 1) {
  41. $rate = '';
  42. }
  43. $data['distribution_channel_id'] = $channelId;
  44. $data['begin_amount'] = $begin_amount;
  45. $data['end_amount'] = $end_amount;
  46. $data['rate'] = $rate;
  47. $result = CommissionRate::create($data);
  48. return $result;
  49. }
  50. /**
  51. * 更新佣金结算
  52. * @param $id
  53. * @param string $begin_amount 起始金额
  54. * @param string $end_amount 结束金额
  55. * @param string $rate 比例
  56. * @param string $channelId
  57. */
  58. public static function updateCommissionRate($id, $begin_amount = '', $end_amount = '', $rate = '', $channelId = '') {
  59. $commissionRate = self::getCommissionRateSingle($id);
  60. if(empty($commissionRate)) {
  61. return;
  62. }
  63. if(is_numeric($rate) && $rate >= 1) {
  64. $rate = '';
  65. }
  66. if($begin_amount) {
  67. $commissionRate['begin_amount'] = $begin_amount;
  68. }
  69. if($end_amount) {
  70. $commissionRate['end_amount'] = $end_amount;
  71. }
  72. if($rate) {
  73. $commissionRate['rate'] = $rate;
  74. }
  75. if($channelId) {
  76. $commissionRate['distribution_channel_id'] = $channelId;
  77. }
  78. $commissionRate->save();
  79. }
  80. /**
  81. * 获取当前渠道当前佣金比例
  82. * @param $channelId
  83. * @return mixed
  84. */
  85. public static function getRateCommissionRate($channelId) {
  86. $rate = Bill::getRate($channelId);
  87. return $rate;
  88. }
  89. }