增加标签处理方法

This commit is contained in:
Anyon 2020-09-21 17:17:25 +08:00
parent c6526438f9
commit 28018a63f4
4 changed files with 25 additions and 14 deletions

View File

@ -54,8 +54,7 @@ class NewsItem extends Controller
protected function _page_filter(&$data) protected function _page_filter(&$data)
{ {
foreach ($data as &$vo) { foreach ($data as &$vo) {
$vo['mark'] = trim($vo['mark'], ','); $vo['mark'] = think_string_to_array($vo['mark'] ?: '');
$vo['mark'] = $vo['mark'] ? explode(',', $vo['mark']) : [];
} }
} }
@ -95,11 +94,11 @@ class NewsItem extends Controller
protected function _form_filter(&$data) protected function _form_filter(&$data)
{ {
if ($this->request->isGet()) { if ($this->request->isGet()) {
[$map, $sort] = [['deleted' => 0, 'status' => 1], 'sort desc,id desc']; $query = $this->app->db->name('DataNewsMark')->where(['deleted' => 0, 'status' => 1]);
$this->mark = $this->app->db->name('DataNewsMark')->where($map)->order($sort)->select()->toArray(); $this->mark = $query->order('sort desc,id desc')->select()->toArray();
$data['mark'] = isset($data['mark']) && $data['mark'] ? explode(',', trim($data['mark'], ',')) : []; $data['mark'] = think_string_to_array($data['mark']);
} else { } else {
$data['mark'] = ',' . join(',', isset($data['mark']) && is_array($data['mark']) ? $data['mark'] : []) . ','; $data['mark'] = think_array_to_string($data['mark'] ?? []);
} }
} }

View File

@ -83,7 +83,7 @@ class ShopGoods extends Controller
$clist = $this->app->db->name('ShopGoodsCate')->whereIn('id', array_column($data, 'cate'))->column('pid,name,status', 'id'); $clist = $this->app->db->name('ShopGoodsCate')->whereIn('id', array_column($data, 'cate'))->column('pid,name,status', 'id');
foreach ($data as &$vo) { foreach ($data as &$vo) {
$vo['cate'] = $clist[$vo['cate']] ?? $vo['cate']; $vo['cate'] = $clist[$vo['cate']] ?? $vo['cate'];
$vo['mark'] = trim($vo['mark'], ',') ? explode(',', trim($vo['mark'], ',')) : []; $vo['mark'] = think_string_to_array($vo['mark'] ?: '');
} }
} }
@ -153,9 +153,9 @@ class ShopGoods extends Controller
$data['code'] = CodeExtend::uniqidNumber(12, 'G'); $data['code'] = CodeExtend::uniqidNumber(12, 'G');
} }
if ($this->request->isGet()) { if ($this->request->isGet()) {
$data['mark'] = think_string_to_array($data['mark']);
$this->marks = GoodsService::instance()->getMarkList(); $this->marks = GoodsService::instance()->getMarkList();
$this->cates = GoodsService::instance()->getCateList('arr2table'); $this->cates = GoodsService::instance()->getCateList('arr2table');
$data['mark'] = isset($data['mark']) && trim($data['mark'], ',') ? explode(',', trim($data['mark'], ',')) : [];
$fields = 'goods_sku `sku`,goods_code,goods_spec `key`,price_selling `selling`,price_market `market`,number_virtual `virtual`,number_express `express`,status'; $fields = 'goods_sku `sku`,goods_code,goods_spec `key`,price_selling `selling`,price_market `market`,number_virtual `virtual`,number_express `express`,status';
$data['data_items'] = json_encode($this->app->db->name('ShopGoodsItem')->where(['goods_code' => $data['code']])->column($fields, 'goods_spec'), JSON_UNESCAPED_UNICODE); $data['data_items'] = json_encode($this->app->db->name('ShopGoodsItem')->where(['goods_code' => $data['code']])->column($fields, 'goods_spec'), JSON_UNESCAPED_UNICODE);
$data['truck_items'] = $this->app->db->name('ShopTruckTemplate')->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc')->column('code,name'); $data['truck_items'] = $this->app->db->name('ShopTruckTemplate')->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc')->column('code,name');
@ -163,7 +163,7 @@ class ShopGoods extends Controller
if (empty($data['cover'])) $this->error('商品图片不能为空!'); if (empty($data['cover'])) $this->error('商品图片不能为空!');
if (empty($data['slider'])) $this->error('轮播图不能为空!'); if (empty($data['slider'])) $this->error('轮播图不能为空!');
// 商品规格保存 // 商品规格保存
$data['mark'] = ',' . (isset($data['mark']) && is_array($data['mark']) ? join(',', $data['mark']) : '') . ','; $data['mark'] = think_array_to_string($data['mark'] ?? []);
[$count, $items] = [0, json_decode($data['data_items'], true)]; [$count, $items] = [0, json_decode($data['data_items'], true)];
foreach ($items as $item) { foreach ($items as $item) {
$count += intval($item[0]['status']); $count += intval($item[0]['status']);
@ -236,7 +236,7 @@ class ShopGoods extends Controller
} }
/** /**
* 商品上下架管理 * 商品上下架
* @auth true * @auth true
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
*/ */

View File

@ -129,7 +129,6 @@ class GoodsService extends Service
return $data; return $data;
} }
/** /**
* 最大分类级别 * 最大分类级别
* @return integer * @return integer

View File

@ -3,9 +3,9 @@
if (!function_exists('think_string_to_array')) { if (!function_exists('think_string_to_array')) {
/** /**
* 字符串转数组 * 字符串转数组
* @param string $text * @param string $text 待转内容
* @param string $separ * @param string $separ 分隔字符
* @return array|false|string[] * @return array
*/ */
function think_string_to_array(string $text, string $separ = ','): array function think_string_to_array(string $text, string $separ = ','): array
{ {
@ -14,6 +14,19 @@ if (!function_exists('think_string_to_array')) {
} }
} }
if (!function_exists('think_array_to_string')) {
/**
* 数组转字符串
* @param array $data 待转数组
* @param string $separ 分隔字符
* @return string
*/
function think_array_to_string(array $data, string $separ = ',')
{
return join($separ, $data);
}
}
if (!function_exists('think_show_goods_spec')) { if (!function_exists('think_show_goods_spec')) {
/** /**
* 商品规格过滤显示 * 商品规格过滤显示