Browse Source

失效商品 定位详情

master
Lemon 6 years ago
parent
commit
579810103e
  1. 8
      app/Constants/v3/Goods.php
  2. 7
      app/Controller/v3/GoodsController.php
  3. 52
      app/Controller/v3/LocationController.php
  4. 15
      app/Model/v3/Area.php
  5. 12
      app/Model/v3/GoodsActivity.php
  6. 11
      app/Model/v3/User.php
  7. 32
      app/Service/v3/Implementations/GoodsService.php
  8. 31
      app/Service/v3/Implementations/LocationService.php
  9. 22
      app/Service/v3/Implementations/OrderListService.php
  10. 2
      app/Service/v3/Interfaces/GoodsServiceInterface.php
  11. 13
      app/Service/v3/Interfaces/LocationServiceInterface.php
  12. 1
      config/autoload/dependencies.php

8
app/Constants/v3/Goods.php

@ -21,5 +21,13 @@ class Goods extends AbstractConstants
*/
const ON_SALE_NO = 2;
/**
* @Message("无限库存")
*/
const IS_INVENTORY = 1;
/**
* @Message("活动商品")
*/
const IS_ACTIVITY = 2;
}

7
app/Controller/v3/GoodsController.php

@ -3,7 +3,6 @@
namespace App\Controller\v3;
use App\Controller\BaseController;
use App\Service\v3\Interfaces\StoreServiceInterface;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\GoodsServiceInterface;
class GoodsController extends BaseController
@ -13,12 +12,6 @@ class GoodsController extends BaseController
* @var GoodsServiceInterface
*/
protected $goodsService;
/**
* @Inject
* @var StoreServiceInterface
*/
protected $storeService;
public function detail()
{
$params = $this->request->all();

52
app/Controller/v3/LocationController.php

@ -3,6 +3,8 @@
namespace App\Controller\v3;
use App\Controller\BaseController;
use App\Service\v3\Interfaces\LocationServiceInterface;
use Hyperf\Di\Annotation\Inject;
/**
* 定位相关
@ -11,6 +13,11 @@ use App\Controller\BaseController;
*/
class LocationController extends BaseController
{
/**
* @Inject
* @var LocationServiceInterface
*/
protected $locationService;
/**
* 获取当前用户定位最近的市场
@ -39,48 +46,7 @@ class LocationController extends BaseController
public function getMarketListByLocation()
{
return $this->success([
'南宁市' => [
[
'id' => 1,
'name' => '东沟岭菜市',
'province_id' => 1,
'province_name' => '广西',
'city_id' => 2,
'city_name' => '南宁市',
'area_id' => 3,
'area_name' => '良庆区',
'address' => '青秀区竹塘路17号',
'lng' => '108.383566',
'lat' => '22.759946',
],
[
'id' => 2,
'name' => '铜鼓岭市场',
'province_id' => 1,
'province_name' => '广西',
'city_id' => 2,
'city_name' => '南宁市',
'area_id' => 3,
'area_name' => '良庆区',
'address' => '青秀区竹塘路17号',
'lng' => '108.383566',
'lat' => '22.759946',
],
[
'id' => 3,
'name' => '华园菜市',
'province_id' => 1,
'province_name' => '广西',
'city_id' => 2,
'city_name' => '南宁市',
'area_id' => 3,
'area_name' => '良庆区',
'address' => '青秀区竹塘路17号',
'lng' => '108.383566',
'lat' => '22.759946',
],
]
]);
$cityIds = [2163,2189];
return $this->success($this->locationService->getMarketListByLocation($cityIds));
}
}

15
app/Model/v3/Area.php

@ -0,0 +1,15 @@
<?php
namespace App\Model\v3;
use App\Model\Model;
class Area extends Model
{
protected $table = 'lanzu_area';
public function markets()
{
return $this->hasMany(Market::class, 'city_id', 'id');
}
}

12
app/Model/v3/GoodsActivity.php

@ -5,11 +5,19 @@ namespace App\Model\v3;
use App\Constants\v3\Goods as GoodsConstants;
use App\Constants\v3\SsdbKeys;
use App\Model\Model;
use App\Service\v3\Interfaces\ShopCartServiceInterface;
use Hyperf\Database\Model\Builder;
use Hyperf\Utils\ApplicationContext;
use App\TaskWorker\SSDBTask;
use Hyperf\Di\Annotation\Inject;
class GoodsActivity extends Model
{
/**
* @Inject
* @var ShopCartServiceInterface
*/
protected $shopCartService;
protected $table = 'lanzu_goods_activity';
protected $casts = [
@ -44,6 +52,6 @@ class GoodsActivity extends Model
public function store()
{
return $this->belongsTo(Store::class, 'store_id', 'goods_id');
return $this->belongsTo(Store::class, 'store_id', 'id');
}
}

11
app/Model/v3/User.php

@ -22,4 +22,15 @@ class User extends Model
'gender',
'language',
];
protected $visible = [
'nick_name',
'avatar',
'openid',
'unionid',
'country',
'province',
'city',
'gender',
'language',
];
}

