Browse Source

入仓同步到mongodb

unknown 9 months ago
parent
commit
aacb12b8c1

+ 18 - 1
application/api/controller/FinishedProductWarehousing.php

@@ -7,6 +7,7 @@ use app\api\controller\OrderSuperLoss;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\ModelNotFoundException;
 use think\exception\DbException;
+use think\Db;
 
 /**
  * 成品入仓维护接口
@@ -441,6 +442,8 @@ class FinishedProductWarehousing extends Api
         if(!$this->request->isPost()){
             $this->error('请求方式错误');
         }
+        //连接mongodb
+        $mongodb = Db::connect(config('database.mongodb'));
         $req = $this->request->param();
         $arr = [
             'Sys_id',
@@ -483,6 +486,8 @@ class FinishedProductWarehousing extends Api
         try{
             $sql = db('成品入仓')->fetchSql(true)->insert($data);
             $bool = db()->query($sql);
+            //新增进MongoDB
+            $res = $mongodb->name('finished_products')->insert($data);
             // 提交事务
             db()->commit();
         } catch (\Exception $e) {
@@ -522,6 +527,8 @@ class FinishedProductWarehousing extends Api
         if(!$this->request->isPost()){
             $this->error('请求方式错误');
         }
+        //连接mongodb
+        $mongodb = Db::connect(config('database.mongodb'));
         $req = $this->request->param();
         $arr = [
             '入仓类型', '仓库编号', '仓库名称',
@@ -561,12 +568,15 @@ class FinishedProductWarehousing extends Api
                 $this->error($existingRecord['jjcp_gdbh'].'工单 -- 印件'.$existingRecord['jjcp_yjno'].'已经进入末版,无法继续操作');
             }
         };
-
         //开启事务
         db()->startTrans();
         try{
             $sql = db('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
             $bool = db()->query($sql);
+            //同步更新monodb数据
+             $res = $mongodb->name('finished_products')
+                ->where('UniqId', (int)$req['UniqId']) // 使用实际的UniqId值
+                ->update($data);
             // 提交事务
             db()->commit();
         } catch (\Exception $e) {
@@ -606,6 +616,8 @@ class FinishedProductWarehousing extends Api
         if(!$this->request->isPost()){
             $this->error('请求方式错误');
         }
+         //连接mongodb
+        $mongodb = Db::connect(config('database.mongodb'));
         $req = $this->request->param();
 
         if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
@@ -616,6 +628,11 @@ class FinishedProductWarehousing extends Api
         db()->startTrans();
         try{
             $bool = db('成品入仓')->where('UniqId',$req['UniqId'])->delete();
+            //同时删除mongdb数据
+            //同步更新monodb数据
+             $res = $mongodb->name('finished_products')
+                ->where('UniqId', (int)$req['UniqId']) // 使用实际的UniqId值
+                ->delete();
             // 提交事务
             db()->commit();
         } catch (\Exception $e) {

+ 12 - 4
composer.json

@@ -33,12 +33,20 @@
         "txthinking/mailer": "^2.0"
     },
     "config": {
-        "preferred-install": "dist"
+        "preferred-install": "dist",
+        "allow-plugins": {
+            "topthink/think-installer": true,
+            "easywechat-composer/easywechat-composer": true
+        }
     },
-    "repositories": [
-        {
+    "repositories": {
+        "packagist": {
+            "type": "composer",
+            "url": "https://packagist.phpcomposer.com"
+        },
+        "0": {
             "type": "git",
             "url": "https://gitee.com/fastadminnet/framework.git"
         }
-    ]
+    }
 }

+ 5 - 1
thinkphp/library/think/db/builder/Mysql.php

@@ -109,8 +109,12 @@ class Mysql extends Builder
             }
         }
 
-        if ($strict && !preg_match('/^[\w\.\*]+$/', $key)) {
+        // if ($strict && !preg_match('/^[\w\.\*]+$/', $key)) {
+        //     throw new Exception('not support data:' . $key);
+        // }
+        if ($strict && !preg_match('/^[\w\.\*\x00-\xff]+$/', $key)) {
             throw new Exception('not support data:' . $key);
+
         }
         if ('*' != $key && ($strict || !preg_match('/[,\'\"\*\(\)`.\s]/', $key))) {
             $key = '`' . $key . '`';