1.提交缺失的东西
This commit is contained in:
@ -101,7 +101,8 @@ class GoodsController extends BaseAdminController
|
|||||||
public function detail()
|
public function detail()
|
||||||
{
|
{
|
||||||
$params = (new GoodsValidate())->goCheck('detail');
|
$params = (new GoodsValidate())->goCheck('detail');
|
||||||
$result = GoodsLogic::detail($params);
|
// $result = GoodsLogic::detail($params);
|
||||||
|
$result = GoodsLogic::info($params['id']);
|
||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@ namespace app\adminapi\logic;
|
|||||||
|
|
||||||
use app\common\model\Goods;
|
use app\common\model\Goods;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\service\UrlServer;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
@ -196,4 +197,70 @@ class GoodsLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
return Goods::findOrEmpty($params['id'])->toArray();
|
return Goods::findOrEmpty($params['id'])->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 商品信息
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 获取商品信息
|
||||||
|
* @param $goods_id
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function info($goods_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
$info['base'] = Db::name('goods')
|
||||||
|
->where(['id' => $goods_id])
|
||||||
|
->withAttr('abs_image', function ($value, $data) {
|
||||||
|
return UrlServer::getFileUrl($data['image']);
|
||||||
|
})
|
||||||
|
->withAttr('content', function ($value){
|
||||||
|
$preg = '/(<img .*?src=")[^https|^http](.*?)(".*?>)/is';
|
||||||
|
$local_url = UrlServer::getFileUrl('/');
|
||||||
|
return preg_replace($preg, "\${1}$local_url\${2}\${3}",$value);
|
||||||
|
})
|
||||||
|
->withAttr('abs_video',function ($value,$data){
|
||||||
|
if($data['video']){
|
||||||
|
return UrlServer::getFileUrl($data['video']);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
})
|
||||||
|
->withAttr('abs_poster',function ($value,$data){
|
||||||
|
if($data['poster']){
|
||||||
|
return UrlServer::getFileUrl($data['poster']);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
})
|
||||||
|
->append(['abs_image','abs_video'])->find();
|
||||||
|
$info['base']['goods_image'] = Db::name('goods_image')
|
||||||
|
->where(['goods_id' => $goods_id])
|
||||||
|
->withAttr('abs_image', function ($value, $data) {
|
||||||
|
return UrlServer::getFileUrl($data['uri']);})
|
||||||
|
->append(['abs_image'])
|
||||||
|
->select();
|
||||||
|
|
||||||
|
$info['item'] = Db::name('goods_item')
|
||||||
|
->where(['goods_id' => $goods_id])
|
||||||
|
->withAttr('abs_image', function ($value, $data) {
|
||||||
|
return UrlServer::getFileUrl($data['image']);
|
||||||
|
})->append(['abs_image'])
|
||||||
|
->select();
|
||||||
|
|
||||||
|
$info['spec'] = Db::name('goods_spec')
|
||||||
|
->where(['goods_id' => $goods_id])
|
||||||
|
->select();
|
||||||
|
|
||||||
|
$spec_value = Db::name('goods_spec_value')
|
||||||
|
->where(['goods_id' => $goods_id])
|
||||||
|
->select();
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
foreach ($spec_value as $k => $v) {
|
||||||
|
$data[$v['spec_id']][] = $v;
|
||||||
|
}
|
||||||
|
foreach ($info['spec'] as $k => $v) {
|
||||||
|
$info['spec'][$k]['values'] = isset($data[$v['id']]) ? $data[$v['id']] : [];
|
||||||
|
}
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user