Browse Source

Merge branch 'goods_for_store'

master
Lemon 5 years ago
parent
commit
d7b75ed2ba
  1. 23
      app/Controller/v3/SearchController.php
  2. 12
      app/Controller/v3/StoreController.php
  3. 11
      app/Model/v3/GoodsActivity.php
  4. 2
      app/Service/v3/Implementations/GoodsActivityService.php
  5. 21
      app/Service/v3/Implementations/SearchService.php
  6. 22
      app/Service/v3/Implementations/StoreService.php
  7. 1
      app/Service/v3/Interfaces/SearchServiceInterface.php
  8. 2
      app/Service/v3/Interfaces/StoreServiceInterface.php
  9. 1
      config/routes.php

23
app/Controller/v3/SearchController.php

@ -3,6 +3,7 @@
namespace App\Controller\v3; namespace App\Controller\v3;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Model\v3\Employees;
use App\Request\v3\SearchGoodsRequest; use App\Request\v3\SearchGoodsRequest;
use App\Request\v3\SearchStoreRequest; use App\Request\v3\SearchStoreRequest;
use App\Service\v3\Interfaces\LocationServiceInterface; use App\Service\v3\Interfaces\LocationServiceInterface;
@ -83,4 +84,26 @@ class SearchController extends BaseController
$data = $this->locationService->searchMarket($keywords,$lng,$lat,$cityId); $data = $this->locationService->searchMarket($keywords,$lng,$lat,$cityId);
return $this->success(['markets' => $data]); return $this->success(['markets' => $data]);
} }
/**
* 服务专员店铺搜索
*/
public function storesForPersonnel()
{
$userId = $this->request->input('user_id');
$page = $this->request->input('page',1);
$pagesize = $this->request->input('pagesize',10);
$ids = $this->request->input('ids','');
$ids = json_decode($ids,true);
$keywords = $this->request->input('keywords','');
$employees = Employees::query()
->where('user_id',$userId)
->whereJsonContains('position', '30')
->first();
if(empty($employees)){
return $this->success(['personnel' => false]);
}
$res = $this->searchService->getStoresForPersonnel($employees->market_id,$ids,$keywords,$page,$pagesize);
return $this->success($res);
}
} }

12
app/Controller/v3/StoreController.php

@ -5,6 +5,7 @@ namespace App\Controller\v3;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Model\v3\Employees;
use App\Model\v3\ServicePersonnel; use App\Model\v3\ServicePersonnel;
use App\Request\v3\StoreIndexRequest; use App\Request\v3\StoreIndexRequest;
use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CategoryServiceInterface;
@ -109,11 +110,16 @@ class StoreController extends BaseController
$userId = $this->request->input('user_id'); $userId = $this->request->input('user_id');
$page = $this->request->input('page',1); $page = $this->request->input('page',1);
$pagesize = $this->request->input('pagesize',10); $pagesize = $this->request->input('pagesize',10);
$personnel = ServicePersonnel::query()->where('user_id',$userId)->first();
if(empty($personnel)){
$ids = $this->request->input('ids','');
$ids = json_decode($ids,true);
$employees = Employees::query()
->where('user_id',$userId)
->whereJsonContains('position', '30')
->first();
if(empty($employees)){
return $this->success(['personnel' => false]); return $this->success(['personnel' => false]);
} }
$res = $this->storeService->getList($personnel->market_id,$page,$pagesize);
$res = $this->storeService->getList($employees->market_id,$ids,$page,$pagesize);
return $this->success($res); return $this->success($res);
} }

11
app/Model/v3/GoodsActivity.php

@ -7,6 +7,7 @@ use App\Constants\v3\OssThumbnail;
use App\Constants\v3\SsdbKeys; use App\Constants\v3\SsdbKeys;
use App\Model\Model; use App\Model\Model;
use App\Service\v3\Interfaces\AttachmentServiceInterface; use App\Service\v3\Interfaces\AttachmentServiceInterface;
use App\Service\v3\Interfaces\GoodsInventoryServiceInterface;
use App\Service\v3\Interfaces\ShopCartServiceInterface; use App\Service\v3\Interfaces\ShopCartServiceInterface;
use App\TaskWorker\SSDBTask; use App\TaskWorker\SSDBTask;
use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\Builder;
@ -31,6 +32,12 @@ class GoodsActivity extends Model
*/ */
protected $attachmentService; protected $attachmentService;
/**
* @Inject
* @var GoodsInventoryServiceInterface
*/
protected $goodsInventoryService;
protected $table = 'lanzu_goods_activity'; protected $table = 'lanzu_goods_activity';
protected $casts = [ protected $casts = [
@ -87,9 +94,11 @@ class GoodsActivity extends Model
{ {
$msg = ''; $msg = '';
// 获取冻结的库存
$inventoryFrozen = $this->goodsInventoryService->getSold(2, $this->attributes['id']);
if ($this->attributes['expire_time'] < time()) { if ($this->attributes['expire_time'] < time()) {
$msg = '已结束'; $msg = '已结束';
} elseif ($this->attributes['inventory'] <= 0 && $this->attributes['is_infinite'] != 1) {
} elseif (($this->attributes['inventory'] <= $inventoryFrozen || $this->attributes['inventory'] <= 0) && $this->attributes['is_infinite'] != 1) {
$msg = '已抢光'; $msg = '已抢光';
} }
return $msg; return $msg;

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

@ -67,7 +67,7 @@ class GoodsActivityService implements GoodsActivityServiceInterface
} }
// 是否超过限购数量 // 是否超过限购数量
if ($goods->restrict_num != 0 && $goods->restrict_num < $num) {
if (($goods->restrict_num <= $inventoryFrozen || $goods->restrict_num <= 0) && $goods->restrict_num < $num) {
return ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT; return ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT;
} }

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

@ -8,6 +8,7 @@ use App\Constants\v3\Goods as GoodsConstants;
use App\Model\v3\Category; use App\Model\v3\Category;
use App\Model\v3\Goods; use App\Model\v3\Goods;
use App\Model\v3\GoodsCategory; use App\Model\v3\GoodsCategory;
use App\Model\v3\Market;
use App\Model\v3\Store; use App\Model\v3\Store;
use App\Service\v3\Interfaces\SearchServiceInterface; use App\Service\v3\Interfaces\SearchServiceInterface;
use Hyperf\Paginator\Paginator; use Hyperf\Paginator\Paginator;
@ -195,4 +196,24 @@ class SearchService implements SearchServiceInterface
{ {
// TODO: Implement undo() method. // TODO: Implement undo() method.
} }
public function getStoresForPersonnel($marketId, $ids,$keywords, $page = 1, $pagesize = 10)
{
$market = Market::query()->withoutGlobalScope('normal')->find($marketId);
$builder = Store::query()->where('market_id',$marketId);
if(!is_null($ids)){
$builder->whereNotIn('id',$ids);
}
if(!is_null($keywords)){
$builder->where('name','like','%'.$keywords.'%');
}
$paginate = $builder->orderBy('is_rest', 'asc')->paginate($pagesize);
$stores = $paginate->toArray();
$market->stores = $stores['data'];
$newIds = array_values(array_column($stores['data'], 'id'));
if(!is_null($ids)){
$newIds = array_merge($newIds,$ids);
}
return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $newIds];
}
} }

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

