'待发放', 1 => '发放成功', 2 => '发放异常', ]; public $reviewStatusList = [ 0 => '待审核', 1 => '审核通过', 2 => '审核拒绝', ]; public $typeDisplayNames = [ 'A' => '单笔充值福利', 'B' => '月卡福利发放', 'C' => '累充福利发放', 'D' => '首充福利发放', 'E' => '单日累充福利发放', 'F' => '周卡福利发放', ]; public $typeNames = [ 'A' => 'single', 'B' => 'daily', 'C' => 'accumulative', 'D' => 'firstPay', 'E' => 'dayAccumulative', 'F' => 'weekly', ]; public function isGiftItemSend($order, $item) { // 每日发放奖励暂时通过send_status来判断是否第一次发放 if ($order['send_status'] == 1 && isset($item['once']) && $item['once']) { return false; } return true; } public function sendByOrder($order, $handleDate = null) { $gift = M('rebate_gifts', 'tab_')->where(['base_game_id' => $order['base_game_id'], 'type' => $order['type'], 'gift_key' => $order['gift_key']])->find(); $hasError = false; $sendResult = ''; if ($gift['game_currency'] > 0) { $result = $this->sendGold($order, $gift['game_currency']); if (!$result['status']) { $hasError = true; } $sendResult .= ($result['message'] ?? '') . ';'; } $index = 1; $giftItems = json_decode($gift['gifts'], true); foreach ($giftItems as $giftItem) { $giftItem['index'] = $index; $index ++; if (!$this->isGiftItemSend($order, $giftItem)) { continue; } $result = $this->sendGift($order, $giftItem); if (!$result['status']) { $hasError = true; } $sendResult .= ($result['message'] ?? '') . ';'; } $data = [ 'send_status' => $hasError ? 2 : 1, 'send_time' => time(), 'send_result' => $sendResult, ]; if ($handleDate) { $data['current_award_date'] = $handleDate; } M('rebate_orders', 'tab_')->where(['id' => $order['id']])->save($data); } private function getClient($baseGameId) { $client = null; switch ($baseGameId) { case 70: $client = new XyyClient(); break; case 73: $client = new SbcqClient(); break; case 75: $client = new XlqyClient(); break; /* case 9: $client = new XlqyClient(); break; */ default: throw new \Exception('客户端未实现'); break; } return $client; } public function sendGold($order, $gold) { $client = $this->getClient($order['base_game_id']); return $client->sendGold($gold, $order); } public function sendGift($order, $giftItem) { $client = $this->getClient($order['base_game_id']); return $client->sendEmail($giftItem, $order); } public function review(array $ids, $status, $handler) { if (!in_array($status, [1, 2])) { throw new \Exception('状态异常'); } if (count($ids) == 0) { throw new \Exception('请选择要操作的记录'); } $orders = M('rebate_orders', 'tab_')->field(['id'])->where(['review_status' => 0, 'id' => ['in', $ids]])->select(); if (count($orders) != count($ids)) { throw new \Exception('含有不存在的记录或者已审核的记录'); } M('rebate_orders', 'tab_')->where(['review_status' => 0, 'id' => ['in', $ids]])->save([ 'review_type' => $handler['type'], 'review_status' => $status, 'review_time' => time(), 'reviewer_id' => $handler['id'], 'reviewer_username' => $handler['username'], ]); } public function sendOnce($type) { $orders = M('rebate_orders', 'tab_')->where(['type' => $type, 'review_status' => 1, 'send_status' => 0])->select(); foreach ($orders as $order) { $this->sendByOrder($order); } } public function sendDaily($type, $date) { $map = [ 'type' => $type, 'review_status' => 1, 'award_started_at' => ['elt', $date], 'award_ended_at' => ['egt', $date], '_string' => '(current_award_date is null or current_award_date < "' . $date . '")' ]; $orders = M('rebate_orders', 'tab_')->where($map)->select(); foreach ($orders as $order) { $this->sendByOrder($order, $date); } } public function listQuery($params, $awardType, $promote = null) { $isExport = $params['is_export'] ?? 0; $page = $params['page'] ?? 0; $limit = $params['limit'] ?? 0; $baseGameId = $params['base_game_id'] ?? 0; $serverId = $params['server_id'] ?? ''; $roleName = $params['role_name'] ?? ''; $userAccount = $params['user_account'] ?? ''; $reviewStatus = $params['review_status'] ?? -1; $sendStatus = $params['send_status'] ?? -1; $reviewerId = $params['reviewer_id'] ?? 0; $reviewType = $params['review_type'] ?? -1; $where = [ '_string' => '1=1', ]; $where['type'] = $awardType; if ($baseGameId != 0) { $where['base_game_id'] = $baseGameId; } if ($userAccount != '') { $where['user_account'] = ['like', $userAccount . '%']; } if ($roleName != '') { $where['role_name'] = ['like', $roleName . '%']; } if ($serverId != '') { $where['server_id'] = $serverId; } if ($reviewStatus != -1) { $where['review_status'] = $reviewStatus; } if ($sendStatus != -1) { $where['send_status'] = $sendStatus; } if ($reviewerId != 0) { $where['reviewer_id'] = $reviewerId; } if ($reviewType != -1) { $where['review_type'] = $reviewType; } if (I('send_time_start', '') != '') { $where['_string'] .= ' and send_time>=' . strtotime(I('send_time_start') . ' 00:00:00'); } if (I('send_time_end', '') != '') { $where['_string'] .= ' and send_time<=' . strtotime(I('send_time_end') . ' 23:59:59'); } if (I('create_time_start', '') != '') { $where['_string'] .= ' and create_time>=' . strtotime(I('create_time_start') . ' 00:00:00'); } if (I('create_time_end', '') != '') { $where['_string'] .= ' and create_time<=' . strtotime(I('create_time_end') . ' 23:59:59'); } if ($promote) { $promoteService = new PromoteService(); $subSql = M('user', 'tab_')->field(['id'])->where(['_string' => 'promote_id in(' . $promoteService->subInSql($promote) . ')'])->select(false); $where['_string'] .= ' and user_id in(' . $subSql . ')'; } $query = M('rebate_orders', 'tab_')->where($where); $count = 0; $records = []; if ($isExport == 1 || $limit == 'all') { $records = $query->order('create_time desc')->select(); $count = count($records); } else { $countQuery = clone $query; $records = $query->order('create_time desc')->page($page, $limit)->select(); $count = $countQuery->count(); } return [$records, $count]; } public function listRange(array $records, $isExport = false) { $users = []; if (count($records) > 0) { $userIds = array_column($records, 'user_id'); $users = M('user', 'tab_')->field(['id', 'promote_account'])->where(['id' => ['in', $userIds]])->select(); $users = index_by_column('id', $users); } $newLine = $isExport == 1 ? "\n" : '
'; foreach ($records as $key => $record) { $user = $users[$record['user_id']]; $records[$key]['promote_account'] = $user['promote_account']; $records[$key]['review_status_text'] = $this->reviewStatusList[$record['review_status']]; $records[$key]['review_time'] = $record['review_time'] > 0 ? date('Y-m-d H:i:s', $record['review_time']) : '--'; $records[$key]['send_status_text'] = $this->sendStatusList[$record['send_status']]; $records[$key]['send_time'] = $record['send_time'] > 0 ? date('Y-m-d H:i:s', $record['send_time']) : '--'; $records[$key]['create_time'] = $record['create_time'] > 0 ? date('Y-m-d H:i:s', $record['create_time']) : '--'; $records[$key]['award_date_range'] = is_null($record['award_started_at']) || is_null($record['award_ended_at']) ? '' : $record['award_started_at'] . ' ~ ' . $record['award_ended_at']; $records[$key]['gift_content'] = implode($newLine, explode('|', $record['gift_content'])); } return $records; } public function getExportHeadings($awardType) { $fields = [ 'base_game_name' => '游戏名称', 'server_name' => '区服', 'user_account' => '账号', 'role_id' => '角色ID', 'role_name' => '角色名称', 'promote_account' => '所属推广员', ]; if ($awardType == 'A') { $fields['pay_amount'] = '充值金额'; } elseif ($awardType == 'B') { $fields['pay_amount'] = '当日累计充值金额'; $fields['award_date_range'] = '可领取福利日期'; } elseif ($awardType == 'C') { $fields['amount'] = '达到档位金额'; } elseif ($awardType == 'D') { $fields['pay_amount'] = '首充金额'; } elseif($awardType == 'E') { $fields['pay_amount'] = '当日累计充值金额'; $fields['award_date'] = '达成日期'; } elseif($awardType == 'F') { $fields['award_date_range'] = '可领取福利日期'; } $fields = array_merge($fields, [ 'gift_content' => '奖励内容', 'create_time' => '订单生成时间', 'review_status_text' => '审核状态', 'review_time' => '审核时间', 'send_status_text' => '发放状态', 'send_time' => '发放时间', 'reviewer_username' => '审核人', ]); return $fields; } public function addSimulateSpend($params, $handler = null) { $baseGameId = $params['base_game_id'] ?? 0; $roleId = $params['role_id'] ?? ''; $amount = $params['amount'] ?? 0; $remark = $params['remark'] ?? ''; if ($baseGameId == 0) { throw new \Exception('请选择游戏'); } if ($roleId == 0) { throw new \Exception('请输入角色ID'); } if ($amount <= 0) { throw new \Exception('金额必须大于0'); } $baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find(); if ($baseGame == null) { throw new \Exception('游戏不存在'); } $gameIds = [$baseGame['android_game_id'], $baseGame['ios_game_id']]; $role = M('user_play_info', 'tab_')->where(['role_id' => $roleId, 'game_id' => ['in', $gameIds]])->find(); if ($role == null) { throw new \Exception('角色不存在'); } $data = [ 'user_id' => $role['user_id'], 'user_account' => $role['user_account'], 'base_game_id' => $baseGame['id'], 'base_game_name' => $baseGame['name'], 'role_id' => $role['role_id'], 'role_name' => $role['role_name'], 'server_id' => $role['server_id'], 'server_name' => $role['server_name'], 'order_no' => '', 'create_time' => time(), 'amount' => $amount, 'remark' => $remark ]; M('simulate_spend', 'tab_')->add($data); } public function reviewSimulateSpend(array $ids, $status, $handler) { if (!in_array($status, [1, 2])) { throw new \Exception('状态异常'); } if (count($ids) == 0) { throw new \Exception('请选择要操作的记录'); } $orders = M('simulate_spend', 'tab_')->field(['id'])->where(['review_status' => 0, 'id' => ['in', $ids]])->select(); if (count($orders) != count($ids)) { throw new \Exception('含有不存在的记录或者已审核的记录'); } M('simulate_spend', 'tab_')->where(['status' => 0, 'id' => ['in', $ids]])->save([ 'status' => $status, 'review_time' => time(), 'reviewer_id' => $handler['id'], 'reviewer_username' => $handler['username'], ]); } }