Browse Source

Merge branch 'phoenix' into develop

master
liangyuyan 6 years ago
parent
commit
a5538f1abe
  1. 36
      app/Admin/Actions/Grid/GoodsNewImage.php
  2. 10
      app/Admin/Controllers/v3/GoodsController.php
  3. 19
      app/Admin/Controllers/v3/GoodsNewController.php
  4. 72
      app/Admin/Forms/GoodsNewImageForm.php
  5. 163
      app/Console/Commands/MigrateStoreAccount.php
  6. 2
      app/Models/v3/Goods.php
  7. 2
      app/Models/v3/GoodsNew.php

36
app/Admin/Actions/Grid/GoodsNewImage.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 [
];
}
}

10
app/Admin/Controllers/v3/GoodsController.php

@ -221,6 +221,16 @@ class GoodsController extends AdminController
$info = StoreModel::getStoreInfo($storeId,'market_id');
$form->market_id = $info->market_id;
}
$tags = $form->input('tags');
$tagsArr = [];
foreach($tags as $kt => $tag){
if(empty($tag)){
unset($tags[$kt]);
continue;
}
$tagsArr[] = $tag;
}
$form->tags = json_encode($tagsArr);
});
});
}

19
app/Admin/Controllers/v3/GoodsNewController.php

@ -3,6 +3,7 @@
namespace App\Admin\Controllers\v3;
use App\Admin\Actions\Grid\GoodsNewCopy;
use App\Admin\Actions\Grid\GoodsNewImage;
use App\Admin\Repositories\v3\GoodsNew;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
@ -62,7 +63,7 @@ class GoodsNewController extends AdminController
$grid->sort->sortable();
$grid->on_sale->switch();
$grid->actions([new GoodsNewCopy()]);
$grid->actions([new GoodsNewCopy(),new GoodsNewImage()]);
$grid->filter(function (Grid\Filter $filter) use($storeList, $categoryList, $goodsCategoryList, $marketList){
$filter->like('name');
$filter->equal('store_id')->select($storeList);
@ -228,13 +229,25 @@ class GoodsNewController extends AdminController
$form->disableEditingCheck();
$form->disableCreatingCheck();
});
// $form->saving(function (Form $form){
$form->saving(function (Form $form){
// $storeId = $form->input('store_id');
// 商品所属市场,根据店铺查询市场
// $info = StoreModel::getStoreInfo($storeId,'market_id');
// $form->market_id = $info->market_id;
// });
$tags = $form->input('tags');
$tagsArr = [];
foreach($tags as $kt => $tag){
if(empty($tag)){
unset($tags[$kt]);
continue;
}
$tagsArr[] = $tag;
}
$form->tags = json_encode($tagsArr);
});
});
}

72
app/Admin/Forms/GoodsNewImageForm.php

@ -0,0 +1,72 @@
<?php
namespace App\Admin\Forms;
use App\Models\v3\GoodsBanners;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
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'];
$coverImg= $input['cover_img'];
$bannerImg= $input['img_banner'];
if($goodsId > 0 && !empty($coverImg)){
$data = ['cover_img' => $coverImg];
GoodsModel::where('id',$goodsId)->update($data);
}
if($goodsId > 0 && !empty($bannerImg)){
$banner = GoodsBannerModel::where('goods_id',$goodsId)->first();
if(empty($banner)){
$banner = new GoodsBanners();
$banner->goods_id = $goodsId;
$banner->type = 1;
$banner->created_at = time();
}
$banner->path = $bannerImg;
$banner->updated_at = time();
$banner->save();
}
return $this->success('修改成功', '/goods_new');
}
/**
* Build a form here.
*/
public function form()
{
$id = $this->getKey();
$goods = GoodsModel::select('name')->find($id);
$goodName = empty($goods->name)?'':$goods->name;
$this->hidden('goods_id')->value($id);
$this->image('cover_img','封面图')->url('ops/files')->help('商品名称:'.$goodName);
$this->image('img_banner','轮播图')->url('ops/files');
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return [];
}
}

163
app/Console/Commands/MigrateStoreAccount.php

@ -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;
}
}

2
app/Models/v3/Goods.php

@ -23,7 +23,7 @@ class Goods extends Model
protected $casts = [
'details_imgs'=>'array',
'tags'=>'array',
// 'tags'=>'array',
'spec'=>'array',
];

2
app/Models/v3/GoodsNew.php

@ -23,7 +23,7 @@ class GoodsNew extends Model
protected $casts = [
'details_imgs'=>'array',
'tags'=>'array',
// 'tags'=>'array',
'spec'=>'array',
];

Loading…
Cancel
Save