OrderItemController.php 3.1 KB

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