MonthlyBonusClear.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\console\service;
  13. use app\console\library\Tools;
  14. use app\common\service\BaseService;
  15. use app\console\model\User as UserModel;
  16. use app\console\model\user\BonusHistory;
  17. use app\console\model\user\CommissionsDetail;
  18. use app\console\model\user\WithdrawMoneyLog;
  19. /**
  20. * 服务类:每月20日结算店内职员的上月的业绩
  21. * Class UserGrade
  22. * @package app\console\service
  23. */
  24. class MonthlyBonusClear extends BaseService
  25. {
  26. /**
  27. * 每月20日结算店内职员的上月的业绩
  28. * @param int $storeId
  29. * @return array|bool
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function clearBonusMoney36(int $storeId)
  35. {
  36. // 获取店内员工的预计佣金
  37. $data = [];
  38. $userList = UserModel::getAllSellers();
  39. $month= (int)date('m');
  40. $year = (int)date('Y');
  41. $to = mktime(0,0,0,$month,1,$year) - 1;
  42. $ym = date('Y-m',$to);
  43. list($prevYear,$prevMonth) = explode('-',$ym);
  44. $from = mktime(0,0,0,(int)$prevMonth,1,(int)$prevYear);
  45. foreach ($userList as $user) {
  46. $infos = CommissionsDetail::getFullBonusInfo36($user,$from,$to,true);
  47. if (count($infos)){
  48. foreach ($infos as $info){
  49. $bflag = BonusHistory::add36($user['user_id'],$prevYear,$prevMonth,$info['shop_id'],$info['role']
  50. ,$info['saleVolume'],$info['refundVolume'],$info['refundCount'],$info['countOvertimeSign']
  51. ,$info['sumOvertimeSign'],$info['bonusRate'],$info['bonusMoney'],$info['orderCount'],$info['bonusLadder'],true);
  52. if ($bflag == false){
  53. log_record(__METHOD__.':false:User:'.$user['user_id'].',shopId:'.$info['shop_id'].',role:'.$info['role']);
  54. continue;
  55. }
  56. //scene 60月奖励金
  57. $flag = WithdrawMoneyLog::addNewLog($user['user_id'],60,$info['bonusMoney'],'',$prevYear.$prevMonth.',shop:'.$info['shop_id'].',role:'.$info['role']);
  58. if ($flag === false){
  59. log_record(__CLASS__.':'.__METHOD__.':failed userId:'.$user['user_id'],'error');
  60. continue;
  61. }
  62. }
  63. }else{
  64. continue;
  65. }
  66. }
  67. // 记录日志
  68. Tools::taskLogs('MonthlyBonusClear', 'clearBonusMoney', [
  69. 'storeId' => $storeId,
  70. 'data' => $data
  71. ]);
  72. return true;
  73. }
  74. public function clearBonusMoney36Test(int $storeId)
  75. {
  76. // 获取店内员工的预计佣金
  77. $lastMonth = false;
  78. $data = [];
  79. $userList = UserModel::getAllSellers();
  80. $month= (int)date('m');
  81. $year = (int)date('Y');
  82. if ($lastMonth == true){
  83. $to = mktime(0,0,0,$month,1,$year) - 1;
  84. }else{
  85. $to = mktime(0,0,0,$month,1,$year);
  86. }
  87. $ym = date('Y-m',$to);
  88. list($prevYear,$prevMonth) = explode('-',$ym);
  89. $from = mktime(0,0,0,(int)$prevMonth,1,(int)$prevYear);
  90. if ($lastMonth == false){
  91. $to = time();
  92. }
  93. $prevMonth = intval($prevMonth);
  94. foreach ($userList as $user) {
  95. $infos = CommissionsDetail::getFullBonusInfo36($user,$from,$to,true);
  96. if (count($infos)){
  97. foreach ($infos as $info){
  98. $bflag = BonusHistory::add36($user['user_id'],$prevYear,$prevMonth,$info['shop_id'],$info['role']
  99. ,$info['saleVolume'],$info['refundVolume'],$info['refundCount'],$info['countOvertimeSign']
  100. ,$info['sumOvertimeSign'],$info['bonusRate'],$info['bonusMoney'],$info['orderCount'],$info['bonusLadder'],true);
  101. if ($bflag == false){
  102. log_record(__METHOD__.':false:User:'.$user['user_id'].',shopId:'.$info['shop_id'].',role:'.$info['role'],'error');
  103. continue;
  104. }
  105. //scene 60月奖励金
  106. $flag = WithdrawMoneyLog::addNewLog($user['user_id'],60,$info['bonusMoney'],'',$prevYear.$prevMonth.',shop:'.$info['shop_id'].',role:'.$info['role']);
  107. if ($flag === false){
  108. log_record(__CLASS__.':'.__METHOD__.':failed userId:'.$user['user_id'],'error');
  109. continue;
  110. }
  111. }
  112. }else{
  113. continue;
  114. }
  115. }
  116. // 记录日志
  117. Tools::taskLogs('MonthlyBonusClear', 'clearBonusMoney', [
  118. 'storeId' => $storeId,
  119. 'data' => $data
  120. ]);
  121. return true;
  122. }
  123. }