123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;use think\facade\Db;
- class CopyGood extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('copygood')
- ->setDescription('the copygood command');
- }
- protected function execute(Input $input, Output $output)
- {
- // 指令输出D
- $spuCode= Db::name("changgood")->cursor();
- Db::startTrans();
- try{
- foreach ($spuCode as $key=>$value){
- echo $value['good_code']."\r\n";
- $spu=substr(makeNo('SKU'),0,-4).str_pad(strval($key+1),4,'0',STR_PAD_LEFT);
- $goodInfo = Db::name("good_basic")->where(["spuCode"=>$value['good_code']])->findOrEmpty();
- if(empty($goodInfo)){
- echo $value['good_code']."无数据\r\n";
- continue;
- }
- unset($goodInfo['id']);
- $goodInfo['spuCode']=$spu;
- $goodInfo['companyNo']='GS2402020907088731';
- $goodInfo['companyName']='北京泰文创供应链管理有限公司';
- $goodInfo['createrid']=0;
- $goodInfo['creater']='system';
- Db::name('good_basic')->save($goodInfo);
- $this->makeNake($value['good_code'],$spu);
- $this->makeSpec($value['good_code'],$spu);
- Db::name('changgood')->where($value)->save(["change_code"=>$spu]);
- }
-
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- $output->writeln($e->getMessage());
-
- }
- $output->writeln('copygood');
- }
-
- public function makeNake($old,$new){
- // spuCode,min_num,nake_fee,cost_fee,delivery_fee,cert_fee,mark_fee,package_fee,other_fee,nake_total
- $Dbname = Db::name("good_nake")->where(["spuCode"=>$old,"is_del"=>0])
- ->column("'{$new}' spuCode,min_num,nake_fee,cost_fee,delivery_fee,cert_fee,mark_fee,package_fee,other_fee,nake_total");
- Db::name('good_nake')->insertAll($Dbname);
- }
-
- public function makeSpec($old,$new){
- // spuCode,min_num,nake_fee,cost_fee,delivery_fee,cert_fee,mark_fee,package_fee,other_fee,nake_total
- $Dbname = Db::name('good_spec')->where(['spuCode'=>$old,'is_del'=>0])
- ->column("'{$new}' spuCode,spec_id,spec_value_id");
- Db::name('good_spec')->insertAll($Dbname);
- }
- }
|