OrderItemController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. util::complete('删除成功');
  18. }
  19. //添加花材
  20. public function actionAddItem()
  21. {
  22. util::complete('添加成功');
  23. }
  24. //赠送花材 ssh 20230411
  25. public function actionGiveItem()
  26. {
  27. $post = Yii::$app->request->post();
  28. $id = $post['id'] ?? 0;
  29. $num = $post['num'] ?? 0;
  30. if (is_numeric($num) == false || $num <= 0) {
  31. util::fail('请填写赠送数量');
  32. }
  33. $orderItem = OrderItemClass::getById($id, true);
  34. if (empty($orderItem)) {
  35. util::fail('没有找到花材');
  36. }
  37. if ($orderItem->mainId != $this->mainId) {
  38. util::fail('无法操作');
  39. }
  40. util::fail('开发中');
  41. $connection = Yii::$app->db;//事务处理
  42. $transaction = $connection->beginTransaction();
  43. try {
  44. $staff = $this->shopAdmin;
  45. $staffName = $staff->name ?? '';
  46. $staffId = $staff->id ?? 0;
  47. $data = ['shopId' => $this->shopId, 'sjId' => $this->sjId, 'staffName' => $staffName, 'staffId' => $staffId];
  48. $respond = OrderItemService::giveProduct($data, $orderItem, $num);
  49. $transaction->commit();
  50. util::success(['info' => $respond], '赠送成功');
  51. } catch (\Exception $e) {
  52. $transaction->rollBack();
  53. Yii::info("赠送出错了:" . $e->getMessage());
  54. util::fail('出错了');
  55. }
  56. }
  57. //重选花材 ssh 2021.3.2
  58. public function actionReset()
  59. {
  60. $post = Yii::$app->request->post();
  61. $id = $post['id'] ?? 0;
  62. $product = $post['product'] ?? '[]';
  63. $product = json_decode($product, true);
  64. //检查花材是否都是同家门店的
  65. ProductClass::valid($product, $this->mainId);
  66. $info = OrderService::getOrderInfo($id);
  67. OrderClass::valid($info, $this->shopId);
  68. //添加修改花材
  69. $orderSn = $info['orderSn'] ?? '';
  70. OrderItemClass::replaceItem($orderSn, $product);
  71. util::complete();
  72. }
  73. //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809
  74. public function actionGetOrderProduct()
  75. {
  76. $id = Yii::$app->request->get('id', 0);
  77. $order = OrderClass::getById($id, true);
  78. OrderClass::valid($order, $this->shopId);
  79. $orderSn = $order->orderSn ?? '';
  80. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId');
  81. $ids = array_column($itemList, 'productId');
  82. if (empty($ids)) {
  83. util::fail('没有找到花材');
  84. }
  85. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  86. if (empty($productList)) {
  87. util::fail('没有找到花材信息');
  88. }
  89. foreach ($productList as $key => $product) {
  90. $productId = $product['id'] ?? 0;
  91. $currentItem = $itemList[$productId] ?? [];
  92. $bigCount = $currentItem['bigNum'] ?? 0;
  93. $smallCount = $currentItem['smallNum'] ?? 0;
  94. $userPrice = $currentItem['userPrice'] ?? 0;
  95. $productList[$key]['bigCount'] = $bigCount;
  96. $productList[$key]['smallCount'] = $smallCount;
  97. $productList[$key]['userPrice'] = $userPrice;
  98. $cover = imgUtil::groupImg($product['cover']);
  99. $productList[$key]['cover'] = $cover;
  100. $bigPrice = $product['unitPrice'] ?? 0;
  101. $smallPrice = $product['smallUnitPrice'] ?? 0;
  102. $productList[$key]['bigPrice'] = $bigPrice;
  103. $productList[$key]['smallPrice'] = $smallPrice;
  104. $productList[$key]['cover'] = $cover;
  105. }
  106. util::success(['productList' => array_values($productList)]);
  107. }
  108. //根据花材id取订单列表 ssh 20211011
  109. public function actionGetOrderInfoList()
  110. {
  111. $get = Yii::$app->request->get();
  112. $productId = $get['productId'] ?? 0;
  113. $product = ProductClass::getById($productId, true);
  114. ProductClass::check($product, $this->mainId);
  115. $where = ['productId' => $productId];
  116. $respond = OrderItemClass::getOrderInfoList($where);
  117. util::success($respond);
  118. }
  119. }