Browse Source

用户token暂时存一个user_id而已

master
weigang 5 years ago
parent
commit
c11b5f86af
  1. 2
      app/Model/v3/ShoppingCart.php
  2. 66
      app/Service/v3/Implementations/CouponRecService.php
  3. 2
      app/Service/v3/Implementations/WxLoginService.php
  4. 1
      app/Service/v3/Interfaces/CouponRecServiceInterface.php

2
app/Model/v3/ShoppingCart.php

@ -3,11 +3,9 @@
namespace App\Model\v3; namespace App\Model\v3;
use App\Model\Model; use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class ShoppingCart extends Model class ShoppingCart extends Model
{ {
use SoftDeletes;
protected $table = 'lanzu_shopping_cart'; protected $table = 'lanzu_shopping_cart';

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

@ -164,13 +164,65 @@ class CouponRecService implements CouponRecServiceInterface
$carts = $this->shopCartService->allForUser($userId, $marketId); $carts = $this->shopCartService->allForUser($userId, $marketId);
$totalAmount = $carts['total']; $totalAmount = $carts['total'];
// 获取用户可用优惠券(1)
$coupons = CouponRec::query()
->join('lanzu_coupon as coupon', 'coupon.id', '=', '')
->where(['user_id' => $userId])
->where('number_remain', '>', 0)
->whereIn('status', [0,1])
->get();
// 获取购物车中商品和店铺的类别
$storeCategoryIds = [];
$goodsCategoryIds = [];
foreach ($carts as $key => &$cart) {
if (isset($cart['store']['category_id']) && $cart['store']['category_id']) {
array_push($storeCategoryIds, $cart['store']['category_id']);
}
if (isset($cart['shopping_cart']) && is_array($cart['shopping_cart'])) {
foreach ($cart['shopping_cart'] as $key2 => &$goods) {
if (isset($goods['goods']['category_id']) && $goods['goods']['category_id']) {
array_push($goodsCategoryIds, $goods['goods']['category_id']);
}
}
}
}
$categoryIds = array_merge($storeCategoryIds, $goodsCategoryIds);
$coupon = ApplicationContext::getContainer()->get(Coupon::class);
$couponRec = ApplicationContext::getContainer()->get(Coupon::class);
$couponTable = $coupon->getTable();
$receiveTable = $couponRec->getTable();
$currentTime = time();
// 获取用户已领取的优惠券,同时是在使用期内的优惠券
$builder = $couponRec->join($couponTable, "{$couponTable}.id", "=", "{$receiveTable}.coupon_id")
->where("{$receiveTable}.user_id", $userId)
->where("{$receiveTable}.number_remain", ">", 0)
->whereIn("{$receiveTable}.status", [0,1])
->where("{$couponTable}.usable_start_time", "<=", $currentTime)
->where("{$couponTable}.usable_end_time", ">=", $currentTime);
if (!empty($marketId)) { # 市场限制
$builder->where(function ($query) use ($marketId, $couponTable) {
return $query->whereJsonContains("{$couponTable}.market_ids", [(string)$marketId])
->orWhereJsonLength("{$couponTable}.market_ids", '=', 0);
});
}
if (!empty($categoryIds)) { # 分类限制
$builder->where(function ($query) use ($categoryIds, $couponTable) {
return $query->whereJsonContains("{$couponTable}.category_ids", $categoryIds)
->orWhereJsonLength("{$couponTable}.category_ids", '=', 0);
});
}
$couponReceives = $builder->orderByRaw("{$couponTable}.usable_end_time ASC")->get();
// 循环摘出失效不可用的优惠券
foreach ($couponReceives as $key => &$couponReceive) {
// 有活动商品不可用优惠券,全部都不可用了
// 不满订单金额
// 今日已使用
}
} }

2
app/Service/v3/Implementations/WxLoginService.php

@ -36,7 +36,7 @@ class WxLoginService implements \App\Service\v3\Interfaces\WxLoginServiceInterfa
// 登录成功 // 登录成功
$hash = ApplicationContext::getContainer()->get(Hashids::class); $hash = ApplicationContext::getContainer()->get(Hashids::class);
$hashIds = $hash->encode((int)$user['id'], time());
$hashIds = $hash->encode((int)$user['id']);
$user['user_token'] = $hashIds; $user['user_token'] = $hashIds;
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);

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

@ -9,4 +9,5 @@ interface CouponRecServiceInterface
public function undo(); public function undo();
public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId); public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId);
public function getListByUser($userId,$type,$page = 1,$pagesize = 5); public function getListByUser($userId,$type,$page = 1,$pagesize = 5);
public function allForOnlineOrderAvailable($userId, $marketId);
} }
Loading…
Cancel
Save