Skip to content

Commit

Permalink
Merge pull request #167 from maxincai/master
Browse files Browse the repository at this point in the history
[Bug修复](1.1.2): 修复 V1.1若干已知bug
  • Loading branch information
maxincai authored Sep 20, 2021
2 parents 161374c + c974ad3 commit 25a8d1a
Show file tree
Hide file tree
Showing 24 changed files with 257 additions and 307 deletions.
2 changes: 1 addition & 1 deletion api-server/app/core/install/src/Command/VersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VersionCommand extends HyperfCommand
*
* @var string
*/
private const VERSION = '1.1.1';
private const VERSION = '1.1.2';

public function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function handle(): array
$uploadFile = json_decode($medium['content'], true);
$mediaType = self::wxMediaType($medium['type']);
$path = isset($uploadFile[$mediaType . 'Path']) ? $uploadFile[$mediaType . 'Path'] : '';
$filename = isset($uploadFile[$mediaType . 'Name']) ? $uploadFile[$mediaType . 'Name'] : '';
if (empty($path)) {
return [
'mediaId' => $medium['mediaId'],
Expand All @@ -93,7 +94,7 @@ public function handle(): array
try {
// TODO 语音转换amr
$corpId = user()['corpId'];
$mediaId = $this->media->upload($corpId, $mediaType, $path);
$mediaId = $this->media->upload($corpId, $mediaType, $path, $filename);
$dbData = [
'id' => $medium['id'],
'media_id' => $mediaId,
Expand Down
3 changes: 2 additions & 1 deletion api-server/app/core/medium/src/Logic/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function getWxMediumId(array $ids, int $corpId): array
$uploadFile = json_decode($medium['content'], true);
$mediaType = self::wxMediaType($medium['type']);
$path = isset($uploadFile[$mediaType . 'Path']) ? $uploadFile[$mediaType . 'Path'] : '';
$filename = isset($uploadFile[$mediaType . 'Name']) ? $uploadFile[$mediaType . 'Name'] : '';
if (empty($path)) {
continue;
}
Expand All @@ -72,7 +73,7 @@ public function getWxMediumId(array $ids, int $corpId): array

try {
// TODO 语音转换amr
$mediaId = $this->media->upload($corpId, $mediaType, $path);
$mediaId = $this->media->upload($corpId, $mediaType, $path, $filename);
$dbData[] = [
'id' => $medium['id'],
'media_id' => $mediaId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ protected function officialAccountBindOpenPlatform(array $authorizationInfo)
$authorizationInfo['authorizer_refresh_token'],
);
$officialAccount = rebind_app($officialAccount, $this->request);
$officialAccount->account->create();
$res = $officialAccount->account->get();
// 如果未绑定过开放平台账号时才自动创建并绑定
if ($res['errcode'] === 89002) {
$officialAccount->account->create();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private function createContactEmployee(int $corpId, int $contactId, int $employe
return;
}

$addWay = isset($followEmployee['add_way']) ? $followEmployee['add_way'] : 0;
// 组织客户与企业用户关联表信息
$createContractEmployeeData = [
'employee_id' => $employeeId,
Expand All @@ -254,7 +255,7 @@ private function createContactEmployee(int $corpId, int $contactId, int $employe
'description' => isset($followEmployee['description']) ? $followEmployee['description'] : '',
'remark_corp_name' => isset($followEmployee['remark_corp_name']) ? $followEmployee['remark_corp_name'] : '',
'remark_mobiles' => isset($followEmployee['remark_mobiles']) ? json_encode($followEmployee['remark_mobiles']) : json_encode([]),
'add_way' => isset($followEmployee['add_way']) ? $followEmployee['add_way'] : 0,
'add_way' => $addWay,
'oper_userid' => isset($followEmployee['oper_userid']) ? $followEmployee['oper_userid'] : '',
'state' => isset($followEmployee['state']) ? $followEmployee['state'] : '',
'corp_id' => $corpId,
Expand All @@ -265,7 +266,7 @@ private function createContactEmployee(int $corpId, int $contactId, int $employe
];
$this->workContactEmployeeService->createWorkContactEmployee($createContractEmployeeData);

$this->createContactTrack($corpId, $contactId, $employeeId, $employeeName, $followEmployee['add_way']);
$this->createContactTrack($corpId, $contactId, $employeeId, $employeeName, $addWay);
}

/**
Expand Down
34 changes: 21 additions & 13 deletions api-server/app/utils/src/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Media
* @param int|string $corpId 企业id
* @param string $path 上传路径
*
* @throws \Throwable
* @return string
*/
public function uploadImage($corpId, string $path): string
{
Expand All @@ -65,7 +65,7 @@ public function uploadImage($corpId, string $path): string
* @param int|string $corpId 企业id
* @param string $path 上传路径
*
* @throws \Throwable
* @return string
*/
public function uploadVoice($corpId, string $path): string
{
Expand All @@ -78,7 +78,7 @@ public function uploadVoice($corpId, string $path): string
* @param int|string $corpId 企业id
* @param string $path 上传路径
*
* @throws \Throwable
* @return string
*/
public function uploadVideo($corpId, string $path): string
{
Expand All @@ -90,12 +90,13 @@ public function uploadVideo($corpId, string $path): string
*
* @param int|string $corpId 企业id
* @param string $path 上传路径
* @param string $filename 文件名
*
* @throws \Throwable
* @return string
*/
public function uploadFile($corpId, string $path): string
public function uploadFile($corpId, string $path, string $filename = ''): string
{
return $this->upload($corpId, 'file', $path);
return $this->upload($corpId, 'file', $path, $filename);
}

/**
Expand All @@ -104,12 +105,13 @@ public function uploadFile($corpId, string $path): string
* @param int|string $corpId 企业id
* @param string $type 上传类型
* @param string $path 上传路径
* @param string $filename 文件名
*
* @throws \Throwable
* @return string
*/
public function upload($corpId, string $type, string $path): string
public function upload($corpId, string $type, string $path, string $filename = ''): string
{
$mediaId = $this->cache->get($this->getCacheKey($corpId, $path));
$mediaId = $this->cache->get($this->getCacheKey($corpId, $path, $filename));
if (! empty($mediaId)) {
return $mediaId;
}
Expand All @@ -120,11 +122,17 @@ public function upload($corpId, string $type, string $path): string
$fileContent = $this->filesystem->read($path);
$tempFile = tempnam(sys_get_temp_dir(), 'Media');
file_put_contents($tempFile, $fileContent, FILE_USE_INCLUDE_PATH);
$wxMediaRes = $mediaService->upload($type, $tempFile);

$form = [];
if (! empty($filename)) {
$form['filename'] = $filename;
}

$wxMediaRes = $mediaService->upload($type, $tempFile, $form);
if ($wxMediaRes['errcode'] != 0) {
throw new CommonException(ErrorCode::INVALID_PARAMS, sprintf('请求数据:%s 响应结果:%s', $path, json_encode($wxMediaRes)));
}
$this->cache->set($this->getCacheKey($corpId, $path), $wxMediaRes['media_id'], 60 * 60 * 24 * 3 - 300);
$this->cache->set($this->getCacheKey($corpId, $path, $filename), $wxMediaRes['media_id'], 60 * 60 * 24 * 3 - 300);
return $wxMediaRes['media_id'];
} catch (\Throwable $e) {
## 记录错误日志
Expand All @@ -136,8 +144,8 @@ public function upload($corpId, string $type, string $path): string
}
}

protected function getCacheKey($corpId, string $path)
protected function getCacheKey($corpId, string $path, string $filename = '')
{
return sprintf('mochat:mediaId:%s:%s', (string) $corpId, md5($path));
return sprintf('mochat:mediaId:%s:%s', (string) $corpId, md5($path . $filename));
}
}
2 changes: 1 addition & 1 deletion api-server/config/autoload/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'max_request' => 100000,
'socket_buffer_size' => 2 * 1024 * 1024,
'buffer_output_size' => 2 * 1024 * 1024,
'package_max_length' => 10 * 1024 * 1024,
'package_max_length' => 20 * 1024 * 1024,
'log_file' => env('LOG_FILE', BASE_PATH . '/runtime/swoole.log'),
'document_root' => BASE_PATH . '/storage/upload/',
'enable_static_handler' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ private function handleDate($params): array
/**
* @throws \JsonException
*/
private function handleDraw(string $win_name, array $params, array $contact, array $prize, array $lottery): array
private function handleDraw(string $winName, array $params, array $contact, array $prize, array $lottery): array
{
## 抽奖信息
$data = [
'lottery_id' => $params['id'],
'contact_id' => $contact['id'],
'prize_id' => 1,
'prize_name' => $win_name,
'prize_name' => $winName,
'receive_qr' => '',
'receive_type' => 0,
'receive_code' => '',
Expand All @@ -231,31 +231,31 @@ private function handleDraw(string $win_name, array $params, array $contact, arr
}

## 奖项总数 中奖数量
if ($win_name !== '谢谢参与') {
if ($winName !== '谢谢参与') {
$prizeNum = 0;
foreach (json_decode($prize['prizeSet'], true, 512, JSON_THROW_ON_ERROR) as $key => $val) {
if ($val['name'] === $win_name) {
if ($val['name'] === $winName) {
$prizeNum = $val['num'];
$data['prize_id'] = $val['id'];
break;
}
}
$totalNum = $this->lotteryContactRecordService->countLotteryContactRecordByLotteryIdPrizeName((int) $params['id'], $win_name);
$totalNum = $this->lotteryContactRecordService->countLotteryContactRecordByLotteryIdPrizeName((int) $params['id'], $winName);
if ($totalNum >= $prizeNum) {
$data['prize_id'] = 1;
$data['prize_name'] = '谢谢参与';
$win_name = '谢谢参与';
$winName = '谢谢参与';
$this->createLotteryContactRecord($data, $contact['id'], $contactData);
throw new CommonException(ErrorCode::INVALID_PARAMS, '很抱歉,您所抽中的奖项已经中完!');
}

foreach (json_decode($prize['exchangeSet'], true, 512, JSON_THROW_ON_ERROR) as $key => $val) {
if ($val['name'] === $win_name) {
if ($val['name'] === $winName) {
$data['receive_type'] = $val['type'];
$data['receive_qr'] = $val['employee_qr'];
if ($val['type'] === 2) {
$winCode = $this->lotteryContactRecordService->countLotteryContactRecordReceiveCodeByLotteryIdPrizeName((int) $params['id'], $win_name, ['receive_code']);
$winCode = array_column($winCode, 'receive_code');
$winCode = $this->lotteryContactRecordService->countLotteryContactRecordReceiveCodeByLotteryIdPrizeName((int) $params['id'], $winName, ['receive_code']);
$winCode = array_column($winCode, 'receiveCode');
$result = array_merge(array_diff($val['exchange_code'], $winCode));
$data['receive_code'] = $result[0];
}
Expand All @@ -276,7 +276,7 @@ private function handleDraw(string $win_name, array $params, array $contact, arr
}
}
$contactData['win_num'] = $contact['winNum'] + 1;
$this->send($contact, $lottery, $params, $win_name);
$this->send($contact, $lottery, $params, $winName);
}
$this->createLotteryContactRecord($data, $contact['id'], $contactData);
return ['prize_name' => $data['prize_name'], 'receive_qr' => file_full_url($data['receive_qr']), 'receive_code' => $data['receive_code']];
Expand Down Expand Up @@ -393,7 +393,7 @@ private function tag(int $lottery_id, int $id, int $type): void
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \JsonException
*/
private function send(array $contact, array $lottery, array $params, string $win_name)
private function send(array $contact, array $lottery, array $params, string $winName)
{
$this->logger->error(sprintf('%s [%s] %s', '活动', date('Y-m-d H:i:s'), 'sds'));
$employee = $this->workEmployeeService->getWorkEmployeesById(explode(',', $contact['employeeIds']), ['wx_user_id']);
Expand All @@ -402,7 +402,7 @@ private function send(array $contact, array $lottery, array $params, string $win
if (empty($touser)) {
return;
}
$content = "【抽奖活动】\n客户昵称:{$params['nickname']}\n活动名称:{$lottery['name']}\n客户行为:客户抽中了奖品:{$win_name}\n<a href='#'>点击查看客户详情 </a>";
$content = "【抽奖活动】\n客户昵称:{$params['nickname']}\n活动名称:{$lottery['name']}\n客户行为:客户抽中了奖品:{$winName}\n<a href='#'>点击查看客户详情 </a>";
$messageRemind = make(MessageRemind::class);
$messageRemind->sendToEmployee((int) $lottery['corpId'], $touser, 'text', $content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Class Show.
* @Controller
*/
class ClockInDays extends AbstractAction
class DayDetail extends AbstractAction
{
use ValidateSceneTrait;

Expand Down Expand Up @@ -81,7 +81,7 @@ public function __construct(RequestInterface $request, ClockInContract $clockInS
}

/**
* @RequestMapping(path="/dashboard/roomClockIn/clockInDays", methods="get")
* @RequestMapping(path="/dashboard/roomClockIn/dayDetail", methods="get")
* @Middlewares({
* @Middleware(DashboardAuthMiddleware::class),
* @Middleware(PermissionMiddleware::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class ContactData extends AbstractAction
use ValidateSceneTrait;
use AutoContactTag;

/**
* @var RequestInterface
*/
protected $request;

/**
* @Inject
* @var ClockInContract
Expand Down Expand Up @@ -94,29 +89,8 @@ class ContactData extends AbstractAction
*/
private $logger;

public function __construct(
\Hyperf\HttpServer\Contract\RequestInterface $request,
ClockInContract $clockInService,
ClockInContactContract $clockInContactService,
WorkEmployeeContract $workEmployeeService,
ClockInContactRecordContract $clockInContactRecordService,
CorpContract $corpService,
WorkContactContract $workContactService,
WorkContactEmployeeContract $workContactEmployeeService
) {
$this->request = $request;
$this->clockInService = $clockInService;
$this->clockInContactService = $clockInContactService;
$this->workEmployeeService = $workEmployeeService;
$this->clockInContactRecordService = $clockInContactRecordService;
$this->corpService = $corpService;
$this->workContactService = $workContactService;
$this->workContactEmployeeService = $workContactEmployeeService;
}

/**
* @RequestMapping(path="/operation/roomClockIn/contactData", methods="get")
* @throws \JsonException
* @return array 返回数组
*/
public function handle(): array
Expand All @@ -126,7 +100,7 @@ public function handle(): array
## 接收参数
$params = $this->request->all();
## 查询数据
return $this->handleDate($params);
return $this->handleData($params);
}

/**
Expand Down Expand Up @@ -162,18 +136,20 @@ protected function messages(): array

/**
* @param $params
* @throws \JsonException
*
* @return array
*/
private function handleDate($params): array
private function handleData($params): array
{
$clockIn = $this->clockInService->getClockInById((int) $params['id'], ['name', 'corp_id', 'type', 'tasks', 'employee_qrcode', 'corp_card_status', 'corp_card']);
$clockIn = $this->clockInService->getClockInById((int) $params['id'], ['name', 'corp_id', 'type', 'tasks', 'employee_qrcode', 'corp_card_status', 'corp_card', 'description']);
$contact = $this->clockInContactService->getClockInContactByClockInIdUnionId((int) $params['id'], $params['union_id'], ['id', 'total_day', 'series_day', 'receive_level']);
$corpInfo = $clockIn['corpCardStatus'] === 1 ? json_decode($clockIn['corpCard'], true, 512, JSON_THROW_ON_ERROR) : '';
if (! empty($corpInfo)) {
$corpInfo['logo'] = file_full_url($corpInfo['logo']);
}
$data = [
'name' => $clockIn['name'],
'description' => $clockIn['description'],
'corp_card_status' => $clockIn['corpCardStatus'],
'corp_info' => $corpInfo,
'type' => $clockIn['type'],
Expand Down
Loading

0 comments on commit 25a8d1a

Please sign in to comment.