diff --git a/backend/modules/shop/controllers/OrderController.php b/backend/modules/shop/controllers/OrderController.php
index 5b318af..21dbe80 100755
--- a/backend/modules/shop/controllers/OrderController.php
+++ b/backend/modules/shop/controllers/OrderController.php
@@ -176,7 +176,7 @@ class OrderController extends Controller
return $this->render('delivery', [
'order' => $order,
'delivery' => $delivery,
- 'deliveryGoods' => json_encode($deliveryGoods)
+ 'deliveryGoods' => $deliveryGoods
]);
}
diff --git a/backend/modules/shop/logic/delivery/DeliveryManager.php b/backend/modules/shop/logic/delivery/DeliveryManager.php
index 1a97af1..f8ab2f4 100644
--- a/backend/modules/shop/logic/delivery/DeliveryManager.php
+++ b/backend/modules/shop/logic/delivery/DeliveryManager.php
@@ -10,6 +10,7 @@ use backend\modules\shop\models\ars\Order;
use backend\modules\shop\models\ars\OrderGoods;
use Yii;
use yii\db\Exception;
+use yii\helpers\ArrayHelper;
class DeliveryManager
{
@@ -27,35 +28,20 @@ class DeliveryManager
if (empty($data['deliveryGoods'])) {
throw new Exception('缺少发货商品信息');
}
- $deliveryGoods = json_decode($data['deliveryGoods']);
$delivery->load($data);
$delivery->order_id = $order->id;
if (!$delivery->save()) {
throw new Exception('保存物流信息失败');
}
- $order->status = Order::STATUS_SHIPMENT_ALL;
-
/*发货商品数据*/
- foreach ($deliveryGoods as $k => $value) {
- $model = new DeliveryGoods();
- $model->delivery_id = $delivery->id;
- $model->order_goods_id = $value->id;
- $model->goods_id = $value->goods_id;
- $model->goods_name = $value->goods_name;
- $model->goods_count = $value->goods_count;
- /*如果是部分发货*/
- if ($model->goods_count < $value->lack_number) {
- $order->status = Order::STATUS_SHIPMENT_PORTION;
- }
- if (!$model->save()) {
- throw new Exception('delivery_goods save false');
- }
- }
+ $orderStatus = self::saveDeliveryGoods($data['deliveryGoods'], $delivery->id);
+ $order->status = $orderStatus;
if (!$order->save()) {
throw new Exception('order shipping_status update false');
}
- if ($order->status == Order::STATUS_SHIPMENT_PORTION|| Delivery::findOne(['!=', 'id', $delivery->id])) {
+
+ if ($orderStatus == Order::STATUS_SHIPMENT_PORTION || Delivery::findOne(['!=', 'id', $delivery->id])) {
$delivery->type = Delivery::TYPE_SHIPMENT_PORTION;
} else {
$delivery->type = Delivery::TYPE_SHIPMENT_ALL;
@@ -72,6 +58,40 @@ class DeliveryManager
}
}
+ /**
+ * @param $deliveryGoods
+ * @param $delivery_id
+ * @return int
+ * @throws Exception
+ * 保存发货商品信息
+ */
+ private static function saveDeliveryGoods($deliveryGoods, $delivery_id)
+ {
+ $status = Order::STATUS_SHIPMENT_ALL;
+ foreach ($deliveryGoods as $id => $goodsCount) {
+ $orderGoods = OrderGoods::findOne($id);
+
+ /*如果是发货数量不是全部,订单状态为部分发货*/
+ $deliveryGoodsCount = DeliveryGoods::find()->where(['order_goods_id' => $id])->sum('goods_count');
+ if (($deliveryGoodsCount + $goodsCount) < $orderGoods->goods_count) { //如果已发货数量未达到order_goods里的数量
+ $status = Order::STATUS_SHIPMENT_PORTION;
+ } elseif (($deliveryGoodsCount + $goodsCount) > $orderGoods->goods_count) {
+ throw new Exception('操作异常,现发货数量超过之前缺少的发货数量');
+ }
+
+ $model = new DeliveryGoods();
+ $model->delivery_id = $delivery_id;
+ $model->order_goods_id = $orderGoods->id;
+ $model->goods_id = $orderGoods->goods_id;
+ $model->goods_name = $orderGoods->goods_name;
+ $model->goods_count = $goodsCount;
+ if (!$model->save()) {
+ throw new Exception('delivery_goods save false');
+ }
+ }
+ return $status;
+ }
+
/**
* @param $order_id
* @return array
@@ -83,8 +103,8 @@ class DeliveryManager
$delivery = Delivery::find()->select('id')->where(['order_id' => $order_id])->all();
/*如果该订单是首次发货*/
if (!$delivery) {
- $unShippend = self::firstDelivery($order_id);
- return ['unShipped' => $unShippend];
+ $unShippedGoods = OrderGoods::find()->where(['order_id' => $order_id])->asArray()->all();
+ return ['unShipped' => $unShippedGoods];
}
$deliveryIds = [];
@@ -111,29 +131,6 @@ class DeliveryManager
return self::getDeliveryGoodsInfo($filter, $order_id);
}
- /**
- * @param $order_id
- * @return array
- * 首次发货直接获取orderGoods的内容
- */
- private static function firstDelivery($order_id)
- {
- $unShippedGoods = [];
- $orderGoods = OrderGoods::find()->where(['order_id' => $order_id])->all();
- foreach ($orderGoods as $k => $v) {
- $unShippedGoods[] = [
- 'id' => $v->id,
- 'goods_id' => $v->goods_id,
- 'goods_img' => $v->goods_img,
- 'goods_name' => $v->goods_name,
- 'goods_count' => $v->goods_count,
- 'lack_number' => $v->goods_count,
- 'sku_value' => $v->sku_value,
- ];
- }
- return $unShippedGoods;
- }
-
/**
* @param $filter
* @param $order_id
@@ -153,19 +150,8 @@ class DeliveryManager
$unShipped[] = $goodsData;
}
}
- $shipped = self::getDeliveryInfo($order_id); //已发货商品信息
- return ['shipped' => $shipped, 'unShipped' => $unShipped];
- }
- /**
- * @param $order_id
- * @return array
- * @throws Exception
- * 通过订单id获取发货信息
- */
- public static function getDeliveryInfo($order_id)
- {
- $deliveryInfo = [];
+ $shipped = [];
$delivery = Delivery::findAll(['order_id' => $order_id]);
foreach ($delivery as $k => $value) {
// $expressTemplate = ExpressTemplate::find()
@@ -176,9 +162,10 @@ class DeliveryManager
// 'exp_name'=> $expressTemplate ? $expressTemplate->name : '',
// 'invoice_no'=> $value->invoice_no
// ]; //物流公司和运单号
- $deliveryInfo[$k]['goodsInfo'] = self::getDeliverGoodsInfo($value->id); //获取商品信息
+ $shipped[$k]['goodsInfo'] = self::getDeliverGoodsInfo($value->id); //获取商品信息
}
- return $deliveryInfo;
+
+ return ['shipped' => $shipped, 'unShipped' => $unShipped];
}
/**
diff --git a/backend/modules/shop/views/delivery/delivery_goods.php b/backend/modules/shop/views/delivery/delivery_goods.php
new file mode 100644
index 0000000..e21f592
--- /dev/null
+++ b/backend/modules/shop/views/delivery/delivery_goods.php
@@ -0,0 +1,25 @@
+
+
+ $model->id]);
+ if ($deliveryGoods) {
+ echo '
';
+ foreach ($deliveryGoods as $value) {
+ echo
+ '' .
+ '商品名称: | ' .
+ '' . $value->goods_name . ' | ' .
+ '
' .
+ '' .
+ '商品数量: | ' .
+ '' . $value->goods_count . ' | ' .
+ '
';
+
+ }
+ echo '
';
+ }
+?>
\ No newline at end of file
diff --git a/backend/modules/shop/views/delivery/logistics.php b/backend/modules/shop/views/delivery/logistics.php
new file mode 100644
index 0000000..4fc3cef
--- /dev/null
+++ b/backend/modules/shop/views/delivery/logistics.php
@@ -0,0 +1,37 @@
+
+
+=
+ DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id',
+ 'order_id',
+ 'shipping_name',
+ 'shipping_id',
+ [
+ 'attribute' => 'type',
+ 'value' => function ($model) {
+ return Delivery::dropDown('type', $model->type);
+ }
+ ],
+ 'status',
+ 'decription:ntext',
+ [
+ 'attribute' => 'created_at',
+ 'value' => function ($model) {
+ return date('Y-m-d H:i:s', $model->created_at);
+ }
+ ],
+ [
+ 'attribute' => 'updated_at',
+ 'value' => function ($model) {
+ return date('Y-m-d H:i:s', $model->updated_at);
+ }
+ ],
+ ],
+ ]);
+?>
\ No newline at end of file
diff --git a/backend/modules/shop/views/delivery/view.php b/backend/modules/shop/views/delivery/view.php
index a1302e2..4ecdaaa 100644
--- a/backend/modules/shop/views/delivery/view.php
+++ b/backend/modules/shop/views/delivery/view.php
@@ -1,7 +1,7 @@
title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
+Yii::$app->params['bsVersion'] = '4.x';
\yii\web\YiiAsset::register($this);
?>
@@ -17,34 +18,26 @@ $this->params['breadcrumbs'][] = $this->title;
= Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?>
- = DetailView::widget([
- 'model' => $model,
- 'attributes' => [
- 'id',
- 'order_id',
- 'shipping_name',
- 'shipping_id',
+ true,
+ 'items' => [
[
- 'attribute' => 'type',
- 'value' => function ($model) {
- return \backend\modules\shop\models\ars\Delivery::dropDown('type', $model->type);
- }
+ 'label' => ' 物流信息',
+ 'content' => $this->render('logistics', [
+ 'model' => $model,
+ ]),
],
- 'status',
- 'decription:ntext',
[
- 'attribute' => 'created_at',
- 'value' => function ($model) {
- return date('Y-m-d H:i:s', $model->created_at);
- }
- ],
- [
- 'attribute' => 'updated_at',
- 'value' => function ($model) {
- return date('Y-m-d H:i:s', $model->updated_at);
- }
+ 'label' => ' 发货商品信息',
+ 'content' => $this->render('delivery_goods', [
+ 'model' => $model,
+ ]),
],
],
- ]) ?>
+ 'position' => TabsX::POS_ABOVE,
+ 'encodeLabels' => false
+ ]);
+ ?>
diff --git a/backend/modules/shop/views/order/delivery_goods.php b/backend/modules/shop/views/order/delivery_goods.php
index 11a0a95..72bb924 100644
--- a/backend/modules/shop/views/order/delivery_goods.php
+++ b/backend/modules/shop/views/order/delivery_goods.php
@@ -18,6 +18,9 @@
border-radius: 10px;
box-shadow:0 4px 30px 2px rgba(223, 225, 230, 0.5) !important;
}
+ input {
+ width: 50%;
+ }
@@ -25,118 +28,132 @@
未发货商品
已发货商品
-
" +
- "" + item.goods_name + " | " +
- "" + item.sku_value + " | " +
- "" + item.lack_number + " | " +
- " | " +
- "" +
- "" +
- "" +
- " | " +
- "";
- $('.unShipped-table').append(tr)
- });
- }
-
- //显示已发货商品
- function showShipped(shipped) {
- shipped.forEach(function(item,index){
- var table = ' ' +
- '' +
- '商品名称 | ' +
- '商品sku | ' +
- '发货数量 | ' +
- '
' +
- '
';
- // var div = document.createElement('div');
- // div.innerText = '运单号:' + item.logisticInfo.invoice_no + '快递公司:'+ item.logisticInfo.exp_name;
- // $('.shipped-box').append(div);
- $('.shipped-box').append(table);
- table = $('.shipped-table').eq(index);
- item.goodsInfo.forEach(function (item,index) {
- var tr = "" +
- "" + item.goods_name + " | " +
- "" + item.sku_value + " | " +
- "" + item.delivery_number + " | " +
- "
";
- $(table).append(tr);
- });
- })
- }
-
- var btnUpdate = $('.btn-update');
- var btnSave = $('.btn-save');
- for (i = 0; i < btnUpdate.length; i++) {
- btnUpdate[i].addEventListener("click", updateGoods);
- btnSave[i].addEventListener("click", saveGoods);
- }
-SCRIPT;
-$this->registerJs($js);
-?>
+//$js = <<