ItemController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use bizGhs\item\services\ItemService;
  6. use common\components\util;
  7. use common\services\xhItemService;
  8. use Yii;
  9. class ItemController extends BaseController
  10. {
  11. public function actionList()
  12. {
  13. $classId = Yii::$app->request->get('classId', 0);
  14. $where['sjId'] = $this->sjId;
  15. if (!empty($classId)) {
  16. $where['classId'] = $classId;
  17. }
  18. $list = ItemClass::getGhsItemList($where);
  19. util::success($list);
  20. }
  21. public function actionAdd()
  22. {
  23. $post = Yii::$app->request->post();
  24. $post['adminId'] = $this->adminId;
  25. // $post['shopId'] = $this->shopId;
  26. $post['sjId'] = $this->sjId;
  27. ItemService::addGhsItem($post);
  28. util::complete('添加成功');
  29. }
  30. public function actionBatchAdd()
  31. {
  32. $post = Yii::$app->request->post();
  33. $data = $post['data']; //[{itemId:1000,classId:2,cost:1,addPrice:1,stockWarning:1}]
  34. //2021.7.11 linqh 参数改为 只传售价,成本价和加价各取一半[{itemId:1000,classId:2,price:1,stockWarning:1}]
  35. if (empty($data)) {
  36. util::fail("请选花材");
  37. }
  38. $data = json_decode($data, true);
  39. if (!is_array($data) || empty($data)) {
  40. util::fail("请选花材");
  41. }
  42. foreach ($data as $v) {
  43. $v['adminId'] = $this->adminId;
  44. $v['sjId'] = $this->sjId;
  45. ItemService::addGhsItem($v);
  46. }
  47. util::complete('添加成功');
  48. }
  49. public function actionUpdate()
  50. {
  51. $data = Yii::$app->request->post();
  52. $data['adminId'] = $this->adminId;
  53. $data['sjId'] = $this->sjId;
  54. ItemService::updateGshItem($data);
  55. util::complete('修改成功');
  56. }
  57. public function actionDelete()
  58. {
  59. util::fail('不能删除哦!');
  60. }
  61. //获取平台里的花材信息
  62. public function actionPlatformItem()
  63. {
  64. $py = Yii::$app->request->get('py', '');
  65. $where = [];
  66. if ($py) {
  67. $where = ['py' => $py];
  68. }
  69. $list = PtItemClass::getItemList($where);
  70. util::success($list);
  71. }
  72. }