GoodsController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: admin
  5. * Date: 2019/12/1
  6. * Time: 13:55
  7. */
  8. namespace business\controllers;
  9. use Yii;
  10. use common\components\util;
  11. use biz\goods\services\GoodsService;
  12. class GoodsController extends BaseController
  13. {
  14. //商品列表 shish 2019.12.7
  15. public function actionList()
  16. {
  17. $where = ['merchantId' => $this->merchantId];
  18. $list = GoodsService::getGoodsList($where);
  19. util::success($list);
  20. }
  21. //添加商品 shish 2019.12.7
  22. public function actionAdd()
  23. {
  24. $data = Yii::$app->request->post();
  25. $data['merchantId'] = $this->merchantId;
  26. $return = GoodsService::addGoods($data);
  27. $id = $return['id'];
  28. $info = GoodsService::getById($id);
  29. util::success($info);
  30. }
  31. //获取商品详情 shish 2019.12.7
  32. public function actionDetail()
  33. {
  34. $id = Yii::$app->request->get('id');
  35. $goods = GoodsService::getGoodsInfo($id);
  36. util::success($goods);
  37. }
  38. //更新商品 shish 2019.12.7
  39. public function actionUpdate()
  40. {
  41. $data = Yii::$app->request->post();
  42. $id = isset($data['id']) ? $data['id'] : 0;
  43. unset($data['id']);
  44. GoodsService::valid($id, $this->merchantId);
  45. $data['merchantId'] = $this->merchantId;
  46. GoodsService::updateGoods($id, $data);
  47. util::ok();
  48. }
  49. //删除商品 shish 2019.12.7
  50. public function actionDelete()
  51. {
  52. $id = Yii::$app->request->get('id', 0);
  53. GoodsService::deleteGoods($id, $this->admin);
  54. util::success();
  55. }
  56. }