PicController.php 4.1 KB

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