@ -58,14 +58,21 @@ class StoreService implements StoreServiceInterface
->first(); ->first();
} }
public function getList($marketId, $page=1, $pagesize=10)
public function getList($marketId,$ids = [], $page=1, $pagesize=10)
{ {
$market = Market::query()->withoutGlobalScope('normal')->find($marketId); $market = Market::query()->withoutGlobalScope('normal')->find($marketId);
$builder = Store::query();
$paginate = $builder->where('market_id',$marketId)->orderBy('is_rest', 'asc')->paginate($pagesize);
$builder = Store::query()->where('market_id',$marketId);
if(!is_null($ids)){
$builder->whereNotIn('id',$ids);
}
$paginate = $builder->orderBy('is_rest', 'asc')->paginate($pagesize);
$stores = $paginate->toArray(); $stores = $paginate->toArray();
$market->stores = $stores['data']; $market->stores = $stores['data'];
return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market];
$newIds = array_values(array_column($stores['data'], 'id'));
if(!is_null($ids)){
$newIds = array_merge($newIds,$ids);
}
return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $newIds];
} }
public function getListByMarketId($marketId, $page=1, $pagesize=10) public function getListByMarketId($marketId, $page=1, $pagesize=10)
@ -87,7 +94,12 @@ class StoreService implements StoreServiceInterface
$paginate = $builder->groupBy(''.$storeTable.'.id')->orderByDesc($storeTable.'.sales')->paginate($pagesize); $paginate = $builder->groupBy(''.$storeTable.'.id')->orderByDesc($storeTable.'.sales')->paginate($pagesize);
$stores = $paginate->map(function ($item, $key) { $stores = $paginate->map(function ($item, $key) {
$item->goods;
$item->goods = Goods::query()
->where('store_id',$item->id)
->where(function ($query){
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1);
})
->limit(5)->get();
return $item; return $item;
})->all(); })->all();

1
app/Service/v3/Interfaces/SearchServiceInterface.php

@ -10,4 +10,5 @@ interface SearchServiceInterface
public function do(); public function do();
public function check(); public function check();
public function undo(); public function undo();
public function getStoresForPersonnel($marketId, $ids,$keywords ,$page=1, $pagesize=10);
} }

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

@ -8,7 +8,7 @@ interface StoreServiceInterface
public function check($storeId); public function check($storeId);
public function undo(); public function undo();
public function detail($storeId); public function detail($storeId);
public function getList($marketId ,$page=1, $pagesize=10);
public function getList($marketId ,$ids = [],$page=1, $pagesize=10);
public function getListByMarketId($marketId ,$page=1, $pagesize=10); public function getListByMarketId($marketId ,$page=1, $pagesize=10);
public function updateIsRest($storeId); public function updateIsRest($storeId);
} }

1
config/routes.php

@ -176,6 +176,7 @@ Router::addGroup('/v3/', function () {
Router::post('horseman/getOrderInfo', 'App\Controller\v3\HorsemanController@getOrderInfo'); Router::post('horseman/getOrderInfo', 'App\Controller\v3\HorsemanController@getOrderInfo');
Router::post('horseman/orderComplete', 'App\Controller\v3\HorsemanController@orderComplete'); Router::post('horseman/orderComplete', 'App\Controller\v3\HorsemanController@orderComplete');
Router::post('goods/bannerDelete', 'App\Controller\v3\GoodsController@bannerDelete'); Router::post('goods/bannerDelete', 'App\Controller\v3\GoodsController@bannerDelete');
Router::post('search/storesForPersonnel', 'App\Controller\v3\SearchController@storesForPersonnel');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);
// 微信支付回调 // 微信支付回调

Loading…
Cancel
Save