| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace business\controllers;
- use biz\goods\services\CategoryService;
- use biz\goods\services\PicCategoryService;
- use biz\goods\services\PicService;
- use Yii;
- use common\components\util;
- class PicController extends BaseController
- {
-
- //图库列表 shish 2019.12.7
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['merchantId'] = $this->merchantId;
- $categoryId = isset($get['categoryId']) && is_numeric($get['categoryId']) ? $get['categoryId'] : -1;
- if ($categoryId != -1) {
- $where['categoryId'] = $get['categoryId'];
- }
- $list = PicCategoryService::getPicList($where);
- util::success($list);
- }
-
- //上传图片 shish 2019.12.7
- public function actionAdd()
- {
- $img = '/uploads/201905/25/jpg/19052591518_12358.jpg';
- $prefix = Yii::$app->params['imgUrl'];
- $url = $prefix . $img;
- $merchantId = Yii::$app->params['merchantId'];
- $time = time();
- $name = '未命名';
- $data = ['img' => $img, 'merchantId' => $merchantId, 'name' => $name, 'addTime' => $time];
- $pic = PicService::add($data);
- util::success(['id' => $pic['id'], 'url' => $url, 'shortUrl' => $img]);
- }
-
- //备注图片 shish 2019.12.8
- public function actionRemark()
- {
- $post = Yii::$app->request->post();
- $picIdList = isset($post['picIdList']) && !empty($post['picIdList']) ? $post['picIdList'] : [];
- unset($post['picIdList']);
- if (empty($picIdList)) {
- util::fail('没有图片需要备注');
- }
- $categoryIdList = isset($post['categoryIdList']) && !empty($post['categoryIdList']) ? $post['categoryIdList'] : [];
- unset($post['categoryIdList']);
- $merchantHas = CategoryService::getCategoryIdList($this->merchantId);
- $diff = array_diff($categoryIdList, $merchantHas);
- if (!empty($diff)) {
- util::fail('只能设置自己的分类');
- }
- $picList = PicService::getByIds($picIdList);
- $add = [];
- foreach ($picList as $picKey => $picVal) {
- if ($picVal['merchantId'] != $this->merchantId) {
- util::fail('只能设置自己的图片');
- }
- $currentId = $picVal['id'];
- PicService::updateById($currentId, $post);
- foreach ($categoryIdList as $categoryId) {
- $add[] = ['categoryId' => $categoryId, 'picId' => $currentId, 'merchantId' => $this->merchantId];
- }
- PicCategoryService::deleteByCondition(['picId' => $currentId]);
- }
- PicCategoryService::batchAdd($add);
- util::ok('备注成功');
- }
- }
|