AntonLV 8 лет назад
Родитель
Сommit
1717cda7ec

+ 9 - 0
inc/classes/BxDolPayments.php

@@ -297,6 +297,15 @@ class BxDolPayments extends BxDolFactory implements iBxDolSingleton
 		$aSrvParams = array($sOrderId);
 		return BxDolService::call($this->_sActive, 'prolong_subscription', $aSrvParams);
     }
+
+    public function generateLicense()
+    {
+        if(!BxDolRequest::serviceExists($this->_sActive, 'generate_license'))
+            return '';
+
+        $aSrvParams = array();
+        return BxDolService::call($this->_sActive, 'generate_license', $aSrvParams, 'Module', true);
+    }
 }
 
 /** @} */

+ 22 - 0
modules/base/payment/classes/BxBaseModPaymentConfig.php

@@ -143,6 +143,28 @@ class BxBaseModPaymentConfig extends BxBaseModGeneralConfig
     {
         return $this->_iAnimationSpeed;
     }
+
+    public function getLicense()
+    {
+        list($fMilliSec, $iSec) = explode(' ', microtime());
+        $fSeed = (float)$iSec + ((float)$fMilliSec * 100000);
+        srand($fSeed);
+
+        $sResult = '';
+        for($i=0; $i < 16; ++$i) {
+            switch(rand(1,2)) {
+                case 1:
+                    $c = chr(rand(ord('A'),ord('Z')));
+                    break;
+                case 2:
+                    $c = chr(rand(ord('0'),ord('9')));
+                    break;
+            }
+            $sResult .= $c;
+        }
+
+        return $sResult;
+    }
 }
 
 /** @} */

+ 22 - 0
modules/base/payment/classes/BxBaseModPaymentModule.php

@@ -57,6 +57,28 @@ class BxBaseModPaymentModule extends BxBaseModGeneralModule
         }
     }
 
