|
|
@@ -2,6 +2,9 @@
|
|
|
|
|
|
namespace business\controllers;
|
|
|
|
|
|
+use biz\goods\services\CategoryService;
|
|
|
+use biz\goods\services\PicCategoryService;
|
|
|
+use biz\goods\services\PicService;
|
|
|
use common\components\business;
|
|
|
use common\components\dirUtil;
|
|
|
use common\components\stringUtil;
|
|
|
@@ -20,6 +23,17 @@ class UploadController extends BaseController
|
|
|
header('Content-type:text/html;charset=utf-8');
|
|
|
$base64 = file_get_contents('php://input');
|
|
|
$base64_image_content = str_replace("content=", "", urldecode($base64));
|
|
|
+
|
|
|
+ $categoryIds = Yii::$app->request->post('categoryId', []);
|
|
|
+ if (!empty($categoryIds)) {
|
|
|
+ $categoryList = CategoryService::getByIds($categoryIds);
|
|
|
+ foreach ($categoryList as $cat) {
|
|
|
+ if ($cat['merchantId'] != $this->merchantId) {
|
|
|
+ util::fail('请选择自己的分类');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//匹配出图片的格式
|
|
|
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
|
|
|
$type = $result[2];
|
|
|
@@ -62,8 +76,21 @@ class UploadController extends BaseController
|
|
|
$smallHeight = ceil((200 * $height) / $width);
|
|
|
$smallFullPathFile = $path . $preFileName . '_small.' . $type;
|
|
|
Image::thumbnail($fullPathFile, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
|
|
|
-
|
|
|
+
|
|
|
$data = business::formatUploadImg($img);
|
|
|
+
|
|
|
+ if (!empty($categoryIds)) {
|
|
|
+ $time = time();
|
|
|
+ $data = ['img' => $img, 'merchantId' => $merchantId, 'name' => '未命名', 'addTime' => $time];
|
|
|
+ $pic = PicService::add($data);
|
|
|
+ $currentId = $pic['id'];
|
|
|
+ $add = [];
|
|
|
+ foreach ($categoryIds as $cat) {
|
|
|
+ $add[] = ['categoryId' => $cat, 'picId' => $currentId, 'merchantId' => $this->merchantId];
|
|
|
+ }
|
|
|
+ PicCategoryService::batchAdd($add);
|
|
|
+ }
|
|
|
+
|
|
|
$data['shortUrl'] = $img;
|
|
|
util::success($data);
|
|
|
}
|