Parcourir la source

新增:后台订单管理支持修改收货地址

萤火科技 il y a 1 an
Parent
commit
4e50a1a236

+ 12 - 1
app/common/model/OrderAddress.php

@@ -34,7 +34,18 @@ class OrderAddress extends BaseModel
      * 追加字段
      * @var array
      */
-    protected $append = ['region'];
+    protected $append = ['cascader', 'region'];
+
+    /**
+     * 获取器:省市区ID集
+     * @param $value
+     * @param $data
+     * @return array
+     */
+    public function getCascaderAttr($value, $data): array
+    {
+        return [$data['province_id'], $data['city_id'], $data['region_id']];
+    }
 
     /**
      * 获取器:地区名称

+ 18 - 6
app/store/controller/order/Event.php

@@ -13,6 +13,7 @@ declare (strict_types=1);
 namespace app\store\controller\order;
 
 use think\response\Json;
+use think\db\exception\DbException;
 use app\store\controller\Controller;
 use app\store\model\Order as OrderModel;
 
@@ -30,7 +31,6 @@ class Event extends Controller
      */
     public function updatePrice(int $orderId): Json
     {
-        // 订单详情
         $model = OrderModel::detail($orderId);
         if ($model->updatePrice($this->postForm())) {
             return $this->renderSuccess('操作成功');
@@ -45,7 +45,6 @@ class Event extends Controller
      */
     public function updateRemark(int $orderId): Json
     {
-        // 订单详情
         $model = OrderModel::detail($orderId);
         if ($model->updateRemark($this->postForm())) {
             return $this->renderSuccess('操作成功');
@@ -53,15 +52,31 @@ class Event extends Controller
         return $this->renderError($model->getError() ?: '操作失败');
     }
 
+    /**
+     * 修改收货地址
+     * @param int $orderId
+     * @return Json
+     */
+    public function updateAddress(int $orderId): Json
+    {
+        $model = OrderModel::detail($orderId);
+        if ($model->updateAddress($this->postForm())) {
+            return $this->renderSuccess('操作成功');
+        }
+        return $this->renderError($model->getError() ?: '操作失败');
+    }
+
     /**
      * 小票打印
      * @param int $orderId
      * @return Json
+     * @throws DbException
      * @throws \cores\exception\BaseException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
      */
     public function printer(int $orderId): Json
     {
-        // 订单详情
         $model = OrderModel::detail($orderId);
         if ($model->printer($this->postForm())) {
             return $this->renderSuccess('操作成功');
@@ -76,7 +91,6 @@ class Event extends Controller
      */
     public function confirmCancel($orderId): Json
     {
-        // 订单详情
         $model = OrderModel::detail($orderId);
         if ($model->confirmCancel($this->postForm())) {
             return $this->renderSuccess('操作成功');
@@ -91,9 +105,7 @@ class Event extends Controller
      */
     public function delete(int $orderId): Json
     {
-        // 订单详情
         $model = OrderModel::detail($orderId);
-        // 确认删除
         if ($model->setDelete()) {
             return $this->renderSuccess('删除成功');
         }

+ 1 - 1
app/store/model/Order.php

@@ -234,7 +234,7 @@ class Order extends OrderModel
      */
     public function updateAddress(array $data): bool
     {
-        return $this->save(['merchant_remark' => $data['content'] ?? '']);
+        return OrderAddress::updateAddress($this['address']['order_address_id'], $data);
     }
 
     /**

+ 18 - 1
app/store/model/OrderAddress.php

@@ -21,5 +21,22 @@ use app\common\model\OrderAddress as OrderAddressModel;
  */
 class OrderAddress extends OrderAddressModel
 {
-
+    /**
+     * 修改订单收货地址
+     * @param int $orderAddressId
+     * @param array $data
+     * @return bool
+     */
+    public static function updateAddress(int $orderAddressId, array $data): bool
+    {
+        static::updateBase([
+            'name' => $data['name'],
+            'phone' => $data['phone'],
+            'province_id' => $data['cascader'][0],
+            'city_id' => $data['cascader'][1],
+            'region_id' => $data['cascader'][2],
+            'detail' => $data['detail'],
+        ], $orderAddressId);
+        return true;    // todo
+    }
 }