shish hace 5 años
padre
commit
93cf729b67

+ 25 - 0
app-ghs/controllers/ShopExtController.php

@@ -63,4 +63,29 @@ class ShopExtController extends BaseController
         util::success($ext);
     }
 
+    //添加修改小菊颜色 shish 20210906
+    public function actionReplaceXj()
+    {
+        $act = Yii::$app->request->get('act', 'add');
+        $id = Yii::$app->request->get('id', 0);
+        $xj = $this->shopExt->xj;
+        $hasIds = [];
+        if (!empty($xj)) {
+            $hasIds = json_decode($xj, true);
+        }
+        if ($act == 'add') {
+            if(in_array($id,$hasIds) == false){
+                $hasIds[] = $id;
+                $this->shopExt->xj = json_encode($hasIds);
+                $this->shopExt->save();
+            }
+        } else {
+            $key = array_search($id,$hasIds);
+            unset($hasIds[$key]);
+            $this->shopExt->xj = json_encode($hasIds);
+            $this->shopExt->save();
+        }
+        util::complete();
+    }
+
 }

+ 53 - 0
app-ghs/controllers/XjController.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace ghs\controllers;
+
+use biz\product\classes\XjClass;
+use common\components\util;
+
+class XjController extends BaseController
+{
+
+    //取出所有小菊 shish 20210904
+    public function actionGetAllXj()
+    {
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        $where['status'] = 1;
+        $list = XjClass::getAllXj();
+        util::success(['list' => $list]);
+    }
+
+    //取出商家小菊 shish 20210904
+    public function actionGetSjXj()
+    {
+        $list = XjClass::getSjXj($this->shopExt);
+        util::success(['list' => $list]);
+    }
+
+    //取出所有小菊,带商家有没有标识 shish 20210904
+    public function actionGetFilterXj()
+    {
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        $where['status'] = 1;
+        $list = XjClass::getAllXj();
+        $ext = $this->shopExt;
+        $xj = $ext->xj ?? '';
+        $hasIds = [];
+        if (!empty($xj)) {
+            $hasIds = json_decode($xj, true);
+        }
+        if (!empty($list)) {
+            foreach ($list as $key => $val) {
+                $id = $val['id'] ?? 0;
+                $list[$key]['has'] = 0;
+                if (in_array($id, $hasIds)) {
+                    $list[$key]['has'] = 1;
+                }
+            }
+        }
+        util::success(['list' => $list]);
+    }
+
+}

+ 68 - 21
biz-ghs/order/classes/OrderClass.php

@@ -114,7 +114,7 @@ class OrderClass extends BaseClass
 
         //花材列表
         $product = $data['product'];
-        $respond = OrderItemClass::replaceItem($orderSn, $product);
+        $respond = OrderItemClass::replaceItem($orderSn, $product, $data);
 
         $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
         $data['sendCost'] = $sendCost;
@@ -210,7 +210,7 @@ class OrderClass extends BaseClass
         $product = $data['product'];
         //删除花材再添加
         OrderItemClass::deleteByCondition(['orderSn' => $orderSn]);
-        $respond = OrderItemClass::replaceItem($orderSn, $product);
+        $respond = OrderItemClass::replaceItem($orderSn, $product, $data);
 
         $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
         $data['sendCost'] = $sendCost;
@@ -427,9 +427,10 @@ class OrderClass extends BaseClass
         $totalSmallNum = 0;
         $kind = 0;
         $itemStat = [];
+        //小菊增加部分
+        $xjAddList = [];
         if (!empty($list)) {
             foreach ($list as $key => $val) {
-                $list[$key]['property'] = $val['rank'] . '级';
                 $price = $val['price'];
                 $totalPrice = stringUtil::calcAdd($totalPrice, $price);
                 $kind++;
@@ -437,7 +438,41 @@ class OrderClass extends BaseClass
                 $currentSmallNum = $val['smallNum'];
                 $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
                 $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
+
+                $list[$key]['property'] = '';
+
+                //小菊
+                if (isset($val['variety']) && $val['variety'] == 1) {
+                    unset($list[$key]);
+                    $currentItemId = $val['id'] ?? 0;
+                    $xjList = OrderXjClass::getAllByCondition(['itemId' => $currentItemId], null, '*');
+                    if (!empty($xjList)) {
+                        foreach ($xjList as $xjKey => $xj) {
+                            $xjBase = $val;
+                            $num = $xj['num'] ?? 0;
+                            $price = $xj['price'] ?? 0;
+                            $name = $xj['name'] ?? '';
+                            $cover = $xj['cover'] ?? '';
+                            if ($num > 0) {
+                                $bigTotalPrice = bcmul($price, $num, 2);
+                                $xjBase['cover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+                                $xjBase['unitPrice'] = $price;
+                                $xjBase['price'] = floatval($bigTotalPrice);
+                                $xjBase['num'] = floatval($num);
+                                $xjBase['bigNum'] = floatval($num);
+                                $xjBase['name'] = $name;
+                                $xjBase['property'] = '';
+                                $xjBase['userPrice'] = $bigTotalPrice;
+                                $xjAddList[] = $xjBase;
+                            }
+                        }
+                    }
+                }
             }
+            if (!empty($xjAddList)) {
+                $list = array_merge($list, $xjAddList);
+            }
+
             $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
         }
         return ['list' => $list, 'itemStat' => $itemStat];
@@ -507,6 +542,28 @@ class OrderClass extends BaseClass
         return $list;
     }
 
