徐总多门店
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.
 
 
 
 
 
 

115 lines
3.8 KiB

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\api\v1\activity;
use app\Request;
use app\services\activity\coupon\StoreCouponIssueServices;
use app\services\activity\coupon\StoreCouponUserServices;
/**
* 优惠券类
* Class StoreCoupons
* @package app\controller\api\store
*/
class StoreCoupons
{
protected $services;
public function __construct(StoreCouponIssueServices $services)
{
$this->services = $services;
}
/**
* 可领取优惠券列表
* @param Request $request
* @return mixed
*/
public function lst(Request $request)
{
$where = $request->getMore([
[['type', 'd'], ''],
[['product_id', 'd'], 0],
[['brand_id', 'd'], 0],
]);
// if ($request->getFromType() == 'pc') $where['type'] = -1;
return app('json')->successful($this->services->getIssueCouponList($request->uid(), $where)['list']);
}
/**
* 领取优惠券
*
* @param Request $request
* @return mixed
*/
public function receive(Request $request)
{
[$couponId] = $request->getMore([
['couponId', 0]
], true);
if (!$couponId || !is_numeric($couponId)) return app('json')->fail('参数错误!');
/** @var StoreCouponIssueServices $couponIssueService */
$couponIssueService = app()->make(StoreCouponIssueServices::class);
$coupon = $couponIssueService->issueUserCoupon((int)$couponId, $request->user(), false);
if ($coupon) {
$coupon = $coupon->toArray();
return app('json')->success('领取成功', $coupon);
}
return app('json')->fail('领取失败');
}
/**
* 我的优惠券数量
* @param Request $request
* @param StoreCouponUserServices $storeCouponUserService
* @return \think\Response
* @throws \think\db\exception\DbException
*/
public function userCount(Request $request, StoreCouponUserServices $storeCouponUserService)
{
$uid = (int)$request->uid();
return app('json')->successful($storeCouponUserService->getUserCounponNum($uid));
}
/**
* 用户已领取优惠券
* @param Request $request
* @param $types
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function user(Request $request, StoreCouponUserServices $storeCouponUserService, $types)
{
$uid = (int)$request->uid();
[$type] = $request->getMore([
['type', 0],
], true);
return app('json')->successful($storeCouponUserService->getUserCounpon($uid, $types, $type));
}
/**
* 优惠券 订单获取
* @param Request $request
* @param $price
* @return mixed
*/
public function order(Request $request, StoreCouponIssueServices $service, $cartId, $new)
{
[$shipping_type, $storeId] = $request->getMore([
['shipping_type', 1],
['store_id', 0],
], true);
return app('json')->successful($service->beUsableCouponList((int)$request->uid(), $cartId, !!$new, (int)$shipping_type, (int)$storeId));
}
}