From f471d267ee5d5be65d6d9aa9fef0f67e368499f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=96=B0=E6=89=8D?= Date: Thu, 21 Oct 2021 22:38:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[Bug=E4=BF=AE=E5=A4=8D](1.1.5):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BC=9A=E8=AF=9D=E5=AD=98=E6=A1=A3=20SQL=20=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=8F=A0=E5=8A=A0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Service/WorkMessageService.php | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/api-server/app/core/work-message/src/Service/WorkMessageService.php b/api-server/app/core/work-message/src/Service/WorkMessageService.php index a5ac58a0..a82f0b21 100644 --- a/api-server/app/core/work-message/src/Service/WorkMessageService.php +++ b/api-server/app/core/work-message/src/Service/WorkMessageService.php @@ -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 @@ -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(); } @@ -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(); } @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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(); } /** @@ -147,7 +152,7 @@ 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(); } /** @@ -155,7 +160,7 @@ public function deleteWorkMessages(array $ids): int */ 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) { @@ -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'); } /** @@ -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); @@ -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]) @@ -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) @@ -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%') @@ -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) @@ -293,7 +298,7 @@ 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'); } /** @@ -301,7 +306,7 @@ public function getWorkMessageMaxId(): int */ 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%') @@ -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%') @@ -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) @@ -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]) @@ -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'); } /** From a9d27cccbdfeaaa4366c22782d973d6e039c00f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=96=B0=E6=89=8D?= Date: Thu, 21 Oct 2021 22:44:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[Bug=E4=BF=AE=E5=A4=8D](1.1.5):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=8A=BD=E5=A5=96=E6=B4=BB=E5=8A=A8=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E6=9C=AA=E4=B8=8A=E4=BC=A0Logo=E5=89=8D=E7=AB=AF=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mochat/lottery/src/Action/Operation/ContactData.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api-server/plugin/mochat/lottery/src/Action/Operation/ContactData.php b/api-server/plugin/mochat/lottery/src/Action/Operation/ContactData.php index 6e377267..1b3e25e6 100644 --- a/api-server/plugin/mochat/lottery/src/Action/Operation/ContactData.php +++ b/api-server/plugin/mochat/lottery/src/Action/Operation/ContactData.php @@ -118,7 +118,7 @@ public function handle(): array // 接收参数 $params = $this->request->all(); // 查询数据 - return $this->handleDate($params); + return $this->handleData($params); } /** @@ -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; From 85fb3b10048c152b891a64c4e4bc689ba3593019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=96=B0=E6=89=8D?= Date: Thu, 21 Oct 2021 22:53:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[Bug=E4=BF=AE=E5=A4=8D](1.1.5):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=B5=81=E5=A4=B1=E6=8F=90=E9=86=92=E7=BC=BA=E5=B0=91?= =?UTF-8?q?=E6=98=B5=E7=A7=B0=E5=8F=8A=E5=A4=B4=E5=83=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Contract/WorkContactContract.php | 3 ++- .../core/work-contact/src/Logic/LossContactLogic.php | 2 +- .../work-contact/src/Service/WorkContactService.php | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/api-server/app/core/work-contact/src/Contract/WorkContactContract.php b/api-server/app/core/work-contact/src/Contract/WorkContactContract.php index 6030bab4..a604e5aa 100644 --- a/api-server/app/core/work-contact/src/Contract/WorkContactContract.php +++ b/api-server/app/core/work-contact/src/Contract/WorkContactContract.php @@ -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; /** * 多条分页. diff --git a/api-server/app/core/work-contact/src/Logic/LossContactLogic.php b/api-server/app/core/work-contact/src/Logic/LossContactLogic.php index fa943cbd..82576192 100644 --- a/api-server/app/core/work-contact/src/Logic/LossContactLogic.php +++ b/api-server/app/core/work-contact/src/Logic/LossContactLogic.php @@ -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 []; } diff --git a/api-server/app/core/work-contact/src/Service/WorkContactService.php b/api-server/app/core/work-contact/src/Service/WorkContactService.php index 90a1202b..94f5a634 100644 --- a/api-server/app/core/work-contact/src/Service/WorkContactService.php +++ b/api-server/app/core/work-contact/src/Service/WorkContactService.php @@ -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(); } /**