Browse Source

Merge branch 'phoenix' of ssh://120.24.33.109:11022/hyzjshwo/lanzu_api_hyperf into phoenix

master
weigang 5 years ago
parent
commit
2ec0ee83d8
  1. 17
      app/Controller/v3/BalanceStatementController.php
  2. 38
      app/Controller/v3/CategoryController.php
  3. 7
      app/Controller/v3/CollectStoreController.php
  4. 85
      app/Controller/v3/CouponController.php
  5. 2
      app/Controller/v3/OrderListController.php
  6. 9
      app/Controller/v3/ShopCartController.php
  7. 2
      app/Controller/v3/UserAddressController.php
  8. 18
      app/Model/v3/Coupon.php
  9. 9
      app/Model/v3/CouponRec.php
  10. 83
      app/Service/v3/Implementations/CouponRecService.php
  11. 29
      app/Service/v3/Implementations/OrderListService.php
  12. 10
      app/Service/v3/Implementations/RevenueListService.php
  13. 11
      app/Service/v3/Implementations/WithdrawalListService.php
  14. 3
      app/Service/v3/Interfaces/CouponRecServiceInterface.php
  15. 2
      app/Service/v3/Interfaces/OrderListServiceInterface.php
  16. 2
      app/Service/v3/Interfaces/RevenueListServiceInterface.php
  17. 2
      app/Service/v3/Interfaces/WithdrawalListServiceInterface.php
  18. 2
      config/routes.php

17
app/Controller/v3/BalanceStatementController.php

@ -22,13 +22,22 @@ class BalanceStatementController extends BaseController
protected $withdrawalListService;
public function getRevenueListByUser()
{
$params = $this->request->all();
return $this->success($this->revenueListService->getListByUser(46));
$userId = $this->request->input('user_id',0);
$page = $this->request->input('page',0);
$pagesize = $this->request->input('pagesize',0);
$startTime = $this->request->input('start_time','');
$endTime = $this->request->input('end_time','');
return $this->success($this->revenueListService->getListByUser($userId, $page, $pagesize ,$startTime,$endTime));
}
public function getWithdrawalListByStore()
{
$params = $this->request->all();
return $this->success($this->withdrawalListService->getListByStore(7));
$storeId = $this->request->input('store_id',0);
$page = $this->request->input('page',0);
$pagesize = $this->request->input('pagesize',0);
$startTime = $this->request->input('start_time','');
$endTime = $this->request->input('end_time','');
$res = $this->withdrawalListService->getListByStore($storeId,$page,$pagesize,$startTime,$endTime);
return $this->success($res);
}
}

38
app/Controller/v3/CategoryController.php

@ -4,6 +4,8 @@ namespace App\Controller\v3;
use App\Controller\BaseController;
use App\Service\v3\Interfaces\CategoryServiceInterface;
use App\Service\v3\Interfaces\BannerServiceInterface;
use App\Constants\v3\Banner;
use Hyperf\Di\Annotation\Inject;
class CategoryController extends BaseController
@ -14,6 +16,12 @@ class CategoryController extends BaseController
*/
protected $categoryService;
/**
* @Inject
* @var BannerServiceInterface
*/
protected $bannerService;
/**
* 获取分类页所有分类
* 1、无参数
@ -22,6 +30,34 @@ class CategoryController extends BaseController
*/
public function all()
{
return $this->success(['category' => $this->categoryService->all()]);
$category = $this->categoryService->all();
//mock datas
$gmarket_id = $this->request->input('gmarket_id', 0);
if($gmarket_id == -1 ) $gmarket_id = 0;
$banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $gmarket_id);
foreach ($category as $key => &$item) {
$hot_types = [];
if(count($item['goods_types']) > 2){
$hot_types = array_slice($item['goods_types'],0,2);
}
$hot_titles = ['当季热销','为你推荐','热卖品类'];
$rand_index = rand(0,2);
$type_banners = [];
if(count($banners)>0){
$r = rand(0,count($banners)-1);
$type_banners = [$banners[$r]];
}
$item['hot_category'] = ['title'=>$hot_titles[$rand_index],'goods_types'=>$hot_types];
$item['banners']=$type_banners;
}
return $this->success(['category' => $category]);
}
}

7
app/Controller/v3/CollectStoreController.php

