success('请求成功'); } /** * 产品表qr_qcode_product同步 */ public function vo1() { $num1 = $this->request->param('num1'); $num2 = $this->request->param('num2'); if($num2<=$num1){ $this->error('同步num1到num2之间的数据, 要求num2大于num1'); } $qcodeProduct = new QcodeProduct(); // 连接到其他数据库 $config = [ 'type' => 'mysql', 'hostname' => '127.0.0.1', 'database' => 'dm_7in6_com', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8mb4', 'prefix' => 'qr_', ]; $db = Db::connect($config); //查询主表记录 $rows1 = $db->name('qcode_product') ->limit($num1,$num2-$num1) ->select(); foreach($rows1 as $v){ //1. 查询mongodb中是否存在该条记录 $bool = $qcodeProduct->where('oid_id',$v['id'])->find(); if ($bool) continue; //2. 获取设置主表数据 $row['oid_id'] = $v['id']; $row['product_name'] = $v['product_name']; $row['product_code'] = $v['product_code']; $row['temple'] = $v['temple']; // unset($row['id']); // $row = array_merge(['oid_id'=>$v['id']],$row); //查询unit表数据 $rows2 = $db->name('qcode_unit') ->where('code',$v['product_code']) ->find(); if($rows2){ if($rows2['main_unit']!=null){ $row['main_unit'] = $rows2['main_unit']; }else{ $row['main_unit'] = ''; } if($rows2['sec_unit']!=null){ $row['sec_unit'] = $rows2['sec_unit']; }else{ $row['sec_unit'] = ''; } if($rows2['proportion']!=null){ $row['proportion'] = $rows2['proportion']; }else{ $row['proportion'] = ''; } }else{ $row['main_unit'] = ''; $row['sec_unit'] = ''; $row['proportion'] = ''; } //3. 插入主表记录到mongodb中 $qcodeProduct = new QcodeProduct(); $qcodeProduct->save($row); } $this->success('成功'); } /** * 公司名称表qr_qcode_gsmc同步 */ public function vo2() { $num1 = $this->request->param('num1'); $num2 = $this->request->param('num2'); if($num2<=$num1){ $this->error('同步num1到num2之间的数据, 要求num2大于num1'); } $qcodeGsmc = new QcodeGsmc(); // 连接到其他数据库 $config = [ 'type' => 'mysql', 'hostname' => '127.0.0.1', 'database' => 'dm_7in6_com', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8mb4', 'prefix' => 'qr_', ]; $db = Db::connect($config); //查询主表记录 $rows1 = $db->name('qcode_gsmc') ->limit($num1,$num2-$num1) ->select(); foreach($rows1 as $v){ //1. 查询mongodb中是否存在该条记录 $bool = $qcodeGsmc->where('oid_id',$v['id'])->find(); if ($bool) continue; //2. 获取设置主表数据 $row = $v; unset($row['id']); $row = array_merge(['oid_id'=>$v['id']],$row); //3. 插入主表记录到mongodb中 $qcodeGsmc = new QcodeGsmc(); $qcodeGsmc->save($row); } $this->success('成功'); } /** * 产品表qr_qcode_classification同步 */ public function vo3() { $num1 = $this->request->param('num1'); $num2 = $this->request->param('num2'); if($num2<=$num1){ $this->error('同步num1到num2之间的数据, 要求num2大于num1'); } $qcodeClassification = new QcodeClassification(); // 连接到其他数据库 $config = [ 'type' => 'mysql', 'hostname' => '127.0.0.1', 'database' => 'dm_7in6_com', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8mb4', 'prefix' => 'qr_', ]; $db = Db::connect($config); //查询主表记录 $rows1 = $db->name('qcode_classification') ->limit($num1,$num2-$num1) ->select(); foreach($rows1 as $v){ //1. 查询mongodb中是否存在该条记录 $bool = $qcodeClassification->where('oid_id',$v['id'])->find(); if ($bool) continue; //2. 获取设置主表数据 $row['oid_id'] = $v['id']; $row['code'] = $v['code']; $row['name'] = $v['name']; $row['status'] = $v['status']; //3. 插入主表记录到mongodb中 $qcodeClassification = new QcodeClassification(); $qcodeClassification->save($row); } $this->success('成功'); } /** * 设置产品表qr_qcode_classification */ public function vo4() { $qcodeClassification = new QcodeProduct(); //查询主表记录 $rows1 = $qcodeClassification->select(); foreach($rows1 as $v){ //2. 获取设置主表数据 $row = []; $row['code'] = substr($v['product_code'],0,4); //3. 插入主表记录到mongodb中 $qcodeClassification = new QcodeProduct(); $row = $qcodeClassification->where('oid_id',$v['oid_id'])->update($row); } $this->success('成功'); } /** * 同步bach * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function vo5() { $num1 = 0; $num2 = 1; if($num2<=$num1){ $this->error('同步num1到num2之间的数据, 要求num2大于num1'); } // 连接到其他数据库 $config = [ 'type' => 'mysql', 'hostname' => '127.0.0.1', 'database' => 'dm_7in6_com', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8mb4', 'prefix' => 'qr_', ]; $db = Db::connect($config); //查询主表记录 $rows1 = $db->name('qcode_bach') ->limit($num1,$num2-$num1) ->order('id desc') ->select(); $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; foreach($rows1 as $v){ //1. 查询mongodb中是否存在该条记录 $bool = $this->model->name($company_id.'_'."qcode_bach")->where('oid_id',$v['id'])->find(); if ($bool) continue; //2. 获取设置主表数据 $row = $v; unset($row['id']); $row = array_merge(['oid_id'=>$v['id']],$row); //3. 插入主表记录到mongodb中 $qcodeBach = new \app\admin\model\QcodeBach(); $qcodeBach->save($row); $pid = $qcodeBach->getLastInsID(); $rows2 = $db->name('qcode_large') ->where('bach_id',$v['id']) ->select(); foreach ($rows2 as $value){ //1. 查询mongodb中是否存在该条记录 $qcodeLarge = new QcodeLarge(); $bool = $qcodeLarge->name($company_id.'_'."qcode_large")->where('oid_id',$value['id'])->find(); if ($bool) continue; $row = $value; $row['old_bach_id'] = $value['bach_id']; $row['bach_id'] = $pid; $row['old_id'] = $value['id']; unset($row['id']); $qcodeLarge->save($row); $pid3 = $qcodeLarge->getLastInsID(); $rows3 = $db->name('qcode_small') ->where('large_id',$value['id']) ->select(); foreach ($rows3 as $value3){ //1. 查询mongodb中是否存在该条记录 $qcodeSmall = new QcodeSmall(); $bool = $qcodeSmall->name($company_id.'_'."qcode_large")->where('oid_id',$value3['id'])->find(); if ($bool) continue; $row = $value3; $row['old_bach_id'] = $value3['bach_id']; $row['old_large_id'] = $value3['large_id']; $row['old_id'] = $value3['id']; $row['bach_id'] = $pid; $row['large_id'] = $pid3; unset($row['id']); $qcodeSmall->save($row); } } } $this->success('成功'); } }