123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?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\Cache;
- use think\facade\Db;
- class good extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->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);
- }
- }
|