CpController.php 1.9 KB

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