diff --git a/app/admin/controller/IndexController.php b/app/admin/controller/IndexController.php index 1cbf5b385..8adcaad5c 100644 --- a/app/admin/controller/IndexController.php +++ b/app/admin/controller/IndexController.php @@ -28,6 +28,6 @@ class IndexController extends BaseAdminController public function demo2() { $res=DemoLogic::test(); - return $this->success('成功',$res); + return $this->success('成功'); } } \ No newline at end of file diff --git a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php index 9736a5ec2..2f1793710 100644 --- a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -85,11 +85,6 @@ class BeforehandOrderCartInfoController extends BaseAdminController } } $find->source_order_info = array_values($json); - $productPrice = StoreProduct::where('id',$res['product_id'])->value('price'); - $procurementOrder = BeforehandOrder::where('id', $find['order_id'])->find(); - $procurementOrder->total_price = bcsub($procurementOrder->total_price, bcmul($productPrice, $res['cart_num'], 2), 2); - $procurementOrder->pay_price = $procurementOrder->total_price; - $procurementOrder->save(); } if ($find->need_num <= 0) { $find->delete_time = time(); diff --git a/app/admin/lists/store_category/StoreCategoryLists.php b/app/admin/lists/store_category/StoreCategoryLists.php index 0be91834b..e9e672069 100644 --- a/app/admin/lists/store_category/StoreCategoryLists.php +++ b/app/admin/lists/store_category/StoreCategoryLists.php @@ -45,8 +45,6 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf public function lists(): array { $userGroups = UserShip::field('id,title')->select()->toArray(); - $userGroups[] = ['id' => 100001, 'title' => '供货价']; - $userGroups[] = ['id' => 100002, 'title' => '零售价']; return StoreCategory::where($this->searchWhere) ->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate']) ->limit($this->limitOffset, $this->limitLength) @@ -56,13 +54,21 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf $item['price_rate'] = $userGroups; } else { $priceRate = reset_index($item['price_rate'], 'id'); + unset($priceRate[100003], $priceRate[100004]); + $temp = []; foreach ($userGroups as $userGroup) { - if (!isset($priceRate[$userGroup['id']])) { - $userGroup['rate'] = 0; - $priceRate[] = $userGroup; + if ($userGroup['id'] == 21 && !empty($priceRate[100001]) && empty($userGroup['rate'])) { + $userGroup['rate'] = $priceRate[100001]['rate']; + unset($priceRate[100001]); + } elseif ($userGroup['id'] == 22 && !empty($priceRate[100002]) && empty($userGroup['rate'])) { + $userGroup['rate'] = $priceRate[100002]['rate']; + unset($priceRate[100002]); + } else { + $userGroup['rate'] = $priceRate[$userGroup['id']]['rate'] ?? 0; } + $temp[] = $userGroup; } - $item['price_rate'] = array_values($priceRate); + $item['price_rate'] = $temp; } $item['is_children'] = StoreCategory::where('pid', $item->id)->count(); // 判断是否有子分类 return $item->toArray(); diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 74cce1485..7caa7a63f 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -183,10 +183,10 @@ class PurchaseProductOfferLogic extends BaseLogic 'expiration_date' => $params['expiration_date'], ]); // $find = StoreProductPrice::where(['offer_id' => $params['id']])->find(); - $product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id')->find(); + $product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find(); $unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name'); $order = BeforehandOrder::where('id', $params['bhoid'])->find(); - $order->pay_price = bcadd($offer['total_price'], $order->pay_price, 2); + $order->pay_price = PurchaseProductOffer::where('order_id', $order['id'])->sum('total_price'); $order->total_price = $order->pay_price; $order->save(); self::setProductGroupPrice($params, $product); @@ -364,13 +364,13 @@ class PurchaseProductOfferLogic extends BaseLogic 'update_time' => time(), 'status' => 0, ]; - $productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate'); + $productCatePriceRate = self::getProductCatePriceRate($product); if (!empty($productCatePriceRate)) { $storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray(); $storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id'); $purchase=0; foreach ($productCatePriceRate as $k => $v) { - if ($v['id'] == 100001) { + if ($v['id'] == 100001 || $v['id'] == 21) { //供货 $data['purchase_lv'] = bcdiv($v['rate'], 100, 2); $data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2); @@ -384,7 +384,7 @@ class PurchaseProductOfferLogic extends BaseLogic $data['cost_lv'] = bcdiv($v['rate'], 100, 2); $data['cost'] = bcmul($purchase, bcadd($data['cost_lv'], 1, 2), 2); continue; - }elseif ($v['id'] == 100002 &&$purchase>0) { + }elseif (($v['id'] == 100002 || $v['id'] == 22) &&$purchase>0) { //零售 $data['price_lv'] = bcdiv($v['rate'], 100, 2); $data['price'] = bcmul($purchase, bcadd($data['price_lv'], 1, 2), 1); @@ -400,7 +400,7 @@ class PurchaseProductOfferLogic extends BaseLogic } continue; } - $baseRate = 100 + $v['rate']; + $baseRate = ($v['id'] == 100001 || $v['id'] == 21) ? 100 : 100 + $v['rate']; if($purchase>0){ $item = [ 'product_id' => $product['id'], @@ -427,4 +427,18 @@ class PurchaseProductOfferLogic extends BaseLogic StoreProductPrice::create($data); } } + + public static function getProductCatePriceRate($product) + { + $productCatePriceRate = StoreCategory::where('id', $product['cate_id'])->value('price_rate'); + if (!empty($productCatePriceRate)) { + return $productCatePriceRate; + } + $productCatePriceRate = StoreCategory::where('id', $product['two_cate_id'])->value('price_rate'); + if (!empty($productCatePriceRate)) { + return $productCatePriceRate; + } + return StoreCategory::where('id', $product['top_cate_id'])->value('price_rate'); + } + } diff --git a/app/admin/logic/store_category/StoreCategoryLogic.php b/app/admin/logic/store_category/StoreCategoryLogic.php index 5404dcadf..0dcd944f9 100644 --- a/app/admin/logic/store_category/StoreCategoryLogic.php +++ b/app/admin/logic/store_category/StoreCategoryLogic.php @@ -29,12 +29,17 @@ class StoreCategoryLogic extends BaseLogic { Db::startTrans(); try { + $priceRate = []; + foreach ($params['price_rate'] as $v) { + $priceRate[$v['id']] = $v; + } StoreCategory::create([ 'pid' => $params['pid'], 'name' => $params['name'], 'data' => $params['data'], 'pic' => $params['pic'], - 'sort' => $params['sort'] + 'sort' => $params['sort'], + 'price_rate' => array_values($priceRate) ]); Db::commit(); @@ -57,13 +62,17 @@ class StoreCategoryLogic extends BaseLogic { Db::startTrans(); try { + $priceRate = []; + foreach ($params['price_rate'] as $v) { + $priceRate[$v['id']] = $v; + } StoreCategory::where('id', $params['id'])->update([ 'pid' => $params['pid'], 'name' => $params['name'], 'data' => $params['data'], 'pic' => $params['pic'], 'sort' => $params['sort'], - 'price_rate' => $params['price_rate'] + 'price_rate' => array_values($priceRate) ]); Db::commit(); diff --git a/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php b/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php index a9ac145d0..24621998b 100644 --- a/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php +++ b/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php @@ -106,8 +106,6 @@ class StoreProductGroupPriceLogic extends BaseLogic $arr=StoreProductGroupPrice::where('product_id',$params['product_id'])->select()->toArray(); $purchase=StoreProduct::where('id',$params['product_id'])->value('purchase'); $arr_two=UserShip::where('id','>',0)->select()->toArray(); - $arr_two[] = ['id' => 100001, 'title' => '供货价']; - $arr_two[] = ['id' => 100002, 'title' => '零售价']; foreach ($arr_two as $k=>$v){ $arr_two[$k]['purchase']=$purchase; $arr_two[$k]['product_id']=$params['product_id'];