OrderItemController.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 actionGive()
  15. {
  16. util::success([]);
  17. }
  18. //重选花材 ssh 2021.3.2
  19. public function actionReset()
  20. {
  21. $post = Yii::$app->request->post();
  22. $id = $post['id'] ?? 0;
  23. $product = $post['product'] ?? '[]';
  24. $product = json_decode($product, true);
  25. //检查花材是否都是同家门店的
  26. ProductClass::valid($product, $this->mainId);
  27. $info = OrderService::getOrderInfo($id);
  28. OrderClass::valid($info, $this->shopId);
  29. //添加修改花材
  30. $orderSn = $info['orderSn'] ?? '';
  31. OrderItemClass::replaceItem($orderSn, $product);
  32. util::complete();
  33. }
  34. //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809
  35. public function actionGetOrderProduct()
  36. {
  37. $id = Yii::$app->request->get('id', 0);
  38. $order = OrderClass::getById($id, true);
  39. OrderClass::valid($order, $this->shopId);
  40. $orderSn = $order->orderSn ?? '';
  41. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId');
  42. $ids = array_column($itemList, 'productId');
  43. if (empty($ids)) {
  44. util::fail('没有找到花材');
  45. }
  46. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  47. if (empty($productList)) {
  48. util::fail('没有找到花材信息');
  49. }
  50. foreach ($productList as $key => $product) {
  51. $productId = $product['id'] ?? 0;
  52. $currentItem = $itemList[$productId] ?? [];
  53. $bigCount = $currentItem['bigNum'] ?? 0;
  54. $smallCount = $currentItem['smallNum'] ?? 0;
  55. $userPrice = $currentItem['userPrice'] ?? 0;
  56. $productList[$key]['bigCount'] = $bigCount;
  57. $productList[$key]['smallCount'] = $smallCount;
  58. $productList[$key]['userPrice'] = $userPrice;
  59. $cover = imgUtil::groupImg($product['cover']);
  60. $productList[$key]['cover'] = $cover;
  61. $bigPrice = $product['unitPrice'] ?? 0;
  62. $smallPrice = $product['smallUnitPrice'] ?? 0;
  63. $productList[$key]['bigPrice'] = $bigPrice;
  64. $productList[$key]['smallPrice'] = $smallPrice;
  65. $productList[$key]['cover'] = $cover;
  66. }
  67. util::success(['productList' => array_values($productList)]);
  68. }
  69. //根据花材id取订单列表 ssh 20211011
  70. public function actionGetOrderInfoList()
  71. {
  72. $get = Yii::$app->request->get();
  73. $productId = $get['productId'] ?? 0;
  74. $product = ProductClass::getById($productId, true);
  75. ProductClass::check($product, $this->mainId);
  76. $where = ['productId' => $productId];
  77. $respond = OrderItemClass::getOrderInfoList($where);
  78. util::success($respond);
  79. }
  80. }