Forráskód Böngészése

修复:后台删除物流公司报错

萤火科技 1 éve
szülő
commit
cbb722353b

+ 8 - 2
app/common/model/Express.php

@@ -40,7 +40,10 @@ class Express extends BaseModel
         // 检索查询条件
         $filter = $this->getFilter($param);
         // 查询列表数据
-        return $this->where($filter)->order(['sort', $this->getPk()])->select();
+        return $this->where($filter)
+            ->where('is_delete', '=', 0)
+            ->order(['sort', $this->getPk()])
+            ->select();
     }
 
     /**
@@ -54,7 +57,10 @@ class Express extends BaseModel
         // 检索查询调价你
         $filter = $this->getFilter($param);
         // 查询列表数据
-        return $this->where($filter)->order(['sort', 'express_id'])->paginate(15);
+        return $this->where($filter)
+            ->where('is_delete', '=', 0)
+            ->order(['sort', $this->getPk()])
+            ->paginate(15);
     }
 
     /**

+ 19 - 10
app/store/model/Express.php

@@ -48,30 +48,39 @@ class Express extends ExpressModel
      */
     public function remove(): bool
     {
-        // 判断当前物流公司是否已被订单使用
-        $Order = new Order;
-        if ($orderCount = $Order->where(['express_id' => $this['express_id']])->count()) {
-            $this->error = '当前物流公司已被' . $orderCount . '个订单使用,不允许删除';
-            return false;
-        }
-        return $this->delete();
+        return $this->save(['is_delete' => 1]);
     }
 
     /**
      * 根据物流公司名称获取ID集
-     * @param array $expressNameArr
+     * @param array $expressNames
      * @return array
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public static function getExpressIds(array $expressNameArr): array
+    public static function getExpressIds(array $expressNames): array
     {
-        $list = (new static)->where('express_name', 'in', $expressNameArr)->select();
+        $list = (new static)->getListByExpressName($expressNames);
         $data = [];
         foreach ($list as $item) {
             $data[$item['express_name']] = $item['express_id'];
         }
         return $data;
     }
+
+    /**
+     * 根据物流公司名称获取列表记录
+     * @param array $expressNames
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    private function getListByExpressName(array $expressNames): array
+    {
+        return (new static)->where('express_name', 'in', $expressNames)
+            ->where('is_delete', '=', 0)
+            ->select();
+    }
 }

+ 3 - 0
数据库修改记录/v2.1.1.sql

@@ -20,3 +20,6 @@ ALTER TABLE `yoshop_order_address` ADD INDEX (`order_id`);
 # 订单记录表 - 订单结算时间
 ALTER TABLE `yoshop_order`
 ADD COLUMN `settled_time` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单结算时间' AFTER `is_settled`;
+
+ALTER TABLE `yoshop_express`
+ADD COLUMN `is_delete`  tinyint(3) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否删除' AFTER `sort`;