CopyGood.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;use think\facade\Db;
  9. class CopyGood extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('copygood')
  15. ->setDescription('the copygood command');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. // 指令输出D
  20. $spuCode= Db::name("changgood")->cursor();
  21. Db::startTrans();
  22. try{
  23. foreach ($spuCode as $key=>$value){
  24. echo $value['good_code']."\r\n";
  25. $spu=substr(makeNo('SKU'),0,-4).str_pad(strval($key+1),4,'0',STR_PAD_LEFT);
  26. $goodInfo = Db::name("good_basic")->where(["spuCode"=>$value['good_code']])->findOrEmpty();
  27. if(empty($goodInfo)){
  28. echo $value['good_code']."无数据\r\n";
  29. continue;
  30. }
  31. unset($goodInfo['id']);
  32. $goodInfo['spuCode']=$spu;
  33. $goodInfo['companyNo']='GS2402020907088731';
  34. $goodInfo['companyName']='北京泰文创供应链管理有限公司';
  35. $goodInfo['createrid']=0;
  36. $goodInfo['creater']='system';
  37. Db::name('good_basic')->save($goodInfo);
  38. $this->makeNake($value['good_code'],$spu);
  39. $this->makeSpec($value['good_code'],$spu);
  40. Db::name('changgood')->where($value)->save(["change_code"=>$spu]);
  41. }
  42. Db::commit();
  43. }catch (\Exception $e){
  44. Db::rollback();
  45. $output->writeln($e->getMessage());
  46. }
  47. $output->writeln('copygood');
  48. }
  49. public function makeNake($old,$new){
  50. // spuCode,min_num,nake_fee,cost_fee,delivery_fee,cert_fee,mark_fee,package_fee,other_fee,nake_total
  51. $Dbname = Db::name("good_nake")->where(["spuCode"=>$old,"is_del"=>0])
  52. ->column("'{$new}' spuCode,min_num,nake_fee,cost_fee,delivery_fee,cert_fee,mark_fee,package_fee,other_fee,nake_total");
  53. Db::name('good_nake')->insertAll($Dbname);
  54. }
  55. public function makeSpec($old,$new){
  56. // spuCode,min_num,nake_fee,cost_fee,delivery_fee,cert_fee,mark_fee,package_fee,other_fee,nake_total
  57. $Dbname = Db::name('good_spec')->where(['spuCode'=>$old,'is_del'=>0])
  58. ->column("'{$new}' spuCode,spec_id,spec_value_id");
  59. Db::name('good_spec')->insertAll($Dbname);
  60. }
  61. }