diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 7846c01..2d46258 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -77,4 +77,17 @@ class GoodsController extends BaseController } return $this->success($res); } + + public function update() + { + $res = $this->goodsService->update($this->request->all()); + return $this->success($res); + } + + public function info() + { + $goodsId = $this->request->input('goods_id',0); + $res = $this->goodsService->info($goodsId); + return $this->success($res); + } } \ No newline at end of file diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 2e3cd91..2e47174 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -108,19 +108,26 @@ class OrderOnlineController extends BaseController } $deliveryDistance = config('distance.delivery_distance'); if(isset($distance) && $distance < $deliveryDistance){ + if($distance >= 1000){ + $distance_text = '距 ' . bcdiv($distance,1000,2) . 'km'; + }else{ + $distance_text = '距 ' . $distance . 'm'; + } $distributionPrice = $this->distributionPriceService->do($distance); $res['location'] = [ 'address' => $address, 'distribution_price' => $distributionPrice, 'distance' => $distance, - 'within' => true + 'within' => true, + 'distribution_text' => '¥ '.$distributionPrice .'(' .$distance_text .')' ]; }else{ $res['location'] = [ 'address' => '', 'distribution_price' => 3.5, - 'distance' => 0, - 'within' => false + 'distance' => $distance, + 'within' => false, + 'distribution_text' => '¥ 3.5' ]; } //返回预约送达时间 数组 @@ -197,14 +204,13 @@ class OrderOnlineController extends BaseController $data = $this->orderOnlineService->do( $params['market_id'], $params['user_id'], - ($params['user_address_id'] ?? 0), + $params['user_address_id'], json_decode($params['store_list']), $params['total_money'], $params['delivery_time_note'], ($params['service_money'] ?? 0), $couponIds, - $params['plat'] ?: '', - ($params['self_take'] ?? 0) + $params['plat'] ?: '' ); return $this->success(['data' => $data]); diff --git a/app/Controller/v3/StoreController.php b/app/Controller/v3/StoreController.php index 2afc46e..5fe8e05 100644 --- a/app/Controller/v3/StoreController.php +++ b/app/Controller/v3/StoreController.php @@ -3,9 +3,11 @@ namespace App\Controller\v3; use App\Controller\BaseController; +use App\Model\v3\ServicePersonnel; use App\Request\v3\StoreIndexRequest; use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CollectStoreServiceInterface; +use App\Service\v3\Interfaces\GoodsServiceInterface; use App\Service\v3\Interfaces\StoreServiceInterface; use Hyperf\Di\Annotation\Inject; use Psr\Http\Message\ResponseInterface; @@ -38,6 +40,12 @@ class StoreController extends BaseController */ protected $businessHoursService; + /** + * @Inject + * @var GoodsServiceInterface + */ + protected $goodsService; + /** * 商户详情页 * 1、商户id用来查询的,还要有user_id @@ -82,4 +90,32 @@ class StoreController extends BaseController $res = $this->businessHoursService->do($storeId,$isRest,$time1,$time2,$time3,$time4); return $this->success($res); } + + public function getGoodsByType() + { + $storeId = $this->request->input('store_id'); + $typeId = $this->request->input('type_id',''); + $goods = $this->goodsService->getByType($storeId,$typeId); + return $this->success($goods); + } + + public function getList() + { + $userId = $this->request->input('user_id'); + $page = $this->request->input('page',1); + $pagesize = $this->request->input('pagesize',10); + $personnel = ServicePersonnel::query()->where('user_id',$userId)->first(); + if(empty($personnel)){ + return $this->success(['personnel' => false]); + } + $res = $this->storeService->getList($personnel->market_id,$page,$pagesize); + return $this->success($res); + } + + public function getCategory() + { + $storeId = $this->request->input('store_id'); + $res = $data['goods_types'] = $this->categoryService->allForStoreIncludeOff($storeId); + return $this->success(['goods_types' => $res]); + } } \ No newline at end of file diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index ff1eaba..6ed70f0 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -63,6 +63,7 @@ class Goods extends Model 'is_effective', 'noneffective_note', 'details_imgs_url', + 'goods_name' ]; protected function boot(): void @@ -125,6 +126,11 @@ class Goods extends Model }); } + public function getGoodsNameAttribute() + { + return $this->attributes['name']; + } + public function getNameAttribute($value) { return $value . ' ' . $this->attributes['goods_unit']; diff --git a/app/Service/v3/Implementations/CategoryService.php b/app/Service/v3/Implementations/CategoryService.php index 63fa60e..268c04a 100644 --- a/app/Service/v3/Implementations/CategoryService.php +++ b/app/Service/v3/Implementations/CategoryService.php @@ -95,4 +95,29 @@ class CategoryService implements CategoryServiceInterface return array_values($returnData); } + + public function allForStoreIncludeOff($storeId) + { + $goodsTypeIds = Goods::query() + ->withoutGlobalScope('normal') + ->where(['store_id' => $storeId]) + ->groupBy('category_id', 'id') + ->pluck('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; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 6740d92..56512fb 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -70,4 +70,29 @@ class GoodsService implements GoodsServiceInterface $res = Goods::query()->with('store')->where('id',$goodsId)->first(); return $res; } + + public function getByType($storeId,$typeId) + { + return Goods::query()->withoutGlobalScope('normal')->where(['store_id' => $storeId,'category_id' => $typeId])->orderByDesc('on_sale')->orderByDesc('created_at')->get()->toArray(); + } + + public function update($params) + { + $goods = Goods::query()->withoutGlobalScope('normal')->find($params['id']); + if (empty($goods)) { + throw new ErrorCodeException( ErrorCode::GOODS_NOT_EXISTS); + } + foreach ($params as $k => $v){ + if(isset($goods->$k)){ + $goods->$k = $v; + } + } + return $goods->save(); + } + + public function info($goodsId) + { + $res = Goods::query()->withoutGlobalScope('normal')->where('id',$goodsId)->first(); + return $res; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index 8389ae4..5f78d80 100644 --- a/app/Service/v3/Implementations/StoreService.php +++ b/app/Service/v3/Implementations/StoreService.php @@ -3,6 +3,7 @@ namespace App\Service\v3\Implementations; +use App\Model\v3\Market; use App\Model\v3\Store; use App\Service\v3\Interfaces\StoreServiceInterface; @@ -52,4 +53,14 @@ class StoreService implements StoreServiceInterface ->where('id',$storeId) ->first(); } + + public function getList($marketId, $page=1, $pagesize=10) + { + $market = Market::query()->find($marketId); + $builder = Store::query(); + $paginate = $builder->where('market_id',$marketId)->paginate($pagesize); + $stores = $paginate->toArray(); + $market->stores = $stores['data']; + return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market]; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index 646d95f..3a158df 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -98,9 +98,15 @@ class UserAddressService implements UserAddressServiceInterface $distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address['address']->lng,$address['address']->lat); $distributionPrice = $this->distributionPriceService->do($distance); + if($distance >= 1000){ + $distance_text = '距 ' . bcdiv($distance,1000,2) . 'km'; + }else{ + $distance_text = '距 ' . $distance . 'm'; + } $res['address'] = $address; $res['delivery_distance'] = $distance; $res['distribution_price'] = $distributionPrice; + $res['distribution_text'] = '¥ '.$distributionPrice .'(' .$distance_text .')'; return $res; } diff --git a/app/Service/v3/Implementations/UserCenterBlockService.php b/app/Service/v3/Implementations/UserCenterBlockService.php index 2572c42..14777b9 100644 --- a/app/Service/v3/Implementations/UserCenterBlockService.php +++ b/app/Service/v3/Implementations/UserCenterBlockService.php @@ -55,13 +55,13 @@ class UserCenterBlockService implements UserCenterBlockServiceInterface # code... // if($item['key'] == 'store'){ - // $blocks[] = [ - // 'type' => 'store_user', - // 'title' => '商户相关', - // 'items' => [ - // ['name' => '商家入口', 'icon' => $img_host . 'user_icons/shop_enter.png', 'type' => 'page', 'path' => '/pages/shopLogin/shopLogin','command'=>'store_login'] - // ] + // $goodsEditor = [ + // 'name' => '商品管理', 'icon' => $img_host . 'user_icons/service2.png', + // 'type' => 'webview', + // 'path' => 'http://localhost:8080/#/pages/goodsManagement/goodsManagement?market_id='.$item['data']['market_id'].'&user_id='.$item['data']['user_id'].'&store_id='.$item['data']['id'], + // 'command'=>'sp_login' // ]; + // array_push($blocks[1]['items'],$goodsEditor); // } if($item['key'] == 'sp'){ @@ -69,7 +69,13 @@ class UserCenterBlockService implements UserCenterBlockServiceInterface 'type' => 'sp_user', 'title' => '服务专员', 'items' => [ - ['name' => '评价', 'icon' => $img_host . 'user_icons/service2.png', 'type' => 'page', 'path' => '/zh_cjdianc/pages/appraise/index?service_personnel_id='.$item['data']['id'],'command'=>'sp_login'] + ['name' => '评价', 'icon' => $img_host . 'user_icons/service2.png', 'type' => 'page', 'path' => '/zh_cjdianc/pages/appraise/index?service_personnel_id='.$item['data']['id'],'command'=>'sp_login'], + [ + 'name' => '商品管理', 'icon' => $img_host . 'user_icons/service2.png', + 'type' => 'page', + 'path' => '/pages/shopList/shopList?personal_id='.$item['data']['id'], + 'command'=>'sp_login' + ] ] ]; } diff --git a/app/Service/v3/Implementations/UserInfoService.php b/app/Service/v3/Implementations/UserInfoService.php index c663af9..168590a 100644 --- a/app/Service/v3/Implementations/UserInfoService.php +++ b/app/Service/v3/Implementations/UserInfoService.php @@ -79,13 +79,13 @@ class UserInfoService implements UserInfoServiceInterface public function getStoreByUID($userId) { - $store = Store::where('user_id',$userId)->select(['id','name'])->first(); + $store = Store::where('user_id',$userId)->select(['id','name','user_id','market_id'])->first(); return $store; } public function getServicePersonnelByUID($userId) { - $sp = ServicePersonnel::where('user_id',$userId)->select(['id'])->first(); + $sp = ServicePersonnel::where('user_id',$userId)->select('id','user_id')->first(); return $sp; } diff --git a/app/Service/v3/Interfaces/CategoryServiceInterface.php b/app/Service/v3/Interfaces/CategoryServiceInterface.php index fdac37b..d79acab 100644 --- a/app/Service/v3/Interfaces/CategoryServiceInterface.php +++ b/app/Service/v3/Interfaces/CategoryServiceInterface.php @@ -11,5 +11,5 @@ interface CategoryServiceInterface public function all(); public function allForStore($storeId); public function allForAppletIndex(); - + public function allForStoreIncludeOff($storeId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsServiceInterface.php b/app/Service/v3/Interfaces/GoodsServiceInterface.php index 53c4b43..0ea31b3 100644 --- a/app/Service/v3/Interfaces/GoodsServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsServiceInterface.php @@ -9,5 +9,9 @@ interface GoodsServiceInterface public function do($goodsId); public function check(Goods $goods,$num = 1); public function undo(); + public function detail($goodsId); public function getBanner($goodsId); + public function getByType($storeId,$typeId); + public function update($params); + public function info($goodsId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/StoreServiceInterface.php b/app/Service/v3/Interfaces/StoreServiceInterface.php index 376575e..7d355e9 100644 --- a/app/Service/v3/Interfaces/StoreServiceInterface.php +++ b/app/Service/v3/Interfaces/StoreServiceInterface.php @@ -8,4 +8,5 @@ interface StoreServiceInterface public function check($storeId); public function undo(); public function detail($storeId); + public function getList($marketId ,$page=1, $pagesize=10); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 11eefa3..f13e1bc 100644 --- a/config/routes.php +++ b/config/routes.php @@ -152,6 +152,11 @@ Router::addGroup('/v3/', function () { Router::post('device/list', 'App\Controller\v3\DeviceController@list'); Router::post('device/unbind', 'App\Controller\v3\DeviceController@unbind'); Router::post('orderOffline/completePage', 'App\Controller\v3\OrderOfflineController@completePage'); + Router::post('store/getGoodsByType', 'App\Controller\v3\StoreController@getGoodsByType'); + Router::post('goods/update', 'App\Controller\v3\GoodsController@update'); + Router::post('store/getList', 'App\Controller\v3\StoreController@getList'); + Router::post('goods/info', 'App\Controller\v3\GoodsController@info'); + Router::post('store/getCategory', 'App\Controller\v3\StoreController@getCategory'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); // 微信支付回调