+    public static function printGroup($current, $content)
+    {
+        //58mm的机器,一行打印16个汉字,32个字母
+        $name = $current['name'] ?? '';
+        $content .= $name . '<BR>';
+        $name = str_repeat(' ', 10);
+
+        $productNum = $current['num'] ?? '';
+        $blankNum = bcsub(12, strlen($productNum));
+        if ($blankNum > 0) {
+            $productNum = $productNum . str_repeat(' ', $blankNum);
+        }
+
+        $productPrice = $current['price'] ?? '';
+        $blankNum = bcsub(7, strlen($productPrice));
+        if ($blankNum > 0) {
+            $productPrice = $productPrice . str_repeat(' ', $blankNum);
+        }
+        $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
+        return $content;
+    }
+
     //云打印 shish 20210709
     public static function onlinePrint($orderInfo)
     {
@@ -533,23 +590,9 @@ class OrderClass extends BaseClass
 
         if (isset($respond['product']) && !empty($respond['product'])) {
             foreach ($respond['product'] as $current) {
-                //58mm的机器,一行打印16个汉字,32个字母
-                $name = $current['name'] ?? '';
-                $content .= $name . '<BR>';
-                $name = str_repeat(' ', 10);
 
-                $productNum = $current['num'] ?? '';
-                $blankNum = bcsub(12, strlen($productNum));
-                if ($blankNum > 0) {
-                    $productNum = $productNum . str_repeat(' ', $blankNum);
-                }
+                $content = self::printGroup($current, $content);
 
-                $productPrice = $current['price'] ?? '';
-                $blankNum = bcsub(7, strlen($productPrice));
-                if ($blankNum > 0) {
-                    $productPrice = $productPrice . str_repeat(' ', $blankNum);
-                }
-                $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
             }
             $content .= '--------------------------------<BR>';
         }
@@ -641,6 +684,8 @@ class OrderClass extends BaseClass
                 $bigUnitPrice = $itemVal['unitPrice'] ?? 0;
                 $smallUnitPrice = $itemVal['smallUnitPrice'] ?? 0;
                 $smallNum = $itemVal['smallNum'] ?? 0;
+
+
                 if ($bigNum > 0) {
                     $bigTotalPrice = bcmul($bigUnitPrice, $bigNum, 2);
                     $printProduct[] = [
@@ -657,6 +702,8 @@ class OrderClass extends BaseClass
                         'price' => floatval($smallTotalPrice),
                     ];
                 }
+
+
             }
         }
 
