Просмотр исходного кода

特价 花材修改成本价和售价 欠款支付显示可调动

shish 5 лет назад
Родитель
Сommit
da293ab982

+ 9 - 2
app-ghs/controllers/ProductController.php

@@ -142,10 +142,10 @@ class ProductController extends BaseController
             //库存预警 按库存从小到大排序
             $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
         } else {
-            if(!empty($productIds)){
+            if (!empty($productIds)) {
                 //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
                 $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
-            }else{
+            } else {
                 $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
             }
 
@@ -495,6 +495,13 @@ class ProductController extends BaseController
         $post['sjId'] = $this->sjId;
         $post['adminId'] = $this->adminId;
         $post['shopId'] = $this->shopId;
+        $price = $post['price'] ?? 0;
+        $addPrice = $post['addPrice'] ?? 0;
+        if ($addPrice > $price) {
+            util::fail('加价不能大于售价');
+        }
+        $cost = bcsub($price, $addPrice, 2);
+        $post['cost'] = $cost;
         ProductClass::addProduct($post);
         util::complete('添加成功');
     }

+ 4 - 1
app-hd/controllers/PurchaseController.php

@@ -81,13 +81,16 @@ class PurchaseController extends BaseController
             $realTime = $validTime - 120;
             $count = $realTime > 0 ? $realTime : 100;
 
+            $custom = CustomClass::getById($customId);
+            $hasDebtPay = $custom['debt'] ?? 0;
+
             $data = [
                 'orderSn' => $orderSn,
                 'actPrice' => $actPrice,
                 'realPrice' => $realPrice,
                 'hasBalancePay' => 1,
                 'hasPayPassword' => 0,
-                'hasDebtPay' => 1,
+                'hasDebtPay' => $hasDebtPay,
                 'count' => $count,
             ];
             util::success($data);

+ 25 - 19
biz-ghs/product/classes/ProductClass.php

@@ -118,16 +118,19 @@ class ProductClass extends BaseClass
             $list[$k]['bigNum'] = $stockInfo['bigNum'];
             $list[$k]['smallNum'] = $stockInfo['smallNum'];
             $list[$k]['itemName'] = $v['name'] ?? '';
-            //换算大小单位对应价格
-            $list[$k]['bigPrice'] = $v['price']; //大单位价格就是product表存的价格
 
-            $smallPrice = bcdiv($v['price'], $ratio, 2);
-            //小单位根据供应商要求+2倍 暂时注释
-            //$smallPrice = bcmul($smallPrice, 2, 2);
+            //原价 shish 20210703
+            $list[$k]['prePrice'] = $v['price'] ?? 0;
+
+            //特价 shish 20210901
+            $discountPrice = $v['discountPrice'] ?? 0;
+            $price = $discountPrice > 0 ? $discountPrice : $v['price'];
+            $list[$k]['price'] = $price;
+            $list[$k]['bigPrice'] = $price;
 
+            $smallPrice = bcdiv($price, $ratio, 2);
             $list[$k]['smallPrice'] = $smallPrice;
-            //原价 shish 20210703
-            $list[$k]['prePrice'] = bcadd($v['cost'], $v['addPrice'], 2);
+
         }
         return $list;
     }
@@ -585,6 +588,13 @@ class ProductClass extends BaseClass
             $itemNum = self::mergeItemNum($v['bigNum'], $v['smallNum'], $ratio);
             //售卖价格
             $itemPrice = $productData[$productId]['price'] ?? 0;
+
+            //折扣价
+            $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
+            if ($discountPrice > 0) {
+                $itemPrice = $discountPrice;
+            }
+
             $userPrice = 0; //用户传的价格
             if (isset($v['price'])) {
                 if ($v['price'] <= 0) {
@@ -592,7 +602,7 @@ class ProductClass extends BaseClass
                 }
                 $userPrice = $v['price'];
                 //用户传价格之后,单价会变化
-                $itemPrice = bcdiv($userPrice,$itemNum,2);
+                $itemPrice = bcdiv($userPrice, $itemNum, 2);
             }
 
             //合计价格
@@ -729,13 +739,12 @@ class ProductClass extends BaseClass
             }
             $upData['cover'] = $data['cover'];
         }
