5 changed files with 321 additions and 4 deletions
-
36app/Admin/Actions/Grid/GoodsNewImage.php
-
19app/Admin/Controllers/v3/GoodsNewController.php
-
105app/Admin/Forms/GoodsNewImageForm.php
-
163app/Console/Commands/MigrateStoreAccount.php
-
2app/Models/v3/GoodsNew.php
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Widgets\Modal; |
||||
|
use App\Admin\Forms\GoodsNewImageForm; |
||||
|
|
||||
|
class GoodsNewImage extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '上传图片'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
$modal = Modal::make() |
||||
|
->xl() |
||||
|
->title($this->title) |
||||
|
->body(GoodsNewImageForm::make()->setKey($id)) |
||||
|
->button($this->title); |
||||
|
|
||||
|
return $modal; |
||||
|
} |
||||
|
|
||||
|
public function parameters() |
||||
|
{ |
||||
|
|
||||
|
return [ |
||||
|
|
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,105 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Forms; |
||||
|
|
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
use Symfony\Component\HttpFoundation\Response; |
||||
|
use App\Models\v3\StoreNew as StoreModel; |
||||
|
use App\Models\v3\GoodsNew as GoodsModel; |
||||
|
use App\Models\v3\GoodsNewBanners as GoodsBannerModel; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class GoodsNewImageForm extends Form |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* Handle the form request. |
||||
|
* |
||||
|
* @param array $input |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
// 获取外部传递参数
|
||||
|
$goodsId = $input['goods_id']; |
||||
|
$storeIds= $input['store_ids']; |
||||
|
|
||||
|
$goods = GoodsModel::find($goodsId); |
||||
|
$goodsBanners = GoodsBannerModel::where('goods_id',$goodsId)->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); |
||||
|
$this->image('cover_img','封面图'); |
||||
|
$this->multipleImage('banners','轮播图'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The data of the form. |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function default() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,163 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Console\Commands; |
||||
|
|
||||
|
use Illuminate\Console\Command; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
|
||||
|
class MigrateStoreAccount extends Command |
||||
|
{ |
||||
|
/** |
||||
|
* The name and signature of the console command. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $signature = 'migrateData:storeAccount'; |
||||
|
|
||||
|
/** |
||||
|
* The console command description. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $description = 'Command 迁移商户流水数据'; |
||||
|
|
||||
|
/** |
||||
|
* Create a new command instance. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Execute the console command. |
||||
|
* |
||||
|
* @return int |
||||
|
*/ |
||||
|
public function handle() |
||||
|
{ |
||||
|
$m = ['120'=>['sort'=>'12'],'12'=>['sort'=>'3'],'112'=>['sort'=>'2'],'110'=>['sort'=>'120']]; |
||||
|
|
||||
|
|
||||
|
|
||||
|
var_dump($m); |
||||
|
return 0; |
||||
|
$oldTableName = 'ims_cjdc_store_account'; |
||||
|
$newTableName = 'lanzu_financial_record'; |
||||
|
// 判断表是否存在
|
||||
|
if(!Schema::hasTable($oldTableName)){ |
||||
|
var_dump('旧表不存在'); |
||||
|
return 0; |
||||
|
} |
||||
|
if(!Schema::hasTable($newTableName)){ |
||||
|
var_dump('新表不存在'); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
$desc='用户店铺首单奖励'; |
||||
|
$comment='用户当面付商户奖励'; |
||||
|
|
||||
|
$desc='新用户下单奖励'; |
||||
|
$comment='用户当面付商户奖励'; |
||||
|
|
||||
|
$desc = '线上外卖订单收入'; |
||||
|
$comment = '用户订单完成'; |
||||
|
|
||||
|
$desc = '线下当面付订单收入'; |
||||
|
$comment = '用户订单完成'; |
||||
|
|
||||
|
$desc = '线上订单退款'; |
||||
|
$comment = '线上订单退款到微信'; |
||||
|
|
||||
|
$desc = '商户提现'; |
||||
|
$comment = '商户提现打款'; |
||||
|
|
||||
|
$oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); |
||||
|
$bar = $this->output->createProgressBar(count($oldData)); |
||||
|
$bar->start(); |
||||
|
$startTime = time(); |
||||
|
$error = []; |
||||
|
foreach ($oldData as $key => $value){ |
||||
|
$storeId = $value->store_id; |
||||
|
$userId = $value->user_id; |
||||
|
if(empty($userId)){ |
||||
|
$error[] = ['id'=>$userId]; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
// 判断是否存在 总账
|
||||
|
$exist = DB::table($newTableName) |
||||
|
->where('user_id',$userId) |
||||
|
->where('user_type',5) |
||||
|
->where('source_id',$value->order_id) |
||||
|
->where('source_type',0) |
||||
|
->where('money_type') |
||||
|
->exists(); |
||||
|
|
||||
|
if(!$exist){ |
||||
|
$newData =[ |
||||
|
'id'=>$userId, |
||||
|
'nick_name'=>$value->name, |
||||
|
|
||||
|
'avatar'=>$value->img, |
||||
|
'openid'=>$value->openid, |
||||
|
|
||||
|
'total_score'=>$value->total_score, |
||||
|
'wallet'=>$value->wallet, |
||||
|
|
||||
|
'real_name'=>$value->user_name, |
||||
|
'tel'=>$value->user_tel, |
||||
|
'unionid'=>$value->unionid, |
||||
|
|
||||
|
'created_at' => strtotime($value->join_time), |
||||
|
'updated_at' => $value->updated_at, |
||||
|
]; |
||||
|
|
||||
|
$res = DB::table($newTableName)->insert($newData); |
||||
|
if(!$res){ |
||||
|
$error[] = ['id'=>$userId]; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 判断是否存在 详细账
|
||||
|
$mod = bcmod((string)$userId, '5', 0); |
||||
|
$newSubTableName = $newTableName.'_'.$mod; |
||||
|
$existSub = DB::table($newSubTableName)->where('id',$userId)->exists(); |
||||
|
if(!$existSub){ |
||||
|
$newData =[ |
||||
|
'id'=>$userId, |
||||
|
'nick_name'=>$value->name, |
||||
|
|
||||
|
'avatar'=>$value->img, |
||||
|
'openid'=>$value->openid, |
||||
|
|
||||
|
'total_score'=>$value->total_score, |
||||
|
'wallet'=>$value->wallet, |
||||
|
|
||||
|
'real_name'=>$value->user_name, |
||||
|
'tel'=>$value->user_tel, |
||||
|
'unionid'=>$value->unionid, |
||||
|
|
||||
|
'created_at' => strtotime($value->join_time), |
||||
|
'updated_at' => $value->updated_at, |
||||
|
]; |
||||
|
|
||||
|
$res = DB::table($newSubTableName)->insert($newData); |
||||
|
if(!$res){ |
||||
|
$error[] = ['id'=>$userId]; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$bar->advance(); |
||||
|
} |
||||
|
$bar->finish(); |
||||
|
var_dump([time()-$startTime]); |
||||
|
var_dump($error); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue