Esempio n. 1
0
 public function actionCreate()
 {
     $params = $this->getParams();
     if (isset($params['total'])) {
         $params['total'] = intval($params['total']);
     }
     if (isset($params['limit'])) {
         $params['limit'] = intval($params['limit']);
     }
     $params['accountId'] = $this->getAccountId();
     //check the coupon time
     $params = Coupon::converCouponTime($params);
     //check the coupon storeType
     Coupon::checkCouponStore($params);
     //check coupon field
     Coupon::checkCouponField($params);
     $coupon = new Coupon();
     $coupon->load($params, '');
     if (false === $coupon->save()) {
         LogUtil::error(['message' => 'Faild to save coupon', 'params' => $params, 'error' => $coupon->getErrors()], 'product');
         throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
     } else {
         //create shortUrl
         $longUrl = Yii::$app->request->hostInfo . '/mobile/product/coupon?couponId=' . $coupon->_id;
         $shortObj = Yii::$app->urlService->shortenUrl($longUrl);
         $coupon->url = $shortObj['Short'];
         $coupon->save();
         return $coupon;
     }
 }