123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use app\admin\model\GoodCombind;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();
- $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);
- }
- }
- }
|