|
|
|
@ -12,7 +12,9 @@ declare (strict_types=1); |
|
|
|
|
|
|
|
|
|
namespace app\api\model; |
|
|
|
|
|
|
|
|
|
use app\api\model\GoodsBrowseLog; |
|
|
|
|
use app\api\service\Goods as GoodsService; |
|
|
|
|
use app\api\service\User as UserService; |
|
|
|
|
use app\api\service\user\Grade as UserGradeService; |
|
|
|
|
use app\api\model\GoodsSku as GoodsSkuModel; |
|
|
|
|
use app\api\model\store\Module as StoreModuleModel; |
|
|
|
@ -113,6 +115,49 @@ class Goods extends GoodsModel |
|
|
|
|
return $this->setGoodsListDataFromApi($list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function browseLog() |
|
|
|
|
{ |
|
|
|
|
$userId = UserService::getCurrentLoginUserId(true); |
|
|
|
|
|
|
|
|
|
$list = GoodsBrowseLog::where([ |
|
|
|
|
'store_id' => request()->header()['storeid'], |
|
|
|
|
'user_id' => $userId, |
|
|
|
|
])->order('id desc')->paginate(15)->column('ctime'); |
|
|
|
|
$list = array_unique($list); |
|
|
|
|
$res = []; |
|
|
|
|
|
|
|
|
|
foreach ($list as $k => $v) { |
|
|
|
|
$all = GoodsBrowseLog::alias('a') |
|
|
|
|
->join('goods b', 'a.goods_id = b.goods_id') |
|
|
|
|
->join('goods_sku c', 'a.goods_id = c.goods_id') |
|
|
|
|
->where([ |
|
|
|
|
'a.store_id' => request()->header()['storeid'], |
|
|
|
|
'a.user_id' => $userId, |
|
|
|
|
'a.ctime' => $v, |
|
|
|
|
'b.is_delete' => 0, |
|
|
|
|
'b.status' => 10 |
|
|
|
|
])->field('a.ctime,a.goods_id,c.goods_props')->order('a.id desc')->select()->toArray(); |
|
|
|
|
foreach ($all as $k2 => &$v2) { |
|
|
|
|
$v2['goods_props'] = \Qiniu\json_decode($v2['goods_props'], 1)[0] ?? ''; |
|
|
|
|
$v2['image'] = $this->getDetails2($v2['goods_id'])->toArray()['goods_images'][0]->toArray()['preview_url'] ?? ''; |
|
|
|
|
} |
|
|
|
|
$res[$v] = $all; |
|
|
|
|
} |
|
|
|
|
return $res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function browseDel() |
|
|
|
|
{ |
|
|
|
|
$userId = UserService::getCurrentLoginUserId(true); |
|
|
|
|
$info = GoodsBrowseLog::where([ |
|
|
|
|
'store_id' => request()->header()['storeid'], |
|
|
|
|
'user_id' => $userId, |
|
|
|
|
])->whereIn('id', $_POST['ids'])->delete(); |
|
|
|
|
return $info; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取商品详情 (详细数据用于页面展示) |
|
|
|
|
* @param int $goodsId 商品ID |
|
|
|
@ -162,10 +207,37 @@ class Goods extends GoodsModel |
|
|
|
|
$goodsInfo->specifications = $newList; |
|
|
|
|
} |
|
|
|
|
//加入足迹 |
|
|
|
|
$userId = UserService::getCurrentLoginUserId(false) ?? ''; |
|
|
|
|
if ($userId) { |
|
|
|
|
$info = GoodsBrowseLog::where([ |
|
|
|
|
'user_id' => $userId, |
|
|
|
|
'goods_id' => $goodsId, |
|
|
|
|
'store_id' => request()->header()['storeid'], |
|
|
|
|
'ctime' => date('Y-m-d') |
|
|
|
|
])->find(); |
|
|
|
|
if (!$info) { |
|
|
|
|
GoodsBrowseLog::insert([ |
|
|
|
|
'user_id' => $userId, |
|
|
|
|
'goods_id' => $goodsId, |
|
|
|
|
'store_id' => request()->header()['storeid'], |
|
|
|
|
'ctime' => date('Y-m-d') |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $goodsInfo->hidden(static::getHidden(['images'])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getDetails2(int $goodsId, bool $verifyStatus = true) |
|
|
|
|
{ |
|
|
|
|
// 关联查询(商品图片、sku列表) |
|
|
|
|
$with = ['images.file']; |
|
|
|
|
// 获取商品记录 |
|
|
|
|
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus); |
|
|
|
|
|
|
|
|
|
return $goodsInfo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取商品详情 (仅包含主商品信息和商品图片) |
|
|
|
|
* @param int $goodsId 商品ID |
|
|
|
|