CommissionController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace addons\BossWeight\backend\controllers;
  3. use addons\BossWeight\common\enums\LevelEnum;
  4. use addons\BossWeight\common\models\AddonsBoss;
  5. use addons\BossWeight\common\models\AddonsBossCommissionLog;
  6. use addons\BossWeight\common\models\AddonsBossLevel;
  7. use addons\BossWeight\common\models\AddonsBossRewardLog;
  8. use addons\BossWeight\common\models\AddonsBossRewardOrderLog;
  9. use common\enums\StatusEnum;
  10. use common\models\base\User;
  11. use Yii;
  12. use common\controllers\AddonsController;
  13. /**
  14. * 结算明细控制器
  15. *
  16. * Class CommissionController
  17. * @package addons\BossWeight\backend\controllers
  18. */
  19. class CommissionController extends AddonsController
  20. {
  21. /**
  22. * @var string
  23. */
  24. // public $layout = "@addons/BossWeight/backend/views/layouts/main";
  25. public $enableCsrfValidation = false;
  26. /**
  27. * 结算周期明细列表
  28. * @Author: lun
  29. * @DateTime: 2021/10/23 0023 10:14
  30. * @Copyright: copyright (c) 2021 广东七件事集团
  31. * @return mixed|void
  32. */
  33. public function actionIndex()
  34. {
  35. $retuest = Yii::$app->request;
  36. if ($retuest->isAjax) {
  37. if ($retuest->isPost) {
  38. // 检查提交的参数
  39. $params = $retuest->post();
  40. $res = Yii::$app->services->validate->validate($params,[
  41. [['page','limit'], 'integer'],
  42. [['keyword'], 'string']
  43. ]);
  44. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  45. $commonission_type = LevelEnum::getCommissionType();// 分红类型
  46. $compute_period = LevelEnum::getComputePeriod();// 分红周期
  47. $where = [];
  48. $where[] = ['=', 'mall_id', $this->mall_id];
  49. // 根据用户昵称搜索
  50. if (isset($params['keyword'])) {
  51. $where[] = ['=', 'user_id', $params['keyword']];
  52. // $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id,'mobile' => $params['keyword'],'status' => StatusEnum::ENABLED])->asArray()->scalar();
  53. // if ($user_id) $where[] = ['=', 'user_id', $user_id];
  54. }
  55. $where[] = ['=', 'status', StatusEnum::ENABLED];
  56. $order = 'id desc';
  57. $with = ['user'];
  58. $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $params['limit']);
  59. $list = AddonsBossCommissionLog::listPage($params, false, true);
  60. if (empty($list)) $this->error('获取失败');
  61. foreach ($list['list'] as &$item) {
  62. $item['start_time'] = date("Y-m-d", strtotime($item['start_time']));
  63. $item['end_time'] = date("Y-m-d", strtotime($item['end_time']));
  64. }
  65. $this->success('获取成功', compact('list', 'commonission_type', 'compute_period'));
  66. }
  67. }
  68. return $this->render($this->action->id);
  69. }
  70. /**
  71. * 分红明细
  72. * @Author: lun
  73. * @DateTime: 2021/11/5 0005 16:58
  74. * @Copyright: copyright (c) 2021 广东七件事集团
  75. * @return mixed|string|void
  76. */
  77. public function actionRewardLog()
  78. {
  79. $retuest = Yii::$app->request;
  80. if ($retuest->isAjax) {
  81. if ($retuest->isPost) {
  82. // 检查提交的参数
  83. $params = $retuest->post();
  84. $res = Yii::$app->services->validate->validate($params,[
  85. [['id','type','start_time','end_time','commission_id'], 'required'],
  86. [['id','type','commission_id'], 'integer'],
  87. [['start_time','end_time'], 'string']
  88. ]);
  89. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  90. // 获取股东等级
  91. $boss_level_list = AddonsBossLevel::getBossLevel([['mall_id' => $this->mall_id]], [],true,'level,name');
  92. $boss_level_arr = array_column($boss_level_list, null,'level');
  93. $settlement_method = LevelEnum::getSettlementMethod();// 结算方式
  94. $compute_type = LevelEnum::getComputeType();// 佣金计算方式
  95. // 获取用户信息
  96. $user = User::find()->select('nickname,avatar_url')->where(['mall_id' => $this->mall_id,'id' => $params['id']])->asArray()->one();
  97. if($params['type'] == 4){
  98. $settlement_config = AddonsBossCommissionLog::find()->select('settlement_config')->where(['id' => $params['commission_id']])->column();
  99. $where = [];
  100. $where[] = ['=', 'mall_id', $this->mall_id];
  101. $where[] = ['between', 'date', str_replace('-','',$params['start_time']), str_replace('-','',$params['end_time'])];
  102. $where[] = ['=', 'status', StatusEnum::ENABLED];
  103. $order = 'id desc';
  104. $params = array('where' => $where, 'order' => $order, 'limit' => $params['limit']);
  105. $list = AddonsBossRewardOrderLog::listPage($params, false, true);
  106. foreach($list['list'] as &$item){
  107. $item['type'] = 4;
  108. $item['settlement_config'] = $settlement_config;
  109. $settlement_config_array = \yii\helpers\Json::decode($settlement_config[0]);
  110. $item['settle_price'] = bcdiv($item['amounts']*$settlement_config_array['weight_turnover_ratio']*$settlement_config_array['weight_level_ratio'],10000,2);
  111. }
  112. }else{
  113. $where = [];
  114. $where[] = ['=', 'mall_id', $this->mall_id];
  115. $where[] = ['=', 'user_id', $params['id']];
  116. $where[] = ['=', 'type', $params['type']];
  117. $where[] = ['between', 'date', str_replace('-','',$params['start_time']), str_replace('-','',$params['end_time'])];
  118. $where[] = ['=', 'is_settlement', StatusEnum::ENABLED];
  119. $where[] = ['=', 'status', StatusEnum::ENABLED];
  120. $order = 'created_at desc';
  121. $params = array('where' => $where, 'order' => $order, 'limit' => $params['limit']);
  122. $list = AddonsBossRewardLog::listPage($params, false, true);
  123. }
  124. $this->success('获取成功', compact('list','boss_level_arr', 'user', 'settlement_method' ,'compute_type'));
  125. }
  126. }
  127. return $this->render($this->action->id);
  128. }
  129. }