+    /**
+     * @page service Service Calls
+     * @section bx_base_payment Base Payment
+     * @subsection bx_base_payment-other Other
+     * @subsubsection bx_base_payment-generate_license generate_license
+     * 
+     * @code bx_srv('bx_payment', 'generate_license'); @endcode
+     * 
+     * Generate license. 
+     *
+     * @return a string with license.
+     * 
+     * @see BxBaseModPaymentModule::serviceGenerateLicense
+     */
+    /** 
+     * @ref bx_base_payment-generate_license "generate_license"
+     */
+    public function serviceGenerateLicense()
+    {
+        return $this->_oConfig->getLicense();
+    }
+
     /**
      * @page service Service Calls
      * @section bx_base_payment Base Payment

+ 28 - 18
modules/boonex/market/classes/BxMarketDb.php

@@ -470,27 +470,37 @@ class BxMarketDb extends BxBaseModTextDb
     	return false;
     }
 
-	public function registerLicense($iProfileId, $iProductId, $iCount, $sOrder, $sLicense, $sType, $sDuration = '', $iTrial = 0)
+    public function registerLicense($iProfileId, $iProductId, $iCount, $sOrder, $sLicense, $sType, $sDuration = '', $iTrial = 0)
     {
     	$CNF = &$this->_oConfig->CNF;
 
-    	$aQueryParams = array(
-    		'profile_id' => $iProfileId,
-    		'product_id' => $iProductId,
-    		'count' => $iCount, 
-    		'order' => $sOrder, 
-    		'license' => $sLicense,
-    		'type' => $sType
-    	);
-
-		$sExpireParam = '';
-		if(!empty($iTrial))
-		    $sExpireParam = ', `expired`=UNIX_TIMESTAMP(DATE_ADD(DATE_ADD(NOW(), INTERVAL ' . (int)$iTrial . ' DAY), INTERVAL ' . (int)$this->getParam($CNF['OPTION_RECURRING_RESERVE']) . ' DAY))';
-		else if(!empty($sDuration) && isset($this->_aRecurringDurations[$sDuration]))
-			$sExpireParam = ', `expired`=UNIX_TIMESTAMP(DATE_ADD(DATE_ADD(NOW(), ' . $this->_aRecurringDurations[$sDuration] . '), INTERVAL ' . (int)$this->getParam($CNF['OPTION_RECURRING_RESERVE']) . ' DAY))';
+        $oPayments = BxDolPayments::getInstance();
+
+        $iProcessed = 0;
+        for($i = 0; $i < $iCount; $i++) {
+            $aQueryParams = array(
+                'profile_id' => $iProfileId,
+                'product_id' => $iProductId,
+                'count' => 1,
+                'order' => $sOrder,
+                'license' => $sLicense,
+                'type' => $sType
+            );
+
+            $sExpireParam = '';
+            if(!empty($iTrial))
+                $sExpireParam = ', `expired`=UNIX_TIMESTAMP(DATE_ADD(DATE_ADD(NOW(), INTERVAL ' . (int)$iTrial . ' DAY), INTERVAL ' . (int)$this->getParam($CNF['OPTION_RECURRING_RESERVE']) . ' DAY))';
+            else if(!empty($sDuration) && isset($this->_aRecurringDurations[$sDuration]))
+                $sExpireParam = ', `expired`=UNIX_TIMESTAMP(DATE_ADD(DATE_ADD(NOW(), ' . $this->_aRecurringDurations[$sDuration] . '), INTERVAL ' . (int)$this->getParam($CNF['OPTION_RECURRING_RESERVE']) . ' DAY))';
+
+            if((int)$this->query("INSERT INTO `" . $CNF['TABLE_LICENSES'] . "` SET " . $this->arrayToSQL($aQueryParams) . ", `added`=UNIX_TIMESTAMP()" . $sExpireParam) == 0)
+                continue;
+
+            $sLicense = $oPayments->generateLicense();
+            $iProcessed += 1;
+        }
 
-    	$sQuery = $this->prepare("INSERT INTO `" . $CNF['TABLE_LICENSES'] . "` SET " . $this->arrayToSQL($aQueryParams) . ", `added`=UNIX_TIMESTAMP()" . $sExpireParam);
-        return (int)$this->query($sQuery) > 0;
+        return $iCount == $iProcessed;
     }
 
     public function prolongLicense($iProfileId, $iProductId, $iCount, $sOrder, $sLicense, $sType, $sDuration = '', $iTrial = 0)
@@ -511,7 +521,7 @@ class BxMarketDb extends BxBaseModTextDb
     			`profile_id` = ? AND 
     			`product_id` = ? AND 
     			`order` = ? 
-    		LIMIT 1", $iProfileId, $iProductId, $sOrder);
+    		LIMIT ?", $iProfileId, $iProductId, $sOrder, $iCount);
 
         return (int)$this->query($sQuery) > 0;
     }

+ 22 - 19
modules/boonex/market/classes/BxMarketModule.php

@@ -979,31 +979,34 @@ class BxMarketModule extends BxBaseModTextModule
     {
     	$aItem = $this->serviceGetCartItem($iItemId);
         if(empty($aItem) || !is_array($aItem))
-			return array();
+            return array();
 
         $iTrial = 0;
-		$sDuration = '';
-		if($sType == BX_MARKET_LICENSE_TYPE_RECURRING) {
-			$aProduct = $this->_oDb->getContentInfoById($iItemId);
-
-			$iTrial = $aProduct[$this->_oConfig->CNF['FIELD_TRIAL_RECURRING']];
-			$sDuration = $aProduct[$this->_oConfig->CNF['FIELD_DURATION_RECURRING']];
-		}
+        $sDuration = '';
+        $sAction = 'register';
+        if($sType == BX_MARKET_LICENSE_TYPE_RECURRING) {
+            $aProduct = $this->_oDb->getContentInfoById($iItemId);
+
+            $iTrial = $aProduct[$this->_oConfig->CNF['FIELD_TRIAL_RECURRING']];
+            $sDuration = $aProduct[$this->_oConfig->CNF['FIELD_DURATION_RECURRING']];
+            
+            if($this->_oDb->hasLicenseByOrder($iClientId, $iItemId, $sOrder))
+                $sAction = 'prolong';
+        }
 
-    	$sAction = $this->_oDb->hasLicenseByOrder($iClientId, $iItemId, $sOrder) ? 'prolong' : 'register';
         if(!$this->_oDb->{$sAction . 'License'}($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType, $sDuration, $iTrial))
             return array();
 
-		bx_alert($this->getName(), 'license_' . $sAction, 0, false, array(
-			'product_id' => $iItemId,
-			'profile_id' => $iClientId,
-			'order' => $sOrder,
-			'license' => $sLicense,
-			'type' => $sType,
-			'count' => $iItemCount,
-			'duration' => $sDuration,
-		    'trial' => $iTrial
-		));
+        bx_alert($this->getName(), 'license_' . $sAction, 0, false, array(
+            'product_id' => $iItemId,
+            'profile_id' => $iClientId,
+            'order' => $sOrder,
+            'license' => $sLicense,
+            'type' => $sType,
+            'count' => $iItemCount,
+            'duration' => $sDuration,
+            'trial' => $iTrial
+        ));
 
         return $aItem;
     }

+ 0 - 22
modules/boonex/payment/classes/BxPaymentConfig.php

@@ -123,28 +123,6 @@ class BxPaymentConfig extends BxBaseModPaymentConfig
         $this->_sCurrencySign = $aCurrencies[$this->_sCurrencyCode];
     }
 
-	public function getLicense()
-    {
-        list($fMilliSec, $iSec) = explode(' ', microtime());
-        $fSeed = (float)$iSec + ((float)$fMilliSec * 100000);
-        srand($fSeed);
-
-        $sResult = '';
-        for($i=0; $i < 16; ++$i) {
-            switch(rand(1,2)) {
-                case 1:
-                    $c = chr(rand(ord('A'),ord('Z')));
-                    break;
-                case 2:
-                    $c = chr(rand(ord('0'),ord('9')));
-                    break;
-            }
-            $sResult .= $c;
-        }
-
-        return $sResult;
-    }
-
     public function getPrice($sType, $aItem)
     {
     	$fPrice = 0;