GoodsController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace addons\StarChain\backend\controllers;
  3. use addons\StarChain\common\services\CategorysService;
  4. use addons\StarChain\common\services\SpuService;
  5. /**
  6. * 商品
  7. */
  8. class GoodsController extends BaseController
  9. {
  10. /**
  11. * 商品列表
  12. *
  13. * @return string
  14. */
  15. public function actionIndex()
  16. {
  17. if ($this->request->isAjax) {
  18. $params = $this->request->getBodyParams();
  19. unset($params['_csrf']);
  20. $service = new SpuService(['mall_id' => $this->mall_id]);
  21. $data = $service->getSpuList($params);
  22. return $data
  23. ? $this->success('ok', $data)
  24. : $this->error($service->error);
  25. }
  26. return $this->render($this->action->id);
  27. }
  28. /**
  29. * 获取分类
  30. *
  31. * @return string
  32. */
  33. public function actionCategory()
  34. {
  35. if ($this->request->isAjax) {
  36. $pid = $this->request->getQueryParam('pid', 0);
  37. $service = new CategorysService(['mall_id' => $this->mall_id]);
  38. return $this->success('ok', $service->list($pid));
  39. }
  40. }
  41. /**
  42. * 商品导入
  43. *
  44. * @return string
  45. */
  46. public function actionStorageAdd()
  47. {
  48. if ($this->request->isAjax) {
  49. $ids = $this->request->getBodyParam('ids');
  50. $service = new SpuService(['mall_id' => $this->mall_id]);
  51. return $service->import($ids)
  52. ? $this->success('ok')
  53. : $this->error($service->error);
  54. }
  55. }
  56. }