@@ -667,15 +714,15 @@ class OrderClass extends BaseClass
         $refund = RefundOrderClass::getByCondition(['relateOrderSn' => $relateOrderSn], true);
         if (!empty($refund)) {
             $refundOrderSn = $refund->orderSn ?? '';
-            $refundProductList = RefundOrderItemClass::getAllByCondition(['orderSn' => $refundOrderSn], null,'*');
+            $refundProductList = RefundOrderItemClass::getAllByCondition(['orderSn' => $refundOrderSn], null, '*');
             if (!empty($refundProductList)) {
                 foreach ($refundProductList as $currentRefund) {
                     $num = $currentRefund['itemNum'] ?? 0;
                     $unitPrice = $currentRefund['itemPrice'] ?? 0;
-                    $currentPrice = bcmul($unitPrice,$num,2);
+                    $currentPrice = bcmul($unitPrice, $num, 2);
                     $refundList[] = [
                         'name' => $currentRefund['name'] ?? '',
-                        'num' => floatval($num).'扎*'.floatval($unitPrice),
+                        'num' => floatval($num) . '扎*' . floatval($unitPrice),
                         'price' => floatval($currentPrice),
                     ];
                 }

+ 29 - 4
biz-ghs/order/classes/OrderItemClass.php

@@ -2,6 +2,7 @@
 
 namespace bizGhs\order\classes;
 
+use biz\product\classes\XjClass;
 use bizGhs\product\classes\ProductClass;
 use common\components\imgUtil;
 use common\components\util;
@@ -45,16 +46,40 @@ class OrderItemClass extends BaseClass
     }
 
     //添加修改花材 ssh 2021.1.22
-    public static function replaceItem($orderSn, $product)
+    public static function replaceItem($orderSn, $product, $post = null)
     {
         $respond = ProductClass::formatProductInfo($product);
         $product = $respond['product'];
         self::deleteByCondition(['orderSn' => $orderSn]);
         foreach ($product as $key => $val) {
-            $product[$key]['orderSn'] = $orderSn;
-            $product[$key]['smallUnit'] = '支';
-            $product[$key]['bigUnit'] = '扎';
+            $val['orderSn'] = $orderSn;
+            $val['smallUnit'] = '支';
+            $val['bigUnit'] = '扎';
+            $item = self::add($val, true);
+            $currentId = $item->id ?? 0;
+            if (isset($item->variety) && $item->variety == 1) {
+                //小菊
+                $unitPrice = $val['unitPrice'] ?? 0;
+                if (isset($post['xj']) && !empty($post['xj'])) {
+                    $xjArr = json_decode($post['xj'], true);
+                    if (is_array($xjArr)) {
+                        $ids = array_column($xjArr, 'id');
+                        $sjInfo = XjClass::getByIds($ids, null, 'id');
+                        $xjData = [];
+                        foreach ($xjArr as $xjItem) {
+                            $id = $xjItem['id'] ?? 0;
+                            $num = $xjItem['num'] ?? 0;
+                            $name = $sjInfo[$id]['name'] ?? '';
+                            $cover = $sjInfo[$id]['cover'] ?? '';
+                            $xjData[] = ['xjId' => $id, 'name' => $name, 'num' => $num, 'price' => $unitPrice, 'itemId' => $currentId, 'cover' => $cover];
+                        }
+                        OrderXjClass::batchAdd($xjData);
+                    }
+                }
+            }
         }
+
+
         self::batchAdd($product);
         return $respond;
     }

+ 13 - 0
biz-ghs/order/classes/OrderXjClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizGhs\order\classes;
+
+use Yii;
+use bizGhs\base\classes\BaseClass;
+
+class OrderXjClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\order\models\OrderXj';
+
+}

+ 15 - 0
biz-ghs/order/models/OrderXj.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizGhs\order\models;
+
+use bizGhs\base\models\Base;
+
+class OrderXj extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsOrderXj';
+    }
+
+}

+ 0 - 2
biz-ghs/order/services/OrderService.php

@@ -493,8 +493,6 @@ class OrderService extends BaseService
         if (empty($order)) {
             util::fail('没有找到订单');
         }
-        //由脚本处理,这里不进行处理,避免重复操作
-        //$order = self::expire($order);
         $info = $order->attributes;
         $respond = OrderClass::groupOrder([$info], $showButton, $showItem, $showExpress, $isList);
         return current($respond);

+ 1 - 0
biz-ghs/product/classes/ProductClass.php

@@ -635,6 +635,7 @@ class ProductClass extends BaseClass
             $tmp['itemId'] = $itemId;
             $tmp['rank'] = $productData[$productId]['rank'] ?? '';
             $tmp['ratio'] = $productData[$productId]['ratio'] ?? 1;
+            $tmp['variety'] = $productData[$productId]['variety'] ?? 0;
             $tmp['unitPrice'] = $itemPrice;
             $tmp['num'] = $itemNum;
             $tmp['bigNum'] = $v['bigNum'];

+ 47 - 0
biz/product/classes/XjClass.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace biz\product\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\imgUtil;
+
+class XjClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\product\models\Xj';
+
+    public static function getAllXj()
+    {
+        $where = [];
+        $where['status'] = 1;
+        $where['delStatus'] = 0;
+        $list = self::getAllByCondition($where, null, '*', null);
+        return self::groupInfo($list);
+    }
+
+    //获取商家小菊颜色
+    public static function getSjXj($ext)
+    {
+        $xj = $ext->xj ?? '';
+        $ids = json_decode($xj, true);
+        $list = self::getAllByCondition(['id' => ['in', $ids]], null, '*', null);
+        return self::groupInfo($list);
+    }
+
+    public static function groupInfo($list)
+    {
+        if (empty($list)) {
+            return [];
+        }
+        foreach ($list as $key => $val) {
+            $shortCover = $val['cover'] ?? '';
+            $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            $list[$key]['cover'] = $cover;
+            $list[$key]['shortCover'] = $shortCover;
+            $list[$key]['bigCover'] = $bigCover;
+        }
+        return $list;
+    }
+
+}

+ 15 - 0
biz/product/models/Xj.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\product\models;
+
+use biz\base\models\Base;
+
+class Xj extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhXj';
+    }
+
+}

+ 12 - 0
biz/product/services/XjService.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\product\services;
+
+use biz\base\services\BaseService;
+
+class XjService extends BaseService
+{
+
+    public static $baseFile = '\biz\product\classes\Xj';
+
+}