1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use app\admin\model\CgdCaixiao;
- use app\admin\model\GoodCombind;
- use app\admin\model\GoodTax;
- use app\admin\model\OrderTax;use app\admin\model\Platform;
- use app\admin\model\Sale;use app\admin\model\SaleCaixiao;
- use app\model\TaxRelation;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Cache;
- use think\facade\Db;
- class caixiao extends Command
- {
- protected $table = null;
- protected $contect = null;
- protected $hour = null;
- protected function cgd(){
- $cgd=new CgdCaixiao();
- $where=[['updatetime','>=',$this->hour]];
- $list = $cgd->with(["originCgd"])->where($where)->select();
- $cgdArr=[];
- foreach ($list as $item){
- echo date('Y-m:d H:i:s')."|".$item->cgdNo."--".$item->mainCode."\r\n";
- $unique = md5($item->cgdNo.$item->updatetime);
- $temp=['order_type'=>2,'uniqkey'=>$unique,'status'=>1,'addtime'=>date('Y-m:d H:i:s')];
- if($this->isInCfp($unique)){
- $order_type= is_null($item->mainCode)?($item->order_source!=8?1:2):3;
- $item['inv_cat_info'] = OrderTax::spuCat($item->spuCode,2,$order_type);
- $item['cat_name'] = json_decode($item->cat_name);
- $temp['data']= json_encode($item,JSON_UNESCAPED_UNICODE);
- $cgdArr[]=$temp;
- }
- }
- if(empty($cgdArr)==false) $this->table->insertAll($cgdArr);
- }
- protected function configure()
- {
- // 指令配置
- $this->setName('caixiao')
- ->setDescription('the caixiao command');
- }
-
- protected function execute(Input $input, Output $output)
- {
- // 指令输出
- $key="caixiao_copy";
- $rs = Cache::store('redis')->get($key);
- if ($rs!=0) return true;
- Cache::store('redis')->set($key,1,180);
- $this->hour=date('Y-m-d H:i:s',strtotime('-1 hours'));
- $this->contect= Db::connect('mysql_cxinv');
- $this->table =$this->contect->name("caixiao_data");
- $this->sale();
- $this->cgd();
- $output->writeln('caixiao');
- }
-
- protected function getPay($plat_id=0){
- $plat =new Platform();
- return $plat->where("id",$plat_id)->value("platform_name","");
- }
-
- protected function sale(){
- $sale=new SaleCaixiao();
- $where=[["updatetime",">=",$this->hour]];
- $list = $sale->where($where)->cursor();
- $qrd=[];
- foreach ($list as $item){
- $unique = md5($item->orderCode.$item->updatetime);
- echo date('Y-m:d H:i:s').'|'.$item->orderCode."\r\n";
- $temp=["order_type"=>1,"uniqkey"=>$unique,"status"=>1,"addtime"=>date('Y-m:d H:i:s')];
- if($this->isInCfp($unique)){
- $item['inv_cat_info'] = OrderTax::spuCat($item->good_code,2);
- $item['cat_name'] = json_decode($item->cat_name);
- $item['remark'] = Sale::where("orderCode",$item->cxCode==""?$item->orderCode:$item->cxCode)->value("remark","");
- $temp["data"]= json_encode($item,JSON_UNESCAPED_UNICODE);
- $qrd[]=$temp;
- }
- }
- if(empty($qrd)==false) $this->table->insertAll($qrd);
- }
-
- protected function isInCfp($unique){
- $ist = $this->contect->name("caixiao_data")->where("uniqkey",$unique)->findOrEmpty();
- return empty($ist);
- }
- }
|