Browse Source

feat: 增加订单保存前的运费计算和grid调整

wechat_public_accounts
iron 5 years ago
parent
commit
0eed19172d
  1. 13
      api/logic/ExpressLogic.php
  2. 6
      backend/modules/shop/models/ars/Order.php
  3. 6
      vendor/iron/grid/GridView.php

13
api/logic/ExpressLogic.php

@ -40,7 +40,7 @@ class ExpressLogic extends BaseObject
$this->order = $order; $this->order = $order;
$allGoods = $this->findDifferentExpressTypeGoods($order);/*获取不同运费计算模式的商品*/ $allGoods = $this->findDifferentExpressTypeGoods($order);/*获取不同运费计算模式的商品*/
$uniformPostage = $this->countGoodsExpress($allGoods['uniformPostageGoods'], Goods::EXPRESS_TYPE_UNIFORM_POSTAGE);/*计算统一运费模式下所有商品运费*/ $uniformPostage = $this->countGoodsExpress($allGoods['uniformPostageGoods'], Goods::EXPRESS_TYPE_UNIFORM_POSTAGE);/*计算统一运费模式下所有商品运费*/
$expressTemplate = $this->countGoodsExpress($allGoods['uniformPostageGoods'], Goods::EXPRESS_TYPE_UNIFORM_POSTATE);/*计算运费模板模式下所有商品的运费*/
$expressTemplate = $this->countGoodsExpress($allGoods['uniformPostageGoods'], Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE);/*计算运费模板模式下所有商品的运费*/
return $uniformPostage > $expressTemplate ? $uniformPostage : $expressTemplate;/*比较两种不同运费计算模式下,取金额大的值为最终收取运费*/ return $uniformPostage > $expressTemplate ? $uniformPostage : $expressTemplate;/*比较两种不同运费计算模式下,取金额大的值为最终收取运费*/
} }
@ -49,7 +49,7 @@ class ExpressLogic extends BaseObject
* @param $order * @param $order
* @return array * @return array
* @throws NotFoundHttpException * @throws NotFoundHttpException
*
* 获取不同运费计算模式的商品
*/ */
private function findDifferentExpressTypeGoods($order) private function findDifferentExpressTypeGoods($order)
{ {
@ -78,6 +78,7 @@ class ExpressLogic extends BaseObject
* @param $type * @param $type
* @return float|int * @return float|int
* @throws NotFoundHttpException * @throws NotFoundHttpException
* 根据不同计费模式计算商品运费
*/ */
private function countGoodsExpress($allGoods, $type) private function countGoodsExpress($allGoods, $type)
{ {
@ -91,10 +92,12 @@ class ExpressLogic extends BaseObject
$extraPrice = 0; $extraPrice = 0;
$areasIds = []; $areasIds = [];
foreach ($allGoods['object'] as $k => $goods) { foreach ($allGoods['object'] as $k => $goods) {
/*计算增重运费*/
$extraPrice += $this->countExtraAmount($allGoods['count'][$k], $allGoods['weight'][$k], $goods->express_template); $extraPrice += $this->countExtraAmount($allGoods['count'][$k], $allGoods['weight'][$k], $goods->express_template);
$areasIds[] = $this->getAreaId($goods->express_template); $areasIds[] = $this->getAreaId($goods->express_template);
} }
$basic = $this->getBasicPriceAndAreaId($areasIds);
$basic = $this->getBasicPriceAndAreaId($areasIds);/*获取首重运费和对应的计费规则id*/
/*返回所有按运费模板计费的商品运费(基础运费 + 所有商品增重运费 - 多余的增重运费)*/
return $basic['price'] + $extraPrice - $this->countSurplusPrice($basic['id']); return $basic['price'] + $extraPrice - $this->countSurplusPrice($basic['id']);
} }
} }
@ -104,7 +107,7 @@ class ExpressLogic extends BaseObject
* @return float|int * @return float|int
* @throws NotFoundHttpException * @throws NotFoundHttpException
* 计算多余(多算的)运费 * 计算多余(多算的)运费
* 选定的作为基础运费的计费规则的对应商品基础数量内的扩展费用
* 选定作为基础运费的计费规则对应商品基础数量内的增重费用
*/ */
private function countSurplusPrice($areaId) private function countSurplusPrice($areaId)
{ {
@ -138,7 +141,7 @@ class ExpressLogic extends BaseObject
* @param $templateId * @param $templateId
* @return float|int * @return float|int
* @throws NotFoundHttpException * @throws NotFoundHttpException
* 计算扩展运费
* 计算增重运费
*/ */
private function countExtraAmount($count, $weight, $templateId) private function countExtraAmount($count, $weight, $templateId)
{ {

6
backend/modules/shop/models/ars/Order.php

@ -3,6 +3,7 @@
namespace backend\modules\shop\models\ars; namespace backend\modules\shop\models\ars;
use Yii; use Yii;
use yii\base\Object;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
/** /**
@ -127,7 +128,10 @@ class Order extends \yii\db\ActiveRecord
public function beforeSave($insert) public function beforeSave($insert)
{ {
if ($this->status === self::STATUS_UNCONFIRMED && $this->type == self::TYPE_SHOPPING) { if ($this->status === self::STATUS_UNCONFIRMED && $this->type == self::TYPE_SHOPPING) {
$this->shipping_amount = $this->countShippingAmount();
$express = Yii::createObject([
'class' => 'api\logic\ExpressLogic',
]);
$this->shipping_amount = $express->countShippingAmount($this);
$this->receivables = $this->goods_amount + $this->shipping_amount; $this->receivables = $this->goods_amount + $this->shipping_amount;
$this->payment_amount = $this->receivables - $this->discount_amount; $this->payment_amount = $this->receivables - $this->discount_amount;
} }

6
vendor/iron/grid/GridView.php

@ -263,8 +263,8 @@ HTML;
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fas fa-file-upload mr-2"></i>导出</button> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fas fa-file-upload mr-2"></i>导出</button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li> <a class="dropdown-item export-page" href="#" data-url="{url}/export">本页</a></li>
<li> <a class="dropdown-item export-all" href="#" data-url="{url}/export">全部</a></li>
<li> <a class="dropdown-item export-page" href="#" data-url="export">本页</a></li>
<li> <a class="dropdown-item export-all" href="#" data-url="export">全部</a></li>
</ul> </ul>
</div> </div>
HTML; HTML;
@ -461,8 +461,6 @@ SCRIPT;
return $this->renderFilter(); return $this->renderFilter();
case '{batch}': case '{batch}':
return $this->renderBatch(); return $this->renderBatch();
case '{url}':
return Yii::$app->request->url;
case '{export}': case '{export}':
return $this->renderExport(); return $this->renderExport();
case '{create}': case '{create}':

Loading…
Cancel
Save