CommissionController.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace addons\Boss\backend\controllers;
  3. use addons\Boss\common\enums\BossEnum;
  4. use addons\Boss\common\enums\LevelEnum;
  5. use addons\Boss\common\models\AddonsBoss;
  6. use addons\Boss\common\models\AddonsBossCommissionLog;
  7. use addons\Boss\common\models\AddonsBossLevel;
  8. use addons\Boss\common\models\AddonsBossRewardLog;
  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\Boss\backend\controllers
  18. */
  19. class CommissionController extends AddonsController
  20. {
  21. /**
  22. * @var string
  23. */
  24. // public $layout = "@addons/Boss/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. $is_sediment = Yii::$app->services->setting->addons->get($this->mall_id, BossEnum::ADDONS_NAME, 'basic.is_sediment');// 分红周期
  48. $where = [];
  49. $where[] = ['=', 'mall_id', $this->mall_id];
  50. // 根据用户昵称搜索
  51. if (isset($params['keyword'])) {
  52. $where[] = ['=', 'user_id', $params['keyword']];
  53. // $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id,'mobile' => $params['keyword'],'status' => StatusEnum::ENABLED])->asArray()->scalar();
  54. // if ($user_id) $where[] = ['=', 'user_id', $user_id];
  55. }
  56. $where[] = ['=', 'status', StatusEnum::ENABLED];
  57. $order = 'id desc,created_at desc';
  58. $with = ['user'];
  59. $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $params['limit']);
  60. $list = AddonsBossCommissionLog::listPage($params, false, true);
  61. if (empty($list)) $this->error('获取失败');
  62. foreach ($list['list'] as &$item) {
  63. $item['start_time'] = date("Y-m-d", strtotime($item['start_time']));
  64. $item['end_time'] = date("Y-m-d", strtotime($item['end_time']));
  65. }
  66. $this->success('获取成功', compact('list', 'commonission_type', 'compute_period','is_sediment'));
  67. }
  68. }
  69. return $this->render($this->action->id);
  70. }
  71. /**
  72. * 分红明细
  73. * @Author: lun
  74. * @DateTime: 2021/11/5 0005 16:58
  75. * @Copyright: copyright (c) 2021 广东七件事集团
  76. * @return mixed|string|void
  77. */
  78. public function actionRewardLog()
  79. {
  80. $retuest = Yii::$app->request;
  81. if ($retuest->isAjax) {
  82. if ($retuest->isPost) {
  83. // 检查提交的参数
  84. $params = $retuest->post();
  85. $res = Yii::$app->services->validate->validate($params,[
  86. [['id','type','start_time','end_time'], 'required'],
  87. [['id','type'], 'integer'],
  88. [['start_time','end_time'], 'string']
  89. ]);
  90. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  91. // 获取股东等级
  92. $boss_level_list = AddonsBossLevel::getBossLevel([['mall_id' => $this->mall_id]], [],true,'level,name');
  93. $boss_level_arr = array_column($boss_level_list, null,'level');
  94. $settlement_method = LevelEnum::getSettlementMethod();// 结算方式
  95. $compute_type = LevelEnum::getComputeType();// 佣金计算方式
  96. // 获取用户信息
  97. $user = User::find()->select('nickname,avatar_url')->where(['mall_id' => $this->mall_id,'id' => $params['id']])->asArray()->one();
  98. $where = [];
  99. $where[] = ['=', 'mall_id', $this->mall_id];
  100. $where[] = ['=', 'user_id', $params['id']];
  101. $where[] = ['=', 'type', $params['type']];
  102. $where[] = ['between', 'date', str_replace('-','',$params['start_time']), str_replace('-','',$params['end_time'])];
  103. $where[] = ['=', 'is_settlement', StatusEnum::ENABLED];
  104. $where[] = ['=', 'status', StatusEnum::ENABLED];
  105. $order = 'created_at desc';
  106. $params = array('where' => $where, 'order' => $order, 'limit' => $params['limit']);
  107. $list = AddonsBossRewardLog::listPage($params, false, true);
  108. foreach($list['list'] as $key => $value){
  109. $value['settlement_config'] = json_decode($value['settlement_config'],true);
  110. $value['settlement_config']['order_type'] = '商城订单';
  111. if(isset($value['settlement_config']['order_source']) && $value['settlement_config']['store_id']){
  112. $value['settlement_config']['order_type'] = $value['settlement_config']['order_source'] == 'store_order' ? '门店订单,门店ID:'.$value['settlement_config']['store_id'] : '门店收银订单,门店ID:'.$value['settlement_config']['store_id'];
  113. }
  114. if(!empty($value['settlement_config']['order_source']) && !empty($value['settlement_config']['mch_id'])){
  115. $value['settlement_config']['order_type'] = '多商户订单';
  116. }
  117. $value['settlement_config'] = json_encode($value['settlement_config']);
  118. $value['commission_type_msg'] = '(元)';
  119. if(in_array($value['type'],[LevelEnum::DIGITAL_PRIZE,LevelEnum::EXTRA_DIGITAL_PRIZE])){
  120. $value['commission_type_msg'] = '(数字币)';
  121. }
  122. $list['list'][$key] = $value;
  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. /**
  130. * 手动执行
  131. * @Author: lun
  132. * @DateTime: 2022/9/14 0014 14:41
  133. * @Copyright: copyright (c) 2021 广东七件事集团
  134. */
  135. public function actionHandleJob()
  136. {
  137. try {
  138. $get = Yii::$app->request->get();
  139. $start_day = $get['start_day'] ?: date('Ymd');
  140. $end_day = $get['end_day'] ?: date('Ymd');
  141. $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Boss', 'basic');
  142. $logic = new \addons\Boss\common\logic\CommissionLogLogic();
  143. $res = $logic->addCommissionLog($this->mall_id, $config, $start_day, $end_day);
  144. if ($res === false) throw new \Exception($logic->getError());
  145. echo '执行成功';
  146. exit;
  147. } catch (\Exception $e) {
  148. echo '错误原因:'.$e->getMessage();
  149. exit;
  150. }
  151. }
  152. /**
  153. * 待结算明细
  154. * @Author: lun
  155. * @DateTime: 2023/7/18 0018 17:33
  156. * @Copyright: copyright (c) 2021 广东七件事集团
  157. * @return mixed|string|void
  158. */
  159. public function actionUnsettled()
  160. {
  161. $retuest = Yii::$app->request;
  162. if ($retuest->isAjax) {
  163. if ($retuest->isGet) {
  164. // 检查提交的参数
  165. $params = $retuest->get();
  166. $res = Yii::$app->services->validate->validate($params,[
  167. [['user_id', 'type', 'is_settlement', 'page', 'limit'], 'integer'],
  168. [['order_no'], 'string']
  169. ]);
  170. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  171. $commonission_type = LevelEnum::getCommissionType();// 分红类型
  172. $boss_levels = AddonsBossLevel::getLevelByColumn($this->mall_id);// 股东等级
  173. $where = [];
  174. $where[] = ['=', 'mall_id', $this->mall_id];
  175. // 根据条件搜索
  176. if (isset($params['user_id'])) $where[] = ['=', 'user_id', $params['user_id']];
  177. if (isset($params['order_no'])) $where[] = ['=', 'order_no', $params['order_no']];
  178. if (isset($params['type'])) $where[] = ['=', 'type', $params['type']];
  179. if (isset($params['is_settlement'])) $where[] = ['=', 'is_settlement', $params['is_settlement']];
  180. $where[] = ['=', 'status', StatusEnum::ENABLED];
  181. $order = 'id desc';
  182. $with = ['user'];
  183. $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $params['limit']);
  184. $list = AddonsBossRewardLog::listPage($params, false, true);
  185. if (empty($list)) $this->error('获取失败');
  186. $this->success('获取成功', compact('list', 'commonission_type', 'boss_levels'));
  187. }
  188. }
  189. return $this->render($this->action->id);
  190. }
  191. }