From e02f976469f1c329ce91037415e5575ae4666cfc Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 8 Sep 2020 17:55:34 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E6=9C=8D=E5=95=86?= =?UTF-8?q?=E5=93=81=E8=A1=A8=E6=95=B0=E6=8D=AE=E6=B8=85=E6=B4=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/v3/GoodsNewController.php | 226 ++++++++++++++++++ app/Admin/Repositories/v3/GoodsNew.php | 16 ++ app/Admin/routes.php | 2 + app/Models/v3/GoodsNew.php | 70 ++++++ app/Models/v3/GoodsNewBanners.php | 18 ++ app/Models/v3/StoreNew.php | 115 +++++++++ resources/lang/zh-CN/goods-new.php | 42 ++++ 7 files changed, 489 insertions(+) create mode 100644 app/Admin/Controllers/v3/GoodsNewController.php create mode 100644 app/Admin/Repositories/v3/GoodsNew.php create mode 100644 app/Models/v3/GoodsNew.php create mode 100644 app/Models/v3/GoodsNewBanners.php create mode 100644 app/Models/v3/StoreNew.php create mode 100644 resources/lang/zh-CN/goods-new.php diff --git a/app/Admin/Controllers/v3/GoodsNewController.php b/app/Admin/Controllers/v3/GoodsNewController.php new file mode 100644 index 0000000..5b4b975 --- /dev/null +++ b/app/Admin/Controllers/v3/GoodsNewController.php @@ -0,0 +1,226 @@ +id->sortable(); + $grid->cover_img_url->image('',50); + $grid->name; + $grid->price; + $grid->column('market_id')->display(function($marketId){ + $item = MarketModel::getMarketInfo($marketId,'name'); + return empty($item) ? '' : $item->name; + }); + $grid->store_id->display(function ($storeId){ + $store = StoreModel::getStoreInfo($storeId,'name'); + return empty($store) ? '' : $store->name; + }); + $grid->category_id->display(function ($categoryId){ + $item = CategoryModel::getInfo($categoryId,'title'); + return empty($item) ? '' : $item->title; + }); + $grid->goods_category_id->display(function ($goodsCategoryId){ + $item = GoodsCategoryModel::getInfo($goodsCategoryId,'title'); + return empty($item) ? '' : $item->title; + }); + + + $grid->sort->sortable(); + $grid->on_sale->switch(); + + $grid->actions([new GoodsCopy()]); + $grid->filter(function (Grid\Filter $filter) { + $filter->like('name'); + }); + + $grid->model()->orderBy('id', 'desc'); + // 每页10条 + $grid->paginate(10); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + // $g = GoodsModel::find(1572); + // dd($g->toArray()); + return Show::make($id, new GoodsNew(), function (Show $show) { + $show->row(function (Show\Row $show) { + $show->width(6)->field('id'); + $show->width(6)->field('name'); + $show->width(6)->category_id->as(function ($categoryId){ + $item = CategoryModel::getInfo($categoryId,'title'); + return empty($item) ? '' : $item->title; + }); + $show->width(6)->store_id->as(function ($storeId){ + $item = GoodsCategoryModel::getInfo($storeId,'name'); + return empty($item) ? '' : $item->name; + }); + $show->width(6)->store_id->as(function ($goodsCategoryId){ + $item = StoreModel::getStoreInfo($goodsCategoryId,'name'); + return empty($item) ? '' : $item->name; + }); + $show->width(6)->cover_img->image(); + $show->width(6)->price; + $show->width(6)->original_price; + $show->width(6)->vip_price; + $show->width(6)->inventory; + $show->width(6)->goods_unit; + + }); + $show->row(function (Show\Row $show) { + $show->width(6)->on_sale_text; + $show->width(6)->content; + $show->width(6)->sort; + $show->width(6)->restrict_num; + $show->width(6)->start_num; + $show->width(6)->is_infinite_text; + + $show->width(6)->tags->as(function ($value){ + return $value; + }); + $show->width(6)->spec->as(function ($value){ + $text = ''; + foreach ($value as $v){ + $text .= '【'.$v['spec_key'] .':'.$v['spec_value'].'】 '; + } + return $text; + }); + $goodsModel = new GoodsModel(); + $show->html(function () use($goodsModel){ + if(empty($this->details_imgs)){ + return ''; + }else{ + // 还需要优化 + $value = $this->details_imgs; + $text = ''; + foreach ($value as $v){ + $img = $goodsModel->imageUrl($v); + $text .= ""; + } + return $text; + } + }); + + // $show->created_at; + // $show->updated_at; + }); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + $builder = GoodsModel::with(['ImageBanners','VideoBanners']); + + return Form::make($builder, function (Form $form) { + $form->hidden('id'); + + // 二级分类 + $categoryList = CategoryModel::getArray([['parent_id','>',0]]); + // 商品类目 + $goodsCategoryList = GoodsCategoryModel::getArray(); + // 店铺 + $storeList = StoreModel::getStoreArray(); + //市场 + // $marketList = MarketModel::getMarketArray(); + + $form->column(6, function (Form $form) use($storeList,$categoryList,$goodsCategoryList ){ + // $form->select('market_id')->required()->options($marketList); + $form->select('category_id')->required()->options($categoryList)->load('goods_category_id', '/api/goods_category_list'); + $form->select('goods_category_id')->required(); + $form->select('store_id')->required()->options($storeList); + $form->text('name')->required()->maxLength(20); + $form->image('cover_img')->required(); + $form->number('sort'); + }); + $form->column(6, function (Form $form) { + $form->currency('price')->required()->floatTwo()->symbol('¥'); + $form->currency('original_price')->required()->floatTwo()->symbol('¥'); + $form->currency('vip_price')->required()->floatTwo()->symbol('¥'); + $form->text('goods_unit')->help('如:斤,个,盒,500克,1000克,1500克等'); + $form->radio('is_infinite')->options(['关闭','开启'])->default(1); + $form->number('inventory')->required()->attribute('min', 1)->default(1); + $form->number('restrict_num')->attribute('min', 0)->default(0)->help('0表示不限购'); + $form->number('start_num')->attribute('min', 1)->default(1); + }); + $form->column(12, function (Form $form) { + $form->hasMany('image_banners', function (Form\NestedForm $form) { + $form->image('path')->width(2); + $form->number('sort')->width(2)->default(0); + $form->hidden('type')->value(1)->default(1); + })->required(); + $form->divider(); + $form->hasMany('video_banners', function (Form\NestedForm $form) { + $form->file('path')->width(2); + $form->number('sort')->width(2)->default(0); + $form->hidden('type')->value(2)->default(2); + }); + $form->divider(); + + $form->multipleImage('details_imgs')->help('按图片顺序上传'); + $form->text('content')->maxLength(50); + $form->text('remark')->maxLength(50); + + $form->tags('tags','标签')->options(['新品','热销','新鲜']); + $form->table('spec', function (NestedForm $table) { + $table->text('spec_key')->help('如:净含量:500克,保质期:120天,包装:12个/盒等'); + $table->text('spec_value'); + }); + $form->switch('on_sale') + ->customFormat(function ($v) { + return $v == '上架' ? 1 : 0; + }) + ->saving(function ($v) { + return $v; + }); + + $form->disableResetButton(); + $form->disableViewCheck(); + $form->disableEditingCheck(); + $form->disableCreatingCheck(); + }); + $form->saved(function (Form $form){ + $storeId = $form->input('store_id'); + + // 商品所属市场,根据店铺查询市场 + $info = StoreModel::getStoreInfo($storeId,'market_id'); + $form->market_id = $info->market_id; + }); + }); + } + +} diff --git a/app/Admin/Repositories/v3/GoodsNew.php b/app/Admin/Repositories/v3/GoodsNew.php new file mode 100644 index 0000000..22d20eb --- /dev/null +++ b/app/Admin/Repositories/v3/GoodsNew.php @@ -0,0 +1,16 @@ +resource('/goods', 'v3\GoodsController'); $router->resource('/goods_activity', 'v3\GoodsActivityController'); + $router->resource('/goods_new', 'v3\GoodsNewController'); + // banner $router->resource('/banners', 'v3\BannersController'); $router->any('/test', 'Test@test'); diff --git a/app/Models/v3/GoodsNew.php b/app/Models/v3/GoodsNew.php new file mode 100644 index 0000000..a7a5876 --- /dev/null +++ b/app/Models/v3/GoodsNew.php @@ -0,0 +1,70 @@ +'array', + 'tags'=>'array', + 'spec'=>'array', + ]; + + public static $_onSale = ['否','是']; + public static $_isInfinite = ['关闭','开启']; + + public function getCoverImgUrlAttribute($value) + { + $value = $value ? $value : $this->cover_img; + return $this->imageUrl($value); + } + public function getOnSaleTextAttribute($value) + { + $value = $value ? $value : $this->on_sale; + return isset(self::$_onSale[$value]) ? self::$_onSale[$value] : ''; + } + public function getIsInfiniteTextAttribute($value) + { + $value = $value ? $value : $this->is_infinite; + return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : ''; + } + public function ImageBanners(){ + return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',1); + } + + public function VideoBanners(){ + return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',2); + + } + + /** + * 处理旧图片 + * @param $value + * @return string + */ + public function imageUrl($value) + { + if(strripos($value,"http") === false){ + return env('OSS_IMG_HOST').'/'.$value; + }else{ + return $value; + } + } +} diff --git a/app/Models/v3/GoodsNewBanners.php b/app/Models/v3/GoodsNewBanners.php new file mode 100644 index 0000000..dd93f1d --- /dev/null +++ b/app/Models/v3/GoodsNewBanners.php @@ -0,0 +1,18 @@ +logo; + return $this->imageUrl($value); + } + + public function getIsRestTextAttribute($value) + { + $value = $value ? $value : $this->is_rest; + return isset(self::$_onRest[$value]) ? self::$_onRest[$value] : ''; + } + public function getIsOpenTextAttribute($value) + { + $value = $value ? $value : $this->is_iopen; + return isset(self::$_isOpen[$value]) ? self::$_isOpen[$value] : ''; + } + + /** + * 获取商家环境图片 + * @param $value $this->environment + * @return array + */ + public function getEnvironmentAttribute($value) + { + $value = $value ? $value : $this->environmant; + return $value ? explode(',',$value) : []; + } + public function setEnvironmentAttribute($value) + { + $this->attributes['environment'] = implode(',',$value); + } + + /** + * 是否开启店铺 + */ + public function getIsOpenAttribute($value) + { + $value = $value ? $value : ''; + return $value ? explode(',',$value) : []; + } + public function setIsOpenAttribute($value) + { + $this->attributes['is_open'] = 1; + } + + /** + * 获取单个店铺信息 + * @param int $id + * @param string $field + * @return string + */ + public static function getStoreInfo($id,$field = '*') + { + return self::select($field)->find($id); + } + + /** + * 获取店铺数组 + * id为键,name为值 + * @return array + */ + public static function getStoreArray() + { + $list = self::select('id','name') + ->where('status',2) + ->whereNull('deleted_at') + ->get(); + $array = []; + if(count($list) > 0){ + foreach ($list as $value) { + $array[$value->id] = $value->name; + } + } + + return $array; + } + + // 处理图片 + public function imageUrl($value) + { + if(strripos($value,"http") === false){ + return env('OSS_IMG_HOST').'/'.$value; + }else{ + return $value; + } + } +} diff --git a/resources/lang/zh-CN/goods-new.php b/resources/lang/zh-CN/goods-new.php new file mode 100644 index 0000000..c67f24e --- /dev/null +++ b/resources/lang/zh-CN/goods-new.php @@ -0,0 +1,42 @@ + [ + 'GoodsNew' => '线上商品清洗', + 'goods_new' => '线上商品清洗', + ], + 'fields' => [ + 'name' => '商品名称', + 'category_id' => '所属分类', + 'goods_category_id' => '商品类目', + 'store_id' => '所属商家', + 'cover_img' => '封面图', + 'cover_img_url' => '封面图', + 'banners' => '轮播图', + + 'price' => '售价', + 'original_price' => '原价', + 'vip_price' => '会员价', + 'on_sale' => '是否上架', + 'on_sale_text' => '是否上架', + 'inventory' => '库存', + 'content' => '简介', + 'sort' => '排序', + 'restrict_num' => '限购份数', + 'start_num' => '起售份数', + 'is_infinite' => '开启无限库存', + 'is_infinite_text' => '开启无限库存', + 'goods_unit' => '商品单位', + 'tags' => '标签', + 'details_imgs' => '详情图片', + 'spec' => '规格', + 'unit_number' => '单位前的数', + 'remark' => '备注', + 'spec_key' =>'规格名称', + 'spec_value' => '规格参数', + 'market_id' => '市场', + 'image_banners' => '轮播图片', + 'video_banners' => '轮播视频' + ], + 'options' => [ + ], +]; From 064fbb3f70a520e1a9c87de330edb3aa30f56d00 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 8 Sep 2020 19:05:21 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=BA=BF=E4=B8=8A?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/MigrateStore.php | 69 ++++++++++++++ app/Console/Commands/couponReport.php | 125 ------------------------- app/Console/Commands/setStoreUsers.php | 71 -------------- 3 files changed, 69 insertions(+), 196 deletions(-) create mode 100644 app/Console/Commands/MigrateStore.php delete mode 100644 app/Console/Commands/couponReport.php delete mode 100644 app/Console/Commands/setStoreUsers.php diff --git a/app/Console/Commands/MigrateStore.php b/app/Console/Commands/MigrateStore.php new file mode 100644 index 0000000..5db6063 --- /dev/null +++ b/app/Console/Commands/MigrateStore.php @@ -0,0 +1,69 @@ +id(); + // }); + // } + $oldData = DB::table('ims_cjdc_store_new')->get(); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $newData = []; + foreach ($oldData as $ka => $va){ + + // $storeUsers = DB::table('lanzu_store_users')->find($va->uid); + // if(!empty($storeUsers)){ + $newData =[ + 'user_category'=>$va->role, + 'store_id'=>$va->storeid + ]; + // DB::table('lanzu_store_users')->where('id',$va->uid)->update($data); + // } + $bar->advance(); + } + + DB::table('lanzu_store_new')->insert($newData); + $bar->finish(); + + return 0; + } +} diff --git a/app/Console/Commands/couponReport.php b/app/Console/Commands/couponReport.php deleted file mode 100644 index 7497b0b..0000000 --- a/app/Console/Commands/couponReport.php +++ /dev/null @@ -1,125 +0,0 @@ -argument('start'); - $end = $this->argument('end'); - $return = $this->option('ret'); - - $start = $start ? $start : date('Y-m-d',time()); - $end = $end ? $end : date('Y-m-d',time()); - $where = [strtotime($start.' 00:00:00'),strtotime($end.' 23:59:59')]; - - // 统计优惠券订单数据-金额 - $orderTotal = DB::select("SELECT - uses.system_coupon_id as ID - ,coupon.title '优惠券标题' - ,SUM(om.money) as '使用优惠券消费总额(实付总金额)' - ,SUM(om.total_money) as '订单总额(不包含配送费,含包装费)' - ,SUM(om.dada_fee) as '配送费' - ,SUM(om.yhq_money2)as '优惠总金额' - ,COUNT(om.id) as '总订单数量' - FROM - ims_system_coupon_user_use uses - INNER JOIN ims_cjdc_order_main om ON uses.order_main_id = om.id - INNER JOIN ims_system_coupon_user coupon ON coupon.id=uses.system_coupon_id - WHERE uses.`status` = 1 AND om.time_add BETWEEN ? AND ? - GROUP BY uses.system_coupon_id ORDER BY uses.system_coupon_id DESC", - $where - ); - - // 查询领取数量和统计数量-总数 - $receiveCoupon = DB::select("SELECT - coupon.id as ID - ,title as '优惠券标题' - ,full_amount as '满足金额' - ,discounts as '优惠金额' - ,inventory AS '发放数量' - ,SUM(IFNULL(receive.number,0)) as '领取数量' - ,IFNULL((SELECT SUM(IFNULL(number,0)) FROM ims_system_coupon_user_use WHERE system_coupon_id = coupon.id AND status = 1 AND use_time BETWEEN ? AND ?),0) AS 使用数量 - FROM - ims_system_coupon_user coupon - LEFT JOIN ims_system_coupon_user_receive receive ON coupon.id = receive.system_coupon_user_id - WHERE receive.created_at BETWEEN ? AND ? - GROUP BY coupon.id ORDER BY coupon.id DESC", - array_merge($where,$where) - ); - - // 查询优惠券订单用户数据 - // $orderList = DB::select("SELECT - // uu.id AS 序号 - // ,IF(uu.status=1,'已使用','已退回') AS 使用状态 - // ,user.id AS 用户ID - // ,main.order_num AS 订单号 - // ,main.money AS 订单金额 - // ,conpon.title AS 优惠券种类 - // ,user.`name` AS 用户昵称 - // ,main.`name` AS 用户姓名 - // ,main.tel AS 用户电话 - // ,main.address AS 用户地址 - // FROM ims_system_coupon_user_use uu - // INNER JOIN ims_system_coupon_user conpon ON conpon.id=uu.system_coupon_id - // INNER JOIN ims_cjdc_user user ON user.id=uu.user_id - // INNER JOIN ims_cjdc_order_main main ON main.id=uu.order_main_id - // WHERE main.time_add BETWEEN ? AND ? - // ORDER BY uu.`status` ASC", - // $where - // ); - - $orderArray = []; - foreach($orderTotal as $value){ - $orderArray[] = (array)$value; - } - $receiveArray = []; - foreach($receiveCoupon as $value){ - $receiveArray[] = (array)$value; - } - $listArray = []; - // foreach($orderList as $value){ - // $listArray[] = (array)$value; - // } - if($return){ - // return json_encode(compact($orderTotal,$receiveCoupon,$orderList)); - }else{ - $this->table(['ID','优惠券标题','使用优惠券消费总额(实付总金额)','订单总额(不包含配送费,含包装费)','配送费','优惠总金额','总订单数量'],$orderArray); - $this->table(['ID','优惠券标题','满足金额','优惠金额','发放数量','已领取数量','使用数量'],$receiveArray); - // $this->table(['序号','使用状态','用户ID','订单号','订单金额','优惠券种类','用户昵称','用户姓名','用户电话','用户地址'],$listArray); - } - } -} diff --git a/app/Console/Commands/setStoreUsers.php b/app/Console/Commands/setStoreUsers.php deleted file mode 100644 index bde3aa8..0000000 --- a/app/Console/Commands/setStoreUsers.php +++ /dev/null @@ -1,71 +0,0 @@ -id(); - }); - } - $account = DB::table('ims_cjdc_account')->get(); - $bar = $this->output->createProgressBar(count($account)); - $bar->start(); - - foreach ($account as $ka => $va){ - $data = []; - $storeUsers = DB::table('lanzu_store_users')->find($va->uid); - if(!empty($storeUsers)){ - $data =[ - 'user_category'=>$va->role, - 'store_id'=>$va->storeid - ]; - DB::table('lanzu_store_users')->where('id',$va->uid)->update($data); - } - $bar->advance(); - } - - $bar->finish(); - - return 0; - } -} From 4420f87f2e1ef3225b992ab42188df3d9761d6d5 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 8 Sep 2020 19:05:58 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E9=A6=96?= =?UTF-8?q?=E5=AD=97=E6=AF=8D=E5=A4=A7=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/CouponReport.php | 125 +++++++++++++++++++++++++ app/Console/Commands/SetStoreUsers.php | 71 ++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 app/Console/Commands/CouponReport.php create mode 100644 app/Console/Commands/SetStoreUsers.php diff --git a/app/Console/Commands/CouponReport.php b/app/Console/Commands/CouponReport.php new file mode 100644 index 0000000..347c393 --- /dev/null +++ b/app/Console/Commands/CouponReport.php @@ -0,0 +1,125 @@ +argument('start'); + $end = $this->argument('end'); + $return = $this->option('ret'); + + $start = $start ? $start : date('Y-m-d',time()); + $end = $end ? $end : date('Y-m-d',time()); + $where = [strtotime($start.' 00:00:00'),strtotime($end.' 23:59:59')]; + + // 统计优惠券订单数据-金额 + $orderTotal = DB::select("SELECT + uses.system_coupon_id as ID + ,coupon.title '优惠券标题' + ,SUM(om.money) as '使用优惠券消费总额(实付总金额)' + ,SUM(om.total_money) as '订单总额(不包含配送费,含包装费)' + ,SUM(om.dada_fee) as '配送费' + ,SUM(om.yhq_money2)as '优惠总金额' + ,COUNT(om.id) as '总订单数量' + FROM + ims_system_coupon_user_use uses + INNER JOIN ims_cjdc_order_main om ON uses.order_main_id = om.id + INNER JOIN ims_system_coupon_user coupon ON coupon.id=uses.system_coupon_id + WHERE uses.`status` = 1 AND om.time_add BETWEEN ? AND ? + GROUP BY uses.system_coupon_id ORDER BY uses.system_coupon_id DESC", + $where + ); + + // 查询领取数量和统计数量-总数 + $receiveCoupon = DB::select("SELECT + coupon.id as ID + ,title as '优惠券标题' + ,full_amount as '满足金额' + ,discounts as '优惠金额' + ,inventory AS '发放数量' + ,SUM(IFNULL(receive.number,0)) as '领取数量' + ,IFNULL((SELECT SUM(IFNULL(number,0)) FROM ims_system_coupon_user_use WHERE system_coupon_id = coupon.id AND status = 1 AND use_time BETWEEN ? AND ?),0) AS 使用数量 + FROM + ims_system_coupon_user coupon + LEFT JOIN ims_system_coupon_user_receive receive ON coupon.id = receive.system_coupon_user_id + WHERE receive.created_at BETWEEN ? AND ? + GROUP BY coupon.id ORDER BY coupon.id DESC", + array_merge($where,$where) + ); + + // 查询优惠券订单用户数据 + // $orderList = DB::select("SELECT + // uu.id AS 序号 + // ,IF(uu.status=1,'已使用','已退回') AS 使用状态 + // ,user.id AS 用户ID + // ,main.order_num AS 订单号 + // ,main.money AS 订单金额 + // ,conpon.title AS 优惠券种类 + // ,user.`name` AS 用户昵称 + // ,main.`name` AS 用户姓名 + // ,main.tel AS 用户电话 + // ,main.address AS 用户地址 + // FROM ims_system_coupon_user_use uu + // INNER JOIN ims_system_coupon_user conpon ON conpon.id=uu.system_coupon_id + // INNER JOIN ims_cjdc_user user ON user.id=uu.user_id + // INNER JOIN ims_cjdc_order_main main ON main.id=uu.order_main_id + // WHERE main.time_add BETWEEN ? AND ? + // ORDER BY uu.`status` ASC", + // $where + // ); + + $orderArray = []; + foreach($orderTotal as $value){ + $orderArray[] = (array)$value; + } + $receiveArray = []; + foreach($receiveCoupon as $value){ + $receiveArray[] = (array)$value; + } + $listArray = []; + // foreach($orderList as $value){ + // $listArray[] = (array)$value; + // } + if($return){ + // return json_encode(compact($orderTotal,$receiveCoupon,$orderList)); + }else{ + $this->table(['ID','优惠券标题','使用优惠券消费总额(实付总金额)','订单总额(不包含配送费,含包装费)','配送费','优惠总金额','总订单数量'],$orderArray); + $this->table(['ID','优惠券标题','满足金额','优惠金额','发放数量','已领取数量','使用数量'],$receiveArray); + // $this->table(['序号','使用状态','用户ID','订单号','订单金额','优惠券种类','用户昵称','用户姓名','用户电话','用户地址'],$listArray); + } + } +} diff --git a/app/Console/Commands/SetStoreUsers.php b/app/Console/Commands/SetStoreUsers.php new file mode 100644 index 0000000..3da7431 --- /dev/null +++ b/app/Console/Commands/SetStoreUsers.php @@ -0,0 +1,71 @@ +id(); + }); + } + $account = DB::table('ims_cjdc_account')->get(); + $bar = $this->output->createProgressBar(count($account)); + $bar->start(); + + foreach ($account as $ka => $va){ + $data = []; + $storeUsers = DB::table('lanzu_store_users')->find($va->uid); + if(!empty($storeUsers)){ + $data =[ + 'user_category'=>$va->role, + 'store_id'=>$va->storeid + ]; + DB::table('lanzu_store_users')->where('id',$va->uid)->update($data); + } + $bar->advance(); + } + + $bar->finish(); + + return 0; + } +} From 77526dede38658246d7f72ffc74c68a228e1d4b4 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 8 Sep 2020 21:28:20 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/MigrateGoods.php | 143 ++++++++++++++++++++++++++ app/Console/Commands/MigrateStore.php | 66 +++++++++--- 2 files changed, 197 insertions(+), 12 deletions(-) create mode 100644 app/Console/Commands/MigrateGoods.php diff --git a/app/Console/Commands/MigrateGoods.php b/app/Console/Commands/MigrateGoods.php new file mode 100644 index 0000000..6795bb2 --- /dev/null +++ b/app/Console/Commands/MigrateGoods.php @@ -0,0 +1,143 @@ +id(); + // }); + // } + $specData = [ + '克' => '净含量', + '斤' => '净含量', + '两' => '净含量', + '只' => '净含量', + '份' => '净含量', + 'g' => '净含量', + 'l' => '净含量', + 'ml' => '净含量', + 'ML' => '净含量', + 'L' => '净含量', + '个' => '净含量', + '条' => '净含量', + '公分' => '净含量', + '边' => '净含量', + '包' => '净含量', + '辣' => '口味', + '馅' => '馅料', + 'mm' => '尺寸' + ]; + $oldData = DB::table('ims_cjdc_goods_new')->get(); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $total = 0; + foreach ($oldData as $value){ + $goodsData =[ + // 'id'=>$value->id, + 'market_id'=>$value->market_id, + 'store_id'=>$value->store_id, + 'on_sale'=> $value->is_show == 1 ? 1 : 0, + 'sort'=>$value->num, + 'price'=>$value->money, + 'original_price'=>$value->money2, + 'vip_price'=>$value->vip_money, + 'sales'=>$value->sales, + 'start_num'=>$value->start_num, + 'restrict_num'=>$value->restrict_num, + 'is_infinite'=> $value->is_max == 1 ? 1 :0, + 'inventory'=>$value->inventory, + 'name'=>$value->name, + 'cover_img'=>$value->logo, + 'goods_unit'=>$value->good_unit, + + 'spec'=>$value->spec, + + 'content'=>$value->content, + 'details'=>$value->details, + ]; + $specs = DB::table('ims_cjdc_spec_combination_new')->where('good_id',$value->id)->get(); + if(!empty($specs)){ + foreach($specs as $vs){ + $spec = ['spec_key'=>'净含量','spec_value'=>$vs->combination]; + if(strstr($vs->combination,'辣')){ + $spec['spec_key'] = '口味'; + }else if(strstr($vs->combination,'馅')){ + $spec['spec_key'] = '馅料'; + }else if(strstr($vs->combination,'mm')){ + $spec['spec_key'] = '尺寸'; + } + $goodsData['spec'] = json_encode($spec); + $newData = $goodsData; + $newBanner = [ + 'type' =>1, + 'path' =>$value->logo, + 'created_at' =>time(), + 'updated_at' =>time(), + ]; + $id = DB::table('lanzu_goods_new')->insertGetId($newData); + $newBanner['goods_id'] = $id; + DB::table('lanzu_goods_banners_new')->insertGetId($newBanner); + $total++; + if($total == 2){ + break; + } + } + }else{ + $newData = $goodsData; + $id = DB::table('lanzu_goods_new')->insertGetId($newData); + $newBanner['goods_id'] = $id; + DB::table('lanzu_goods_banners_new')->insertGetId($newBanner); + $total++; + if($total == 2){ + break; + } + } + + $bar->advance(); + } + + $bar->finish(); + echo '\r\n '; + echo time()-$startTime; + echo '\r\n '.$total; + return 0; + } +} diff --git a/app/Console/Commands/MigrateStore.php b/app/Console/Commands/MigrateStore.php index 5db6063..4e32ae0 100644 --- a/app/Console/Commands/MigrateStore.php +++ b/app/Console/Commands/MigrateStore.php @@ -44,26 +44,68 @@ class MigrateStore extends Command // $table->id(); // }); // } + $oldData = DB::table('ims_cjdc_store_new')->get(); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); + $startTime = time(); + $total = 0; $newData = []; - foreach ($oldData as $ka => $va){ - - // $storeUsers = DB::table('lanzu_store_users')->find($va->uid); - // if(!empty($storeUsers)){ - $newData =[ - 'user_category'=>$va->role, - 'store_id'=>$va->storeid - ]; - // DB::table('lanzu_store_users')->where('id',$va->uid)->update($data); - // } + foreach ($oldData as $value){ + $storeData =[ + 'id'=>$value->id, + 'market_id'=>$value->market_id, + 'is_open'=> $value->is_open == 1 ? 1 : 0, + 'is_rest'=> $value->is_rest == 1 ? 1 : 0, + 'status'=>$value->state, + 'category_id'=>$value->md_type, + 'user_id'=>$value->user_id, + 'admin_id'=>$value->admin_id, + + 'mm_user_id'=>$value->mm_user_id, + 'sort'=>$value->number, + 'loudspeaker_imei'=>$value->loudspeaker_imei, + 'is_infinite'=> $value->is_max == 1 ? 1 :0, + 'name'=>$value->name, + 'logo'=>$value->logo, + + 'announcement'=>$value->announcement, + 'address' => $value->address, + 'business_license'=>$value->yyzz, + 'zm_img' => $value->zm_img, + 'fm_img'=>$value->fm_img, + + 'tel' => $value->tel, + 'link_name'=>$value->link_name, + 'link_tel' => $value->link_tel, + 'expire_time'=> strtotime($value->rzdq_time), + 'time1' => $value->time1, + 'time2'=>$value->time2, + 'time3' => $value->time3, + 'time4'=>$value->time4, + + 'award_money' => $value->award_money, + 'sales'=>$value->score, + 'grade' => $value->sales, + + 'code'=>$value->code, + 'environment' => $value->environment, + + 'introduction'=> strip_tags($value->introduction), + ]; + // preg_match('/[0-9]/', $string, $matches, PREG_OFFSET_CAPTURE); + $storeData['stall_info'] = ''; + $storeData['lng'] = ''; + $storeData['lat'] = ''; + + // DB::table('lanzu_store_new')->insert($newData); + $bar->advance(); } - DB::table('lanzu_store_new')->insert($newData); $bar->finish(); - + echo '\r\n '; + echo time()-$startTime; return 0; } } From 970a3667e178ee87e8fd351777b3a9b6ea96243e Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 9 Sep 2020 10:37:36 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/MigrateStore.php | 59 +++++++++++++++++++-------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/app/Console/Commands/MigrateStore.php b/app/Console/Commands/MigrateStore.php index 4e32ae0..b885032 100644 --- a/app/Console/Commands/MigrateStore.php +++ b/app/Console/Commands/MigrateStore.php @@ -44,16 +44,24 @@ class MigrateStore extends Command // $table->id(); // }); // } - - $oldData = DB::table('ims_cjdc_store_new')->get(); + $oldTableName = 'ims_cjdc_store_new'; + $newTableName = 'lanzu_store_new'; + + $oldData = DB::table($oldTableName)->orderBy('id','desc')->get(); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $startTime = time(); - $total = 0; + $error = []; $newData = []; - foreach ($oldData as $value){ + foreach ($oldData as $key => $value){ + $storeId = $value->id; + // 判断在新表是否存在 + $exist = DB::table($newTableName)->where('id',$storeId)->exists(); + if($exist){ + continue; + } $storeData =[ - 'id'=>$value->id, + 'id'=>$storeId, 'market_id'=>$value->market_id, 'is_open'=> $value->is_open == 1 ? 1 : 0, 'is_rest'=> $value->is_rest == 1 ? 1 : 0, @@ -65,13 +73,12 @@ class MigrateStore extends Command 'mm_user_id'=>$value->mm_user_id, 'sort'=>$value->number, 'loudspeaker_imei'=>$value->loudspeaker_imei, - 'is_infinite'=> $value->is_max == 1 ? 1 :0, 'name'=>$value->name, 'logo'=>$value->logo, 'announcement'=>$value->announcement, 'address' => $value->address, - 'business_license'=>$value->yyzz, + 'business_license'=> ($storeId == 365) ? '' :$value->yyzz,/* 因为365的数据的营业资质数据乱码,目前只有365这个店铺的有问题 */ 'zm_img' => $value->zm_img, 'fm_img'=>$value->fm_img, @@ -79,7 +86,7 @@ class MigrateStore extends Command 'link_name'=>$value->link_name, 'link_tel' => $value->link_tel, 'expire_time'=> strtotime($value->rzdq_time), - 'time1' => $value->time1, + 'time1' => $value->time, 'time2'=>$value->time2, 'time3' => $value->time3, 'time4'=>$value->time4, @@ -91,21 +98,37 @@ class MigrateStore extends Command 'code'=>$value->code, 'environment' => $value->environment, - 'introduction'=> strip_tags($value->introduction), + 'introduction'=> strip_tags($value->details), + + 'created_at' => time(), + 'updated_at' => time(), ]; - // preg_match('/[0-9]/', $string, $matches, PREG_OFFSET_CAPTURE); - $storeData['stall_info'] = ''; - $storeData['lng'] = ''; - $storeData['lat'] = ''; - - // DB::table('lanzu_store_new')->insert($newData); + + // 获商户摊号 + $stallInfo = ''; + $res = preg_match('/[0-9]/', $value->name, $matches, PREG_OFFSET_CAPTURE); + if($res && count($matches)>0){ + $stallInfo = substr($value->name,$matches[0][1]); + } + $storeData['stall_info'] = $stallInfo; + // 商户经纬度 + if(!empty($value->coordinates)){ + $coordinatesArr = explode(',',$value->coordinates); + $storeData['lng'] = $coordinatesArr[1]; + $storeData['lat'] = $coordinatesArr[0]; + } + $newData = $storeData; + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$storeId]; + break; + } $bar->advance(); } - $bar->finish(); - echo '\r\n '; - echo time()-$startTime; + var_dump([time()-$startTime]); + var_dump($error); return 0; } } From c5ff8db836651fc82873856d40d8b02693e2d173 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 9 Sep 2020 17:06:37 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=BA=BF=E4=B8=8A=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=B8=85=E6=B4=97=E5=8A=9F=E8=83=BD=E5=92=8C=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Grid/GoodsCopy.php | 3 - app/Admin/Actions/Grid/GoodsNewCopy.php | 36 ++++++ .../Controllers/v3/GoodsNewController.php | 11 +- app/Admin/Forms/GoodsNewCopyForm.php | 105 ++++++++++++++++ app/Console/Commands/MigrateGoods.php | 112 ++++++++++-------- app/Console/Commands/MigrateShoppingCart.php | 93 +++++++++++++++ app/Console/Commands/MigrateStore.php | 21 +++- .../Commands/MigrateStoreWithdrawal.php | 98 +++++++++++++++ app/Console/Commands/MigrateUser.php | 98 +++++++++++++++ .../Commands/MigrateUserCollection.php | 90 ++++++++++++++ app/Models/v3/GoodsNew.php | 8 +- resources/lang/zh-CN/goods-new.php | 4 +- 12 files changed, 609 insertions(+), 70 deletions(-) create mode 100644 app/Admin/Actions/Grid/GoodsNewCopy.php create mode 100644 app/Admin/Forms/GoodsNewCopyForm.php create mode 100644 app/Console/Commands/MigrateShoppingCart.php create mode 100644 app/Console/Commands/MigrateStoreWithdrawal.php create mode 100644 app/Console/Commands/MigrateUser.php create mode 100644 app/Console/Commands/MigrateUserCollection.php diff --git a/app/Admin/Actions/Grid/GoodsCopy.php b/app/Admin/Actions/Grid/GoodsCopy.php index e144d7b..00be8b5 100644 --- a/app/Admin/Actions/Grid/GoodsCopy.php +++ b/app/Admin/Actions/Grid/GoodsCopy.php @@ -4,9 +4,6 @@ namespace App\Admin\Actions\Grid; use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Widgets\Modal; -use App\Models\v3\Store as StoreModel; -use Dcat\Admin\Form; -use App\Models\v3\Goods as GoodsModel; use App\Admin\Forms\GoodsCopyForm; class GoodsCopy extends RowAction diff --git a/app/Admin/Actions/Grid/GoodsNewCopy.php b/app/Admin/Actions/Grid/GoodsNewCopy.php new file mode 100644 index 0000000..58ef25e --- /dev/null +++ b/app/Admin/Actions/Grid/GoodsNewCopy.php @@ -0,0 +1,36 @@ +getKey(); + + $modal = Modal::make() + ->xl() + ->title($this->title) + ->body(GoodsNewCopyForm::make()->setKey($id)) + ->button($this->title); + + return $modal; + } + + public function parameters() + { + + return [ + + ]; + } +} diff --git a/app/Admin/Controllers/v3/GoodsNewController.php b/app/Admin/Controllers/v3/GoodsNewController.php index 5b4b975..5de9282 100644 --- a/app/Admin/Controllers/v3/GoodsNewController.php +++ b/app/Admin/Controllers/v3/GoodsNewController.php @@ -2,7 +2,7 @@ namespace App\Admin\Controllers\v3; -use App\Admin\Actions\Grid\GoodsCopy; +use App\Admin\Actions\Grid\GoodsNewCopy; use App\Admin\Repositories\v3\GoodsNew; use Dcat\Admin\Form; use Dcat\Admin\Grid; @@ -13,7 +13,6 @@ use App\Models\v3\StoreNew as StoreModel; use Dcat\Admin\Form\NestedForm; use App\Models\v3\GoodsNew as GoodsModel; use App\Models\v3\Market as MarketModel; -use Dcat\Admin\Grid\Displayers\Actions; use App\Models\v3\GoodsCategory as GoodsCategoryModel; class GoodsNewController extends AdminController @@ -51,7 +50,7 @@ class GoodsNewController extends AdminController $grid->sort->sortable(); $grid->on_sale->switch(); - $grid->actions([new GoodsCopy()]); + $grid->actions([new GoodsNewCopy()]); $grid->filter(function (Grid\Filter $filter) { $filter->like('name'); }); @@ -144,7 +143,7 @@ class GoodsNewController extends AdminController */ protected function form() { - $builder = GoodsModel::with(['ImageBanners','VideoBanners']); + $builder = GoodsModel::with(['ImageNewBanners','VideoNewBanners']); return Form::make($builder, function (Form $form) { $form->hidden('id'); @@ -178,13 +177,13 @@ class GoodsNewController extends AdminController $form->number('start_num')->attribute('min', 1)->default(1); }); $form->column(12, function (Form $form) { - $form->hasMany('image_banners', function (Form\NestedForm $form) { + $form->hasMany('image_new_banners', function (Form\NestedForm $form) { $form->image('path')->width(2); $form->number('sort')->width(2)->default(0); $form->hidden('type')->value(1)->default(1); })->required(); $form->divider(); - $form->hasMany('video_banners', function (Form\NestedForm $form) { + $form->hasMany('video_new_banners', function (Form\NestedForm $form) { $form->file('path')->width(2); $form->number('sort')->width(2)->default(0); $form->hidden('type')->value(2)->default(2); diff --git a/app/Admin/Forms/GoodsNewCopyForm.php b/app/Admin/Forms/GoodsNewCopyForm.php new file mode 100644 index 0000000..52e1abb --- /dev/null +++ b/app/Admin/Forms/GoodsNewCopyForm.php @@ -0,0 +1,105 @@ +get(); + $markets = StoreModel::whereIn('id',$storeIds)->pluck('market_id','id'); + foreach($storeIds as $key =>$value){ + $storeId = $value; + $model = new GoodsModel(); + + $model->store_id = $storeId; + $model->market_id = $markets[$storeId]; + $model->category_id = $goods->category_id; + + $model->name = $goods->name; + $model->cover_img = $goods->cover_img; + $model->goods_unit = $goods->goods_unit; + + $model->tags = $goods->tags; + $model->spec = $goods->spec; + $model->details_imgs = $goods->details_imgs; + $model->content = $goods->content; + $model->details = $goods->details; + + $model->price = $goods->price; + $model->original_price = $goods->original_price; + $model->vip_price = $goods->vip_price; + + $model->start_num = $goods->start_num; + $model->restrict_num = $goods->restrict_num; + $model->is_infinite = $goods->is_infinite; + $model->inventory = $goods->inventory; + + $model->on_sale = $goods->on_sale; + $model->sort = $goods->sort; + $model->remark = $goods->remark; + + if($model->save() && !empty($goodsBanners)){ + $goodsId = $model->getKey(); + $banners = []; + foreach($goodsBanners as $kb => $vb){ + $banners[] = [ + 'goods_id' => $goodsId, + 'type' => $vb->type, + 'path' => $vb->path, + 'sort' => $vb->sort, + 'created_at' => time(), + 'updated_at' => time(), + ]; + GoodsBannerModel::insert($banners); + } + }; + } + + return $this->success('修改成功', '/goods'); + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->getKey(); + $goods = GoodsModel::select('name')->find($id); + $this->hidden('goods_id')->value($id); + $this->display('name')->value($goods->name); + $stores = StoreModel::getStoreArray(); + $this->multipleSelect('store_ids','选择店铺')->required()->options($stores)->help('选择店铺,将当前商品复制到所选店铺。注意选择重复店铺问题!!!'); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +} diff --git a/app/Console/Commands/MigrateGoods.php b/app/Console/Commands/MigrateGoods.php index 6795bb2..146d08d 100644 --- a/app/Console/Commands/MigrateGoods.php +++ b/app/Console/Commands/MigrateGoods.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; class MigrateGoods extends Command { @@ -38,41 +39,52 @@ class MigrateGoods extends Command */ public function handle() { - // 如果表不存在则创建 - // if(!Schema::hasTable('lanzu_store_users')){ - // Schema::create('lanzu_store_users',function (Blueprint $table){ - // $table->id(); - // }); - // } - $specData = [ - '克' => '净含量', - '斤' => '净含量', - '两' => '净含量', - '只' => '净含量', - '份' => '净含量', - 'g' => '净含量', - 'l' => '净含量', - 'ml' => '净含量', - 'ML' => '净含量', - 'L' => '净含量', - '个' => '净含量', - '条' => '净含量', - '公分' => '净含量', - '边' => '净含量', - '包' => '净含量', - '辣' => '口味', - '馅' => '馅料', - 'mm' => '尺寸' - ]; - $oldData = DB::table('ims_cjdc_goods_new')->get(); + $oldTableName = 'ims_cjdc_goods_new'; + $oldSpecTableName = 'ims_cjdc_spec_combination_new'; + $oldStoreTableName = 'ims_cjdc_store_new'; + + $newTableName = 'lanzu_goods_new'; + $newBannerTableName = 'lanzu_goods_banners_new'; + + // 判断表是否存在 + if(!Schema::hasTable($oldTableName)){ + var_dump('旧商品表不存在'); + return 0; + } + if(!Schema::hasTable($oldSpecTableName)){ + var_dump('旧规格表不存在'); + return 0; + } + if(!Schema::hasTable($oldStoreTableName)){ + var_dump('旧的店铺表不存在'); + return 0; + } + if(!Schema::hasTable($newTableName)){ + var_dump('新商品表不存在'); + return 0; + } + if(!Schema::hasTable($newBannerTableName)){ + var_dump('新商品的banners表不存在'); + return 0; + } + + $oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); + $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $startTime = time(); $total = 0; + $error = []; foreach ($oldData as $value){ + $goodsId = $value->id; + // 判断店铺是否存在,如果商品的店铺不在,则不存这个商品 + $storeExist = DB::table($oldStoreTableName)->where('id',$value->store_id)->exists(); + if(!$storeExist){ + continue; + } $goodsData =[ // 'id'=>$value->id, - 'market_id'=>$value->market_id, + 'market_id' => $oldStoreData[$value->store_id], 'store_id'=>$value->store_id, 'on_sale'=> $value->is_show == 1 ? 1 : 0, 'sort'=>$value->num, @@ -88,13 +100,11 @@ class MigrateGoods extends Command 'cover_img'=>$value->logo, 'goods_unit'=>$value->good_unit, - 'spec'=>$value->spec, - - 'content'=>$value->content, - 'details'=>$value->details, + 'content'=> strip_tags($value->content), + 'details'=> strip_tags($value->details), ]; - $specs = DB::table('ims_cjdc_spec_combination_new')->where('good_id',$value->id)->get(); - if(!empty($specs)){ + $specs = DB::table($oldSpecTableName)->where('good_id',$goodsId)->get(); + if(count($specs) > 0){ foreach($specs as $vs){ $spec = ['spec_key'=>'净含量','spec_value'=>$vs->combination]; if(strstr($vs->combination,'辣')){ @@ -104,7 +114,9 @@ class MigrateGoods extends Command }else if(strstr($vs->combination,'mm')){ $spec['spec_key'] = '尺寸'; } - $goodsData['spec'] = json_encode($spec); + + $goodsData['spec'] = json_encode([$spec]); + $newData = $goodsData; $newBanner = [ 'type' =>1, @@ -112,32 +124,34 @@ class MigrateGoods extends Command 'created_at' =>time(), 'updated_at' =>time(), ]; - $id = DB::table('lanzu_goods_new')->insertGetId($newData); - $newBanner['goods_id'] = $id; - DB::table('lanzu_goods_banners_new')->insertGetId($newBanner); - $total++; - if($total == 2){ + $id = DB::table($newTableName)->insertGetId($newData); + + if(!$id){ + $error[] = ['id'=>$goodsId]; break; } + $newBanner['goods_id'] = $id; + DB::table($newBannerTableName)->insertGetId($newBanner); + $total++; } }else{ $newData = $goodsData; - $id = DB::table('lanzu_goods_new')->insertGetId($newData); - $newBanner['goods_id'] = $id; - DB::table('lanzu_goods_banners_new')->insertGetId($newBanner); - $total++; - if($total == 2){ + $res= $id = DB::table($newTableName)->insertGetId($newData); + if(!$res){ + $error[] = ['id'=>$goodsId]; break; } + $newBanner['goods_id'] = $id; + DB::table($newBannerTableName)->insertGetId($newBanner); + $total++; } - $bar->advance(); } $bar->finish(); - echo '\r\n '; - echo time()-$startTime; - echo '\r\n '.$total; + var_dump([time()-$startTime]); + var_dump($total); + var_dump($error); return 0; } } diff --git a/app/Console/Commands/MigrateShoppingCart.php b/app/Console/Commands/MigrateShoppingCart.php new file mode 100644 index 0000000..7e7db70 --- /dev/null +++ b/app/Console/Commands/MigrateShoppingCart.php @@ -0,0 +1,93 @@ +orderBy('id','asc')->get(); + $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $cartId = $value->id; + // 判断在新表是否存在 + $exist = DB::table($newTableName)->where('id',$cartId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$cartId, + 'market_id'=> isset($oldStoreData[$value->store_id])?$oldStoreData[$value->store_id]:0, + 'store_id'=>$value->store_id, + 'goods_id'=>$value->good_id, + 'user_id'=>$value->user_id, + + 'num'=>$value->num, + 'activity_type'=>1, + 'created_at' => time(), + 'updated_at' => time(), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$cartId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Console/Commands/MigrateStore.php b/app/Console/Commands/MigrateStore.php index b885032..33dd897 100644 --- a/app/Console/Commands/MigrateStore.php +++ b/app/Console/Commands/MigrateStore.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; class MigrateStore extends Command { @@ -38,14 +39,19 @@ class MigrateStore extends Command */ public function handle() { - // 如果表不存在则创建 - // if(!Schema::hasTable('lanzu_store_users')){ - // Schema::create('lanzu_store_users',function (Blueprint $table){ - // $table->id(); - // }); - // } $oldTableName = 'ims_cjdc_store_new'; $newTableName = 'lanzu_store_new'; + $storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */ + $storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */ + // 判断表是否存在 + if(!Schema::hasTable($oldTableName)){ + var_dump('旧表不存在'); + return 0; + } + if(!Schema::hasTable($newTableName)){ + var_dump('新表不存在'); + return 0; + } $oldData = DB::table($oldTableName)->orderBy('id','desc')->get(); $bar = $this->output->createProgressBar(count($oldData)); @@ -100,6 +106,9 @@ class MigrateStore extends Command 'introduction'=> strip_tags($value->details), + 'store_applet_img' => $storeImgPath.$storeId.'.jpg', + 'cash_code_img' => $storePayPath.$storeId.'.jpg', + 'created_at' => time(), 'updated_at' => time(), ]; diff --git a/app/Console/Commands/MigrateStoreWithdrawal.php b/app/Console/Commands/MigrateStoreWithdrawal.php new file mode 100644 index 0000000..57bf9d1 --- /dev/null +++ b/app/Console/Commands/MigrateStoreWithdrawal.php @@ -0,0 +1,98 @@ + 1,3 => 3, 1 => 4]; + $oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $withdrawalId = $value->id; + // 判断记录在新表是否存在 + $exist = DB::table($newTableName)->where('id',$withdrawalId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$withdrawalId, + 'store_id'=>$value->store_id, + + 'name'=>$value->name, + 'tel'=>$value->tel, + 'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0, + 'check_time'=>strtotime($value->sh_time), + 'state'=>$value->state, + + 'apply_cash'=>$value->tx_cost, + 'real_cash'=>$value->sj_cost, + 'bank_card'=>$value->yhk_num, + 'bank_info'=>$value->yh_info, + + 'created_at' => strtotime($value->time), + 'updated_at' => strtotime($value->sh_time), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$withdrawalId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Console/Commands/MigrateUser.php b/app/Console/Commands/MigrateUser.php new file mode 100644 index 0000000..f39aaf2 --- /dev/null +++ b/app/Console/Commands/MigrateUser.php @@ -0,0 +1,98 @@ + 1,3 => 3, 1 => 4]; + $oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $userId = $value->id; + // 判断记录在新表是否存在 + $exist = DB::table($newTableName)->where('id',$userId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$userId, + 'nick_name'=>$value->name, + + 'avatar'=>$value->img, + 'openid'=>$value->openid, + // 'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0, + 'total_score'=>$value->total_score, + 'wallet'=>$value->wallet, + + 'real_name'=>$value->real_name, + 'tel'=>$value->tel, + 'unionid'=>$value->unionid, + 'status'=>$value->status, + + 'created_at' => strtotime($value->join_time), + 'updated_at' => strtotime($value->sh_time), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$userId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Console/Commands/MigrateUserCollection.php b/app/Console/Commands/MigrateUserCollection.php new file mode 100644 index 0000000..1e65173 --- /dev/null +++ b/app/Console/Commands/MigrateUserCollection.php @@ -0,0 +1,90 @@ +orderBy('id','asc')->get(); + $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $collectionId = $value->id; + // 判断记录在新表是否存在 + $exist = DB::table($newTableName)->where('id',$collectionId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$collectionId, + 'store_id'=>$value->store_id, + 'user_id'=>$value->user_id, + 'market_id'=> isset($oldStoreData[$value->store_id])?$oldStoreData[$value->store_id]:0, + + 'created_at' => time(), + 'updated_at' => time(), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$collectionId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Models/v3/GoodsNew.php b/app/Models/v3/GoodsNew.php index a7a5876..026e2b2 100644 --- a/app/Models/v3/GoodsNew.php +++ b/app/Models/v3/GoodsNew.php @@ -45,12 +45,12 @@ class GoodsNew extends Model $value = $value ? $value : $this->is_infinite; return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : ''; } - public function ImageBanners(){ - return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',1); + public function ImageNewBanners(){ + return $this->hasMany('\App\Models\v3\GoodsNewBanners','goods_id','id')->where('type',1); } - public function VideoBanners(){ - return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',2); + public function VideoNewBanners(){ + return $this->hasMany('\App\Models\v3\GoodsNewBanners','goods_id','id')->where('type',2); } diff --git a/resources/lang/zh-CN/goods-new.php b/resources/lang/zh-CN/goods-new.php index c67f24e..63251c9 100644 --- a/resources/lang/zh-CN/goods-new.php +++ b/resources/lang/zh-CN/goods-new.php @@ -34,8 +34,8 @@ return [ 'spec_key' =>'规格名称', 'spec_value' => '规格参数', 'market_id' => '市场', - 'image_banners' => '轮播图片', - 'video_banners' => '轮播视频' + 'image_new_banners' => '轮播图片', + 'video_new_banners' => '轮播视频' ], 'options' => [ ],