-        if (isset($data['cost'])) {
-            if (empty($data['cost'])) {
-                util::fail("请输入花材成本价");
-            }
-            $upData['cost'] = $data['cost'];
+        if (isset($data['discountPrice']) && is_numeric($data['discountPrice'])) {
+            $upData['discountPrice'] = $data['discountPrice'];
+        }
+        if (isset($data['price']) && is_numeric($data['price'])) {
+            $upData['price'] = $data['price'];
         }
-
         if (isset($data['weight'])) {
             $upData['weight'] = $data['weight'];
         }
@@ -929,7 +938,6 @@ class ProductClass extends BaseClass
     public static function addProduct($data)
     {
         $classId = $data['classId'] ?? 0;
-        $cost = $data['cost'] ?? false;
         $addPrice = $data['addPrice'] ?? false;
         $stockWarning = $data['stockWarning'] ?? false;
         $data['py'] = stringUtil::py($data['name']);
@@ -961,8 +969,8 @@ class ProductClass extends BaseClass
         if (!$classId) {
             util::fail("请选择分类");
         }
-        if ($cost === false) {
-            util::fail("请输入花材的成本价");
+        if (isset($data['price']) == false || is_numeric($data['price']) == false) {
+            util::fail("请输入价");
         }
         if ($addPrice === false) {
             util::fail("请输入花材的加价");
@@ -979,7 +987,6 @@ class ProductClass extends BaseClass
         if ($weight === false) {
             util::fail("请输入花材重量");
         }
-
         $existItemClass = ItemClassClass::exists(['id' => $classId, 'sjId' => $data['sjId']]);
         if (!$existItemClass) {
             util::fail("花材分类不存在");
@@ -1008,7 +1015,6 @@ class ProductClass extends BaseClass
                 }
             }
 
-            $data['price'] = $data['cost'] + $data['addPrice'];
             //根据sjId, 找到所有的shopId,都添加
             $shopIds = ShopService::getShopIds($data['sjId']);
             foreach ($shopIds as $shopId) {

+ 1 - 1
biz-ghs/product/services/ProductService.php

@@ -23,7 +23,7 @@ class ProductService extends BaseService
         if($itemInfoData){
             foreach ($itemInfoData as $v){
                 $v['classId'] = self::ALL_CLASS_ID;
-                if($v['price'] < $v['cost']+ $v['addPrice']){
+                if($v['price'] > $v['discountPrice'] && $v['discountPrice'] > 0){
                     $saleItem[] = $v;
                 }
             }

+ 7 - 0
biz-hd/purchase/classes/PurchaseClass.php

@@ -89,6 +89,13 @@ class PurchaseClass extends BaseClass
 
             $itemNum = ProductClass::mergeItemNum($product['bigNum'], $product['smallNum'], $ratio);//采购数量
             $price = $productData[$productId]['price']; //卖的单价
+
+            //折扣价
+            $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
+            if ($discountPrice > 0) {
+                $price = $discountPrice;
+            }
+
             //每个花材总价(原价)
             $productPrePrice = bcmul($itemNum, $price, 2); //采购总价
             //供应商开单的每个花材总价,可能会改价

+ 0 - 5
biz/item/classes/PtItemClass.php

@@ -61,7 +61,6 @@ class PtItemClass extends BaseClass
     public static function addItem($data)
     {
         $classId = $data['classId'] ?? 0;
-        $cost = $data['cost'] ?? false;
         $addPrice = $data['addPrice'] ?? false;
         $stockWarning = $data['stockWarning'] ?? false;
         $py = isset($data['py']) && !empty($data['py']) ? $data['py'] : stringUtil::py($data['name']);
@@ -73,7 +72,6 @@ class PtItemClass extends BaseClass
         $weight = $data['weight'] ?? false;
         $data['bigUnit'] = $data['bigUnit'] ?? '扎';
         $data['smallUnit'] = $data['smallUnit'] ?? '支';
-
         if (preg_match("/^[1-9][0-9]*$/", $data['ratio']) == false || $data['ratio'] <= 0) {
             util::fail('比例请填写整数,并且大于0');
         }
@@ -81,9 +79,6 @@ class PtItemClass extends BaseClass
         if (!$classId) {
             util::fail("请选择分类");
         }
-        if ($cost === false) {
-            util::fail("请输入花材的成本价");
-        }
         if ($addPrice === false) {
             util::fail("请输入花材的加价");
         }