@ -22,11 +22,12 @@ class CollectStoreController extends BaseController
$exists = $this->collectStoreService->check($params['user_id'],$params['store_id']);
//如果已收藏则删除
if($exists){
$res = $this->collectStoreService->undo($params['user_id'],$params['store_id']);
$this->collectStoreService->undo($params['user_id'],$params['store_id']);
}else{
$res = $this->collectStoreService->do($params['user_id'],$params['store_id']);
$this->collectStoreService->do($params['user_id'],$params['store_id']);
}
return $this->success($res);
$res = (bool) $this->collectStoreService->check($params['user_id'],$params['store_id']);
return $this->success(['is_collect' => $res]);
}
public function getListByUser()

85
app/Controller/v3/CouponController.php

@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Controller\v3;
use Hyperf\Di\Annotation\Inject;
use App\Controller\BaseController;
use App\Service\v3\Interfaces\CouponRecServiceInterface;
class CouponController extends BaseController
{
/**
* @Inject
* @var CouponRecServiceInterface
*/
protected $couponRecService;
/**
* 获取用户可领取优惠卷接口
*/
public function getSystemCouponUserList()
{
}
//统计用户
public function userCouponAccount()
{
}
/**
* 用户领取优惠卷
*/
public function userReceiveCoupon()
{
}
/**
* 获取用户已经领取的优惠卷列表
*/
public function getUserReceiveCouponList()
{
}
/**
* 获取用户当前订单可用的优惠券列表
* 按分类(1订单 等优惠)分组返回
*/
public function getListByUser()
{
$userId = $this->request->input('user_id');
$page = $this->request->input('page');
$pagesize = $this->request->input('pagesize');
$type = $this->request->input('type','1');
/**
* $type unused 未使用 used 已使用 expired已失效
*/
switch ($type){
case 'unused':
$res = $this->couponRecService->getUnusedListByUser($userId,$page,$pagesize);
break;
case 'used':
$res = $this->couponRecService->getUsedListByUser($userId,$page,$pagesize);
break;
case 'expired':
$res = $this->couponRecService->getExpiredListByUser($userId,$page,$pagesize);
break;
}
return $this->success($res);
}
}

2
app/Controller/v3/OrderListController.php

@ -48,7 +48,7 @@ class OrderListController extends BaseController
public function offlineForStore()
{
$params = $this->request->all();
$list = $this->orderListService->offlineByStore($params['store_id'], $params['tab'], $params['page'], $params['pagesize']);
$list = $this->orderListService->offlineByStore($params['store_id'], $params['tab'], $params['page'], $params['pagesize'],$params['start_time'],$params['end_time']);
return $this->success($list);
}
}

9
app/Controller/v3/ShopCartController.php

@ -20,7 +20,14 @@ class ShopCartController extends BaseController
//获取购物车失效商品信息
$res['store_lists_invalid'] = $this->shopCartService->undo();
//计算购物车价格
$res['total'] = '820.00';
$res['total'] = $this->shopCartService->getTotal();
return $this->success($res);
}
public function info()
{
$res['shopcart']['count'] = $this->shopCartService->countGoods();
$res['shopcart']['total'] = $this->shopCartService->getTotal();
return $this->success($res);
}
}

2
app/Controller/v3/UserAddressController.php

@ -32,7 +32,7 @@ class UserAddressController extends BaseController
public function get()
{
$userAddressId = $this->request->input('$user_address_id');
$userAddressId = $this->request->input('user_address_id');
$res = $this->userAddressService->get($userAddressId);
return $this->success($res);
}

18
app/Model/v3/Coupon.php

@ -11,4 +11,22 @@ class Coupon extends Model
protected $table = 'lanzu_coupon';
protected $appends = [
'full_amount_text',
'discounts_text'
];
public function getFullAmountTextAttribute()
{
return '满'.$this->attributes['full_amount'].'可用';
}
public function getDiscountsTextAttribute()
{
if($this->attributes['discount_type'] == 1){
return '¥'.$this->attributes['discounts'];
}elseif($this->attributes['discount_type'] == 2){
return floatval($this->attributes['discounts'])."";
}
}
}

9
app/Model/v3/CouponRec.php

