Browse Source

Merge branch 'comunity_bind' of ssh://120.24.33.109:11022/hyzjshwo/lanzu_api_hyperf into comunity_bind

# Conflicts:
#	app/Model/CouponUserUse.php
#	app/Service/CouponService.php
#	app/Service/CouponServiceInterface.php
master
liangyuyan 6 years ago
parent
commit
6fccbd0f2e
  1. 4
      app/Controller/OrderController.php
  2. 9
      app/Model/CouponUserUse.php
  3. 41
      app/Service/CouponService.php
  4. 4
      app/Service/CouponServiceInterface.php
  5. 15
      app/Service/OrderService.php
  6. 2
      app/Service/OrderServiceInterface.php
  7. 1
      config/routes.php

4
app/Controller/OrderController.php

@ -102,8 +102,8 @@ class OrderController extends BaseController
* 用户取消订单
*/
public function onlineCancel(){
$globalOrderId = $this->request->input('global_order_id');
return $this->success($this->orderService->onlineCancel($globalOrderId));
$OrderId = $this->request->input('order_id');
return $this->success($this->orderService->onlineCancel($OrderId));
}
}

9
app/Model/CouponUserUse.php

@ -6,11 +6,12 @@ namespace App\Model;
class CouponUserUse extends Model
{
/* 状态 */
// 正常使用
const STATE_USE = 1;
// 已退回用户
const STATE_REFUND = 2;
const COUPON_USE_STATE_USED = 1;
// 退回用户
const COUPON_USE_STATE_CANCEL = 2;
public $timestamps = false;
protected $table = 'ims_system_coupon_user_use';
}

41
app/Service/CouponService.php

@ -7,6 +7,7 @@ use Hyperf\DbConnection\Db;
use App\Model\CouponUserRecType;
use App\Model\Coupon;
use App\Model\CouponRec;
use App\Model\CouponUserUse;
use Hyperf\Utils\ApplicationContext;
use App\TaskWorker\SSDBTask;
use App\Constants\SsdbKeysPrefix;
@ -221,7 +222,42 @@ class CouponService implements CouponServiceInterface
}
/**
* 删除-优惠券今日使用的缓存
* 取消订单返券
* @param $order_id
* @return bool
*/
public function refundOrderCoupons($order_id,$user_id){
$coupon = CouponUserUse::where([
['order_main_id','=',$order_id],
['status','=',CouponUserUse::COUPON_USE_STATE_USED],
])
->select('id','user_receive_id','number')
->first();
// 返回用户优惠券数量并更新状态
$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})");
// 更新使用记录状态为已退回
CouponUserUse::where([
['id','=',$coupon->id],
['status','=',CouponUserUse::COUPON_USE_STATE_USED],
])
->update([
'status' => CouponUserUse::COUPON_USE_STATE_CANCEL,
'return_time' => time(),
'update_time' => time(),
]);
//删除当日 redis 使用记录缓存
$redis = ApplicationContext::getContainer()->get(Redis::class);
$remRes = $redis->sRem(
'coupon_'.date('Ymd').'_used_'.$user_id,
$coupon->system_coupon_id
);
return $res;
}
/* 删除-优惠券今日使用的缓存
* @param $userId
* @param $couponId
* @param $couponRecId
@ -236,8 +272,5 @@ class CouponService implements CouponServiceInterface
'coupon_'.date('Ymd').'_used_'.$userId,
$couponId
);
return $res;
}
}

4
app/Service/CouponServiceInterface.php

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

15
app/Service/OrderService.php

@ -704,8 +704,14 @@ class OrderService implements OrderServiceInterface
/**
* @inheritDoc
*/
public function onlineCancel($global_order_id){
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);
return $res;
}
/**
* @inheritDoc
@ -739,11 +745,11 @@ class OrderService implements OrderServiceInterface
$couponUses = CouponUserUse::query()
->select('id','system_coupon_id','user_id','number','user_receive_id')
->where('order_main_id',$orderMain->id)
->where('status',CouponUserUse::STATE_USE)
->where('status',CouponUserUse::COUPON_USE_STATE_USED)
->select();
if(!empty($couponUse)){
foreach($couponUses as $use){
$use->status = CouponUserUse::STATE_USE;
$use->status = CouponUserUse::COUPON_USE_STATE_USED;
$use->return_time = $time;
$use->update_time = $time;
$use->save();
@ -773,4 +779,5 @@ class OrderService implements OrderServiceInterface
return false;
}
}
}

2
app/Service/OrderServiceInterface.php

@ -53,7 +53,7 @@ interface OrderServiceInterface
* @param $global_order_id
* @return mixed
*/
public function onlineCancel($global_order_id);
public function onlineCancel($order_id);
/**
* 线上订单退款

1
config/routes.php

@ -50,6 +50,7 @@ Router::addGroup('/v1/',function (){
//订单相关
Router::post('Order/addOnline', 'App\Controller\OrderController@addOnlineOrder');
Router::post('Order/addOffline', 'App\Controller\OrderController@addOfflineOrder');
Router::post('Order/onlineCancel', 'App\Controller\OrderController@onlineCancel');
//小程序支付相关
Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline');

Loading…
Cancel
Save