Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
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
c827b662
authored
Jan 09, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
sku标签完成
parent
23ea6cf2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
107 deletions
app/Http/Controllers/Api/SkuApiController.php
app/Http/Controllers/SkuController.php
app/Http/Services/SkuService.php
app/Model/TagsModel.php
resources/views/script/BatchAddSkuTagScript.blade.php
resources/views/script/SkuListScript.blade.php
resources/views/web/BatchAddSkuTag.blade.php
app/Http/Controllers/Api/SkuApiController.php
View file @
c827b662
...
...
@@ -178,6 +178,16 @@ class SkuApiController extends Controller
public
function
BatchAddSkuTag
(
$request
)
{
$skuIds
=
$request
->
get
(
'sku_ids'
);
$this
->
response
(
0
,
'批量新增标签成功'
);
$skuTags
=
$request
->
get
(
'sku_tags'
);
(
new
SkuService
())
->
batchAddSkuTags
(
$skuIds
,
$skuTags
);
$this
->
response
(
0
,
'设置标签成功'
);
}
//获取所有系统标签
public
function
GetSystemTagList
(
$request
)
{
$skuService
=
new
SkuService
();
$data
=
$skuService
->
getSystemTags
();
$this
->
response
(
0
,
'ok'
,
$data
,
count
(
$data
));
}
}
app/Http/Controllers/SkuController.php
View file @
c827b662
...
...
@@ -45,7 +45,7 @@ class SkuController extends Controller
public
function
SkuList
(
$request
)
{
$skuTags
=
TagsModel
::
where
(
'tag_use'
,
16
)
->
where
(
'tag_type'
,
2
)
->
pluck
(
'tag_name'
,
'tag_name'
)
->
toArray
(
);
$skuTags
=
TagsModel
::
getTagNamesByTagUse
(
16
,
2
);
$this
->
data
[
'skuTags'
]
=
$skuTags
;
//获取筛选框的品牌数据
$brandSelectValue
=
[];
...
...
app/Http/Services/SkuService.php
View file @
c827b662
...
...
@@ -7,6 +7,8 @@ use App\Http\Controllers\Filter\SkuListFilter;
use
App\Model\IntracodeModel
;
use
App\Model\RedisModel
;
use
App\Model\SkuUploadLogModel
;
use
App\Model\TagsModel
;
use
GuzzleHttp\Client
;
use
Illuminate\Support\Facades\DB
;
use
PhpAmqpLib\Connection\AMQPStreamConnection
;
use
PhpAmqpLib\Message\AMQPMessage
;
...
...
@@ -95,14 +97,18 @@ class SkuService
$intraCodeModel
=
new
IntracodeModel
();
$encodedList
=
array_column
(
$list
,
'encoded'
);
$encodedUsers
=
$intraCodeModel
->
getEncodedUserByEncoded
(
$encodedList
);
$list
=
array_map
(
function
(
$item
)
use
(
$encodedUsers
)
{
$list
=
array_map
(
function
(
$item
)
use
(
$encodedUsers
,
$redis
)
{
$encoded
=
array_get
(
$item
,
'encoded'
,
0
);
$item
[
'encoded_user_name'
]
=
array_get
(
$encodedUsers
,
$encoded
,
''
);
$item
[
'moq'
]
=
$item
[
'moq'
]
?:
0
;
$item
[
'stock'
]
=
$item
[
'stock'
]
?:
0
;
$item
[
'cp_time'
]
=
$item
[
'cp_time'
]
?
date
(
'Y-m-d H:i:s'
,
$item
[
'cp_time'
])
:
''
;
$goodsTag
=
$redis
->
hget
(
'goods_tag'
,
$item
[
'goods_id'
]);
$goodsTag
=
$goodsTag
?
json_decode
(
$goodsTag
,
true
)
:
''
;
$item
[
'sku_tags'
]
=
$goodsTag
?
array_get
(
$goodsTag
,
'customer_tag'
)
:
''
;
return
$item
;
},
$list
);
$list
=
$this
->
transformInvalidSkuTag
(
$list
);
}
return
[
'list'
=>
$list
,
...
...
@@ -110,6 +116,38 @@ class SkuService
];
}
//这个是用来区分商品标签是否有效
public
function
transformInvalidSkuTag
(
$skuList
)
{
foreach
(
$skuList
as
&
$sku
)
{
$validGoodsTags
=
TagsModel
::
where
(
'tag_use'
,
16
)
->
where
(
'tag_type'
,
2
)
->
where
(
'status'
,
TagsModel
::
STATUS_OK
)
->
pluck
(
'tag_name'
)
->
toArray
();
$skuTags
=
!
empty
(
$sku
[
'sku_tags'
])
?
explode
(
' '
,
$sku
[
'sku_tags'
])
:
[];
if
(
empty
(
$sku
[
'sku_tags'
]))
{
$sku
[
'invalid_sku_tags'
]
=
$sku
[
'valid_sku_tags'
]
=
''
;
continue
;
}
$invalidSkuTags
=
$validSkuTags
=
[];
//然后判断哪些是离职,哪些是在职的
foreach
(
$skuTags
as
$tag
)
{
if
(
empty
(
$tag
))
{
continue
;
}
if
(
!
in_array
(
$tag
,
$validGoodsTags
))
{
$invalidSkuTags
[]
=
$tag
;
}
else
{
$validSkuTags
[]
=
$tag
;
}
}
$sku
[
'invalid_sku_tags'
]
=
$invalidSkuTags
?
implode
(
','
,
$invalidSkuTags
)
:
''
;
$sku
[
'valid_sku_tags'
]
=
$validSkuTags
?
implode
(
','
,
$validSkuTags
)
:
''
;
}
unset
(
$sku
);
return
$skuList
;
}
//设置精选
public
function
setPreferSku
(
$skuIds
,
$prefer
)
{
...
...
@@ -237,4 +275,42 @@ class SkuService
}
return
$result
;
}
public
function
getSystemTags
()
{
$tags
=
TagsModel
::
where
(
'tag_use'
,
16
)
->
where
(
'tag_type'
,
2
)
->
where
(
'status'
,
TagsModel
::
STATUS_OK
)
->
pluck
(
'tag_name'
,
'tag_name'
)
->
toArray
();
$result
=
[];
foreach
(
$tags
as
$key
=>
$value
)
{
if
(
empty
(
$value
))
{
continue
;
}
$result
[]
=
[
'tag_id'
=>
$value
,
'tag_name'
=>
$value
,
];
}
return
$result
;
}
public
function
batchAddSkuTags
(
$skuIds
,
$skuTags
)
{
$redis
=
new
RedisModel
();
$skuIds
=
explode
(
','
,
$skuIds
);
$skuTags
=
explode
(
','
,
$skuTags
);
foreach
(
$skuIds
as
$skuId
)
{
$skuId
=
(
int
)
$skuId
;
$goodsTag
=
$redis
->
hget
(
'goods_tag'
,
$skuId
);
if
(
$goodsTag
)
{
$goodsTag
=
json_decode
(
$goodsTag
,
true
);
$goodsTag
[
'customer_tag'
]
=
implode
(
" "
,
$skuTags
);
}
else
{
$goodsTag
=
[
'customer_tag'
=>
implode
(
" "
,
$skuTags
),
];
}
$redis
->
hset
(
'goods_tag'
,
$skuId
,
json_encode
(
$goodsTag
));
$redis
->
lpush
(
'update_list_sku'
,
$skuId
);
}
}
}
\ No newline at end of file
app/Model/TagsModel.php
View file @
c827b662
...
...
@@ -7,7 +7,20 @@ use Illuminate\Database\Eloquent\Model;
class
TagsModel
extends
Model
{
protected
$connection
=
'tag'
;
protected
$table
=
'tags'
;
protected
$table
=
'tags'
;
protected
$primaryKey
=
'id'
;
public
$timestamps
=
false
;
const
STATUS_OK
=
1
;
public
static
function
getTagNamesByTagUse
(
$tagUse
,
$tagType
)
{
return
TagsModel
::
where
(
'tag_use'
,
$tagUse
)
->
where
(
'tag_type'
,
$tagType
)
->
pluck
(
'tag_name'
,
'tag_name'
)
->
toArray
();
}
public
static
function
getTagsByTagUse
(
$tagUse
,
$tagType
)
{
return
TagsModel
::
where
(
'tag_use'
,
$tagUse
)
->
where
(
'tag_type'
,
$tagType
)
->
toArray
();
}
}
resources/views/script/BatchAddSkuTagScript.blade.php
View file @
c827b662
...
...
@@ -7,15 +7,15 @@
let
xmSelect
=
layui
.
xmSelect
;
let
tagsInput
=
layui
.
tagsInput
;
form
.
on
(
'submit(a
uditSupplier
)'
,
function
(
data
)
{
form
.
on
(
'submit(a
ddSkuTag
)'
,
function
(
data
)
{
admin
.
showLoading
({
type
:
3
});
let
s
upplierIds
=
getQueryVariable
(
'supplier
_ids'
);
let
url
=
'/api/s
upplier_tag/BatchAddTag?supplier_ids='
+
supplierIds
;
let
s
ku_ids
=
getQueryVariable
(
'sku
_ids'
);
let
url
=
'/api/s
ku/BatchAddSkuTag'
;
$
.
ajax
({
url
:
url
,
type
:
'
GE
T'
,
type
:
'
POS
T'
,
async
:
true
,
data
:
data
.
field
,
dataType
:
'json'
,
...
...
@@ -43,7 +43,7 @@
function
getTagOption
(
element
)
{
//获取系统标签列表
let
url
=
'/api/s
upplier_tag
/GetSystemTagList'
;
let
url
=
'/api/s
ku
/GetSystemTagList'
;
let
tagResult
=
ajax
(
url
);
let
tagList
=
tagResult
.
data
;
return
{
...
...
@@ -66,57 +66,13 @@
for
(
let
i
in
arr
)
{
tagIds
+=
arr
[
i
].
tag_id
+
','
;
}
let
idName
=
's
ystem
_tags'
;
let
idName
=
's
ku
_tags'
;
$
(
'#'
+
idName
).
val
(
tagIds
);
},
};
}
let
systemTagOption
=
getTagOption
(
's
ystem
_tags_selector'
,
2
);
let
systemTagOption
=
getTagOption
(
's
ku
_tags_selector'
,
2
);
let
tagSelector
=
xmSelect
.
render
(
systemTagOption
);
//自定义标签
$
(
'#customer_tags'
).
tagsInput
({});
//点击添加选择的供应商到待修改列表
$
(
document
).
on
(
'click'
,
'#addSupplierToList'
,
function
()
{
let
supplierCode
=
$
(
'#supplier_selector'
).
val
();
if
(
!
supplierCode
)
{
layer
.
msg
(
'请先选择需要操作的供应商'
,
{
icon
:
5
});
return
;
}
let
suppliers
=
{
!!
json_encode
(
$suppliers
)
!!
};
let
supplier
=
suppliers
[
supplierCode
];
let
selectedSupplierIds
=
$
(
'#supplier_ids'
).
val
();
selectedSupplierIds
=
selectedSupplierIds
?
selectedSupplierIds
.
split
(
','
)
:
[];
if
(
jQuery
.
inArray
(
supplier
[
'supplier_id'
].
toString
(),
selectedSupplierIds
)
===
0
)
{
layer
.
msg
(
'列表已经有该供应商,请重新选择'
,
{
icon
:
6
});
return
;
}
let
appendHtml
=
`
<tr>
<td>
${
supplier
[
'supplier_name'
]}
</td>
<td>
${
supplier
[
'system_tags'
]}
</td>
<td>
${
supplier
[
'customer_tags'
]}
</td>
<td><button type="button" class="layui-btn layui-btn-xs deleteSupplier" value="
${
supplier
[
'supplier_id'
]}
">删除</button> </td>
</tr>
`
;
selectedSupplierIds
.
push
(
supplier
[
'supplier_id'
]);
$
(
'#supplier_ids'
).
val
(
selectedSupplierIds
.
join
(
','
));
$
(
'#operateSupplierList'
).
append
(
appendHtml
);
//清空
$
(
'#supplier_selector'
).
val
(
''
);
form
.
render
();
});
$
(
document
).
on
(
'click'
,
'.deleteSupplier'
,
function
()
{
let
selectedSupplierIds
=
$
(
'#supplier_ids'
).
val
();
let
deleteSupplierId
=
$
(
this
).
attr
(
'value'
);
selectedSupplierIds
=
selectedSupplierIds
?
selectedSupplierIds
.
split
(
','
)
:
[];
selectedSupplierIds
.
splice
(
jQuery
.
inArray
(
deleteSupplierId
,
selectedSupplierIds
),
1
);
$
(
'#supplier_ids'
).
val
(
selectedSupplierIds
.
join
(
','
));
$
(
this
).
parents
(
'tr'
).
remove
();
});
});
</script>
\ No newline at end of file
resources/views/script/SkuListScript.blade.php
View file @
c827b662
...
...
@@ -68,17 +68,21 @@
{
field
:
'cn_delivery_time'
,
title
:
'大陆交期'
,
align
:
'center'
,
width
:
100
},
{
field
:
'hk_delivery_time'
,
title
:
'香港交期'
,
align
:
'center'
,
width
:
100
},
{
field
:
'sku_tags'
,
title
:
'标签'
,
align
:
'center'
,
width
:
150
,
templet
:
function
(
data
)
{
if
(
data
.
invalid_sku_tags
)
{
return
`<span>
${
data
.
valid_sku_tags
}
</span>`
+
` <span style="color: #D7D7D7">
${
data
.
invalid_sku_tags
}
</span>`
;
}
else
{
return
`<span>
${
data
.
valid_sku_tags
}
</span>`
}
}
},
{
field
:
'status_name'
,
title
:
'状态'
,
align
:
'center'
,
width
:
70
,
templet
:
function
(
d
)
{
return
d
.
goods_status
==
1
?
"
<
a
class
=
'layui-btn layui-btn-xs'
>
上架
<
/a>"
:
"
<
a
class
=
'layui-btn layui-btn-xs layui-btn-danger'
>
下架
<
/a>"
;
}
},
// {
// field: 'is_expire', title: '过期', align: 'center', width: 80, templet: function (d) {
// return d.is_expire === 1 ? "
<
a
class
=
'layui-btn layui-btn-xs layui-btn-danger'
>
是
<
/a>"
:
// "
<
a
class
=
'layui-btn layui-btn-xs'
>
否
<
/a>"
;
// }
// },
{
field
:
'is_prefer'
,
title
:
'精选'
,
align
:
'center'
,
width
:
70
,
templet
:
function
(
d
)
{
return
d
.
is_prefer
?
"是"
:
"否"
;
...
...
@@ -387,9 +391,13 @@
});
$
(
"#set_sku_tag"
).
click
(
function
()
{
let
checkStatus
=
table
.
checkStatus
(
'skuList'
);
let
data
=
checkStatus
.
data
;
let
skuIds
=
Array
.
from
(
data
,
({
goods_id
})
=>
goods_id
);
skuIds
=
skuIds
.
join
(
','
);
layer
.
open
({
type
:
2
,
content
:
'/sku/Batch
SetSkuTag?view=iframe'
,
content
:
'/sku/Batch
AddSkuTag?view=iframe&sku_ids='
+
skuIds
,
area
:
[
'800px'
,
'600px'
],
title
:
'批量设置SKU标签'
,
end
:
function
()
{
...
...
resources/views/web/BatchAddSkuTag.blade.php
View file @
c827b662
...
...
@@ -7,34 +7,28 @@
<div
class=
"layui-card"
>
<div
class=
"layui-card-header"
style=
"height: 230px"
>
<blockquote
class=
"layui-elem-quote layui-text"
>
<b>
标签新增
</b>
<b>
设置标签
</b>
</blockquote>
<input
type=
"hidden"
name=
"s
upplier_ids"
id=
"supplier_ids
"
>
<input
type=
"hidden"
name=
"s
ku_ids"
id=
"sku_ids"
value=
"{{request()->get('sku_ids')}}
"
>
<div
class=
"layui-form-item"
>
<div
class=
"layui-input-block"
style=
"margin-left: -30px"
>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
系统标签 :
</label>
<div
class=
"layui-input-block"
style=
"margin-top: 15px"
>
<div
id=
"s
ystem
_tags_selector"
class=
"layui-input-inline"
style=
"width: 100%;"
>
<div
id=
"s
ku
_tags_selector"
class=
"layui-input-inline"
style=
"width: 100%;"
>
</div>
<input
type=
"hidden"
name=
"system_tags"
id=
"system_tags"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
自定义标签 :
</label>
<div
class=
"layui-input-block"
style=
"margin-top: 15px"
>
<input
name=
"customer_tags"
id=
"customer_tags"
>
<input
type=
"hidden"
name=
"sku_tags"
id=
"sku_tags"
>
</div>
<span
style=
"margin-left: 110px"
>
选择标签会覆盖原有标签
</span>
</div>
</div>
</div>
<div
class=
"layui-form-item"
>
<div
align=
"center"
style=
"margin-top: 10px;text-align: right"
>
<button
type=
"button"
class=
"layui-btn layui-btn-sm layui-btn-info submit-loading"
lay-submit
lay-filter=
"a
uditSupplier
"
>
确认
lay-filter=
"a
ddSkuTag
"
>
确认
</button>
<button
type=
"button"
class=
"layui-btn layui-btn-sm layui-btn-primary"
lay-submit
lay-filter=
"cancel"
>
取消
...
...
@@ -42,36 +36,5 @@
</div>
</div>
</div>
<div
class=
"layui-card-body"
>
<blockquote
class=
"layui-elem-quote layui-text"
>
<b>
选择需要新增标签的供应商
</b>
</blockquote>
<div
class=
"layui-row"
style=
"margin-bottom: 12px"
>
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('supplier_selector','供应商选择 : ',null,
$supplierCodes,['width'=> '500px']) !!}
<button
type=
"button"
class=
"layui-btn-sm layui-btn"
style=
"margin-top: 5px;margin-left: 5px;"
id=
"addSupplierToList"
>
确认添加到操作列表
</button>
</div>
<table
class=
"layui-table"
>
<colgroup>
<col
width=
"300"
>
<col
width=
"400"
>
<col
width=
"400"
>
<col
width=
"200"
>
</colgroup>
<thead>
<tr>
<th>
供应商名称
</th>
<th>
系统标签
</th>
<th>
自定义标签
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody
id=
"operateSupplierList"
>
</tbody>
</table>
</div>
</div>
</form>
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