Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

李洋 / 消息系统

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • CMS-Message
  • app
  • Http
  • Controllers
  • BatchController.php
BatchController.php 6.33 KB
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use RedisDB;

class BatchController extends Controller
{
    public function Entrance(Request $request, $id ){
        //统一入口
        $this->$id($request, $id);
    }

    private function Export($errcode=0,$errmsg='成功',$data=''){
        echo json_encode(['errcode'=>$errcode,'errmsg'=>$errmsg,'data'=>$data]);
        exit();
    }

    //生成spu唯一识别信息
    private function create_spu_mongo()
    {
        set_time_limit(0);
        $starttime = explode(' ',microtime());
        echo microtime();

        $mongo=new \MongoClient(env('MONGO_HOST', ''));
        $mongodb=$mongo->ichunt->spu;


        $count=100;
        $db=DB::connection('spu');


        for($table=0;$table<10;$table++){
            for ($p=1;$p<$count+1;$p++){
                $data=[];
                $list=$db->table('lie_spu_'.$table)->select('spu_name','brand_id','spu_id')->paginate(1000,['*'],'',$p);
                foreach ($list as $k=>$v){
                    $data[]=[
                        'spu_id'=>$v->spu_id,
                        'spu_name'=>$v->spu_name,
                        'brand_id'=>$v->brand_id
                    ];
                }
                $result=$mongodb->batchInsert($data);
                $count=$list->lastPage();
            }
        }

        //程序运行时间
        $endtime = explode(' ',microtime());
        $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
        $thistime = round($thistime,3);
        echo "本程序执行耗时:".$thistime." 秒。".time();

    }

    private function create_sku_mongo()
    {
        set_time_limit(0);
        $starttime = explode(' ',microtime());
        echo microtime();

        $mongo=new \MongoClient(env('MONGO_HOST', ''));
        $mongodb=$mongo->ichunt->sku;


        $count=100;

        for ($dbcode=0;$dbcode<10;$dbcode++){

            $db=DB::connection('sku_'.$dbcode);

            for($table=0;$table<10;$table++){
                for ($p=1;$p<$count+1;$p++){
                    $data=[];
                    $list=$db->table('lie_sku_'.$table)->select('goods_id','spu_id','moq','supplier_id')->paginate(10000,['*'],'',$p);
                    foreach ($list as $k=>$v){
                        $data[]=[
                            'goods_id'=>intval($v->goods_id),
                            'spu_id'  =>intval($v->spu_id),
                            'supplier_id'=>intval($v->supplier_id),
                            'moq'=>intval($v->moq)
                        ];
                    }
                    $mongodb->batchInsert($data);
                    $count=$list->lastPage();
                }
            }
        }


        //程序运行时间
        $endtime = explode(' ',microtime());
        $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
        $thistime = round($thistime,3);
        echo "本程序执行耗时:".$thistime." 秒。".time();

    }

    private function create_spu_redis($request){

        set_time_limit(0);

        $redis=RedisDB::connection();
        $db=DB::connection('spu');
        $table=$request->input('table');
        $data=[];
        $list=$db->table('lie_spu_'.$table)
            ->select('spu_id','class_id1','class_id2','brand_id','class_id3','spu_name','status','images_l','images_s','encap','pdf','spu_brief','has_rohs','attrs','spu_detail','sale_time','create_time','update_time','remark','bussiness_area')
            ->paginate(1000);

        foreach ($list as $k=>$v){
            $info=(array)$v;
            $info['class_id']=0;

            if(!empty($info['class_id1'])){
                $info['class_id']=$info['class_id1'];
            }
            if(!empty($info['class_id2'])){
                $info['class_id']=$info['class_id2'];
            }
            if(!empty($info['class_id3'])){
                $info['class_id']=$info['class_id3'];
            }

            $info['class_name']=$redis->hget('class',$info['class_id']);


            $info['brand_name']=$redis->hget('brand',$info['brand_id']);


            switch ($info['status']){
                case 0:
                    $info['status_name']='审核中';
                    break;
                case 1:
                    $info['status_name']='上架';
                    break;
                case 2:
                    $info['status_name']='审核不通过';
                    break;
                case 3:
                    $info['status_name']='下架';
                    break;
                default :
                    $info['status_name']='未知';
            }

            $info['create_time_s']=date('Y-m-d H:i',$info['create_time']);

            $data[$v->spu_id]=json_encode($info);
        }
        $result=$redis->hmset('spu',$data);
        $objdata['count']=$list->count();
        $objdata['last_page']=$list->lastPage();

        if($result=='OK'){
            $this->Export(0,'',$objdata);
        }else{
            $this->Export(20001,'写入Redis出错');
        }
    }

    //生成spu唯一识别信息
    private function spu_redis()
    {
        echo 'kkk';die;
        set_time_limit(0);
        $starttime = explode(' ',microtime());
        echo microtime();

        $redis=RedisDB::connection();


        $count=100;
        $db=DB::connection('spu');


        for($table=0;$table<10;$table++){
            for ($p=1;$p<$count+1;$p++){
                $data=[];
                $list=$db->table('lie_spu_'.$table)
                    ->select('spu_id','class_id1','class_id2','brand_id','class_id3','spu_name','status','images_l','images_s','encap','pdf','spu_brief','has_rohs','attrs','spu_detail','sale_time','create_time','update_time','remark','bussiness_area')
                    ->paginate(1000,['*'],'',$p);
                foreach ($list as $k=>$v){
                    $v=(array)$v;
                    $data[$v['spu_id']]=json_encode($v);
                }
                $result=$redis->hmset('spu',$data);
                $count=$list->lastPage();
            }
        }

        //程序运行时间
        $endtime = explode(' ',microtime());
        $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
        $thistime = round($thistime,3);
        echo "本程序执行耗时:".$thistime." 秒。".time();

    }

    private function sku_redis(){
        
    }
}