14 changed files with 295 additions and 2 deletions
-
12app/Constants/v3/OrderState.php
-
9app/Controller/v3/HomeController.php
-
40app/Controller/v3/OrderListController.php
-
10app/Model/v3/Market.php
-
10app/Model/v3/Order.php
-
10app/Model/v3/OrderGoods.php
-
37app/Model/v3/OrderMain.php
-
39app/Request/v3/UserOrderListRequest.php
-
60app/Service/v3/Implementations/OrderListService.php
-
41app/Service/v3/Implementations/UserCenterBlockService.php
-
11app/Service/v3/Interfaces/OrderListServiceInterface.php
-
13app/Service/v3/Interfaces/UserCenterBlockServiceInterface.php
-
2config/autoload/dependencies.php
-
3config/routes.php
@ -0,0 +1,40 @@ |
|||
<?php |
|||
|
|||
namespace App\Controller\v3; |
|||
|
|||
use App\Controller\BaseController; |
|||
use App\Request\v3\UserOrderListRequest; |
|||
use App\Service\v3\Interfaces\OrderListServiceInterface; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
use Psr\Http\Message\ResponseInterface; |
|||
|
|||
/** |
|||
* 订单列表控制器,用户的,商户的 |
|||
* Class OrderListController |
|||
* @package App\Controller\v3 |
|||
*/ |
|||
class OrderListController extends BaseController |
|||
{ |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var OrderListServiceInterface |
|||
*/ |
|||
protected $orderListService; |
|||
|
|||
/** |
|||
* 用户订单列表(线上订单) |
|||
* 1、用户ID、订单类型tab、分页 |
|||
* 2、返回数据,市场相关id、名称、电话; |
|||
* 3、返回数据,订单商品,id、名称、封面图; |
|||
* 4、返回数据,订单相关,订单ID、订单号、下单时间、订单状态、订单总额; |
|||
* @param UserOrderListRequest $request |
|||
* @return ResponseInterface |
|||
*/ |
|||
public function onlineForUser(UserOrderListRequest $request) |
|||
{ |
|||
$params = $request->validated(); |
|||
$list = $this->orderListService->onlineByUser($params['user_id'], $params['tab'], $params['page'], $params['pagesize']); |
|||
return $this->success($list); |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
<?php |
|||
|
|||
namespace App\Model\v3; |
|||
|
|||
use App\Model\Model; |
|||
|
|||
class Market extends Model |
|||
{ |
|||
protected $table = 'lanzu_market'; |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
<?php |
|||
|
|||
namespace App\Model\v3; |
|||
|
|||
use App\Model\Model; |
|||
|
|||
class Order extends Model |
|||
{ |
|||
protected $table = 'lanzu_order'; |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
<?php |
|||
|
|||
namespace App\Model\v3; |
|||
|
|||
use App\Model\Model; |
|||
|
|||
class OrderGoods extends Model |
|||
{ |
|||
protected $table = 'lanzu_order_goods'; |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?php |
|||
|
|||
namespace App\Model\v3; |
|||
|
|||
use App\Model\Model; |
|||
|
|||
class OrderMain extends Model |
|||
{ |
|||
protected $table = 'lanzu_order_main'; |
|||
|
|||
protected $appends = [ |
|||
'created_at_text' |
|||
]; |
|||
|
|||
public function getCreatedAtTextAttribute() |
|||
{ |
|||
return date('Y-m-d H:i:s', $this->attributes['created_at']); |
|||
} |
|||
|
|||
public function market() |
|||
{ |
|||
return $this->belongsTo(Market::class, 'market_id', 'id'); |
|||
} |
|||
|
|||
public function orderGoods() |
|||
{ |
|||
// firstKey是中间表联当前表的列,secondKey是远程表对应中间表的列,localKey是当前表关联中间表的列,secondLocalKey是中间表关联远程表的列
|
|||
return $this->hasManyThrough( |
|||
OrderGoods::class, |
|||
Order::class, |
|||
'order_main_id', |
|||
'order_id', |
|||
'id', |
|||
'id' |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Request\v3; |
|||
|
|||
use App\Request\BaseFormRequest; |
|||
|
|||
class UserOrderListRequest extends BaseFormRequest |
|||
{ |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
*/ |
|||
public function rules(): array |
|||
{ |
|||
return [ |
|||
'user_id' => 'required|nonempty|integer', |
|||
'tab' => 'nonempty', |
|||
'page' => 'required|nonempty', |
|||
'pagesize' => 'required|nonempty', |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @return array |
|||
*/ |
|||
public function messages(): array |
|||
{ |
|||
return [ |
|||
'*.*' => ':attribute无效', |
|||
]; |
|||
} |
|||
|
|||
public function attributes(): array |
|||
{ |
|||
return parent::attributes(); |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Implementations; |
|||
|
|||
use App\Constants\v3\OrderState; |
|||
use App\Model\v3\OrderMain; |
|||
use App\Service\v3\Interfaces\OrderListServiceInterface; |
|||
use Hyperf\Paginator\Paginator; |
|||
|
|||
class OrderListService implements OrderListServiceInterface |
|||
{ |
|||
|
|||
public function do() |
|||
{ |
|||
// TODO: Implement do() method.
|
|||
} |
|||
|
|||
public function check() |
|||
{ |
|||
// TODO: Implement check() method.
|
|||
} |
|||
|
|||
public function undo() |
|||
{ |
|||
// TODO: Implement undo() method.
|
|||
} |
|||
|
|||
public function onlineByUser($userId, $tab, $page=1, $pagesize=10) |
|||
{ |
|||
$builder = OrderMain::query() |
|||
->select('id', 'global_order_id', 'money', 'state', 'market_id', 'created_at') |
|||
->with(['orderGoods' => function($query) { |
|||
$query->select(['lanzu_order_goods.id', 'lanzu_order_goods.name', 'lanzu_order_goods.cover_img']); |
|||
}]) |
|||
->with(['market' => function($query) { |
|||
$query->select(['lanzu_market.id', 'lanzu_market.name', 'lanzu_market.tel']); |
|||
}]) |
|||
->where(['user_id' => $userId]); |
|||
switch ($tab) { |
|||
case 'all': |
|||
break; |
|||
case 'completed': |
|||
$builder->whereIn('state', OrderState::FINISH); |
|||
break; |
|||
case 'unpaid': |
|||
$builder->where(['state' => OrderState::UNPAID]); |
|||
break; |
|||
case 'receiving': |
|||
$builder->whereIn('state', OrderState::RECEIVING); |
|||
break; |
|||
case 'refund': |
|||
$builder->whereIn('state', OrderState::REFUND); |
|||
break; |
|||
} |
|||
|
|||
$paginate = $builder->paginate($pagesize); |
|||
$orders = $paginate->toArray(); |
|||
return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']]; |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Implementations; |
|||
|
|||
use App\Service\v3\Interfaces\UserCenterBlockServiceInterface; |
|||
|
|||
class UserCenterBlockService implements UserCenterBlockServiceInterface |
|||
{ |
|||
|
|||
public function do() |
|||
{ |
|||
// TODO: Implement do() method.
|
|||
} |
|||
|
|||
public function check() |
|||
{ |
|||
// TODO: Implement check() method.
|
|||
} |
|||
|
|||
public function undo() |
|||
{ |
|||
// TODO: Implement undo() method.
|
|||
} |
|||
|
|||
public function all() |
|||
{ |
|||
return [ |
|||
[ |
|||
'type' => 'user', |
|||
'title' => '我的', |
|||
'items' => [ |
|||
['name' => '收货地址', 'icon' => '', 'type' => 'page', 'path' => ''], |
|||
['name' => '商家入口', 'icon' => '', 'type' => 'page', 'path' => ''], |
|||
['name' => '在线客服', 'icon' => '', 'type' => 'page', 'path' => ''], |
|||
['name' => '当面付订单查询', 'icon' => '', 'type' => 'page', 'path' => ''], |
|||
] |
|||
] |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Interfaces; |
|||
|
|||
interface OrderListServiceInterface |
|||
{ |
|||
public function do(); |
|||
public function check(); |
|||
public function undo(); |
|||
public function onlineByUser($userId, $tab, $page=1, $pagesize=10); |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Service\v3\Interfaces; |
|||
|
|||
|
|||
interface UserCenterBlockServiceInterface |
|||
{ |
|||
public function do(); |
|||
public function check(); |
|||
public function undo(); |
|||
public function all(); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue