Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8638708a
authored
Nov 08, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
购物车
parent
0b40e1c4
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
112 additions
and
232 deletions
.env
.idea/workspace.xml
app/Http/Controllers/Api/CartApiController.php
app/Http/Services/CartService.php
app/Http/Services/ThirdService.php
app/Models/CartModel.php
routes/api.php
.env
View file @
8638708a
...
@@ -46,3 +46,5 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
...
@@ -46,3 +46,5 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
PUBLIC_URL=http://www.semour.com
PUBLIC_URL=http://www.semour.com
#商品服务网址
GOODS_INFO_URL=http://192.168.1.237:60014
.idea/workspace.xml
deleted
100644 → 0
View file @
0b40e1c4
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"fb90add0-1393-48c2-9f26-72365d42cd03"
name=
"变更"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Controllers/Api/UserAddressApiController.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Controllers/Api/UserAddressApiController.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Controllers/Api/UserApiController.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Controllers/Api/UserApiController.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Controllers/UserAddressesController.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Controllers/UserAddressController.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Requests/BaseRequest.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Requests/BaseRequest.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Requests/UserRegister.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Requests/UserRegister.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Models/UserAddressModel.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Models/UserAddressModel.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/routes/api.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/routes/api.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/app/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/app/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/app/public/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/app/public/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/framework/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/framework/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/framework/cache/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/framework/cache/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/framework/cache/data/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/framework/cache/data/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/framework/sessions/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/framework/sessions/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/framework/testing/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/framework/testing/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/framework/views/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/framework/views/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/logs/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/logs/.gitignore"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
<option
name=
"HIGHLIGHT_NON_ACTIVE_CHANGELIST"
value=
"false"
/>
<option
name=
"LAST_RESOLUTION"
value=
"IGNORE"
/>
</component>
<component
name=
"ComposerSettings"
doNotAsk=
"true"
synchronizationState=
"SYNCHRONIZE"
>
<pharConfigPath>
$PROJECT_DIR$/composer.json
</pharConfigPath>
<execution
/>
</component>
<component
name=
"Git.Settings"
>
<option
name=
"RECENT_GIT_ROOT_PATH"
value=
"$PROJECT_DIR$"
/>
</component>
<component
name=
"GitSEFilterConfiguration"
>
<file-type-list>
<filtered-out-file-type
name=
"LOCAL_BRANCH"
/>
<filtered-out-file-type
name=
"REMOTE_BRANCH"
/>
<filtered-out-file-type
name=
"TAG"
/>
<filtered-out-file-type
name=
"COMMIT_BY_MESSAGE"
/>
</file-type-list>
</component>
<component
name=
"PhpWorkspaceProjectConfiguration"
>
<include_path>
<path
value=
"$PROJECT_DIR$/vendor/swiftmailer/swiftmailer"
/>
<path
value=
"$PROJECT_DIR$/vendor/psy/psysh"
/>
<path
value=
"$PROJECT_DIR$/vendor/fakerphp/faker"
/>
<path
value=
"$PROJECT_DIR$/vendor/asm89/stack-cors"
/>
<path
value=
"$PROJECT_DIR$/vendor/fideloper/proxy"
/>
<path
value=
"$PROJECT_DIR$/vendor/ramsey/uuid"
/>
<path
value=
"$PROJECT_DIR$/vendor/ramsey/collection"
/>
<path
value=
"$PROJECT_DIR$/vendor/composer"
/>
<path
value=
"$PROJECT_DIR$/vendor/brick/math"
/>
<path
value=
"$PROJECT_DIR$/vendor/egulias/email-validator"
/>
<path
value=
"$PROJECT_DIR$/vendor/theseer/tokenizer"
/>
<path
value=
"$PROJECT_DIR$/vendor/league/mime-type-detection"
/>
<path
value=
"$PROJECT_DIR$/vendor/league/commonmark"
/>
<path
value=
"$PROJECT_DIR$/vendor/fruitcake/laravel-cors"
/>
<path
value=
"$PROJECT_DIR$/vendor/league/flysystem"
/>
<path
value=
"$PROJECT_DIR$/vendor/mockery/mockery"
/>
<path
value=
"$PROJECT_DIR$/vendor/phpoption/phpoption"
/>
<path
value=
"$PROJECT_DIR$/vendor/opis/closure"
/>
<path
value=
"$PROJECT_DIR$/vendor/nikic/php-parser"
/>
<path
value=
"$PROJECT_DIR$/vendor/doctrine/instantiator"
/>
<path
value=
"$PROJECT_DIR$/vendor/ralouphie/getallheaders"
/>
<path
value=
"$PROJECT_DIR$/vendor/doctrine/lexer"
/>
<path
value=
"$PROJECT_DIR$/vendor/doctrine/inflector"
/>
<path
value=
"$PROJECT_DIR$/vendor/scrivo/highlight.php"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/type"
/>
<path
value=
"$PROJECT_DIR$/vendor/psr/http-factory"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/diff"
/>
<path
value=
"$PROJECT_DIR$/vendor/psr/simple-cache"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/recursion-context"
/>
<path
value=
"$PROJECT_DIR$/vendor/psr/http-client"
/>
<path
value=
"$PROJECT_DIR$/vendor/voku/portable-ascii"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/resource-operations"
/>
<path
value=
"$PROJECT_DIR$/vendor/psr/container"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/code-unit-reverse-lookup"
/>
<path
value=
"$PROJECT_DIR$/vendor/psr/event-dispatcher"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/object-enumerator"
/>
<path
value=
"$PROJECT_DIR$/vendor/psr/http-message"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/comparator"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/environment"
/>
<path
value=
"$PROJECT_DIR$/vendor/psr/log"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/global-state"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/exporter"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/object-reflector"
/>
<path
value=
"$PROJECT_DIR$/vendor/monolog/monolog"
/>
<path
value=
"$PROJECT_DIR$/vendor/sebastian/version"
/>
<path
value=
"$PROJECT_DIR$/vendor/myclabs/deep-copy"
/>
<path
value=
"$PROJECT_DIR$/vendor/facade/flare-client-php"
/>
<path
value=
"$PROJECT_DIR$/vendor/facade/ignition"
/>
<path
value=
"$PROJECT_DIR$/vendor/facade/ignition-contracts"
/>
<path
value=
"$PROJECT_DIR$/vendor/phpunit/phpunit"
/>
<path
value=
"$PROJECT_DIR$/vendor/phpunit/php-timer"
/>
<path
value=
"$PROJECT_DIR$/vendor/phpunit/php-file-iterator"
/>
<path
value=
"$PROJECT_DIR$/vendor/phpunit/php-text-template"
/>
<path
value=
"$PROJECT_DIR$/vendor/phpunit/php-token-stream"
/>
<path
value=
"$PROJECT_DIR$/vendor/phpunit/php-code-coverage"
/>
<path
value=
"$PROJECT_DIR$/vendor/nunomaduro/collision"
/>
<path
value=
"$PROJECT_DIR$/vendor/tijsverkoyen/css-to-inline-styles"
/>
<path
value=
"$PROJECT_DIR$/vendor/laravel/tinker"
/>
<path
value=
"$PROJECT_DIR$/vendor/hamcrest/hamcrest-php"
/>
<path
value=
"$PROJECT_DIR$/vendor/laravel/framework"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-mbstring"
/>
<path
value=
"$PROJECT_DIR$/vendor/guzzlehttp/psr7"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/finder"
/>
<path
value=
"$PROJECT_DIR$/vendor/guzzlehttp/promises"
/>
<path
value=
"$PROJECT_DIR$/vendor/vlucas/phpdotenv"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/routing"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/deprecation-contracts"
/>
<path
value=
"$PROJECT_DIR$/vendor/guzzlehttp/guzzle"
/>
<path
value=
"$PROJECT_DIR$/vendor/dragonmantank/cron-expression"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/css-selector"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-intl-grapheme"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-php80"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer"
/>
<path
value=
"$PROJECT_DIR$/vendor/nesbot/carbon"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-ctype"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/mime"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-php72"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/error-handler"
/>
<path
value=
"$PROJECT_DIR$/vendor/filp/whoops"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-php73"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/event-dispatcher-contracts"
/>
<path
value=
"$PROJECT_DIR$/vendor/phar-io/version"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/console"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-intl-idn"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/event-dispatcher"
/>
<path
value=
"$PROJECT_DIR$/vendor/phar-io/manifest"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/polyfill-iconv"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/http-foundation"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/var-dumper"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/translation-contracts"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/http-kernel"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/string"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/service-contracts"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/process"
/>
<path
value=
"$PROJECT_DIR$/vendor/symfony/translation"
/>
<path
value=
"$PROJECT_DIR$/vendor/laravel/ui"
/>
<path
value=
"$PROJECT_DIR$/vendor/_laravel_idea"
/>
</include_path>
</component>
<component
name=
"ProjectId"
id=
"2GLaKmM80GSH0Rk212pAfPdF2Hx"
/>
<component
name=
"ProjectLevelVcsManager"
>
<ConfirmationsSetting
value=
"1"
id=
"Add"
/>
</component>
<component
name=
"ProjectViewState"
>
<option
name=
"hideEmptyMiddlePackages"
value=
"true"
/>
<option
name=
"showLibraryContents"
value=
"true"
/>
</component>
<component
name=
"PropertiesComponent"
>
<property
name=
"DatabaseDriversLRU"
value=
"mysql"
/>
<property
name=
"RunOnceActivity.OpenProjectViewOnStart"
value=
"true"
/>
<property
name=
"RunOnceActivity.ShowReadmeOnStart"
value=
"true"
/>
<property
name=
"WebServerToolWindowFactoryState"
value=
"false"
/>
<property
name=
"last_opened_file_path"
value=
"$PROJECT_DIR$/app/Http/Services"
/>
<property
name=
"nodejs_interpreter_path.stuck_in_default_project"
value=
"undefined stuck path"
/>
<property
name=
"nodejs_package_manager_path"
value=
"npm"
/>
<property
name=
"vue.rearranger.settings.migration"
value=
"true"
/>
</component>
<component
name=
"RecentsManager"
>
<key
name=
"CopyFile.RECENT_KEYS"
>
<recent
name=
"\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Services"
/>
<recent
name=
"\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers\Api"
/>
<recent
name=
"\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Models"
/>
<recent
name=
"\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views"
/>
<recent
name=
"\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\sku"
/>
</key>
<key
name=
"MoveFile.RECENT_KEYS"
>
<recent
name=
"\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\home"
/>
<recent
name=
"\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers"
/>
</key>
</component>
<component
name=
"RunManager"
>
<configuration
name=
"phpunit.xml"
type=
"PHPUnitRunConfigurationType"
factoryName=
"PHPUnit"
>
<TestRunner
scope=
"XML"
/>
<method
v=
"2"
/>
</configuration>
</component>
<component
name=
"SpellCheckerSettings"
RuntimeDictionaries=
"0"
Folders=
"0"
CustomDictionaries=
"0"
DefaultDictionary=
"应用程序级"
UseSingleDictionary=
"true"
transferred=
"true"
/>
<component
name=
"TaskManager"
>
<task
active=
"true"
id=
"Default"
summary=
"默认任务"
>
<changelist
id=
"fb90add0-1393-48c2-9f26-72365d42cd03"
name=
"变更"
comment=
""
/>
<created>
1666170258203
</created>
<option
name=
"number"
value=
"Default"
/>
<option
name=
"presentableId"
value=
"Default"
/>
<updated>
1666170258203
</updated>
<workItem
from=
"1666170260162"
duration=
"17108000"
/>
<workItem
from=
"1666835076791"
duration=
"693000"
/>
<workItem
from=
"1667266026118"
duration=
"39544000"
/>
</task>
<servers
/>
</component>
<component
name=
"TypeScriptGeneratedFilesManager"
>
<option
name=
"version"
value=
"3"
/>
</component>
<component
name=
"Vcs.Log.History.Properties"
>
<option
name=
"COLUMN_ID_ORDER"
>
<list>
<option
value=
"Default.Root"
/>
<option
value=
"Default.Author"
/>
<option
value=
"Default.Date"
/>
<option
value=
"Default.Subject"
/>
</list>
</option>
</component>
</project>
\ No newline at end of file
app/Http/Controllers/Api/CartApiController.php
View file @
8638708a
...
@@ -3,7 +3,10 @@
...
@@ -3,7 +3,10 @@
namespace
App\Http\Controllers\Api
;
namespace
App\Http\Controllers\Api
;
use
App\Http\Requests\UserRegister
;
use
App\Http\Requests\UserRegister
;
use
App\Http\Services\CartService
;
use
App\Http\Services\InquiryService
;
use
App\Models\User
;
use
App\Models\User
;
use
Facade\Ignition\Support\Packagist\Package
;
use
Illuminate\Foundation\Auth\RegistersUsers
;
use
Illuminate\Foundation\Auth\RegistersUsers
;
use
Illuminate\Foundation\Auth\ThrottlesLogins
;
use
Illuminate\Foundation\Auth\ThrottlesLogins
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
...
@@ -17,25 +20,25 @@ use Illuminate\Support\Facades\Validator;
...
@@ -17,25 +20,25 @@ use Illuminate\Support\Facades\Validator;
class
CartApiController
extends
Controller
class
CartApiController
extends
Controller
{
{
use
ThrottlesLogins
,
RegistersUsers
;
//添加购物车, items: {"goods_id":1166788996788323407,"goods_number":2}
public
function
addCart
(
Request
$request
)
public
function
addCart
(
Request
$request
)
{
{
$validator
=
Validator
::
make
(
$request
->
all
(),
[
$validator
=
Validator
::
make
(
$request
->
all
(),
[
'email'
=>
'required|string|email|max:255'
,
'items'
=>
'required|string'
,
'password'
=>
'required|string|min:8'
,
],
[
],
[
'
password.min'
=>
'Password must be at least 8
characters long.'
'
items.min'
=>
'items must be at least 1
characters long.'
]);
]);
if
(
$validator
->
fails
())
{
if
(
$validator
->
fails
())
{
return
$this
->
setError
(
$validator
->
errors
()
->
first
());
return
$this
->
setError
(
$validator
->
errors
()
->
first
());
}
}
$data
=
$request
->
only
([
'items'
,
'data'
,
]);
$result
=
CartService
::
addCart
(
$data
,
$request
->
user
->
user_id
);
$this
->
incrementLoginAttempts
(
$request
);
return
!
$result
?
$this
->
setError
(
'Add cart failed , please contact administrator'
)
:
$this
->
setSuccess
(
'Add inquiry success'
);
return
$this
->
setError
(
'Login failure'
);
}
}
...
...
app/Http/Services/CartService.php
View file @
8638708a
...
@@ -2,31 +2,76 @@
...
@@ -2,31 +2,76 @@
namespace
App\Http\Services
;
namespace
App\Http\Services
;
use
App\Exceptions\InvalidRequestException
;
use
App\Models\Inquiry
;
use
App\Models\Inquiry
;
use
App\Models\InquiryItems
;
use
App\Models\InquiryItems
;
use
App\Models\InquiryItemsModel
;
use
App\Models\InquiryModel
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Redis
;
use
App\Models\CartModel
;
//购物车服务器层
//购物车服务器层
class
CartService
class
CartService
{
{
//添加购物车
//添加购物车
public
static
function
addCart
(
$data
,
$user
)
public
static
function
addCart
(
$data
,
$user
_id
)
{
{
return
DB
::
transaction
(
function
()
use
(
$data
,
$user
)
{
$items
=
\Arr
::
get
(
$data
,
'item'
,
[]);
try
{
$inquiryItems
=
[];
$con
=
DB
::
connection
();
$con
->
beginTransaction
();
$items
=
json_decode
(
\Arr
::
get
(
$data
,
'items'
,
[]),
true
);
$redis
=
Redis
::
connection
();
$goodsInfoArr
=
ThirdService
::
getGoodsInfo
(
array_column
(
$items
,
"goods_id"
));
foreach
(
$items
as
$item
)
{
foreach
(
$items
as
$item
)
{
$inquiryItems
[]
=
[
$goods_id
=
$item
[
'goods_id'
];
'user_id'
=>
$user
->
user_id
,
$temp
=
[
'user_id'
=>
$user_id
,
'goods_id'
=>
$item
[
'goods_id'
],
'goods_id'
=>
$item
[
'goods_id'
],
'goods_number'
=>
$item
[
'goods_number'
],
'create_goods_price'
=>
$item
[
'create_goods_price'
],
'create_time'
=>
time
(),
'update_time'
=>
time
(),
];
];
$skuInfo
=
$goodsInfoArr
[
$goods_id
];
//sku库存
$digikeyInfo
=
$redis
->
hget
(
"sku_raw_map"
,
$goods_id
);
//digikey 编码
if
(
$digikeyInfo
){
$digikeyArr
=
json_decode
(
$digikeyInfo
,
true
);
$temp
[
"raw_goods_sn"
]
=
$digikeyArr
[
"raw_goods_id"
];
$temp
[
"raw_goods_packing"
]
=
$digikeyArr
[
"pack"
];
$temp
[
"raw_brand_name"
]
=
$digikeyArr
[
"raw_brand_name"
];
}
$checkHas
=
CartModel
::
where
([
"user_id"
=>
$user_id
,
"goods_id"
=>
$goods_id
])
->
first
();
if
(
$checkHas
){
//存在累计库存
$temp
[
"goods_number"
]
=
$skuInfo
[
"stock"
]
>
(
$item
[
'goods_number'
]
+
$checkHas
[
"goods_number"
])
?
$item
[
'goods_number'
]
+
$checkHas
[
"goods_number"
]
:
$skuInfo
[
"stock"
];
$temp
[
"update_time"
]
=
time
();
$flag
=
CartModel
::
where
([
"user_id"
=>
$user_id
,
"goods_id"
=>
$goods_id
])
->
update
(
$temp
);
if
(
!
$flag
){
return
false
;
}
}
else
{
//不存在插入购物车
$temp
[
"goods_number"
]
=
$skuInfo
[
"stock"
]
>
$item
[
'goods_number'
]
?
$item
[
'goods_number'
]
:
$skuInfo
[
"stock"
];
$temp
[
"create_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
$flag
=
CartModel
::
insertGetId
(
$temp
);
if
(
!
$flag
){
return
false
;
}
}
}
$con
->
commit
();
return
true
;
}
catch
(
\Exception
$e
){
$con
->
rollback
();
throw
new
InvalidRequestException
(
$e
->
getMessage
()
.
$e
->
getLine
());
}
}
return
InquiryItems
::
addInquiryItems
(
$inquiryItems
);
});
}
}
}
}
app/Http/Services/ThirdService.php
0 → 100644
View file @
8638708a
<?php
namespace
App\Http\Services
;
use
App\Exceptions\InvalidRequestException
;
use
App\Http\Models\Order\OrderModel
;
use
Illuminate\Support\Facades\Http
;
use
Illuminate\Support\Facades\Log
;
use
SoapClient
;
use
App\Http\Services\SaleOrderDetailsService
;
//调用第三方api接口服务层
class
ThirdService
{
//获取商品详情
public
static
function
getGoodsInfo
(
$goods_ids
){
$url
=
env
(
'GOODS_INFO_URL'
,
''
)
.
'/synchronization'
;
$req_params
[
'goods_id'
]
=
implode
(
','
,
$goods_ids
);
$response
=
Http
::
asForm
()
->
post
(
$url
,
$req_params
);
if
(
request
()
->
input
(
"debug"
)
==
1
){
print_r
(
$url
);
print_r
(
"<br/>"
);
print_r
(
$req_params
);
print_r
(
"<br/>"
);
print_r
(
$response
->
body
());
print_r
(
"<br/>"
);
die
();
}
$res
=
json_decode
(
$response
->
body
(),
true
);
if
(
!
$res
||
$res
[
'errcode'
]
!=
0
)
{
return
[];
}
return
$res
[
'data'
];
}
}
app/Models/CartModel.php
View file @
8638708a
<?php
<?php
namespace
App\
Http\Models\Order
;
namespace
App\
Models
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
class
CartModel
extends
Model
class
CartModel
extends
Model
{
{
protected
$primaryKey
=
'cart_id'
;
protected
$primaryKey
=
'cart_id'
;
protected
$table
=
'cart'
;
public
$timestamps
=
false
;
public
$timestamps
=
false
;
...
@@ -21,5 +22,4 @@ class CartModel extends Model
...
@@ -21,5 +22,4 @@ class CartModel extends Model
}
}
}
}
routes/api.php
View file @
8638708a
...
@@ -43,5 +43,7 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
...
@@ -43,5 +43,7 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route
::
get
(
'country/list'
,
'CountryApiController@list'
);
Route
::
get
(
'country/list'
,
'CountryApiController@list'
);
Route
::
POST
(
'cart/addCart'
,
'CartApiController@addCart'
);
//添加购物车
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment