PicController.php 4.2 KB

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