diff --git a/app/Jobs/notice.php b/app/Jobs/notice.php index 5e140d3..353b47c 100644 --- a/app/Jobs/notice.php +++ b/app/Jobs/notice.php @@ -164,9 +164,9 @@ public function updateGoods(): void $goods[$product['itemId']] = $product; $itemIds[] = $product['itemId']; } + $items = Good::query()->whereIn('itemid', $itemIds)->with('item')->get(); + DB::transaction(function () use ($goods, $itemIds, $noticeIdMapItemId, $items) { - DB::transaction(function () use ($goods, $itemIds, $noticeIdMapItemId) { - $items = Good::query()->whereIn('itemid', $itemIds)->with('item')->get(); $notices = []; foreach ($items as $item) { $item->fill($goods[$item->itemid]); diff --git a/app/Models/Notice.php b/app/Models/Notice.php index 1ea9d4f..3989190 100644 --- a/app/Models/Notice.php +++ b/app/Models/Notice.php @@ -2,6 +2,8 @@ namespace App\Models; +use App\helpers\apiRequest; + /** * @property int $notice_id * @property int $notice_type @@ -12,4 +14,13 @@ */ class Notice extends Base { + public static function deleteNotice(int|array $notice_d): bool + { + if (!is_array($notice_d)) { + $notice_d = [$notice_d]; + } + $ids = implode(',', $notice_d); + $res = apiRequest::api('/Notic/doNotics', ['notice_ids' => $ids]); + return $res['errCode'] == '0000'; + } } diff --git a/app/helpers/apiRequest.php b/app/helpers/apiRequest.php index 727d3dd..131cb16 100644 --- a/app/helpers/apiRequest.php +++ b/app/helpers/apiRequest.php @@ -89,16 +89,24 @@ public static function requests(Client $client, string $url, mixed $param = [], * @throws GuzzleException * @throws Exception */ - public static function GetToken(): string + public static function getToken(): string { $token = Cache::get('token'); if ($token) { return $token; } + $appId = env('APP_ID'); + if (!$appId) { + throw new Exception('app_id不能为空'); + } + $appKey = env('APP_KEYX'); + if (!$appKey) { + throw new Exception('app_keyx不能为空'); + } + $url = rtrim(env('API_DOMAIN'), '/') . '/Index/getToken'; $now = date('Y-m-d H:i:s'); - $appId = env('APP_ID'); - $appKey = env('APP_KEYX'); + $sign = sprintf("app_id=%s:app_key=%s:tamptimes=%s", $appId, $appKey, $now); $sign = strtoupper(md5($sign)); $form = [ @@ -127,11 +135,16 @@ public static function api($path, mixed $param = [], int $timeout = 5, array $ex /** * @throws GuzzleException + * @throws Exception */ public static function apis($path, Client $client, mixed $param = [], int $timeout = 5, array $extern = []): mixed { - $url = rtrim(env('API_DOMAIN'), '/') . $path; - $token = self::GetToken(); + $domain = env('API_DOMAIN'); + if (!$domain) { + throw new Exception('接口域名不能为空'); + } + $url = rtrim($domain, '/') . $path; + $token = self::getToken(); $param['token'] = $token; return self::requests($client, $url, $param, FormType::json, true, $timeout, $extern); }