Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

master
Lemon 5 years ago
parent
commit
91e91869bd
  1. 1
      app/Controller/v3/GoodsRecommendController.php
  2. 3
      app/Model/v3/Goods.php
  3. 3
      app/Model/v3/GoodsActivity.php
  4. 4
      app/Model/v3/ShoppingCart.php
  5. 5
      app/Model/v3/UserAddress.php
  6. 10
      app/Service/v3/Implementations/ActivityService.php
  7. 18
      app/Service/v3/Implementations/CategoryService.php
  8. 4
      app/Service/v3/Implementations/SearchService.php
  9. 2
      app/Service/v3/Implementations/ShopCartUpdateService.php
  10. 15
      app/Service/v3/Implementations/UserAddressService.php
  11. 2
      app/Service/v3/Implementations/WithdrawalListService.php

1
app/Controller/v3/GoodsRecommendController.php

@ -47,7 +47,6 @@ class GoodsRecommendController extends BaseController
break;
case Tabs::APPLET_INDEX_OFFICE:
$categoryIds = [97,98];
var_dump('ids', $categoryIds);
// 查询出三级分类
$goodsCategoryIds = GoodsCategory::query()->whereIn('category_id', $categoryIds)->pluck('id');
$builder = $builder->where(function ($query) use ($categoryIds, $goodsCategoryIds) {

3
app/Model/v3/Goods.php

@ -100,7 +100,8 @@ class Goods extends Model
public function getCartNumAttribute()
{
return 0;
$userId = $this->request->user->id ?? 0;
return $userId ? (integer)$this->shopCartService->check($userId, $this->id,1) : 0;
}
public function getIsEffectiveAttribute()

3
app/Model/v3/GoodsActivity.php

@ -68,7 +68,8 @@ class GoodsActivity extends Model
public function getCartNumAttribute()
{
return 0;
$userId = $this->request->user->id ?? 0;
return $userId ? (integer)$this->shopCartService->check($userId, $this->id,1) : 0;
}
public function getIsEffectiveAttribute()

4
app/Model/v3/ShoppingCart.php

@ -3,11 +3,11 @@
namespace App\Model\v3;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
// use Hyperf\Database\Model\SoftDeletes;
class ShoppingCart extends Model
{
use SoftDeletes;
// use SoftDeletes;
protected $table = 'lanzu_shopping_cart';
protected $fillable = [

5
app/Model/v3/UserAddress.php

@ -27,4 +27,9 @@ class UserAddress extends Model
protected $casts = [
'tags' => 'array'
];
public function setTagsAttribute($value)
{
$this->attributes['tags'] = json_encode(json_decode($value, true));
}
}

10
app/Service/v3/Implementations/ActivityService.php

@ -28,11 +28,11 @@ class ActivityService implements ActivityServiceInterface
{
$builder = GoodsActivity::query()
->with(['store'])
->where(['type' => $type]);
if ($marketId != -1) {
$builder = $builder->where('market_id', $marketId);
}
->where(['type' => $type])
->where(function ($query) use ($marketId) {
$query->whereJsonContains("market_ids", [(string)$marketId])
->orWhereJsonLength("market_ids", '=', 0);
});
return $builder->get()->toArray();
}

18
app/Service/v3/Implementations/CategoryService.php

@ -50,16 +50,26 @@ class CategoryService implements CategoryServiceInterface
public function allForStore($storeId)
{
$goodsTypeIds = Goods::query()->select('id','category_id')
$goodsTypeIds = Goods::query()
->where(['store_id' => $storeId])
->groupBy('category_id', 'id')
->get()->toArray();
->pluck('category_id');
return Category::query()
->whereIn('id', array_values(array_column($goodsTypeIds, 'category_id')))
$categories = Category::query()
->with(['goodsCategory'])
->whereIn('id', $goodsTypeIds)
->orderBy('sort', 'DESC')
->orderBy('id', 'DESC')
->get()->toArray();
foreach ($categories as $key => &$item) {
$item['goods_category_ids'] = '';
if (isset($item['goods_category']) && $item['goods_category']) {
$item['goods_category_ids'] = implode(',', array_values(array_column($item['goods_category'], 'id')));
}
}
return $categories;
}
public function allForAppletIndex()

4
app/Service/v3/Implementations/SearchService.php

@ -26,6 +26,10 @@ class SearchService implements SearchServiceInterface
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1);
});;
if (isset($params['store_id']) && $params['store_id']) {
$builder->where(['store_id' => $params['store_id']]);
}
if (isset($params['type_id']) && $params['type_id']) {
$typeIds = explode(',', $params['type_id']);
$builder->whereIn('category_id', $typeIds);

2
app/Service/v3/Implementations/ShopCartUpdateService.php

@ -50,7 +50,7 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface
throw new ErrorCodeException($goodsCheck);
}
return ShoppingCart::query()->updateOrCreate(
return ShoppingCart::query()->lockForUpdate()->updateOrCreate(
[
'user_id' => $userId,
'goods_id' => $goodsId,

15
app/Service/v3/Implementations/UserAddressService.php

@ -65,7 +65,10 @@ class UserAddressService implements UserAddressServiceInterface
public function get($userAddressId)
{
return UserAddress::query()->find($userAddressId);
$address['address'] = UserAddress::query()->find($userAddressId);
$address['tags'] = $this->getTags();
return $address;
}
public function getList($userId)
@ -89,5 +92,15 @@ class UserAddressService implements UserAddressServiceInterface
return $res;
}
public function getTags()
{
return [
['id' => 1, 'name' => '家'],
['id' => 2, 'name' => '父母家'],
['id' => 3, 'name' => '岳父母家'],
['id' => 4, 'name' => '公司'],
['id' => 5, 'name' => '朋友家'],
];
}
}

2
app/Service/v3/Implementations/WithdrawalListService.php

@ -27,7 +27,7 @@ class WithdrawalListService implements WithdrawalListServiceInterface
if(!empty($startTime) && !empty($endTime)){
$builder->whereBetween('created_at',[$startTime,$endTime]);
}
$paginate = $builder->paginate($pagesize);
$paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize);
$orders = $paginate->toArray();
return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']];
}
Loading…
Cancel
Save