PicController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace business\controllers;
  3. use biz\goods\services\CategoryService;
  4. use biz\goods\services\PicCategoryService;
  5. use biz\goods\services\PicService;
  6. use Yii;
  7. use common\components\util;
  8. class PicController extends BaseController
  9. {
  10. //图库列表 shish 2019.12.7
  11. public function actionList()
  12. {
  13. $get = Yii::$app->request->get();
  14. $where = [];
  15. $where['merchantId'] = $this->merchantId;
  16. $categoryId = isset($get['categoryId']) && is_numeric($get['categoryId']) ? $get['categoryId'] : -1;
  17. if ($categoryId != -1) {
  18. $where['categoryId'] = $get['categoryId'];
  19. }
  20. $list = PicCategoryService::getPicList($where);
  21. util::success($list);
  22. }
  23. //上传图片 shish 2019.12.7
  24. public function actionAdd()
  25. {
  26. $img = '/uploads/201905/25/jpg/19052591518_12358.jpg';
  27. $prefix = Yii::$app->params['imgHost'];
  28. $url = $prefix . $img;
  29. $merchantId = $this->merchantId;
  30. $time = time();
  31. $name = '未命名';
  32. $data = ['img' => $img, 'merchantId' => $merchantId, 'name' => $name, 'addTime' => $time];
  33. $pic = PicService::add($data);
  34. util::success(['id' => $pic['id'], 'url' => $url, 'shortUrl' => $img]);
  35. }
  36. //备注图片 shish 2019.12.8
  37. public function actionRemark()
  38. {
  39. $post = Yii::$app->request->post();
  40. $picIdList = isset($post['picIdList']) && !empty($post['picIdList']) ? $post['picIdList'] : [];
  41. unset($post['picIdList']);
  42. if (empty($picIdList)) {
  43. util::fail('没有图片需要备注');
  44. }
  45. $categoryIdList = isset($post['categoryIdList']) && !empty($post['categoryIdList']) ? $post['categoryIdList'] : [];
  46. unset($post['categoryIdList']);
  47. $merchantHas = CategoryService::getCategoryIdList($this->merchantId);
  48. $diff = array_diff($categoryIdList, $merchantHas);
  49. if (!empty($diff)) {
  50. util::fail('只能设置自己的分类');
  51. }
  52. $picList = PicService::getByIds($picIdList);
  53. $add = [];
  54. foreach ($picList as $picKey => $picVal) {
  55. if ($picVal['merchantId'] != $this->merchantId) {
  56. util::fail('只能设置自己的图片');
  57. }
  58. $currentId = $picVal['id'];
  59. PicService::updateById($currentId, $post);
  60. foreach ($categoryIdList as $categoryId) {
  61. $add[] = ['categoryId' => $categoryId, 'picId' => $currentId, 'merchantId' => $this->merchantId];
  62. }
  63. PicCategoryService::deleteByCondition(['picId' => $currentId]);
  64. }
  65. PicCategoryService::batchAdd($add);
  66. util::ok('备注成功');
  67. }
  68. //查看图片详情 shish 2019.12.8
  69. public function actionDetail()
  70. {
  71. $id = Yii::$app->request->get('id', 0);
  72. $info = PicService::getById($id);
  73. PicService::valid($info, $this->merchantId);
  74. $pic = PicService::getPic($info);
  75. util::success($pic);
  76. }
  77. //删除图片 shish 2019.12.8
  78. public function actionDelete()
  79. {
  80. $id = Yii::$app->request->get('id', 0);
  81. $info = PicService::getById($id);
  82. PicService::valid($info, $this->merchantId);
  83. PicService::delPic($id);
  84. util::ok('删除成功');
  85. }
  86. //置顶 shish 2019.12.8
  87. public function actionTop()
  88. {
  89. $id = Yii::$app->request->get('id', 0);
  90. $info = PicService::getById($id);
  91. PicService::valid($info, $this->merchantId);
  92. PicService::top($info);
  93. util::ok();
  94. }
  95. //发送到微信 shish 2019.12.8
  96. public function actionSendToWx()
  97. {
  98. $id = Yii::$app->request->get('id', 0);
  99. util::ok();
  100. }
  101. }