Skip to content

Commit

Permalink
Merge pull request #180 from maxincai/master
Browse files Browse the repository at this point in the history
1.1.5 bug修复
  • Loading branch information
maxincai authored Oct 21, 2021
2 parents 6547f8d + 85fb3b1 commit ce2637a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public function getWorkContactById(int $id, array $columns = ['*']): array;
* 查询多条 - 根据ID.
* @param array $ids ID
* @param array|string[] $columns 查询字段
* @param bool $withTrashed 是否包含软删除
* @return array 数组
*/
public function getWorkContactsById(array $ids, array $columns = ['*']): array;
public function getWorkContactsById(array $ids, array $columns = ['*'], bool $withTrashed = false): array;

/**
* 多条分页.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private function getEmployee($employeeIds)
*/
private function getContact($contactIds)
{
$contact = $this->contact->getWorkContactsById($contactIds, ['id', 'name', 'avatar']);
$contact = $this->contact->getWorkContactsById($contactIds, ['id', 'name', 'avatar'], true);
if (empty($contact)) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ public function getWorkContactById(int $id, array $columns = ['*']): array
* 查询多条 - 根据ID.
* @param array $ids ID
* @param array|string[] $columns 查询字段
* @param bool $withTrashed 是否包含软删除
* @return array 数组
*/
public function getWorkContactsById(array $ids, array $columns = ['*']): array
public function getWorkContactsById(array $ids, array $columns = ['*'], bool $withTrashed = false): array
{
return $this->model->getAllById($ids, $columns);
$query = $this->model::newModel();
if ($withTrashed) {
$query = $query->withTrashed();
}

$data = $query->find($ids, $columns);
$data || $data = collect([]);
return $data->toArray();
}

/**
Expand Down
45 changes: 25 additions & 20 deletions api-server/app/core/work-message/src/Service/WorkMessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function __construct(int $corpId)
$this->query = Db::table($this->model->getTable());
}

protected function newQuery()
{
return Db::table($this->model->getTable());
}

/**
* 查询单条 - 根据ID.
* @param int $id ID
Expand All @@ -54,7 +59,7 @@ public function __construct(int $corpId)
*/
public function getWorkMessageById(int $id, array $columns = ['*']): array
{
$data = $this->query->find($id, $columns);
$data = $this->newQuery()->find($id, $columns);
$data || $data = collect([]);
return $data->toArray();
}
Expand All @@ -67,7 +72,7 @@ public function getWorkMessageById(int $id, array $columns = ['*']): array
*/
public function getWorkMessagesById(array $ids, array $columns = ['*']): array
{
$data = $this->query->whereIn('id', $ids)->get($columns);
$data = $this->newQuery()->whereIn('id', $ids)->get($columns);
$data || $data = collect([]);
return $data->toArray();
}
Expand Down Expand Up @@ -102,7 +107,7 @@ public function getWorkMessageList(array $where, array $columns = ['*'], array $
public function createWorkMessage(array $data): int
{
$newData = $this->model->columnsFormat($data, true, true);
return $this->query->insertGetId($newData);
return $this->newQuery()->insertGetId($newData);
}

/**
Expand All @@ -115,7 +120,7 @@ public function createWorkMessages(array $data): bool
$newData = array_map(function ($item) {
return $this->model->columnsFormat($item, true, true);
}, $data);
return $this->query->insert($newData);
return $this->newQuery()->insert($newData);
}

/**
Expand All @@ -127,7 +132,7 @@ public function createWorkMessages(array $data): bool
public function updateWorkMessageById(int $id, array $data): int
{
$newData = $this->model->columnsFormat($data, true, true);
return $this->query->where('id', $id)->update($newData);
return $this->newQuery()->where('id', $id)->update($newData);
}

/**
Expand All @@ -137,7 +142,7 @@ public function updateWorkMessageById(int $id, array $data): int
*/
public function deleteWorkMessage(int $id): int
{
return (int) $this->query->where('id', $id)->delete();
return (int) $this->newQuery()->where('id', $id)->delete();
}

/**
Expand All @@ -147,15 +152,15 @@ public function deleteWorkMessage(int $id): int
*/
public function deleteWorkMessages(array $ids): int
{
return (int) $this->query->whereIn('id', $ids)->delete();
return (int) $this->newQuery()->whereIn('id', $ids)->delete();
}

/**
* {@inheritdoc}
*/
public function getWorkMessagesLast(string $from, array $toIds, int $toType = 0, array $columns = ['*']): array
{
$subQuery = Db::table($this->model->getTable())->where('from', $from)->where('tolist_type', $toType);
$subQuery = $this->newQuery()->where('from', $from)->where('tolist_type', $toType);
if ($toType !== 2) {
$subQuery->where(function ($query) use ($toIds) {
foreach ($toIds as $key => $toId) {
Expand Down Expand Up @@ -184,7 +189,7 @@ public function getWorkMessagesLast(string $from, array $toIds, int $toType = 0,
*/
public function getWorkMessageIndexEndSeq(): int
{
return (int) $this->query->orderBy('msg_time', 'desc')->limit(1)->value('seq');
return (int) $this->newQuery()->orderBy('msg_time', 'desc')->limit(1)->value('seq');
}

/**
Expand All @@ -195,7 +200,7 @@ public function getWorkMessageIndexEndSeq(): int
*/
public function getWorkMessagesByMsgId(array $msgIds, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->whereIn('msg_id', $msgIds)
->get($columns);

Expand All @@ -216,7 +221,7 @@ public function getWorkMessagesByMsgId(array $msgIds, array $columns = ['*']): a
*/
public function getWorkMessagesRangeByCorpId(int $corpId, string $from, string $tolist, int $messageId, string $operator, int $limit, string $order, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->where('corp_id', $corpId)
->where('id', $operator, $messageId)
->whereRaw("((`from` = ? AND `tolist`->'$[0]' = ?) OR (`from` = ? AND `tolist`->'$[0]' = ?))", [$from, $tolist, $tolist, $from])
Expand All @@ -240,7 +245,7 @@ public function getWorkMessagesRangeByCorpId(int $corpId, string $from, string $
*/
public function getWorkMessagesRangeByCorpIdWxRoomId(int $corpId, string $wxRoomId, int $messageId, string $operator, int $limit, string $order, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->where('corp_id', $corpId)
->where('id', $operator, $messageId)
->where('wx_room_id', $wxRoomId)
Expand All @@ -258,7 +263,7 @@ public function getWorkMessagesRangeByCorpIdWxRoomId(int $corpId, string $wxRoom
*/
public function getWorkMessagesByMsgIdActionFrom(array $msgIds, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->whereIn('msg_id', $msgIds)
->where('action', 0)
->where('from', 'like', 'wm%')
Expand All @@ -275,7 +280,7 @@ public function getWorkMessagesByMsgIdActionFrom(array $msgIds, array $columns =
*/
public function getWorkMessagesByCorpIdActionFrom(int $corpId, string $from, string $start_time, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->where('corp_id', $corpId)
->where('action', 0)
->where('from', $from)
Expand All @@ -293,15 +298,15 @@ public function getWorkMessagesByCorpIdActionFrom(int $corpId, string $from, str
*/
public function getWorkMessageMaxId(): int
{
return (int) $this->query->orderBy('id', 'desc')->limit(1)->value('id');
return (int) $this->newQuery()->orderBy('id', 'desc')->limit(1)->value('id');
}

/**
* 查询多条
*/
public function getWorkMessageByCorpIdRoomIdMsgType(int $corpId, array $roomIds, int $msgType, array $between_id, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->whereBetween('id', $between_id)
->where('corp_id', $corpId)
->where('from', 'like', 'wm%')
Expand All @@ -319,7 +324,7 @@ public function getWorkMessageByCorpIdRoomIdMsgType(int $corpId, array $roomIds,
*/
public function getWorkMessageByCorpIdRoomIdMsgTypeKeyword(int $corpId, array $roomIds, int $msgType, string $keyword, array $between_id, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->whereBetween('id', $between_id)
->where('corp_id', $corpId)
->where('from', 'like', 'wm%')
Expand All @@ -335,7 +340,7 @@ public function getWorkMessageByCorpIdRoomIdMsgTypeKeyword(int $corpId, array $r

public function getLastMessageByEmployeeWxIdAndContactWxId(string $employeeWxId, string $contactWxId)
{
$data = $this->query
$data = $this->newQuery()
->where('tolist_type', 1)
->where('action', 0)
->where('from', $employeeWxId)
Expand All @@ -353,7 +358,7 @@ public function getLastMessageByEmployeeWxIdAndContactWxId(string $employeeWxId,
*/
public function getWorkMessagesRangeByIdCorpIdWxRoomIdMsgTime(int $corpId, int $roomId, array $columns = ['*']): array
{
$data = $this->query
$data = $this->newQuery()
->whereRaw('action = 0')
->whereRaw('corp_id = ?', [$corpId])
->whereRaw('room_id = ?', [$roomId])
Expand All @@ -375,7 +380,7 @@ public function getWorkMessageLastSeqByCorpId(int $corpId): int
if ($seq = $this->cache->get(sprintf('mochat:messageLastSeq:%d', $corpId))) {
return (int) $seq;
}
return (int) $this->query->where('corp_id', $corpId)->orderBy('msg_time', 'desc')->limit(1)->value('seq');
return (int) $this->newQuery()->where('corp_id', $corpId)->orderBy('msg_time', 'desc')->limit(1)->value('seq');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function handle(): array
// 接收参数
$params = $this->request->all();
// 查询数据
return $this->handleDate($params);
return $this->handleData($params);
}

/**
Expand Down Expand Up @@ -158,17 +158,17 @@ protected function messages(): array
* @param $params
* @throws \JsonException
*/
private function handleDate($params): array
private function handleData($params): array
{
$lottery = $this->lotteryService->getLotteryById((int)$params['id'], ['name', 'description', 'corp_id', 'time_type', 'start_time', 'end_time', 'contact_tags']);
$prize = $this->lotteryPrizeService->getLotteryPrizeByLotteryId((int)$params['id'], ['corp_card', 'prize_set', 'is_show', 'draw_set', 'exchange_set']);
// 企业名片
$corp = json_decode($prize['corpCard'], true, 512, JSON_THROW_ON_ERROR);
$corp['logo'] = file_full_url($corp['logo']);
$corp['logo'] = ! empty($corp['logo']) ? file_full_url((string) $corp['logo']) : '';
// 奖项设置
$prizeSet = json_decode($prize['prizeSet'], true, 512, JSON_THROW_ON_ERROR);
foreach ($prizeSet as $key => $val) {
$prizeSet[$key]['image'] = str_contains($val['image'], 'http') ? $val['image'] : file_full_url($val['image']);
$prizeSet[$key]['image'] = str_contains($val['image'], 'http') ? $val['image'] : file_full_url((string) $val['image']);
unset($prizeSet[$key]['num'], $prizeSet[$key]['rate']);
}
$prize['prizeSet'] = $prizeSet;
Expand Down

0 comments on commit ce2637a

Please sign in to comment.