ItemController.php 3.8 KB

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