ItemController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if(empty($data)){
  35. util::fail("参数错误");
  36. }
  37. $data = json_decode($data,true);
  38. if(!is_array($data) || empty($data)){
  39. util::fail("参数格式错误");
  40. }
  41. foreach ($data as $v){
  42. $v['adminId'] = $this->adminId;
  43. $v['sjId'] = $this->sjId;
  44. ItemService::addGhsItem($v);
  45. }
  46. util::complete('添加成功');
  47. }
  48. public function actionUpdate()
  49. {
  50. $data = Yii::$app->request->post();
  51. $data['adminId'] = $this->adminId;
  52. $data['sjId'] = $this->sjId;
  53. ItemService::updateGshItem($data);
  54. util::complete('修改成功');
  55. }
  56. public function actionDelete()
  57. {
  58. util::fail('不能删除哦!');
  59. }
  60. //获取平台里的花材信息
  61. public function actionPlatformItem()
  62. {
  63. $py = Yii::$app->request->get('py', '');
  64. $where = [];
  65. if ($py) {
  66. $where = ['py' => $py];
  67. }
  68. $list = PtItemClass::getItemList($where);
  69. util::success($list);
  70. }
  71. }