123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use app\admin\model\Unit;use PhpOffice\PhpSpreadsheet\Cell\Coordinate;use PhpOffice\PhpSpreadsheet\IOFactory;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 makeGood extends Command
- {
- protected $db;
- protected function configure()
- {
- // 指令配置
- $this->setName('makegood')
- ->setDescription('the makegood command');
- }
- protected function execute(Input $input, Output $output)
- {
- // 指令输出
- $output->writeln('makegood');
- $file ="./public/exece.xlsx";
- $spreadsheet =IOFactory::load($file);
- // 选择第一个工作表
- ini_set("memory_limit","-1");
- $this->db=Db::connect("mysql_sys");
- // $this->getNake();return;
- $worksheet = $spreadsheet->getActiveSheet();
- $height = $worksheet->getHighestRow();
- // 获取最高的列号
- $highestColumn = $worksheet->getHighestColumn();
- $number = Coordinate::columnIndexFromString($highestColumn);
- $header=[
- '',
- 'spuCode',
- 'good_name',
- 'cat_id',
- 'brand_id',
- 'good_unit',
- 'good_type',
- 'companyNo',
- 'moq',
- 'customized',
- 'tax',
- 'supplierNo',
- 'is_auth',
- 'is_stock',
- 'after_sales',
- 'craft_desc',
- 'good_remark',
- 'good_size',
- 'weight',
- 'packing_way',
- 'packing_size',
- 'packing_spec',
- 'packing_list',
- 'packing_weight',
- 'good_bar',
- 'supply_area',
- 'delivery_place',
- 'origin_place',
- 'delivery_day',
- 'lead_time',
- 'sample_day',
- 'sample_fee',
- 'cert_fee',
- 'packing_fee',
- 'cost_fee',
- 'mark_fee',
- 'demo_fee',
- 'open_fee',
- 'noble_metal',
- 'noble_weight',
- 'is_gold_price',
- 'cgd_gold_price',
- 'market_price',
- 'nake_price',
- 'is_step',
- 'supplier_origin_price',
- 'cgd_supplier_code',
- 'cgd_apply_id',
- 'cgd_apply_name',
- 'is_exclusive',
- 'is_diff',
- 'config',
- 'other_config',
- 'stock_moq',
- 'is_support_barter',
- 'is_combind',
- 'plat_code'];
- $data=[];
- for ($i=2;$i<=$height;$i++){
- $temp=[];
- for ($j=1;$j<=$number;$j++){
- if(isset($header[$j])){
- $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
- }else{
- break;
- }
- }
- $temp['spuCode'] = substr(makeNo('SKU'),0,-4).str_pad(strval($i),4,"0",STR_PAD_LEFT);
- $temp['companyName'] = $this->getCompanyName($temp['companyNo']);
- $temp['supplierName'] = $this->getCompanyName($temp['supplierNo']);
- $temp['cgd_supplier_name'] = $this->getCompanyName($temp['cgd_supplier_code']);
- $temp['delivery_place']= $this->getAddress($temp['delivery_place']);
- $temp['origin_place']= $this->getAddress($temp['origin_place']);
- $temp['good_unit']= $this->getUnit($temp['good_unit']);
- $data[]=$temp;
- if($i%1000==0){
- Db::name('good_temp')->insertAll($data);
- $data=[];
- }
- }
- if(!empty($data)) Db::name('good_temp')->insertAll($data);
- $this->getOnline();
- $this->getNake();
- }
-
- public function getCompanyName($code){
- return $this->db->name("headquarters")->where("code",$code)->value("name",'');
- }
- public function getUnit($unit_name){
- $unit=Unit::where("unit",$unit_name)->findOrEmpty();
- if($unit->isEmpty()){
- $info =Unit::create(["unit"=>$unit_name]);
- return $info->id;
- }
- return $unit->id;
- }
-
- public function getAddress($addr){
- $p_c_a =get_address($addr);
- $addeRss=[];
- $province = Db::name('province')
- ->field('province_code,name')
- ->where('name', $p_c_a['province'])
- ->findOrEmpty();
- $addeRss[]=$province['province_code'];
- $city = Db::name('city')
- ->field('city_code,name')
- ->where(['name' => $p_c_a['city']?:$p_c_a['province'], 'province_code' => $province['province_code'] ?: ''])
- ->findOrEmpty();
- $addeRss[]=$city['city_code']?? $province['province_code'];
- $area = Db::name('area')
- ->field('area_code,name')
- ->where(['name' => $p_c_a['district'], 'city_code' => $city['city_code'] ?:''])
- ->findOrEmpty();
-
- $addeRss[]= $area['area_code']?? '';
-
- return implode(",",$addeRss);
- }
-
- public function getOnline(){
- $file ='./public/add.xlsx';
- $spreadsheet =IOFactory::load($file);
- $worksheet = $spreadsheet->getActiveSheet();
- $height = $worksheet->getHighestRow();
- // 获取最高的列号
- $highestColumn = $worksheet->getHighestColumn();
- $number = Coordinate::columnIndexFromString($highestColumn);
- $data=[];
- $header=["",'spuCode','skuCode','platform_code','is_compliance','compliance_remark','plat_code','is_fixed'];
- for ($i=2;$i<=$height;$i++){
- $temp=[];
- for ($j=1;$j<=$number;$j++){
- if(isset($header[$j])){
- $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
- }else{
- break;
- }
- }
- $temp['spuCode'] = Db::name("good_temp")->where(["plat_code"=>$temp['plat_code']])->value("spuCode",'');
- $temp['skuCode'] = substr(makeNo('SN'),0,-4).str_pad(strval($i),4,'0',STR_PAD_LEFT);
- $data[]=$temp;
- if($i%1000==0){
- Db::name('good_platform_temp')->insertAll($data);
- $data=[];
- }
- }
- if(!empty($data)) Db::name('good_platform_temp')->insertAll($data);
- $this->getLadder();
- }
-
-
- public function getLadder(){
- $file ='./public/ladder.xlsx';
- $spreadsheet =IOFactory::load($file);
- $worksheet = $spreadsheet->getActiveSheet();
- $height = $worksheet->getHighestRow();
-
- // 获取最高的列号
- $highestColumn = $worksheet->getHighestColumn();
- $number = Coordinate::columnIndexFromString($highestColumn);
- $data=[];
- $header=['','skuCode','min_num','sale_price','origin_price','market_price','market_platform','origin_rate','cost_fee','plat_code'];
- for ($i=2;$i<=$height;$i++){
- $temp=[];
- for ($j=1;$j<=$number;$j++){
- if(isset($header[$j])){
- $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
- }else{
- break;
- }
- }
- $temp['skuCode'] = Db::name('good_platform_temp')->where(['plat_code'=>$temp['plat_code']])->value('skuCode','');
- $data[]=$temp;
- if($i%1000==0){
- Db::name('good_ladder_temp')->insertAll($data);
- $data=[];
- }
- }
- if(!empty($data))Db::name('good_ladder_temp')->insertAll($data);
- }
-
- public function getNake(){
- $file ='./public/nake.xlsx';
- $spreadsheet =IOFactory::load($file);
- $worksheet = $spreadsheet->getActiveSheet();
- $height = $worksheet->getHighestRow();
-
- // 获取最高的列号
- $highestColumn = $worksheet->getHighestColumn();
- $number = Coordinate::columnIndexFromString($highestColumn);
- $data=[];
- $header=['','spuCode','min_num','nake_fee','cost_fee','delivery_fee','cert_fee','mark_fee','package_fee','other_fee','nake_total','plat_code'];
- for ($i=2;$i<=$height;$i++){
- $temp=[];
- for ($j=1;$j<=$number;$j++){
- if(isset($header[$j])){
- $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
- }else{
- break;
- }
- }
- $temp['spuCode'] = Db::name('good_temp')->where(['plat_code'=>$temp['plat_code']])->value('spuCode','');
- $data[]=$temp;
- if($i%1000==0){
- Db::name('good_nake_temp')->insertAll($data);
- $data=[];
- }
- }
- if(!empty($data))Db::name('good_nake_temp')->insertAll($data);
-
- }
- }
|