@ -9,6 +9,15 @@ class CouponRec extends Model
protected $table = 'lanzu_coupon_receive';
protected $appends = [
'used_num'
];
public function getUsedNumAttribute()
{
return ($this->attributes['number'] - $this->attributes['number_remain']);
}
public function coupon()
{
return $this->hasOne(Coupon::class,'id','coupon_id');

83
app/Service/v3/Implementations/CouponRecService.php

@ -76,4 +76,87 @@ class CouponRecService implements CouponRecServiceInterface
->get()
->toArray();
}
/**
* 用户未使用优惠券列表
*/
public function getUnusedListByUser($userId,$page = 1,$pagesize = 5)
{
//查询可用优惠券
$builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id')
->where([
['lanzu_coupon_receive.user_id' ,'=', $userId],
['lanzu_coupon.usable_end_time' ,'>', time()],
['lanzu_coupon_receive.number_remain' ,'>', 0]
]);
$builder = $builder->whereIn('lanzu_coupon_receive.status',[0,1])
->select(
'lanzu_coupon.title',
'lanzu_coupon.discounts',
'lanzu_coupon.full_amount',
'lanzu_coupon.discount_type',
'lanzu_coupon.introduce',
'lanzu_coupon.usable_end_time',
'lanzu_coupon_receive.number',
'lanzu_coupon_receive.number_remain'
)
->orderBy('lanzu_coupon.weigh','desc');
$paginate = $builder->paginate($pagesize);
$couponList = $paginate->toArray();
foreach ($couponList['data'] as $key => &$coupon) {
//拼接满减文字提示
$coupon['full_amount_text'] = '满' . $coupon['full_amount'] . "可用";
//判断是折扣优惠券还是满减优惠券
if($coupon['discount_type'] == 1){
$coupon['discounts_text'] = '¥'.$coupon['discounts'];
}elseif($coupon['discount_type'] == 2){
$coupon['discounts_text'] = floatval($coupon['discounts'])."";
}
}
return ['has_more_pages' => $paginate->hasMorePages(), 'coupon_list' => $couponList['data']];
}
/**
* 用户已使用
*/
public function getUsedListByUser($userId,$page = 1,$pagesize = 5)
{
//查询可用优惠券
$builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id')
->where('lanzu_coupon_receive.user_id' ,$userId)
->whereIn('lanzu_coupon_receive.status',[1,2])
->select(
'lanzu_coupon.title',
'lanzu_coupon.discounts',
'lanzu_coupon.full_amount',
'lanzu_coupon.discount_type',
'lanzu_coupon.introduce',
'lanzu_coupon.usable_end_time',
'lanzu_coupon_receive.number',
'lanzu_coupon_receive.number_remain'
)
->orderBy('lanzu_coupon_receive.updated_at','desc');
$paginate = $builder->paginate($pagesize);
$couponList = $paginate->toArray();
foreach ($couponList['data'] as $key => &$coupon) {
//拼接满减文字提示
$coupon['full_amount_text'] = '满' . $coupon['full_amount'] . "可用";
//判断是折扣优惠券还是满减优惠券
if($coupon['discount_type'] == 1){
$coupon['discounts_text'] = '¥'.$coupon['discounts'];
}elseif($coupon['discount_type'] == 2){
$coupon['discounts_text'] = floatval($coupon['discounts'])."";
}
}
return ['has_more_pages' => $paginate->hasMorePages(), 'coupon_list' => $couponList['data']];
}
/**
* 用户已失效
*/
public function getExpiredListByUser($userId,$page = 1,$pagesize = 5)
{
}
}

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

@ -82,16 +82,16 @@ class OrderListService implements OrderListServiceInterface
case 'all':
break;
case 'completed':
$builder->whereIn('state', OrderState::FINISH);
$builder->whereIn('lanzu_order_main.state', OrderState::FINISH);
break;
case 'unpaid':
$builder->where(['state' => OrderState::UNPAID]);
$builder->where(['lanzu_order_main.state' => OrderState::UNPAID]);
break;
case 'receiving':
$builder->whereIn('state', OrderState::RECEIVING);
$builder->whereIn('lanzu_order_main.state', OrderState::RECEIVING);
break;
case 'refund':
$builder->whereIn('state', OrderState::REFUND);
$builder->whereIn('lanzu_order_main.state', OrderState::REFUND);
break;
}
@ -111,37 +111,34 @@ class OrderListService implements OrderListServiceInterface
return $res;
}
public function offlineByStore($storeId, $tab, $page=1, $pagesize=10)
public function offlineByStore($storeId, $tab, $page=1, $pagesize=10 ,$start_time = '',$end_time = '')
{
$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;
case 'completed':
$builder->whereIn('state', OrderState::FINISH);
$builder->whereIn('lanzu_order_main.state', OrderState::FINISH);
break;
case 'unpaid':
$builder->where(['state' => OrderState::UNPAID]);
$builder->where(['lanzu_order_main.state' => OrderState::UNPAID]);
break;
case 'receiving':
$builder->whereIn('state', OrderState::RECEIVING);
$builder->whereIn('lanzu_order_main.state', OrderState::RECEIVING);
break;
case 'refund':
$builder->whereIn('state', OrderState::REFUND);
$builder->whereIn('lanzu_order_main.state', OrderState::REFUND);
break;
}
if(!empty($start_time) && !empty($end_time)){
$builder->whereBetween('lanzu_order_main.created_at',[strtotime($start_time.' 23:59:59'),strtotime($end_time.' 23:59:59')]);
}
$paginate = $builder->paginate($pagesize);
$orders = $paginate->toArray();
return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']];

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

