shish 1 год назад
Родитель
Сommit
d98e53e7f7

+ 31 - 0
app-hd/controllers/OrderItemController.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace hd\controllers;
+
+use bizHd\order\classes\OrderItemClass;
+use bizHd\product\classes\ProductClass;
+use Yii;
+use common\components\util;
+
+class OrderItemController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    public function actionGetOrderInfoList()
+    {
+        $get = Yii::$app->request->get();
+        $productId = $get['productId'] ?? 0;
+        $product = ProductClass::getById($productId, true);
+        if (empty($product)) {
+            util::fail('没有找到花材');
+        }
+        if ($product->mainId != $this->mainId) {
+            util::fail('不是你的花材');
+        }
+        $where = ['itemId' => $productId];
+        $respond = OrderItemClass::getOrderInfoList($where);
+        util::success($respond);
+    }
+
+}

+ 76 - 0
biz-hd/order/classes/OrderItemClass.php

@@ -2,9 +2,12 @@
 
 namespace bizHd\order\classes;
 
+use biz\sj\services\MerchantService;
 use biz\stat\classes\StatItemClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\stock\classes\StockRecordClass;
+use bizHd\custom\classes\CustomClass;
+use bizHd\order\services\OrderGoodsService;
 use common\components\dict;
 use common\components\imgUtil;
 use Yii;
@@ -15,6 +18,79 @@ class OrderItemClass extends BaseClass
 
     public static $baseFile = '\bizHd\order\models\OrderItem';
 
+    public static function getOrderInfoList($where)
+    {
+        $respond = self::getList('orderSn,id', $where, 'id DESC');
+        if (!empty($respond['list'])) {
+            $currentList = $respond['list'];
+            $snList = array_column($currentList, 'orderSn');
+            $snList = array_unique(array_filter($snList));
+
+            $order = 'addTime DESC';
+            $where = ['orderSn' => ['in', $snList]];
+            $data = OrderClass::getList('*', $where, $order);
+
+            $myInfoList = [];
+            if (!empty($data['list'])) {
+
+                //获取订单的商品信息
+                $goodsList = OrderGoodsService::getGoodsListByOrderSns($snList);
+
+                //获取订花人的用户信息
+                $orderUserIds = array_column($data['list'], 'customId');
+                $orderUserIds = array_unique(array_filter($orderUserIds));
+                $customList = CustomClass::getCustomByIds($orderUserIds);
+
+                $sjIdList = array_column($data['list'], 'sjId');
+                $sjIdList = array_filter(array_unique($sjIdList));
+                $merchantList = MerchantService::getByIds($sjIdList, null, 'id');
+
+                $periodData = [0 => '上午', 1 => '下午', 2 => '晚上'];
+                $defaultImg = imgUtil::groupImg('');
+                foreach ($data['list'] as $key => $val) {
+                    $id = $val['id'];
+                    $customId = $val['customId'];
+                    $currentActPrice = $val['actPrice'] ?? 0;
+                    $currentSendCost = $val['sendCost'] ?? 0;
+                    $currentPrice = bcsub($currentActPrice, $currentSendCost, 2);
+                    //没有商品显示的样式
+                    $goodsInfoList = [['title' => '', 'coverUrl' => $defaultImg, 'unitPrice' => $currentPrice, 'num' => 1]];
+                    if (isset($goodsList[$id])) {
+                        $goodsInfoList = $goodsList[$id];
+                    }
+                    $data['list'][$key]['goodsInfoList'] = $goodsInfoList;
+                    $data['list'][$key]['bookAvatar'] = isset($customList[$customId]['smallAvatarUrl']) ? $customList[$customId]['smallAvatarUrl'] : '';
+                    $sjId = $val['sjId'];
+                    $data['list'][$key]['name'] = isset($merchantList[$sjId]['name']) ? $merchantList[$sjId]['name'] : '';
+                    $data['list'][$key]['reachTime'] = OrderClass::getReachTime($val);
+                    $requireReachTime = '';
+                    if ($val['reachDate'] != '0000-00-00') {
+                        $reachPeriodId = $val['reachPeriod'];
+                        $reachPeriod = isset($periodData[$reachPeriodId]) ? $periodData[$reachPeriodId] : '上午';
+                        $requireReachTime = date("m-d", strtotime($val['reachDate'])) . ' ' . $reachPeriod;
+                    }
+                    $data['list'][$key]['requireReachTime'] = $requireReachTime;
+                    $shortCover = $val['cover'] ?? '';
+                    $data['list'][$key]['cover'] = imgUtil::groupImg($shortCover);
+                }
+
+                foreach($data['list'] as $key => $val) {
+                    $orderSn = $val['orderSn'];
+                    $myInfoList[$orderSn] = $val;
+                }
+
+            }
+
+            foreach ($respond['list'] as $key => $val) {
+                $orderSn = $val['orderSn'] ?? '';
+                $currentInfo = $myInfoList[$orderSn]??[];
+                $respond['list'][$key]['orderInfo'] = $currentInfo;
+            }
+
+        }
+        return $respond;
+    }
+
     //添加记录
     public static function addData($data, $custom)
     {

+ 1 - 1
biz-hd/order/services/OrderService.php

@@ -352,7 +352,7 @@ class OrderService extends BaseService
         }
 
         $data = self::getList('*', $where, $order);
-        if (isset($data['list']) == false || empty($data['list'])) {
+        if (empty($data['list'])) {
             return $data;
         }