ItemController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 bizGhs\product\classes\ProductClass;
  8. use Yii;
  9. class ItemController extends BaseController
  10. {
  11. //列出所有花材,包括特价花材列表 ssh 20220315
  12. public function actionShowList()
  13. {
  14. $where['mainId'] = $this->mainId;
  15. $where['delStatus'] = 0;
  16. $list = ItemClass::getShowList($where);
  17. util::success(['list' => $list]);
  18. }
  19. public function actionAdd()
  20. {
  21. $post = Yii::$app->request->post();
  22. $post['adminId'] = $this->adminId;
  23. $post['sjId'] = $this->sjId;
  24. $connection = Yii::$app->db;//事务处理
  25. $transaction = $connection->beginTransaction();
  26. try {
  27. ItemService::addGhsItem($post);
  28. $transaction->commit();
  29. util::complete('添加成功');
  30. } catch (Exception $e) {
  31. $transaction->rollBack();
  32. util::fail('添加失败');
  33. }
  34. }
  35. //批量添加花材
  36. public function actionBatchAdd()
  37. {
  38. $shopAdmin = $this->shopAdmin;
  39. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  40. util::fail('超管才能操作');
  41. }
  42. $post = Yii::$app->request->post();
  43. //[{itemId:1000,classId:2,price:1,stockWarning:1}]
  44. $data = $post['data'];
  45. if (empty($data)) {
  46. util::fail("请选花材");
  47. }
  48. $data = json_decode($data, true);
  49. if (!is_array($data) || empty($data)) {
  50. util::fail("请选花材");
  51. }
  52. $sjId = $this->sjId;
  53. $ids = array_column($data,'itemId');
  54. $ids = array_unique(array_filter($ids));
  55. $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId'=>['in',$ids]]);
  56. if(!empty($has)){
  57. util::fail("有花材已经添加过了");
  58. }
  59. $connection = Yii::$app->db;//事务处理
  60. $transaction = $connection->beginTransaction();
  61. try {
  62. foreach ($data as $v) {
  63. $v['adminId'] = $this->adminId;
  64. $v['sjId'] = $sjId;
  65. ItemService::addGhsItem($v);
  66. }
  67. $transaction->commit();
  68. util::complete('添加成功');
  69. } catch (Exception $e) {
  70. $transaction->rollBack();
  71. util::fail();
  72. }
  73. }
  74. public function actionDelete()
  75. {
  76. util::fail('不能删除哦!');
  77. }
  78. //获取平台里的花材信息
  79. public function actionPlatformItem()
  80. {
  81. $py = Yii::$app->request->get('py', '');
  82. $where = [];
  83. if ($py) {
  84. $where = ['py' => $py];
  85. }
  86. $list = PtItemClass::getItemList($where);
  87. util::success($list);
  88. }
  89. }