123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\console\service;
- use app\console\library\Tools;
- use app\common\service\BaseService;
- use app\console\model\User as UserModel;
- use app\console\model\user\BonusHistory;
- use app\console\model\user\CommissionsDetail;
- use app\console\model\user\WithdrawMoneyLog;
- /**
- * 服务类:每月20日结算店内职员的上月的业绩
- * Class UserGrade
- * @package app\console\service
- */
- class MonthlyBonusClear extends BaseService
- {
- /**
- * 每月20日结算店内职员的上月的业绩
- * @param int $storeId
- * @return array|bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function clearBonusMoney36(int $storeId)
- {
- // 获取店内员工的预计佣金
- $data = [];
- $userList = UserModel::getAllSellers();
- $month= (int)date('m');
- $year = (int)date('Y');
- $to = mktime(0,0,0,$month,1,$year) - 1;
- $ym = date('Y-m',$to);
- list($prevYear,$prevMonth) = explode('-',$ym);
- $from = mktime(0,0,0,(int)$prevMonth,1,(int)$prevYear);
- foreach ($userList as $user) {
- $infos = CommissionsDetail::getFullBonusInfo36($user,$from,$to,true);
- if (count($infos)){
- foreach ($infos as $info){
- $bflag = BonusHistory::add36($user['user_id'],$prevYear,$prevMonth,$info['shop_id'],$info['role']
- ,$info['saleVolume'],$info['refundVolume'],$info['refundCount'],$info['countOvertimeSign']
- ,$info['sumOvertimeSign'],$info['bonusRate'],$info['bonusMoney'],$info['orderCount'],$info['bonusLadder'],true);
- if ($bflag == false){
- log_record(__METHOD__.':false:User:'.$user['user_id'].',shopId:'.$info['shop_id'].',role:'.$info['role']);
- continue;
- }
- //scene 60月奖励金
- $flag = WithdrawMoneyLog::addNewLog($user['user_id'],60,$info['bonusMoney'],'',$prevYear.$prevMonth.',shop:'.$info['shop_id'].',role:'.$info['role']);
- if ($flag === false){
- log_record(__CLASS__.':'.__METHOD__.':failed userId:'.$user['user_id'],'error');
- continue;
- }
- }
- }else{
- continue;
- }
- }
- // 记录日志
- Tools::taskLogs('MonthlyBonusClear', 'clearBonusMoney', [
- 'storeId' => $storeId,
- 'data' => $data
- ]);
- return true;
- }
- public function clearBonusMoney36Test(int $storeId)
- {
- // 获取店内员工的预计佣金
- $lastMonth = false;
- $data = [];
- $userList = UserModel::getAllSellers();
- $month= (int)date('m');
- $year = (int)date('Y');
- if ($lastMonth == true){
- $to = mktime(0,0,0,$month,1,$year) - 1;
- }else{
- $to = mktime(0,0,0,$month,1,$year);
- }
- $ym = date('Y-m',$to);
- list($prevYear,$prevMonth) = explode('-',$ym);
- $from = mktime(0,0,0,(int)$prevMonth,1,(int)$prevYear);
- if ($lastMonth == false){
- $to = time();
- }
- $prevMonth = intval($prevMonth);
- foreach ($userList as $user) {
- $infos = CommissionsDetail::getFullBonusInfo36($user,$from,$to,true);
- if (count($infos)){
- foreach ($infos as $info){
- $bflag = BonusHistory::add36($user['user_id'],$prevYear,$prevMonth,$info['shop_id'],$info['role']
- ,$info['saleVolume'],$info['refundVolume'],$info['refundCount'],$info['countOvertimeSign']
- ,$info['sumOvertimeSign'],$info['bonusRate'],$info['bonusMoney'],$info['orderCount'],$info['bonusLadder'],true);
- if ($bflag == false){
- log_record(__METHOD__.':false:User:'.$user['user_id'].',shopId:'.$info['shop_id'].',role:'.$info['role'],'error');
- continue;
- }
- //scene 60月奖励金
- $flag = WithdrawMoneyLog::addNewLog($user['user_id'],60,$info['bonusMoney'],'',$prevYear.$prevMonth.',shop:'.$info['shop_id'].',role:'.$info['role']);
- if ($flag === false){
- log_record(__CLASS__.':'.__METHOD__.':failed userId:'.$user['user_id'],'error');
- continue;
- }
- }
- }else{
- continue;
- }
- }
- // 记录日志
- Tools::taskLogs('MonthlyBonusClear', 'clearBonusMoney', [
- 'storeId' => $storeId,
- 'data' => $data
- ]);
- return true;
- }
- }
|