This commit is contained in:
zhouchangcheng 2024-05-27 17:52:02 +08:00
parent 609f5ceb65
commit 3da00000d6
3 changed files with 31 additions and 7 deletions

View File

@ -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]);

View File

@ -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';
}
}

View File

@ -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);
}