CpController.php 2.1 KB

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