GoodsController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. GoodsService::updateGoods($id, $data);
  46. util::ok();
  47. }
  48. //删除商品 shish 2019.12.7
  49. public function actionDelete()
  50. {
  51. $id = Yii::$app->request->get('id', 0);
  52. GoodsService::deleteGoods($id, $this->admin);
  53. util::success();
  54. }
  55. }