CpController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\cp\classes\CpClass;
  4. use bizGhs\cp\classes\CpClassClass;
  5. use common\components\imgUtil;
  6. use common\components\stringUtil;
  7. use common\components\util;
  8. use Yii;
  9. class CpController extends BaseController
  10. {
  11. //根据分类id取集合,带分页 ssh 20231228
  12. public function actionList()
  13. {
  14. $get = Yii::$app->request->get();
  15. $classId = $get['classId'] ?? 0;
  16. $search = $get['search'] ?? '';
  17. $mainId = $this->mainId ?? 0;
  18. $where = [];
  19. $where['mainId'] = $mainId;
  20. $where['delStatus'] = 0;
  21. if (!empty($search)) {
  22. if (stringUtil::isLetter($search)) {
  23. $where['py'] = ['like', $search];
  24. } else {
  25. $where['name'] = ['like', $search];
  26. }
  27. } else {
  28. if (!empty($classId)) {
  29. $where['classId'] = $classId;
  30. }
  31. }
  32. $respond = CpClass::getCpList($where);
  33. util::success($respond);
  34. }
  35. //添加产品 ssh 20240106
  36. public function actionAddCp()
  37. {
  38. $post = Yii::$app->request->post();
  39. $post['mainId'] = $this->mainId;
  40. $post['adminId'] = $this->adminId;
  41. if (isset($post['name']) == false || empty($post['name'])) {
  42. util::fail('请填写名称');
  43. }
  44. $post['py'] = stringUtil::py($post['name']);
  45. $staff = $this->shopAdmin;
  46. $staffName = $staff->name ?? '';
  47. $post['staffName'] = $staffName;
  48. $shop = $this->shop;
  49. unset($post['id']);
  50. CpClass::addCp($post, $shop);
  51. util::complete('添加成功');
  52. }
  53. public function actionUpdateCp()
  54. {
  55. util::complete();
  56. }
  57. //查看详情 ssh 20240219
  58. public function actionDetail()
  59. {
  60. $get = Yii::$app->request->get();
  61. $id = $get['id'] ?? 0;
  62. $cp = CpClass::getById($id);
  63. if ($cp['mainId'] != $this->mainId) {
  64. util::fail('无法查看');
  65. }
  66. $classId = $cp['classId'] ?? 0;
  67. $class = CpClassClass::getById($classId, true);
  68. $className = $class->name ?? '';
  69. $shortCover = $class->cover ?? '';
  70. $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  71. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  72. $cp['shortCover'] = $shortCover;
  73. $cp['cover'] = $smallCover;
  74. $cp['smallCover'] = $smallCover;
  75. $cp['bigCover'] = $bigCover;
  76. $cp['className'] = $className;
  77. util::success($cp);
  78. }
  79. }