ItemController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace hd\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use bizGhs\item\services\ItemService;
  6. use bizHd\product\classes\ProductClass;
  7. use common\components\dict;
  8. use common\components\util;
  9. use Yii;
  10. class ItemController extends BaseController
  11. {
  12. //增加和减少半扎 ssh 20250417
  13. public function actionChangeHalf()
  14. {
  15. $post = Yii::$app->request->post();
  16. $productId = $post['productId'] ?? '';
  17. $add = $post['add'] ?? 0;
  18. $remark = $post['remark'] ?? '';
  19. $product = ProductClass::getLockById($productId);
  20. if (empty($product)) {
  21. util::fail('没有找到花材');
  22. }
  23. if ($product->mainId != $this->mainId) {
  24. util::fail('不是你的花材');
  25. }
  26. if ($product->ratioType == 1) {
  27. util::fail('若干扎的花材不能减半份');
  28. }
  29. //避免重复提交
  30. util::checkRepeatCommit($this->adminId, 4);
  31. $connection = Yii::$app->db;
  32. $transaction = $connection->beginTransaction();
  33. try {
  34. $shop = $this->shop;
  35. $staff = $this->shopAdmin;
  36. $staffName = $staff->name ?? '';
  37. $staffId = $staff->id;
  38. $adminId = $this->adminId;
  39. $params = [
  40. 'staffId' => $staffId,
  41. 'staffName' => $staffName,
  42. 'adminId' => $adminId,
  43. 'remark' => $remark,
  44. ];
  45. ItemClass::modifyHalf($shop, $product, $params, $add);
  46. $product = ProductClass::getLockById($productId);
  47. $stock = $product->stock;
  48. $stock = floatval($stock);
  49. $transaction->commit();
  50. util::success(['stock' => $stock]);
  51. } catch (\Exception $e) {
  52. $transaction->rollBack();
  53. Yii::info("加减半份失败原因:" . $e->getMessage());
  54. util::fail('加减半份失败');
  55. }
  56. }
  57. //检测是否要刷新
  58. public function actionCheckRefresh()
  59. {
  60. $mainId = $this->mainId;
  61. $staffId = $this->shopAdminId;
  62. $respond = Yii::$app->redis->executeCommand('GET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  63. if ($respond == 'yes') {
  64. util::success(['remind' => 1]);
  65. }
  66. util::complete();
  67. }
  68. //列出所有花材,包括特价花材列表 ssh 20220315
  69. public function actionShowList()
  70. {
  71. $headers = Yii::$app->getRequest()->getHeaders();
  72. $requestVersion = $headers->get('appVersion');
  73. $currentVersion = dict::getDict('appVersion');
  74. if ($requestVersion < $currentVersion) {
  75. util::fail('请先升级系统');
  76. }
  77. $get = Yii::$app->request->get();
  78. $isCashier = $get['isCashier'] ?? 0;
  79. $mainId = $this->mainId;
  80. if ($isCashier == 1) {
  81. //去掉收银台提示价格更新
  82. $staffId = $this->shopAdminId;
  83. Yii::$app->redis->executeCommand('DEL', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  84. }
  85. $where['mainId'] = $mainId;
  86. $where['delStatus'] = 0;
  87. $where['status'] = 1;
  88. $list = \bizHd\item\classes\ItemClass::getShowList($where);
  89. util::success(['list' => $list]);
  90. }
  91. public function actionAdd()
  92. {
  93. util::fail('开发中');
  94. }
  95. public function actionBatchAdd()
  96. {
  97. util::fail('开发中');
  98. }
  99. public function actionDelete()
  100. {
  101. util::fail('不能删除哦!');
  102. }
  103. //获取平台里的花材信息
  104. public function actionPlatformItem()
  105. {
  106. $py = Yii::$app->request->get('py', '');
  107. $where = [];
  108. if ($py) {
  109. $where = ['py' => $py];
  110. }
  111. $list = PtItemClass::getItemList($where);
  112. util::success($list);
  113. }
  114. }