Browse Source

下单成功 添加特价商品购买记录

master
Lemon 6 years ago
parent
commit
aeb45f7d21
  1. 6
      app/Controller/PurchaseLimitController.php
  2. 18
      app/Service/CouponService.php
  3. 2
      app/Service/CouponServiceInterface.php
  4. 15
      app/Service/OrderService.php
  5. 16
      app/Service/PurchaseLimitService.php
  6. 2
      app/Service/PurchaseLimitServiceInterface.php
  7. 2
      app/Service/ShopCarService.php
  8. 2
      config/routes.php

6
app/Controller/PurchaseLimitController.php

@ -22,6 +22,12 @@ class PurchaseLimitController extends BaseController
return $this->success($res);
}
public function ssdbPurchaseRecord()
{
$res = $this->purchaseLimitService->ssdbPurchaseRecord($this->request->all(),214);
return $this->success($res);
}
public function test()
{
$res = $this->purchaseLimitService->test($this->request->all());

18
app/Service/CouponService.php

@ -226,13 +226,18 @@ class CouponService implements CouponServiceInterface
* @param $order_id
* @return bool
*/
public function refundOrderCoupons($order_id,$user_id){
public function refundOrderCoupons($order_id){
$coupon = CouponUserUse::where([
['order_main_id','=',$order_id],
['status','=',CouponUserUse::COUPON_USE_STATE_USED],
])
['order_main_id','=',$order_id],
['status','=',CouponUserUse::COUPON_USE_STATE_USED],
])
->select('id','user_receive_id','number')
->first();
if (empty($coupon)) {
return '';
}
// 返回用户优惠券数量并更新状态
$res = Db::update("UPDATE ims_system_coupon_user_receive SET number_remain=number_remain+{$coupon->number}, status=IF(number=number_remain,0,1), update_time=".time().""
." WHERE id={$coupon->user_receive_id} AND number>=(number_remain+{$coupon->number})");
@ -249,9 +254,12 @@ class CouponService implements CouponServiceInterface
]);
//删除当日 redis 使用记录缓存
$order_main = OrderMain::where('id',$order_id)
->select('global_order_id','user_id')
->first();
$redis = ApplicationContext::getContainer()->get(Redis::class);
$remRes = $redis->sRem(
'coupon_'.date('Ymd').'_used_'.$user_id,
'coupon_'.date('Ymd').'_used_'.$order_main->user_id,
$coupon->system_coupon_id
);
return $res;

2
app/Service/CouponServiceInterface.php

@ -27,6 +27,6 @@ interface CouponServiceInterface
*/
public function getOrderCanUseCoupons($orderAmount, $marketId, $userId, $fields=[], $type=1, $storeTypeIds=[0]);
public function refundOrderCoupons($order_id,$user_id);
public function refundOrderCoupons($order_id);
public function clearTodayCouponUsed($userId, $couponId);
}

15
app/Service/OrderService.php

@ -34,6 +34,12 @@ class OrderService implements OrderServiceInterface
*/
protected $couponService;
/**
* @Inject
* @var PurchaseLimitServiceInterface
*/
protected $purchaseLimitService;
/**
* @inheritDoc
*/
@ -271,6 +277,9 @@ class OrderService implements OrderServiceInterface
return '订单商品异常';
}
//判断是否有购买特价商品
$this->purchaseLimitService->ssdbPurchaseRecord($orderGoods,$data['user_id'],$dataMain['global_order_id']);
// 修改总订单金额,金额是计算来的
// TODO 这部分其实可以结合处理优化一下,循环前后关联处理太多
$updateOrderMain = OrderMain::query()->where(['id' => $orderMainId])->update(['money' => $orderAmountTotal, 'total_money' => $dataMain['money']]);
@ -705,12 +714,10 @@ class OrderService implements OrderServiceInterface
* @inheritDoc
*/
public function onlineCancel($order_id){
$order_main = OrderMain::where('id',$order_id)
->select('global_order_id','user_id')
->first();
OrderMain::where('id',$order_id)
->update(['state' => OrderMain::ORDER_STATE_CANCEL]);
$res = $this->couponService->refundOrderCoupons($order_id,$order_main->user_id);
//撤销redis 用券记录
$res = $this->couponService->refundOrderCoupons($order_id);
return $res;
}
/**

16
app/Service/PurchaseLimitService.php

@ -29,11 +29,19 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface
return $res;
}
public function ssdbPurchaseRecord($params)
public function ssdbPurchaseRecord($data,$user_id,$global_order_id)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'], $params['order_id']);
$ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'],60);
foreach ($data as $k => $v){
if($v['money'] == 0.01){
//添加特价商品购买记录到ssdb
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'], $global_order_id);
$end_timestamp = strtotime(date('Y-m-d').'23:59:59');
$end_time = $end_timestamp - time();
$ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'],$end_time);
}
}
return true;
}
public function test($params)

2
app/Service/PurchaseLimitServiceInterface.php

@ -8,7 +8,7 @@ interface PurchaseLimitServiceInterface
{
public function getStoreIdByMarketId($params);
public function ssdbPurchaseRecord($params);
public function ssdbPurchaseRecord($params,$user_id,$global_order_id);
public function test($params);
}

2
app/Service/ShopCarService.php

@ -19,7 +19,7 @@ class ShopCarService implements ShopCarServiceInterface
{
//获取ssdb购买记录
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'], $params['good_id']);
$record_exists = $ssdb->exec('get',PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id']);
if($record_exists)
{
$error = [

2
config/routes.php

@ -56,7 +56,7 @@ Router::addGroup('/v1/',function (){
//小程序支付相关
Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline');
Router::post('wxminipay/offline', 'App\Controller\PaymentController@wxminiPayOffline');
//加入购物车
Router::post('ShopCar/addShopCar', 'App\Controller\ShopCarController@addShopCar');
Router::post('ShopCar/updateShopCar', 'App\Controller\ShopCarController@updateShopCar');

Loading…
Cancel
Save