OrderItemController.php 4.4 KB

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