OrderItemController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\OrderClass;
  4. use bizGhs\order\classes\OrderItemClass;
  5. use bizGhs\order\services\OrderItemService;
  6. use bizGhs\order\services\OrderService;
  7. use bizGhs\product\classes\ProductClass;
  8. use common\components\imgUtil;
  9. use common\components\util;
  10. use Yii;
  11. class OrderItemController extends BaseController
  12. {
  13. public $guestAccess = [];
  14. //删除花材 ssh 20240123
  15. public function actionDelItem()
  16. {
  17. $post = Yii::$app->request->post();
  18. $id = $post['id'] ?? 0;
  19. $smallId = $post['smallId'] ?? 0;
  20. $order = OrderClass::getById($id, true);
  21. if (empty($order)) {
  22. util::fail('没有订单');
  23. }
  24. if ($order->book == 0) {
  25. util::fail('不是预订单');
  26. }
  27. if (floatval($order->actPrice) != 0) {
  28. util::fail('订单金额不是0');
  29. }
  30. util::complete('删除成功');
  31. }
  32. //添加花材
  33. public function actionAddItem()
  34. {
  35. $post = Yii::$app->request->post();
  36. $id = $post['id'] ?? 0;
  37. $data = $post['data'] ?? 0;
  38. $arr = json_decode($data, true);
  39. $order = OrderClass::getById($id, true);
  40. if (empty($order)) {
  41. util::fail('没有订单');
  42. }
  43. if ($order->book == 0) {
  44. util::fail('不是预订单');
  45. }
  46. if (floatval($order->actPrice) != 0) {
  47. util::fail('订单金额不是0');
  48. }
  49. print_r($arr);
  50. die;
  51. util::complete('添加成功');
  52. }
  53. //赠送花材 ssh 20230411
  54. public function actionGiveItem()
  55. {
  56. $post = Yii::$app->request->post();
  57. $id = $post['id'] ?? 0;
  58. $num = $post['num'] ?? 0;
  59. if (is_numeric($num) == false || $num <= 0) {
  60. util::fail('请填写赠送数量');
  61. }
  62. $orderItem = OrderItemClass::getById($id, true);
  63. if (empty($orderItem)) {
  64. util::fail('没有找到花材');
  65. }
  66. if ($orderItem->mainId != $this->mainId) {
  67. util::fail('无法操作');
  68. }
  69. util::fail('开发中');
  70. $connection = Yii::$app->db;//事务处理
  71. $transaction = $connection->beginTransaction();
  72. try {
  73. $staff = $this->shopAdmin;
  74. $staffName = $staff->name ?? '';
  75. $staffId = $staff->id ?? 0;
  76. $data = ['shopId' => $this->shopId, 'sjId' => $this->sjId, 'staffName' => $staffName, 'staffId' => $staffId];
  77. $respond = OrderItemService::giveProduct($data, $orderItem, $num);
  78. $transaction->commit();
  79. util::success(['info' => $respond], '赠送成功');
  80. } catch (\Exception $e) {
  81. $transaction->rollBack();
  82. Yii::info("赠送出错了:" . $e->getMessage());
  83. util::fail('出错了');
  84. }
  85. }
  86. //重选花材 ssh 2021.3.2
  87. public function actionReset()
  88. {
  89. $post = Yii::$app->request->post();
  90. $id = $post['id'] ?? 0;
  91. $product = $post['product'] ?? '[]';
  92. $product = json_decode($product, true);
  93. //检查花材是否都是同家门店的
  94. ProductClass::valid($product, $this->mainId);
  95. $info = OrderService::getOrderInfo($id);
  96. OrderClass::valid($info, $this->shopId);
  97. //添加修改花材
  98. $orderSn = $info['orderSn'] ?? '';
  99. OrderItemClass::replaceItem($orderSn, $product);
  100. util::complete();
  101. }
  102. //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809
  103. public function actionGetOrderProduct()
  104. {
  105. $id = Yii::$app->request->get('id', 0);
  106. $order = OrderClass::getById($id, true);
  107. OrderClass::valid($order, $this->shopId);
  108. $orderSn = $order->orderSn ?? '';
  109. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId');
  110. $ids = array_column($itemList, 'productId');
  111. if (empty($ids)) {
  112. util::fail('没有找到花材');
  113. }
  114. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  115. if (empty($productList)) {
  116. util::fail('没有找到花材信息');
  117. }
  118. foreach ($productList as $key => $product) {
  119. $productId = $product['id'] ?? 0;
  120. $currentItem = $itemList[$productId] ?? [];
  121. $bigCount = $currentItem['bigNum'] ?? 0;
  122. $smallCount = $currentItem['smallNum'] ?? 0;
  123. $userPrice = $currentItem['userPrice'] ?? 0;
  124. $productList[$key]['bigCount'] = $bigCount;
  125. $productList[$key]['smallCount'] = $smallCount;
  126. $productList[$key]['userPrice'] = $userPrice;
  127. $cover = imgUtil::groupImg($product['cover']);
  128. $productList[$key]['cover'] = $cover;
  129. $bigPrice = $product['unitPrice'] ?? 0;
  130. $smallPrice = $product['smallUnitPrice'] ?? 0;
  131. $productList[$key]['bigPrice'] = $bigPrice;
  132. $productList[$key]['smallPrice'] = $smallPrice;
  133. $productList[$key]['cover'] = $cover;
  134. }
  135. util::success(['productList' => array_values($productList)]);
  136. }
  137. //根据花材id取订单列表 ssh 20211011
  138. public function actionGetOrderInfoList()
  139. {
  140. $get = Yii::$app->request->get();
  141. $productId = $get['productId'] ?? 0;
  142. $product = ProductClass::getById($productId, true);
  143. ProductClass::check($product, $this->mainId);
  144. $where = ['productId' => $productId];
  145. $respond = OrderItemClass::getOrderInfoList($where);
  146. util::success($respond);
  147. }
  148. }