// +---------------------------------------------------------------------- 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; } }