PicController.php 3.3 KB

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