PicTextController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\CategoryClass;
  4. use Yii;
  5. use bizHd\pictext\classes\PicTextClass;
  6. use common\components\util;
  7. class PicTextController extends BaseController
  8. {
  9. public function actionList()
  10. {
  11. $where = [];
  12. $where['mainId'] = $this->mainId;
  13. $where['delStatus'] = 0;
  14. $where['type'] = 1;
  15. $list = PicTextClass::getList('id, title, addTime', $where, 'addTime desc');
  16. util::success($list);
  17. }
  18. public function actionAdd()
  19. {
  20. $post = Yii::$app->request->post();
  21. $content = $post['content'];
  22. $post['content'] = $content;
  23. $post['mainId'] = $this->mainId;
  24. // $post['staffId'] = intval($this->shopAdmin->id);
  25. // 类别 1. 花束分类说明(运用于分类的商品) 2. 商品特有说明(非商品简介,优先级可高于分类说明) 3. 售前与售后说明
  26. $post['type'] = PicTextClass::TYPE_CATEGORY; // type 默认为 1
  27. $id = PicTextClass::add($post);
  28. util::success($id);
  29. }
  30. public function actionUpdate()
  31. {
  32. $post = Yii::$app->request->post();
  33. $id = $post['id'];
  34. $picText = PicTextClass::getById($id, true);
  35. if (empty($picText)) {
  36. util::fail('没有找到图文');
  37. }
  38. if ($picText->mainId != $this->mainId) {
  39. util::fail('没有权限修改');
  40. }
  41. $post['staffId'] = intval($this->shopAdmin->id);
  42. $id = PicTextClass::updateById($id, $post);
  43. util::success('修改成功');
  44. }
  45. public function actionUpdateCategoryId()
  46. {
  47. $post = Yii::$app->request->post();
  48. $id = $post['id'];
  49. $categoryId = intval($post['categoryId']);
  50. if ($categoryId <= 0) {
  51. util::fail('分类id出错');
  52. }
  53. $picText = PicTextClass::getById($id, true, 'id, mainId, type');
  54. if (empty($picText)) {
  55. util::fail('没有找到图文');
  56. }
  57. if ($picText->type != PicTextClass::TYPE_CATEGORY) {
  58. util::fail('图文类型不支持设置分类');
  59. }
  60. if ($picText->mainId != $this->mainId) {
  61. util::fail('没有权限修改');
  62. }
  63. $updateCount = CategoryClass::updateByCondition(['id' => $categoryId, 'mainId' => $this->mainId], ['picTextId' => $id]);
  64. //CategoryClass::updateById($id, ['picTextId' => $id]);
  65. if ($updateCount <= 0) {
  66. util::fail('变更失败');
  67. }
  68. util::success('变更成功');
  69. }
  70. public function actionDel()
  71. {
  72. $id = intval(Yii::$app->request->post('id'));
  73. $picText = PicTextClass::getById($id, true);
  74. if (empty($picText)) {
  75. util::fail('图文id不对');
  76. }
  77. if ($picText->mainId != $this->mainId) {
  78. util::fail('没有权限');
  79. }
  80. PicTextClass::updateById($id, ['delStatus'=>1]);
  81. util::complete('成功删除');
  82. }
  83. public function actionDetail()
  84. {
  85. $id = intval(Yii::$app->request->get('id'));
  86. $picText = PicTextClass::getById($id, true);
  87. if (empty($picText)) {
  88. util::fail('没有找到图片');
  89. }
  90. if ($picText->mainId != $this->mainId) {
  91. util::fail('没有权限');
  92. }
  93. util::success($picText);
  94. }
  95. }