和蕙健康小程序后端
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.

51 lines
1.5 KiB

9 months ago
<?php
namespace addons\shopro\controller\user;
9 months ago
use addons\shopro\traits\CouponSend;
use app\admin\model\shopro\user\User;
use think\Db;
9 months ago
use think\helper\Str;
use addons\shopro\controller\Common;
use app\admin\model\shopro\user\Coupon as UserCouponModel;
class Coupon extends Common
{
9 months ago
use CouponSend;
9 months ago
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
public function index()
{
$user = auth_user();
$type = $this->request->param('type', 'can_use'); // 优惠券类型:geted=已领取,can_use=可用,cannot_use=暂不可用,used=已使用,expired=已过期,invalid=已失效(包含已使用和已过期)
$userCoupons = UserCouponModel::with('coupon')->where('user_id', $user->id);
if (in_array($type, ['geted', 'can_use', 'cannot_use', 'used', 'expired', 'invalid'])) {
$userCoupons = $userCoupons->{Str::camel($type)}();
}
$userCoupons = $userCoupons->order('id', 'desc')->paginate($this->request->param('list_rows', 10));
$this->success('获取成功', $userCoupons);
}
9 months ago
/**
* 领取优惠券
*/
public function ling() {
$user = auth_user();
$user_id = $user->id;
$coupon_id = $this->request->param('coupon_id');
$users = User::whereIn('id', $user_id)->select();
Db::transaction(function () use ($users, $coupon_id) {
$this->manualSend($users, $coupon_id);
});
$this->success('领取成功');
}
9 months ago
}