/**
  * check the code in the excel
  */
 public function actionCheckCode()
 {
     $params = Yii::$app->request->post();
     $productId = $params['productId'];
     //$productId = '1429862376675049';
     if (empty($productId)) {
         throw new BadRequestHttpException('missing param productId');
     }
     $fileKey = 'file';
     if (empty($_FILES[$fileKey])) {
         throw new BadRequestHttpException('missing param ' . $fileKey);
     }
     $accountId = $this->getAccountId();
     $where = ['accountId' => $accountId, 'sku' => $productId];
     $result = Product::findOne($where);
     LogUtil::info(['file' => $_FILES, 'where' => $where], 'promotimeCode');
     if (empty($result)) {
         throw new BadRequestHttpException(Yii::t("product", "product_deleted"));
     }
     unset($where);
     //upload config
     $config = ['maxSize' => self::MAXSIZE, 'allowFiles' => self::$ALLOWFILES, 'pathFormat' => self::PATHFORMAT, 'privateBucket' => true];
     //upload to qiniu
     $upload = new Uploader($fileKey, $config, 'upload', 1);
     $fileInfo = $upload->getFileInfo();
     $rootPath = Yii::$app->getRuntimePath() . '/code/';
     if (!is_dir($rootPath)) {
         FileHelper::createDirectory($rootPath, 0777, true);
     }
     $fileName = $fileInfo['title'];
     $locationPath = $rootPath . $fileName . $fileInfo['type'];
     if (empty($fileName)) {
         throw new InvalidParameterException($fileInfo['state']);
     }
     $checkArgs = ['qiniuBucket' => QINIU_DOMAIN_PRIVATE, 'productId' => $productId, 'filePath' => Yii::$app->qiniu->getPrivateUrl($fileName), 'locationPath' => $locationPath, 'fileName' => $fileName, 'accountId' => (string) $accountId, 'description' => 'Direct: Check if promotion codes to be imported is unique'];
     $jobId = Yii::$app->job->create('backend\\modules\\product\\job\\PromotionCheckCode', $checkArgs);
     return ['message' => 'OK', 'data' => ['token' => $jobId, 'filename' => $fileName]];
 }
Пример #2
0
 /**
  * Catch the file
  **/
 private function _catch()
 {
     $CONFIG = $this->config;
     $query = $this->getQuery();
     $params = $this->getParams();
     /* 上传配置 */
     $config = array("pathFormat" => $CONFIG['catcherPathFormat'], "maxSize" => $CONFIG['catcherMaxSize'], "allowFiles" => $CONFIG['catcherAllowFiles'], "oriName" => "remote.png");
     $fieldName = $CONFIG['catcherFieldName'];
     /* 抓取远程图片 */
     $list = array();
     if (isset($params[$fieldName])) {
         $source = $params[$fieldName];
     } else {
         $source = $query[$fieldName];
     }
     foreach ($source as $imgUrl) {
         $item = new Uploader($imgUrl, $config, "remote");
         $info = $item->getFileInfo();
         array_push($list, array("state" => $info["state"], "url" => $info["url"], "size" => $info["size"], "title" => htmlspecialchars($info["title"]), "original" => htmlspecialchars($info["original"]), "source" => htmlspecialchars($imgUrl)));
     }
     /* 返回抓取数据 */
     return Json::encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list));
 }
Пример #3
0
 public function actionCheckMembers()
 {
     $fileKey = 'file';
     if (empty($_FILES[$fileKey])) {
         throw new BadRequestHttpException('missing param ' . $fileKey);
     }
     $accountId = $this->getAccountId();
     //upload config
     $config = ['maxSize' => self::MAXSIZE, 'allowFiles' => self::$ALLOWFILES, 'pathFormat' => self::PATHFORMAT, 'privateBucket' => true];
     //upload to qiniu
     $upload = new Uploader($fileKey, $config, 'upload', 1);
     $fileInfo = $upload->getFileInfo();
     $rootPath = Yii::$app->getRuntimePath() . '/code/';
     if (!is_dir($rootPath)) {
         FileHelper::createDirectory($rootPath, 0777, true);
     }
     $fileName = $fileInfo['title'];
     $locationPath = $rootPath . $fileName . $fileInfo['type'];
     if (empty($fileName)) {
         throw new InvalidParameterException($fileInfo['state']);
     }
     $checkArgs = ['qiniuBucket' => QINIU_DOMAIN_PRIVATE, 'accountId' => (string) $accountId, 'filePath' => Yii::$app->qiniu->getPrivateUrl($fileName), 'locationPath' => $locationPath, 'fileName' => $fileName, 'description' => 'Direct: Check if the file of member has already exists.'];
     $jobId = Yii::$app->job->create('backend\\modules\\member\\job\\MemberCheckCode', $checkArgs);
     return ['message' => 'OK', 'data' => ['token' => $jobId, 'filename' => $fileName]];
 }