订单关闭,返还平台购物卡和店铺抵扣券
This commit is contained in:
parent
004e200f42
commit
4b4d52c1f2
@ -160,11 +160,13 @@ class StoreCouponUserDao extends BaseDao
|
|||||||
* 增加优惠券余额
|
* 增加优惠券余额
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param $amount
|
* @param $amount
|
||||||
|
* @param $order
|
||||||
|
* @param $mark
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function increase($id, $amount)
|
public function increase($id, $amount, $order, $mark = '')
|
||||||
{
|
{
|
||||||
$storeCouponUser = StoreCouponUser::where('coupon_user_id', $id)->find();
|
$storeCouponUser = StoreCouponUser::where('coupon_user_id', $id)->find();
|
||||||
if (empty($storeCouponUser)) {
|
if (empty($storeCouponUser)) {
|
||||||
@ -174,6 +176,7 @@ class StoreCouponUserDao extends BaseDao
|
|||||||
if (!$storeCouponUser->save()) {
|
if (!$storeCouponUser->save()) {
|
||||||
throw new ValidateException('优惠券余额更新出错');
|
throw new ValidateException('优惠券余额更新出错');
|
||||||
}
|
}
|
||||||
|
StoreCouponDetail::income($order, $storeCouponUser['coupon_user_id'], $storeCouponUser->coupon_price, $mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,11 +196,12 @@ class StoreCouponUserDao extends BaseDao
|
|||||||
throw new ValidateException('优惠券不存在');
|
throw new ValidateException('优惠券不存在');
|
||||||
}
|
}
|
||||||
$isBalance = $storeCouponUser->isbalance();
|
$isBalance = $storeCouponUser->isbalance();
|
||||||
$couponPrice = bcsub($storeCouponUser->coupon_price, $amount, 2);
|
$couponBalance = bcsub($storeCouponUser->coupon_price, $amount, 2);
|
||||||
if ($isBalance && $couponPrice > 0) {
|
$couponBalance = max($couponBalance, 0);
|
||||||
$storeCouponUser->coupon_price = $couponPrice;
|
if ($isBalance) {
|
||||||
|
$storeCouponUser->coupon_price = $couponBalance;
|
||||||
}
|
}
|
||||||
if ($couponPrice <= 0 || !$isBalance) {
|
if ($couponBalance <= 0 || !$isBalance) {
|
||||||
$storeCouponUser->status = 1;
|
$storeCouponUser->status = 1;
|
||||||
}
|
}
|
||||||
if (!$storeCouponUser->save()) {
|
if (!$storeCouponUser->save()) {
|
||||||
|
@ -13,6 +13,8 @@ class StoreCouponDetail extends BaseModel
|
|||||||
|
|
||||||
const TYPE_EXPEND = 1; //支出
|
const TYPE_EXPEND = 1; //支出
|
||||||
const TYPE_INCOME = 2; //收入
|
const TYPE_INCOME = 2; //收入
|
||||||
|
const STATUS_VALID = 1; //有效的
|
||||||
|
const STATUS_INVALID = 0; //无效的
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
@ -35,6 +37,11 @@ class StoreCouponDetail extends BaseModel
|
|||||||
return $this->hasOne(StoreCoupon::class, 'coupon_id', 'coupon_id');
|
return $this->hasOne(StoreCoupon::class, 'coupon_id', 'coupon_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function couponUser()
|
||||||
|
{
|
||||||
|
return $this->hasOne(StoreCouponUser::class, 'coupon_user_id', 'coupon_user_id');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用优惠券
|
* 使用优惠券
|
||||||
* @param $order
|
* @param $order
|
||||||
@ -61,10 +68,11 @@ class StoreCouponDetail extends BaseModel
|
|||||||
* @param $order
|
* @param $order
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param $amount
|
* @param $amount
|
||||||
|
* @param $mark
|
||||||
* @param $status
|
* @param $status
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function income($order, $id, $amount, $status = 1)
|
public static function income($order, $id, $amount, $mark = '', $status = 1)
|
||||||
{
|
{
|
||||||
$detailModel = new self();
|
$detailModel = new self();
|
||||||
$detailModel->uid = $order['uid'];
|
$detailModel->uid = $order['uid'];
|
||||||
@ -75,6 +83,7 @@ class StoreCouponDetail extends BaseModel
|
|||||||
$detailModel->amount = $amount;
|
$detailModel->amount = $amount;
|
||||||
$detailModel->pay_price = $order['pay_price'];
|
$detailModel->pay_price = $order['pay_price'];
|
||||||
$detailModel->status = $status;
|
$detailModel->status = $status;
|
||||||
|
$detailModel->mark = $mark;
|
||||||
$detailModel->create_time = time();
|
$detailModel->create_time = time();
|
||||||
$detailModel->save();
|
$detailModel->save();
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
namespace crmeb\jobs;
|
namespace crmeb\jobs;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\dao\store\coupon\StoreCouponUserDao;
|
||||||
|
use app\common\model\store\coupon\StoreCouponDetail;
|
||||||
|
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||||
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
||||||
use app\common\repositories\store\product\ProductAttrValueRepository;
|
use app\common\repositories\store\product\ProductAttrValueRepository;
|
||||||
@ -45,7 +48,21 @@ class CancelGroupOrderJob implements JobInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count($couponId)) {
|
if (count($couponId)) {
|
||||||
app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]);
|
$storeCouponDetails = StoreCouponDetail::with('couponUser')
|
||||||
|
->where('group_order_id', $groupOrder->group_order_id)
|
||||||
|
->where('type', StoreCouponDetail::TYPE_EXPEND)
|
||||||
|
->where('status', StoreCouponDetail::STATUS_VALID)
|
||||||
|
->select();
|
||||||
|
$otherCoupon = [];
|
||||||
|
foreach ($storeCouponDetails as $item) {
|
||||||
|
if (in_array($item['couponUser']['coupon_type'], [StoreCouponRepository::TYPE_STORE_COUPON, StoreCouponRepository::TYPE_PLATFORM_CARD])) {
|
||||||
|
$mark = '订单关闭,返还' . $item['couponUser']['coupon_title'] . '金额';
|
||||||
|
(new StoreCouponUserDao())->increase($item['coupon_user_id'], $item['amount'], $groupOrder, $mark);
|
||||||
|
} else {
|
||||||
|
$otherCoupon[] = $item['coupon_user_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app()->make(StoreCouponUserRepository::class)->updates($otherCoupon, ['status' => 0]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return $job->delete();
|
return $job->delete();
|
||||||
|
@ -26,6 +26,7 @@ class AutoCancelGroupOrderListen extends TimerService implements ListenerInterfa
|
|||||||
public function handle($event): void
|
public function handle($event): void
|
||||||
{
|
{
|
||||||
$this->tick(60000, function () {
|
$this->tick(60000, function () {
|
||||||
|
/** @var StoreGroupOrderRepository $storeGroupOrderRepository */
|
||||||
$storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
|
$storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
|
||||||
request()->clearCache();
|
request()->clearCache();
|
||||||
$timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
|
$timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
|
||||||
|
@ -28,7 +28,7 @@ class OrderDeliveryListen implements ListenerInterface
|
|||||||
}
|
}
|
||||||
$coupon->coupon_price = $order->total_price;
|
$coupon->coupon_price = $order->total_price;
|
||||||
$couponUser = $repo->sendCoupon($coupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY);
|
$couponUser = $repo->sendCoupon($coupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY);
|
||||||
StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $coupon->coupon_price);
|
StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $coupon->coupon_price, $coupon['title']);
|
||||||
|
|
||||||
if (!empty($orderProduct->product->give_coupon_ids)) {
|
if (!empty($orderProduct->product->give_coupon_ids)) {
|
||||||
$giveCoupons = $repo->getGiveCoupon($orderProduct->product->give_coupon_ids);
|
$giveCoupons = $repo->getGiveCoupon($orderProduct->product->give_coupon_ids);
|
||||||
@ -43,7 +43,7 @@ class OrderDeliveryListen implements ListenerInterface
|
|||||||
$repo->endTime = '2025-07-01';
|
$repo->endTime = '2025-07-01';
|
||||||
$repo->status = -1;
|
$repo->status = -1;
|
||||||
$couponUser = $repo->sendCoupon($giveCoupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY);
|
$couponUser = $repo->sendCoupon($giveCoupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY);
|
||||||
StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price, 0);
|
StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price, $giveCoupon['title'], 0);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::info('自动发放买赠优惠券:' . $e->getMessage());
|
Log::info('自动发放买赠优惠券:' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user