You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
3.7 KiB
132 lines
3.7 KiB
<?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 App\Constants\v3\ErrorCode;
|
|
use App\Exception\ErrorCodeException;
|
|
use App\Constants\v3\OrderState;
|
|
use App\Model\v3\OrderMain;
|
|
use App\Request\v3\UserRequest;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use App\Controller\BaseController;
|
|
use App\Service\v3\Interfaces\CouponRecServiceInterface;
|
|
use App\Request\v3\CouponReceiveRequest;
|
|
|
|
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(UserRequest $request)
|
|
{
|
|
$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已失效
|
|
*/
|
|
|
|
$res['coupon_list'] = $this->couponRecService->getListByUser($userId,$type,$page,$pagesize);
|
|
$res['statistics'] = $this->couponRecService->statistics($userId);
|
|
|
|
return $this->success($res);
|
|
}
|
|
|
|
public function getAvailableListByNewUser()
|
|
{
|
|
$userId = $this->request->input("user_id", 0);
|
|
$receiveType = $this->request->input("receive_type", 0);
|
|
$newUserCheck = OrderMain::query()
|
|
->where('user_id',$userId)
|
|
->whereIn('state',OrderState::CAN_DEL)
|
|
->whereIn('state',OrderState::REFUND)
|
|
->exists();
|
|
if($newUserCheck){
|
|
return $this->success(
|
|
[
|
|
'status' => 'error',
|
|
'message' => '不是新用户无法领券',
|
|
'text'=>'关注懒族菜市微信公众号,更多精彩活动一手掌握!'
|
|
]
|
|
);
|
|
}
|
|
$res = $this->couponRecService->getAvailableList($userId,$receiveType);
|
|
if(empty($res->not_receive)){
|
|
return $this->success(
|
|
[
|
|
'status' => 'error',
|
|
'message' => '优惠券已经被抢光了',
|
|
'text'=>'关注懒族菜市微信公众号,更多精彩活动一手掌握!'
|
|
]
|
|
);
|
|
}
|
|
return $this->success($res);
|
|
}
|
|
|
|
/**
|
|
* 用户领取优惠卷
|
|
*/
|
|
public function Receive(CouponReceiveRequest $request)
|
|
{
|
|
$userId = $this->request->input("user_id", 0);
|
|
$receiveType = $this->request->input("receive_type", 0);
|
|
$ids = $this->request->input("ids", '');
|
|
$res = $this->couponRecService->receive($userId,$receiveType,$ids);
|
|
if(!empty($res['success'])){
|
|
return $this->success([
|
|
'status' => 'ok',
|
|
'message' => '红包领取成功,请到“我的-红包”中查看']
|
|
);
|
|
}else{
|
|
throw new ErrorCodeException(ErrorCode::COUPON_RECEIVE_FAILURE);
|
|
}
|
|
}
|
|
}
|