|
|
@@ -3,7 +3,9 @@
|
|
|
namespace bizHd\purchase\services;
|
|
|
|
|
|
use biz\ghs\models\Ghs;
|
|
|
+use biz\shop\classes\ShopCouponClass;
|
|
|
use biz\shop\models\Shop;
|
|
|
+use biz\shop\models\ShopCoupon;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
use bizGhs\order\classes\OrderClass;
|
|
|
use bizGhs\order\services\OrderService;
|
|
|
@@ -47,6 +49,10 @@ class PurchaseService extends BaseService
|
|
|
if ($getType == PurchaseClass::GET_TYPE_SELF_GET) {
|
|
|
$sendType = OrderClass::SEND_TYPE_NO;
|
|
|
}
|
|
|
+ $couponId = $data['couponId'] ?? 0;
|
|
|
+ $discountType = $respond->discountType ?? dict::getDict('discountType', 'noDiscount');
|
|
|
+ $discountAmount = $respond->discountAmount ?? 0;
|
|
|
+ $customPrice = $respond->actPrice;
|
|
|
$arr = [
|
|
|
'product' => $product,
|
|
|
'merchantId' => $currentSjId,
|
|
|
@@ -69,6 +75,10 @@ class PurchaseService extends BaseService
|
|
|
'customShopAdminName' => $shopAdminName,
|
|
|
'ghsId' => $ghsId,
|
|
|
'orderType' => OrderClass::ORDER_TYPE_HD_ADD,
|
|
|
+ 'couponId' => $couponId,
|
|
|
+ 'discountType' => $discountType,
|
|
|
+ 'discountAmount' => $discountAmount,
|
|
|
+ 'customPrice' => $customPrice,
|
|
|
];
|
|
|
$result = OrderClass::addOrder($arr);
|
|
|
$saleId = $result['id'] ?? 0;
|
|
|
@@ -142,6 +152,11 @@ class PurchaseService extends BaseService
|
|
|
$saleId = $purchase->saleId;
|
|
|
//销售单失效
|
|
|
OrderClass::cancel($saleId);
|
|
|
+ $couponId = $purchase->couponId;
|
|
|
+ if (!empty($couponId)) {
|
|
|
+ $coupon = ShopCoupon::getById($couponId, true);
|
|
|
+ ShopCouponClass::rollback($coupon);
|
|
|
+ }
|
|
|
}
|
|
|
return $purchase;
|
|
|
}
|
|
|
@@ -151,7 +166,6 @@ class PurchaseService extends BaseService
|
|
|
{
|
|
|
$payWay = dict::getDict('payWay', 'debtPay');
|
|
|
self::payAfter($info, $payWay);
|
|
|
-
|
|
|
$saleId = $info->saleId ?? 0;
|
|
|
$order = OrderClass::getById($saleId, true);
|
|
|
OrderService::payAfter($order, $payWay);
|
|
|
@@ -230,6 +244,18 @@ class PurchaseService extends BaseService
|
|
|
$shop->cgUnSend += 1;
|
|
|
$shop->save();
|
|
|
|
|
|
+ //使用优惠券
|
|
|
+ $couponId = $info->couponId;
|
|
|
+ if (!empty($couponId)) {
|
|
|
+ $coupon = ShopCouponClass::getLockById($couponId);
|
|
|
+ if ($coupon->take != ShopCouponClass::TAKE_UN) {
|
|
|
+ Yii::info("优惠券已经被使用 orderId:{$info->id} couponId:{$couponId}");
|
|
|
+ util::fail('优惠券已经被使用');
|
|
|
+ }
|
|
|
+ $coupon->status = ShopCouponClass::STATUS_USED;
|
|
|
+ $coupon->save();
|
|
|
+ }
|
|
|
+
|
|
|
/**零售的供货商资产变化**/
|
|
|
$ghsId = $info->ghsId ?? 0;
|
|
|
$ghs = Ghs::findBySql('select * from ' . Ghs::tableName() . ' where id = :id for update', ['id' => $ghsId])->one();
|