ItemController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }