123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <?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 good extends Command
- {
- private $db;
- protected function configure()
- { $this->setName('good')
- ->setDescription('the good command');
- }
- protected function execute(Input $input, Output $output)
- {
- $this->db =Db::connect("mysql2");
- $data = $this->Getdata();
- foreach ($data as $value){
- $value['spucode']= str_replace("GY","SPU",$value['good_code']);
- $value['item_code']=str_replace("GY","SKU",$value['good_code']);
- $isT=Db::name("good")->where("good_code","=",$value['good_code'])->find();
- $temp=[
- "spuCode"=>$value['spucode'],
- "good_code"=>$value['good_code'],
- "createrid"=>0,
- "ownerid"=>0,
- "cgderid"=>0,
- "creater"=>$value['creater']??"",
- "owner"=>$value['owner']??"",
- "cgder"=>$value['cg_saler']==""?"":$value['cg_saler'],
- "gys_code"=>$value['gys_code'],
- "license"=>'',
- "platform_code"=>$value['item']??"",
- "cat_id"=>$this->getCat($value['sort_f'],$value['sort_s'],$value['sort_t']),
- "addtime"=>isset($value['addtime'])&&$value['addtime']!=""? $value['addtime']:date("Y-m-d H:i:s"),
- "updatetime"=>isset($value['updatetime'])&&$value['updatetime']!=""? $value['updatetime']:date("Y-m-d H:i:s"),
- ];
- if($isT){
- Db::name("good")->where($isT)->save($temp);
- }else{
- Db::name("good")->save($temp);
- }
- $this->addType($value);
- $this->laddle($value);
- }
- }
- public function laddle($value){
- if($value['step_num_1']!=""){
- $temp=[
- "skuCode"=>$value['item_code'],
- "platform_code"=>$value['item']??"",
- "min_num"=>$value['step_num_1'],
- "max_num"=>$value['step_num_2']??0,
- "sale_price"=>$value['step_price_1'],
- "origin_price"=>$value['market_fee'],
- "ladder"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $upda= Db::name("good_ladder")->where(["skuCode"=>$value['item_code'],"platform_code"=>$temp['platform_code'],"ladder"=>$temp['ladder']])->find();
- if($upda){
- Db::name("good_ladder")->where($upda)->save($temp);
- }else{
- Db::name("good_ladder")->save($temp);
- }
- }
- if($value['step_num_2']!=""){
- $temp=[
- "skuCode"=>$value['item_code'],
- "platform_code"=>$value['item']??"",
- "min_num"=>$value['step_num_2'],
- "max_num"=>$value['step_num_3']??0,
- "sale_price"=>$value['step_price_2'],
- "origin_price"=>$value['market_fee'],
- "ladder"=>2,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $upda= Db::name("good_ladder")->where(["skuCode"=>$value['item_code'],"platform_code"=>$temp['platform_code'],"ladder"=>$temp['ladder']])->find();
- if($upda){
- Db::name("good_ladder")->where($upda)->save($temp);
- }else{
- Db::name("good_ladder")->save($temp);
- }
- }
- if($value['step_num_3']!=""){
- $temp=[
- "skuCode"=>$value['item_code'],
- "platform_code"=>$value['item']??"",
- "min_num"=>$value['step_num_3'],
- "max_num"=>0,
- "sale_price"=>$value['step_price_3'],
- "origin_price"=>$value['market_fee'],
- "ladder"=>3,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $upda= Db::name("good_ladder")->where(["skuCode"=>$value['item_code'],"platform_code"=>$temp['platform_code'],"ladder"=>$temp['ladder']])->find();
- if($upda){
- Db::name("good_ladder")->where($upda)->save($temp);
- }else{
- Db::name("good_ladder")->save($temp);
- }
- }
- }
- public function getCat($f,$s,$t){
- if($f==''){
- return 0;
- }
- $first = Db::name("cat")->where(['cat_name'=>$f,"level"=>1])->find();
- if(empty($first)){
- return 0;
- }
- if($s==""){
- return $first['id'];
- }
- $sec = Db::name("cat")->where(['cat_name'=>$s,"level"=>2,"pid"=>$first['id']])->find();
- if(empty($sec)){
- return $first['id'];
- }
- if($t==""){
- return $sec['id'];
- }
- $thd = Db::name("cat")->where(['cat_name'=>$t,"level"=>3,"pid"=>$sec['id']])->find();
- if(empty($thd)){
- return $sec['id'];
- }
- return $thd['id'];
- }
- public function addType($value){
- $data=[
- "skuCode"=>$value['item_code'],
- "spuCode"=>$value['spucode'],
- "good_name"=>$value['good_name'],
- "good_desc"=>'',
- "good_img"=>'',
- "good_type"=>$value['good_type'],
- "good_title"=>'',
- "barnd"=>$value['brand'],
- "model"=>$value['model'],
- "origin_place"=>$value['good_addr'],
- "unit"=>$value['unit'],
- "weight"=>$value['good_weight'],
- "color"=>$value['color']??'',
- "material"=>$value['material']??'',
- "craft_desc"=>'',
- "specs"=>$value['specs'],
- "good_size"=>"",
- "packing_size"=>$value['pack_size'],
- "packing_way"=>"",
- "packing_specs"=>"",
- "packing_weight"=>"0",
- "bar_code"=>$value['bar_code'],
- "supply_area"=>$value['supply_area'],
- "packing_img"=>"",
- "delivery_place"=>$value['shipment'],
- "delivery_day"=>intval($value['logistics']),
- "market_price"=>$value['market_fee'],
- "warn_stock"=>0,
- "web_url"=>"",
- "is_diff"=>$value['is_diff']=="是"?1 :0,
- "cert_fee"=>$value['cert_fee']??0,
- "packing_fee"=>$value['packing_fee']??0,
- "mark_fee"=>$value['mark_fee']??0,
- "cost_fee"=>$value['cost_fee']??0,
- "demo_fee"=>0,
- "noble_metal"=>$value['noble_metal'],
- "open_fee"=>0,
- "response_time"=>intval($value['fk_day']),
- "lead_time"=>intval($value['duration']),
- "custom_moq"=>intval($value['min_num']),
- "custome_day"=>0,
- "sample_day"=>intval($value['sampling_period']),
- "sample_fee"=>floor($value['sample_fee']),
- "nake_price"=>$value['nake_fee'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $ist = Db::name("good_type")->where(["skuCode"=>$data['skuCode']])->find();
- if($ist){
- Db::name("good_type")->where($ist)->save($data);
- }else{
- Db::name("good_type")->save($data);
- }
- }
- public function Getplat($name){
- $plat=Db::name("platform")->where(["paltform_name"=>$name])->find();
- return isset($plat['paltform_code'])&&$plat['paltform_code']!='' ?$plat['paltform_code']:$name;
- }
- public function Getdata(){
- $date = date("Y-m-d H:i:s",strtotime("-1 day"));
- $sql="SELECT
- b.Date1618678149288 as 'addtime',
- b.ShortText1621438752474 as 'good_code',
- b.ShortText1615776172238 as 'item',
- (SELECT
- b_.`name`
- FROM
- h_org_user b_
- WHERE b_.id =b.creater) as 'creater',
- (SELECT
- b_.`name`
- FROM
- h_org_user b_
- WHERE b_.id =b.`owner`) as 'owner',
- b.text1615776332933 as 'good_name',
- b.ShortText1622973543024 as 'old_item',
- b.ShortText1618630964434 as 'tkcode',
- b.text1615776271768 as 'item_code',
- b.text1618981719029 as 'spucode',
- b.text1615776440661 as 'model',
- b.text1615776695388 as 'color',
- b.text1615776685415 as 'material',
- b.text1618677034797 as 'technology',
- b.ShortText1615776786473 as 'unit',
- b.text1618677035673 as 'good_type',
- b.text1619509430228 as 'specs',
- b.ShortText1618677119629 as 'is_main',
- b.ShortText1617875730953 as 'is_diff',
- ifnull(b.Number1618677207590,0) as 'good_weight',
- ifnull(b.Number1619054377997,0) as 'box_weight',
- b.ShortText1618677229373 as 'box_specs',
- b.text1618677251640 as 'box_size',
- b.text1618677252567 as 'pack_size',
- b.ShortText1618677280883 as 'bar_code',
- b.ShortText1618677293358 as 'good_addr',
- b.ShortText1618677303623 as 'fk_day',
- b.ShortText1618677324610 as 'supply_area',
- b.text1619517580239 as 'shipment',
- ifnull(b.ShortText1615776990102,'') as 'gys_code',
- b.Number1618677463881 as 'min_num',
- b.number1619054436137 as 'order_minnum',
- b.Number1617867853654 as 'duration',
- b.Number1618677510201 as 'sampling_period',
- ifnull(b.Number1618677523586,0) as 'sample_fee',
- ifnull(b.number1615788597819,0) as 'nake_fee',
- b.number1617867867574 as 'logistics',
- ifnull(b.number1615788674789,0) as 'logistics_fee',
- ifnull(b.number1615788650916,0) as 'cert_fee',
- ifnull(b.number1615788639684,0) as 'packing_fee',
- ifnull(b.number1615788611295,0) as 'mark_fee',
- ifnull(b.number1617875705335,0) as 'cost_fee',
- ifnull(b.number1615788686735,0) as 'unit_price',
- ifnull(b.ShortText1615454226082,'') as 'noble_metal',
- ifnull(b.number1618677641446,0) as 'metal_weight',
- ifnull(b.Number1616399256021,0) as 'market_fee',
- b.ShortText1616119282513 as 'wsm_nature',
- b.ShortText1619054472299 as 'is_step',
- b.ShortText1618677768792 as 'tax',
- b.Number1618677857395 as 'step_num_1',
- b.Number1619054496274 as 'step_post_1',
- b.Number1618677862829 as 'step_price_1',
- b.number1618677888101 as 'step_num_2',
- b.number1619054497412 as 'step_post_2',
- b.number1618677890766 as 'step_price_2',
- b.number1618677920417 as 'step_num_3',
- b.number1619054516068 as 'step_post_3',
- b.number1618677922828 as 'step_price_3',
- b.number1618677997457 as 'sale_1',
- b.number1618677998335 as 'sale_2',
- b.number1618678013601 as 'sale_3',
- b.number1618964483608 as 'sale_other',
- (SELECT
- b_.`name`
- FROM
- h_org_user b_
- WHERE b_.id = JSON_EXTRACT (
- b.StaffSelector1616205980618,
- '$[0].id'
- )) as 'cg_saler',
- b.ShortText1618678061783 as 'is_online',
- b.ShortText1618678132819 as 'fund',
- b.ShortText1615802884401 as 'brand',
- b.ShortText1615776612618 as 'sort_f',
- b.text1615776646788 as 'sort_s',
- b.ShortText1618558317611 as 'sort_t',
- b.ShortText1616222832962 as 'supplier',
- b.ShortText1631180192195 as 'change',
- b.modifiedTime as 'updatetime'
- from ibt0b_SPXX b ";
- $result = $this->db->query($sql);
- return $result;
- }
- }
|