@ -23,11 +23,17 @@ class RevenueListService implements RevenueListServiceInterface
// TODO: Implement undo() method.
}
public function getListByUser($userId)
public function getListByUser($userId, $page=1, $pagesize=10 ,$startTime = '',$endTime = '')
{
$financialRecord = new FinancialRecord();
$mod = bcmod((string)$userId, '5', 0);
$financialRecord->suffix($mod);
return $financialRecord::query()->get();
$builder = $financialRecord->where('user_id',$userId);
if(!empty($startTime) && !empty($endTime)){
$builder->whereBetween('created_at',[strtotime($startTime.' 23:59:59'),strtotime($endTime.' 23:59:59')]);
}
$paginate = $builder->paginate($pagesize);
$revenues = $paginate->toArray();
return ['has_more_pages' => $paginate->hasMorePages(), 'revenue_list' => $revenues['data']];
}
}

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

@ -21,9 +21,14 @@ class WithdrawalListService implements WithdrawalListServiceInterface
// TODO: Implement undo() method.
}
public function getListByStore($storeId)
public function getListByStore($storeId, $page=1, $pagesize=10 ,$startTime = '',$endTime = '')
{
$res = StoreWithdrawal::query()->where('store_id',$storeId)->get();
return $res;
$builder = StoreWithdrawal::query()->where('store_id',$storeId);
if(!empty($startTime) && !empty($endTime)){
$builder->whereBetween('created_at',[strtotime($startTime.' 23:59:59'),strtotime($endTime.' 23:59:59')]);
}
$paginate = $builder->paginate($pagesize);
$orders = $paginate->toArray();
return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']];
}
}

3
app/Service/v3/Interfaces/CouponRecServiceInterface.php

@ -8,4 +8,7 @@ interface CouponRecServiceInterface
public function check();
public function undo();
public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId);
public function getUnusedListByUser($userId,$page = 1,$pagesize = 5);
public function getUsedListByUser($userId,$page = 1,$pagesize = 5);
public function getExpiredListByUser($userId,$page = 1,$pagesize = 5);
}

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

@ -9,5 +9,5 @@ interface OrderListServiceInterface
public function undo();
public function onlineByUser($userId, $tab, $page=1, $pagesize=10);
public function onlineByStore($userId, $tab, $page, $pagesize);
public function offlineByStore($userId, $tab, $page, $pagesize);
public function offlineByStore($userId, $tab, $page, $pagesize,$start_time = '',$end_time = '');
}

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

@ -12,5 +12,5 @@ interface RevenueListServiceInterface
public function undo();
public function getListByUser($userId);
public function getListByUser($userId, $page=1, $pagesize=10 ,$startTime = '',$endTime = '');
}

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

@ -9,5 +9,5 @@ interface WithdrawalListServiceInterface
public function do();
public function check();
public function undo();
public function getListByStore($storeId);
public function getListByStore($storeId, $page=1, $pagesize=10 ,$startTime = '',$endTime = '');
}

2
config/routes.php

@ -128,4 +128,6 @@ Router::addGroup('/v3/', function () {
Router::post('userAddress/setDefault', 'App\Controller\v3\UserAddressController@setDefault');
Router::post('userAddress/get', 'App\Controller\v3\UserAddressController@get');
Router::post('userAddress/delete', 'App\Controller\v3\UserAddressController@delete');
Router::post('coupon/getListByUser', 'App\Controller\v3\CouponController@getListByUser');
Router::post('shopCart/info', 'App\Controller\v3\ShopCartController@info');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);
Loading…
Cancel
Save