32
app/Service/v3/Implementations/GoodsService.php

@ -5,7 +5,9 @@ namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\GoodsServiceInterface;
use Hyperf\DbConnection\Db;
use App\Model\v3\Goods;
use App\Constants\v3\Store;
use App\Constants\v3\goods as goodsConstants;
use App\Model\v3\GoodsActivity;
class GoodsService implements GoodsServiceInterface
{
public function do($goodsId)
@ -15,9 +17,33 @@ class GoodsService implements GoodsServiceInterface
}
public function check($goodsId)
public function check($goodsId,$num = 1,$activity_type = 1)
{
// TODO: Implement check() method.
if($activity_type == goodsConstants::IS_ACTIVITY) {
$builder = GoodsActivity::query();
}else{
$builder = Goods::query();
}
$data = $builder->with('store')->where('id', $goodsId)->first();
//活动商品 校验
if($activity_type == goodsConstants::IS_ACTIVITY) {
if($data->expire_time < time()){
return '活动已结束';
}
}
if($data->store->is_rest != Store::IS_OPEN_YES){
return '店铺已休息';
}
if($data->on_sale == 0 || !is_null($data->deleted_at)){
return '商品已下架';
}
if($data->is_infinite != 1 && $data->inventory < $num){
return '库存不足';
}
return '';
}
public function undo()

31
app/Service/v3/Implementations/LocationService.php

@ -0,0 +1,31 @@
<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\LocationServiceInterface;
use App\Model\v3\Area;
use App\Model\v3\Market;
class LocationService implements LocationServiceInterface
{
public function do()
{
// TODO: Implement do() method.
}
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
public function getMarketListByLocation($cityIds)
{
$res = Area::query()->with('markets')->whereIn('id',$cityIds)->get();
return $res;
}
}

22
app/Service/v3/Implementations/OrderListService.php

@ -96,16 +96,18 @@ class OrderListService implements OrderListServiceInterface
public function offlineByStore($storeId, $tab, $page=1, $pagesize=10)
{
$builder = Order::query()
->with(['orderMain' => function($query) {
$query->where('lanzu_order_main.type',4);
}])
->with(['user' => function($query) {
$query->select(['lanzu_user.id', 'lanzu_user.nick_name']);
}])
->where([
'store_id' => $storeId
]);
$builder = Order::Join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.id')
->where('store_id', $storeId)
->where('lanzu_order_main.type',4)
->with('user');
$sw = [
'all'=>'',
'completed'=> OrderState::FINISH,
'unpaid'=> OrderState::UNPAID,
'receiving' => OrderState::RECEIVING,
'refund' => OrderState::REFUND
];
switch ($tab) {
case 'all':
break;

2
app/Service/v3/Interfaces/GoodsServiceInterface.php

@ -5,7 +5,7 @@ namespace App\Service\v3\Interfaces;
interface GoodsServiceInterface
{
public function do($goodsId);
public function check($goodsId);
public function check($goodsId,$num = 1,$activity_type = 1);
public function undo();
public function getBanner();
}

13
app/Service/v3/Interfaces/LocationServiceInterface.php

@ -0,0 +1,13 @@
<?php
namespace App\Service\v3\Interfaces;
interface LocationServiceInterface
{
public function do();
public function check();
public function undo();
public function getMarketListByLocation($cityIds);
}

1
config/autoload/dependencies.php

@ -57,4 +57,5 @@ return [
\App\Service\v3\Interfaces\StoreLoginServiceInterface::class => \App\Service\v3\Implementations\StoreLoginService::class,
\App\Service\v3\Interfaces\StoreInfoServiceInterface::class => \App\Service\v3\Implementations\StoreInfoService::class,
\App\Service\v3\Interfaces\BannerServiceInterface::class => \App\Service\v3\Implementations\BannerService::class,
\App\Service\v3\Interfaces\LocationServiceInterface::class => \App\Service\v3\Implementations\LocationService::class,
];
Loading…
Cancel
Save