PicController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. $post['price'] = isset($post['price']) && !empty($post['price']) ? $post['price'] : 0;
  44. $picIdList = isset($post['picIdList']) && !empty($post['picIdList']) ? $post['picIdList'] : [];
  45. unset($post['picIdList']);
  46. if (empty($picIdList)) {
  47. util::fail('没有图片需要备注');
  48. }
  49. $categoryIdList = isset($post['categoryIdList']) && !empty($post['categoryIdList']) ? $post['categoryIdList'] : [];
  50. unset($post['categoryIdList']);
  51. if (empty($categoryIdList)) {
  52. util::fail('请选择分类');
  53. }
  54. $merchantHas = CategoryService::getCategoryIdList($this->merchantId);
  55. $diff = array_diff($categoryIdList, $merchantHas);
  56. if (!empty($diff)) {
  57. util::fail('只能选择自己的分类');
  58. }
  59. $picList = PicService::getByIds($picIdList);
  60. $add = [];
  61. foreach ($picList as $picKey => $picVal) {
  62. if ($picVal['merchantId'] != $this->merchantId) {
  63. util::fail('只能设置自己的图片');
  64. }
  65. $currentId = $picVal['id'];
  66. PicService::updateById($currentId, $post);
  67. foreach ($categoryIdList as $categoryId) {
  68. $add[] = ['categoryId' => $categoryId, 'picId' => $currentId, 'merchantId' => $this->merchantId];
  69. }
  70. PicCategoryService::deleteByCondition(['picId' => $currentId]);
  71. }
  72. PicCategoryService::batchAdd($add);
  73. util::complete('备注成功');
  74. }
  75. //查看图片详情 shish 2019.12.8
  76. public function actionDetail()
  77. {
  78. $id = Yii::$app->request->get('id', 0);
  79. $info = PicService::getById($id);
  80. PicService::valid($info, $this->merchantId);
  81. $pic = PicService::getPic($info);
  82. util::success($pic);
  83. }
  84. //删除图片 shish 2019.12.8
  85. public function actionDelete()
  86. {
  87. $id = Yii::$app->request->post('id', 0);
  88. $info = PicService::getById($id);
  89. PicService::valid($info, $this->merchantId);
  90. PicService::delPic($id);
  91. util::complete('删除成功');
  92. }
  93. //置顶 shish 2019.12.8
  94. public function actionTop()
  95. {
  96. $id = Yii::$app->request->post('id', 0);
  97. $info = PicService::getById($id);
  98. PicService::valid($info, $this->merchantId);
  99. PicService::top($info);
  100. util::complete();
  101. }
  102. //发送到微信 shish 2019.12.8
  103. public function actionSendToWx()
  104. {
  105. $id = Yii::$app->request->get('id', 0);
  106. util::complete();
  107. }
  108. //分享 shish 2020.5.8
  109. public function actionShare()
  110. {
  111. util::fail('即将开通');
  112. }
  113. }