|
|
@@ -154,7 +154,7 @@ class GoodsService extends BaseService
|
|
|
* @param $id
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getInfo($goodsId, $userId=0)
|
|
|
+ public function getInfo($goodsId, $userId=0, $updateView=true)
|
|
|
{
|
|
|
$field = ['a.*'];
|
|
|
$info = $this->model->from('goods as a')->with(['category','skuList'])
|
|
|
@@ -198,8 +198,10 @@ class GoodsService extends BaseService
|
|
|
unset($v);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- $this->updateView($userId, $goodsId);
|
|
|
+ // 更新访问量
|
|
|
+ if($updateView){
|
|
|
+ $this->updateView($userId, $goodsId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $info;
|
|
|
@@ -207,6 +209,82 @@ class GoodsService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取要购买或结算的商品列表
|
|
|
+ * @param $userId
|
|
|
+ * @param array $params
|
|
|
+ * @return array|false|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
|
|
|
+ */
|
|
|
+ public function getBuyList($userId, $params=[])
|
|
|
+ {
|
|
|
+ $goodsId = isset($params['goods_id'])? $params['goods_id'] : 0;
|
|
|
+ $skuId = isset($params['sku_id'])? $params['sku_id'] : 0;
|
|
|
+ $num = isset($params['num'])? $params['num'] : 0;
|
|
|
+ $cartIds = isset($params['cart_ids'])? $params['cart_ids'] : '';
|
|
|
+ $cartIds = $cartIds? explode('|', $cartIds) : [];
|
|
|
+ if(empty($goodsId) && empty($cartIds)){
|
|
|
+ $this->error = 2901;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsId && (empty($skuId) || $num<=0)){
|
|
|
+ $this->error = 2901;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $goods = [];
|
|
|
+ if($goodsId){
|
|
|
+ $info = $this->getInfo($goodsId, $userId, false);
|
|
|
+ if($info){
|
|
|
+ $info['num'] = $num;
|
|
|
+ $info['sku'] = GoodsSkuModel::where(['goods_id'=> $goodsId,'sku_id'=> $skuId,'mark'=>1])->first();
|
|
|
+ $goods[] = $info;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ $goods = CartsModel::with(['sku'])->from('carts as a')
|
|
|
+ ->leftJoin('goods as b','b.goods_id','=','a.goods_id')
|
|
|
+ ->leftJoin('goods_sku as c','c.sku_id','=','a.sku_id')
|
|
|
+ ->whereIn('a.id', $cartIds)
|
|
|
+ ->where(['a.status' => 1, 'a.mark' => 1,'b.status'=>1,'b.mark'=>1])
|
|
|
+ ->where('b.cost_price', '>', 0)
|
|
|
+ ->select(['b.goods_id','b.merch_id','b.goods_name','b.supply_type','b.main_img','b.cost_price','b.retail_price','b.limit_num','b.lowest_num','b.brand_name','a.num','a.sku_id'])
|
|
|
+ ->get();
|
|
|
+ if($goods){
|
|
|
+
|
|
|
+ // 价格等参数格式化
|
|
|
+ $locale = RedisService::get("caches:locale:lang_{$userId}");
|
|
|
+ $locale = $locale ? $locale : session('locale_lang');
|
|
|
+ $locale = $locale ? $locale : 'zh-cn';
|
|
|
+ $supplyList = config('goods.supplyList');
|
|
|
+
|
|
|
+ $usdtPrice = RedisService::get("caches:wallets:usdt_rate");
|
|
|
+ if($usdtPrice<=0){
|
|
|
+ $usdtCnyPrice = ConfigService::make()->getConfigByCode('usdt_cny_price', 7.2);
|
|
|
+ $usdtPrice = $usdtCnyPrice>0 && $usdtCnyPrice< 100? $usdtCnyPrice : 0;
|
|
|
+ }
|
|
|
+ $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
|
|
|
+ $xdPrice = $xdPrice > 0 && $xdPrice <= 10000 ? $xdPrice : 100;
|
|
|
+
|
|
|
+ foreach ($goods as &$item) {
|
|
|
+ $item['detail_img'] = isset($item['detail_img']) && $item['detail_img'] ? json_decode($item['detail_img'], true) : [];
|
|
|
+ $item['supply_name'] = isset($supplyList[$item['supply_type']]) ? $supplyList[$item['supply_type']] : '';
|
|
|
+ $item['usdt_price'] = $usdtPrice;
|
|
|
+ $item['xd_price_rate'] = $xdPrice;
|
|
|
+ $item['original_price'] = $item['cost_price'];
|
|
|
+ $item['cost_price'] = $usdtPrice > 0 ? moneyFormat($item['cost_price'] / $usdtPrice * $xdPrice, 2) : $item['cost_price'];
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($goods)){
|
|
|
+ $this->error = 2901;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $goods;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 添加/更新购物车
|
|
|
* @param $userId
|
|
|
* @param $goodsId
|
|
|
@@ -263,7 +341,7 @@ class GoodsService extends BaseService
|
|
|
->leftJoin('goods_sku as c','c.sku_id','=','a.sku_id')
|
|
|
->where(['a.status' => 1, 'a.mark' => 1,'b.status'=>1,'b.mark'=>1])
|
|
|
->where('b.cost_price', '>', 0)
|
|
|
- ->select(['b.*','a.num','a.sku_id'])
|
|
|
+ ->select(['b.goods_id','b.merch_id','b.goods_name','b.supply_type','b.main_img','b.cost_price','b.retail_price','b.limit_num','b.lowest_num','b.brand_name','a.num','a.sku_id'])
|
|
|
->orderBy('a.create_time','desc')
|
|
|
->limit($pageSize)
|
|
|
->get();
|
|
|
@@ -326,6 +404,9 @@ class GoodsService extends BaseService
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 运费
|
|
|
+ */
|
|
|
public function getFreight($userId, $addressId,$skuList)
|
|
|
{
|
|
|
$cacheKey = "caches:goods:freight:{$userId}_{$addressId}_".md5(json_encode($skuList,256));
|