setName('good') ->setDescription('the good command'); } protected function execute(Input $input, Output $output) { // 指令输出 $this->date=date("Y-m-d H:i:s",time()-3600); $goodset =Cache::store("redis")->get("goodSet"); if($goodset ==1) return; Cache::store("redis")->set("goodSet",1,1800); try{ $this->goodBasic(); $this->goodZx(); // Cache::store("redis")->set("goodSet",0); }catch (\Exception $e){ // Cache::store("redis")->set("goodSet",0); $output->writeln("【".date("Y-m-d H:i:s")."】".$e->getMessage()); } } public function addGood($data){ if(empty($data)) return; foreach ($data as $v){ $is=Db::name("good")->where("spuCode",$v['spuCode'])->findOrEmpty(); if(empty($is)){ $array=[ "spuCode"=>$v['spuCode'], "good_name"=>$v['good_name'], "companyNo"=>$v['companyNo'], "supplierNo"=>$v['supplierNo'], "is_stock"=>$v['is_stock'], "craft_desc"=>$v['craft_desc'], "after_sales"=>$v['after_sales'], "good_img"=>$v['good_img'], "good_thumb_img"=>$v['good_thumb_img'], "good_info_img"=>$v['good_info_img'], "creater"=>$v['creater'], "createrid"=>$v['createrid'], "cat_name"=>$v['cat_id'], "unit_name"=>$v['good_unit'], "isZx"=>$v['isZx'], "status"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; Db::name("good")->insert($array); echo "【".date("Y-m-d H:i:s")."】 添加商品{$v['spuCode']}进入类目表\r\n"; }else{ echo "【".date("Y-m-d H:i:s")."】 更新商品{$v['spuCode']}进入类目表\r\n"; } } } /** * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function goodBasic(){ $list =Db::connect('mysql_wsm') ->name('good_basic') ->withAttr("cat_id",function ($v){ return Db::connect('mysql_wsm')->name('cat')->where("id",$v)->value("cat_name",""); }) ->withAttr("good_unit",function ($m){ return Db::connect('mysql_wsm')->name('unit')->where("id",$m)->value("unit",""); })->field("spuCode,good_name,cat_id,good_unit,craft_desc,after_sales,supplierNo,companyNo,good_img, good_info_img,good_thumb_img,creater,createrid,is_stock,0 isZx") ->where("updatetime",">=", $this->date) ->where("status","=", 1) ->select()->toArray(); return $this->addGood($list); } public function goodZx(){ $list =Db::connect('mysql_wsm') ->name('good_zixun') ->withAttr("cat_id",function ($v){ return Db::connect('mysql_wsm')->name('cat')->where("id",$v)->value("cat_name",""); }) ->withAttr("good_unit",function ($v){ return Db::connect('mysql_wsm')->name('unit')->where("id",$v)->value("unit",""); }) ->field("spuCode,good_name,craft_desc,'' after_sales,cat_id,good_unit,supplierNo,companyNo,good_img,good_info_img,good_thumb_img,creater,createrid,0 is_stock,1 isZx") ->where("addtime",">=", $this->date) ->select()->toArray(); return $this->addGood($list); } }