PicController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace business\controllers;
  3. use biz\goods\services\PicCategoryService;
  4. use biz\goods\services\PicService;
  5. use Yii;
  6. use common\components\util;
  7. class PicController extends BaseController
  8. {
  9. //图库列表 shish 2019.12.7
  10. public function actionList()
  11. {
  12. $get = Yii::$app->request->get();
  13. $where = [];
  14. $where['merchantId'] = $this->merchantId;
  15. $categoryId = isset($get['categoryId']) && is_numeric($get['categoryId']) ? $get['categoryId'] : -1;
  16. if ($categoryId != -1) {
  17. $where['categoryId'] = $get['categoryId'];
  18. }
  19. $list = PicCategoryService::getPicList($where);
  20. util::success($list);
  21. }
  22. //上传图片 shish 2019.12.7
  23. public function actionAdd()
  24. {
  25. $img = '/uploads/201905/25/jpg/19052591518_12358.jpg';
  26. $prefix = Yii::$app->params['imgUrl'];
  27. $url = $prefix . $img;
  28. $merchantId = Yii::$app->params['merchantId'];
  29. $time = time();
  30. $name = '未命名';
  31. $data = ['img' => $img, 'merchantId' => $merchantId, 'name' => $name, 'addTime' => $time];
  32. $pic = PicService::add($data);
  33. util::success(['id' => $pic['id'], 'url' => $url, 'shortUrl' => $img]);
  34. }
  35. }