DailyBonus.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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;
  16. use app\console\model\User as UserModel;
  17. use app\console\model\user\BonusHistory;
  18. use app\console\model\user\CommissionsDetail;
  19. /**
  20. * 服务类:每日计算店内职员的当月的业绩
  21. * Class UserGrade
  22. * @package app\console\service
  23. */
  24. class DailyBonus extends BaseService
  25. {
  26. /**
  27. * 每日计算店内职员的当月的业绩v.1.3.6
  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 calBonusMoney36(int $storeId)
  35. {
  36. // 获取店内员工的预计佣金
  37. $data = [];
  38. $userList = UserModel::getAllSellers();
  39. $month= (int)date('m');
  40. $year = (int)date('Y');
  41. $from = mktime(0,0,0,$month,1,$year);
  42. $to = time();
  43. // 遍历整理数据
  44. foreach ($userList as $user) {
  45. $infos = CommissionsDetail::getFullBonusInfo36($user,$from,$to);
  46. if (count($infos)){
  47. foreach ($infos as $info){
  48. $bflag = BonusHistory::add36($user['user_id'],$year,$month,$info['shop_id'],$info['role']
  49. ,$info['saleVolume'],$info['refundVolume'],$info['refundCount'],$info['countOvertimeSign']
  50. ,$info['sumOvertimeSign'],$info['bonusRate'],$info['bonusMoney'],$info['orderCount'],$info['bonusLadder']);
  51. if ($bflag == false){
  52. log_record(__METHOD__.':false:User:'.$user['user_id'].',shopId:'.$info['shop_id'].',role:'.$info['role']);
  53. }
  54. }
  55. }else{
  56. continue;
  57. }
  58. }
  59. // 记录日志
  60. Tools::taskLogs('DailyBonus', 'calBonusMoney', [
  61. 'storeId' => $storeId,
  62. 'data' => $data
  63. ]);
  64. return true;
  65. }
  66. }