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(); $this->GoodBind(); }catch (\Exception $e){ $output->writeln("【".date("Y-m-d H:i:s")."】".$e->getMessage()); } } public function addGood($data){ if(empty($data)) return; $saleAll=[]; foreach ($data as $v){ $is=\app\admin\model\Good::where("spuCode",$v['spuCode'])->findOrEmpty(); if($is->isEmpty() || ($is->isZx==1 && $is->updatetime!=$v['updatetime'])){ $array=[ "id"=>$is->isEmpty()?null:$is->id, "spuCode"=>$v['spuCode'], "good_name"=>$v['good_name'], "companyNo"=>$v['companyNo'], "companyName"=>$v['companyName'], "supplierNo"=>$v['supplierNo'], "supplierName"=>$v['supplierName'], "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'], "isCombind"=>$v['is_combind'], "isChild"=>$v['isChild'], "cgd_supplierNo"=>$v['cgd_supplier_code'], "cgd_supplierName"=>$v['cgd_supplier_name'], "exam_info"=>"", "status"=>0, "addtime"=>$v['addtime'], "updatetime"=>$v['updatetime'], ]; $saleAll[]=$array; echo "【".date("Y-m-d H:i:s")."】 添加商品{$v['spuCode']}进入类目表\r\n"; } } if(empty($saleAll)==false)(new \app\admin\model\Good())->saveAll($saleAll); } /** * @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')->alias("a") ->leftJoin("good_tax b","a.spuCode=b.spuCode") ->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("a.spuCode,good_name,cat_id,good_unit,craft_desc,after_sales,supplierNo,companyNo,supplierName,companyName,good_img, good_info_img,good_thumb_img,creater,createrid,is_stock,0 isZx,is_combind,cgd_supplier_code,cgd_supplier_name,isChild,addtime,updatetime ,b.tax_id,b.tax,b.inv_good_name") ->where("updatetime",">=", $this->date) ->where("status","=", 1) ->select()->toArray(); return $this->addGood($list); } public function goodZx(){ $list =Db::connect('mysql_wsm') ->name('good_zixun') ->alias('a') ->leftJoin('good_tax b','a.spuCode=b.spuCode') ->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("a.spuCode,good_name,craft_desc,'' after_sales,cat_id,good_unit,supplierNo,a.companyNo,supplierName,companyName,good_img, good_info_img,good_thumb_img,creater,createrid,0 is_stock,1 isZx,is_combind,cgd_supplier_code,cgd_supplier_name,isChild, addtime,updatetime,b.tax_id,b.tax,b.inv_good_name") ->where("addtime",">=", $this->date) ->select()->toArray(); return $this->addGood($list); } public function GoodBind(){ $list =Db::connect('mysql_wsm')->name("good_combind") ->where('createtime','>=', $this->date) ->select(); if(empty($list)==false){ $add=[]; foreach($list as $item){ unset($item['id']); $ist=GoodCombind::where(["spuCode"=>$item['spuCode'],"childCode"=>$item['childCode']])->findOrEmpty(); if($ist->isEmpty())$add[]=$item; } (new \app\admin\model\GoodCombind())->saveAll($add); } } }