|
|
@@ -10,61 +10,63 @@ use bizMall\base\classes\BaseClass;
|
|
|
|
|
|
class CouponClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
- public static $baseFile = '\bizMall\coupon\models\Coupon';
|
|
|
-
|
|
|
- //获取客户没有使用的优惠券,默认取最新的6张
|
|
|
- public static function getUnUseCoupon($userId, $num = 6)
|
|
|
- {
|
|
|
- $time = time();
|
|
|
- return self::getLimitList('*', ['userId' => $userId, 'status' => 0, 'deadline>' => $time], $num, 'addTime DESC');
|
|
|
- }
|
|
|
-
|
|
|
- //使用优惠券 ssh 2020.3.10
|
|
|
- public static function useCoupon($couponId, $orderId)
|
|
|
- {
|
|
|
- if (empty($couponId)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- $coupon = self::getById($couponId, true);
|
|
|
- if (empty($coupon)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- $coupon->status = 1;
|
|
|
- $coupon->orderId = $orderId;
|
|
|
- $coupon->save();
|
|
|
-
|
|
|
- //老带新获得的优惠券
|
|
|
- if ($coupon->source == 1) {
|
|
|
- $time = time();
|
|
|
- $sourceId = $coupon->sourceId;
|
|
|
- $invite = InviteClass::getById($sourceId, true);
|
|
|
- if (!empty($invite)) {
|
|
|
- $invite->status = 1;
|
|
|
- $invite->orderTime = $time;
|
|
|
- $invite->save();
|
|
|
- //下单人数+1
|
|
|
- $introUserId = $invite->introUserId;
|
|
|
- $introStat = InviteStatClass::getByCondition(['userId' => $introUserId], true);
|
|
|
- if (!empty($introStat)) {
|
|
|
- $introStat->orderNum += 1;
|
|
|
- $introStat->save();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //增加优惠券 ssh 2020.5.5
|
|
|
- public static function add($data, $returnObject = false)
|
|
|
- {
|
|
|
- $model = Yii::createObject(['class' => static::$baseFile]);
|
|
|
- $model->add($data, $returnObject);
|
|
|
- //领券次数增加
|
|
|
- $userId = $data['userId'];
|
|
|
- $userAsset = $userAsset = UserAssetClass::getByUserId($userId);
|
|
|
- $getCouponNum = $userAsset['getCouponNum'];
|
|
|
- $getCouponNum++;
|
|
|
- UserAssetClass::updateByUserId($userId, ['getCouponNum' => $getCouponNum]);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ public static $baseFile = '\bizMall\coupon\models\Coupon';
|
|
|
+
|
|
|
+ //获取客户没有使用的优惠券,默认取最新的6张
|
|
|
+ public static function getUnUseCoupon($userId, $num = 6)
|
|
|
+ {
|
|
|
+ $time = time();
|
|
|
+ //return self::getLimitList('*', ['userId' => $userId, 'status' => 0, 'deadline>' => $time], $num, 'addTime DESC');
|
|
|
+ //deadline字段去掉了
|
|
|
+ return self::getLimitList('*', ['userId' => $userId, 'status' => 0], $num, 'addTime DESC');
|
|
|
+ }
|
|
|
+
|
|
|
+ //使用优惠券 ssh 2020.3.10
|
|
|
+ public static function useCoupon($couponId, $orderId)
|
|
|
+ {
|
|
|
+ if (empty($couponId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $coupon = self::getById($couponId, true);
|
|
|
+ if (empty($coupon)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $coupon->status = 1;
|
|
|
+ $coupon->orderId = $orderId;
|
|
|
+ $coupon->save();
|
|
|
+
|
|
|
+ //老带新获得的优惠券
|
|
|
+ if ($coupon->source == 1) {
|
|
|
+ $time = time();
|
|
|
+ $sourceId = $coupon->sourceId;
|
|
|
+ $invite = InviteClass::getById($sourceId, true);
|
|
|
+ if (!empty($invite)) {
|
|
|
+ $invite->status = 1;
|
|
|
+ $invite->orderTime = $time;
|
|
|
+ $invite->save();
|
|
|
+ //下单人数+1
|
|
|
+ $introUserId = $invite->introUserId;
|
|
|
+ $introStat = InviteStatClass::getByCondition(['userId' => $introUserId], true);
|
|
|
+ if (!empty($introStat)) {
|
|
|
+ $introStat->orderNum += 1;
|
|
|
+ $introStat->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //增加优惠券 ssh 2020.5.5
|
|
|
+ public static function add($data, $returnObject = false)
|
|
|
+ {
|
|
|
+ $model = Yii::createObject(['class' => static::$baseFile]);
|
|
|
+ $model->add($data, $returnObject);
|
|
|
+ //领券次数增加
|
|
|
+ $userId = $data['userId'];
|
|
|
+ $userAsset = $userAsset = UserAssetClass::getByUserId($userId);
|
|
|
+ $getCouponNum = $userAsset['getCouponNum'];
|
|
|
+ $getCouponNum++;
|
|
|
+ UserAssetClass::updateByUserId($userId, ['getCouponNum' => $getCouponNum]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|