OrderItemController.php 4.0 KB

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