Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lzzzzl
/
liexin_scm_service
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
2545e46b
authored
Apr 21, 2020
by
lzzzzl
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
物料五福
parent
26f15586
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
9 deletions
app/Http/Controllers/ServicesController.php
app/Http/Model/GoodsModel.php
app/Http/Controllers/ServicesController.php
View file @
2545e46b
...
@@ -286,10 +286,13 @@ class ServicesController extends Controller
...
@@ -286,10 +286,13 @@ class ServicesController extends Controller
* 写入物料信息
* 写入物料信息
*/
*/
public
function
ApiInsertGoodsInfo
(
$request
)
{
public
function
ApiInsertGoodsInfo
(
$request
)
{
$arr
=
array
(
$params
=
$request
->
only
([
'goods_name'
,
'goods_cn_name'
,
'brand_name'
,
'erp_goods_id'
,
'admin_name'
,
'admin_id'
]);
'brand_name'
=>
'MOUSER'
if
(
empty
(
$params
[
'goods_name'
])
||
empty
(
$params
[
'goods_cn_name'
])
||
empty
(
$params
[
'brand_name'
])
||
empty
(
$params
[
'erp_goods_id'
])
||
empty
(
$params
[
'admin_id'
])
||
empty
(
$params
[
'admin_name'
]))
);
return
$this
->
apiReturn
(
$Errcode
=
101
,
$level
=
1
,
$dataArr
=
[]);
$data
=
(
new
GoodsModel
())
->
InsertGoodsInfo
(
$arr
);
$params
[
'add_time'
]
=
time
();
$params
[
'update_time'
]
=
time
();
$data
=
(
new
GoodsModel
())
->
InsertGoodsInfo
(
$params
);
}
}
/**
/**
...
...
app/Http/Model/GoodsModel.php
View file @
2545e46b
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
namespace
App\Http\Model
;
namespace
App\Http\Model
;
use
Common\Model\RedisModel
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Config
;
use
Config
;
use
DB
;
use
DB
;
use
RedisDB
;
use
RedisDB
;
use
Request
;
use
Request
;
use
ScmWmsCommon\SnModel
;
class
GoodsModel
extends
Model
class
GoodsModel
extends
Model
{
{
...
@@ -21,6 +22,7 @@ class GoodsModel extends Model
...
@@ -21,6 +22,7 @@ class GoodsModel extends Model
if
(
$connection
){
if
(
$connection
){
$this
->
connection
=
$connection
;
$this
->
connection
=
$connection
;
}
}
$this
->
redis
=
new
RedisModel
();
}
}
/**
/**
...
@@ -37,7 +39,7 @@ class GoodsModel extends Model
...
@@ -37,7 +39,7 @@ class GoodsModel extends Model
}
}
$data
=
$this
->
$data
=
$this
->
select
(
'goods_name'
,
'goods_cn_name'
,
'goods_sn'
,
'brand_name'
,
'erp_id'
)
->
select
(
'goods_name'
,
'goods_cn_name'
,
'goods_sn'
,
'brand_name'
,
'erp_
goods_
id'
)
->
where
(
$map
)
->
where
(
$map
)
->
leftJoin
(
'brand'
,
'brand.brand_id'
,
'goods.goods_id'
)
->
leftJoin
(
'brand'
,
'brand.brand_id'
,
'goods.goods_id'
)
->
paginate
(
$limit
,[
'*'
],
'p'
,
$page
)
->
paginate
(
$limit
,[
'*'
],
'p'
,
$page
)
->
...
@@ -52,9 +54,61 @@ class GoodsModel extends Model
...
@@ -52,9 +54,61 @@ class GoodsModel extends Model
public
function
InsertGoodsInfo
(
$arr
)
{
public
function
InsertGoodsInfo
(
$arr
)
{
$str
=
DB
::
connection
(
$this
->
connection
)
->
transaction
(
function
()
use
(
$arr
){
$str
=
DB
::
connection
(
$this
->
connection
)
->
transaction
(
function
()
use
(
$arr
){
$brand_name
=
$arr
[
'brand_name'
];
$brand_name
=
$arr
[
'brand_name'
];
$brand_exist
=
DB
::
connection
(
'mysql'
)
->
table
(
'brand'
)
->
where
(
'brand_name'
,
'='
,
$brand_name
)
->
first
();
$admin_name
=
$arr
[
'admin_name'
];
// $data = $this->where('rule_code', $ruleCode)->first();
$admin_id
=
$arr
[
'admin_id'
];
var_dump
(
$brand_exist
);
$erp_id
=
$arr
[
'erp_goods_id'
];
$brand_exist
=
DB
::
connection
(
'mysql'
)
->
table
(
'brand'
)
->
select
(
'brand_id'
)
->
where
(
'brand_name'
,
'='
,
$brand_name
)
->
first
();
// 获取品牌ID,品牌不存在,则进行写入
if
(
!
$brand_exist
)
{
$brand_params
=
array
(
'brand_name'
=>
$brand_name
,
'admin_name'
=>
$admin_name
,
'admin_id'
=>
$admin_id
,
'add_time'
=>
time
(),
'update_time'
=>
time
()
);
$brand_id
=
DB
::
connection
(
'mysql'
)
->
table
(
'brand'
)
->
insertGetId
(
$brand_params
);
// 缓存品牌
$this
->
brand2Redis
(
$brand_id
,
$brand_name
);
}
else
{
$brand_id
=
$brand_exist
->
brand_id
;
}
$arr
[
'brand_id'
]
=
$brand_id
;
$arr
[
'goods_sn'
]
=
(
new
SnModel
())
->
sn
(
"goods_sn"
);
unset
(
$arr
[
'brand_name'
]);
// 写入DB
$goods_id
=
$this
->
insertGetId
(
$arr
);
// ERPID GOODSID REDIS
$this
->
erpId2GoodsId
(
$erp_id
,
$goods_id
);
// GOODSID GOODS REDIS
$this
->
goodsId2Goods
(
$goods_id
,
json_encode
(
$arr
));
});
});
}
}
/**
* 缓存品牌
*/
private
function
brand2Redis
(
$brand_id
,
$brand_name
)
{
$encrypt_bi
=
md5
(
$brand_id
);
$this
->
redis
->
hset
(
'scm_brand'
,
$encrypt_bi
,
$brand_name
);
}
/**
* ERPID、GOODSID缓存
*/
private
function
erpId2GoodsId
(
$erp_id
,
$goods_id
)
{
$encrypt_ei
=
md5
(
$erp_id
);
$this
->
redis
->
hset
(
'scm_goods_erp_id'
,
$encrypt_ei
,
$goods_id
);
}
/**
* GOODSID、GOODS 缓存
*/
private
function
goodsId2Goods
(
$goods_id
,
$goods
)
{
$encrypt_gi
=
md5
(
$goods_id
);
$this
->
redis
->
hset
(
'scm_goods_goods_id'
,
$encrypt_gi
,
$goods
);
}
}
}
\ No newline at end of file
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