PicController.php 3.4 KB

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