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.
79 lines
2.4 KiB
79 lines
2.4 KiB
<?php
|
|
|
|
namespace App\Service\v3\Implementations;
|
|
|
|
use App\Model\ShopCar;
|
|
use App\Model\v3\Coupon;
|
|
use App\Model\v3\CouponRec;
|
|
use App\Service\v3\Interfaces\CouponRecServiceInterface;
|
|
use Hyperf\DbConnection\Db;
|
|
use Hyperf\Redis\Redis;
|
|
use Hyperf\Utils\ApplicationContext;
|
|
|
|
class CouponRecService implements CouponRecServiceInterface
|
|
{
|
|
|
|
public function do()
|
|
{
|
|
// TODO: Implement do() method.
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// TODO: Implement check() method.
|
|
}
|
|
|
|
public function undo()
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
|
|
/**
|
|
* 获取当前订单可使用的优惠券
|
|
* @param $totalAmount
|
|
* @param $userId
|
|
* @param $marketId
|
|
* @param $type
|
|
* @param $storeTypeIds
|
|
* @return array
|
|
*/
|
|
public function allForOrderOlAvailable($totalAmount, $userId, $marketId, $type, $storeTypeIds = [])
|
|
{
|
|
// 用户今日使用过的优惠券
|
|
$redis = ApplicationContext::getContainer()->get(Redis::class);
|
|
$couponTodayUsedIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId);
|
|
$currentTime = time();
|
|
|
|
$builder = Db::table('lanzu_coupon_receive as receive')
|
|
->join('lanzu_coupon as coupon', 'coupon.id', '=', 'receive.coupon_id', 'inner');
|
|
|
|
if (is_array($couponTodayUsedIds)&&!empty($couponTodayUsedIds)) {
|
|
$builder->whereNotIn('coupon.id', $couponTodayUsedIds);
|
|
}
|
|
|
|
foreach ($storeTypeIds as $key => &$item) {
|
|
$item = (string)$item;
|
|
}
|
|
|
|
if (!empty($storeTypeIds)) {
|
|
$builder->whereJsonContains('coupon.storetype_ids', $storeTypeIds);
|
|
}
|
|
|
|
$builder->where(['receive.user_id' => $userId])
|
|
->whereIn('receive.status', [0,1])
|
|
->where('receive.number_remain', '>', 0)
|
|
->whereIn('coupon.type', [1,$type])
|
|
->where('coupon.full_amount', '<=', $totalAmount)
|
|
->where('coupon.usable_start_time', '<=', $currentTime)
|
|
->where('coupon.usable_end_time', '>=', $currentTime)
|
|
->where('coupon.usable_number', '<=', Db::raw('receive.number_remain'));
|
|
|
|
if ($marketId) {
|
|
$builder->whereJsonContains('coupon.market_ids', [(string)$marketId]);
|
|
}
|
|
|
|
return $builder->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC')
|
|
->get()
|
|
->toArray();
|
|
}
|
|
}
|