3 changed files with 69 additions and 196 deletions
-
69app/Console/Commands/MigrateStore.php
-
125app/Console/Commands/couponReport.php
-
71app/Console/Commands/setStoreUsers.php
@ -0,0 +1,69 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class MigrateStore extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:store'; |
|||
|
|||
/** |
|||
* 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() |
|||
{ |
|||
// 如果表不存在则创建
|
|||
// if(!Schema::hasTable('lanzu_store_users')){
|
|||
// Schema::create('lanzu_store_users',function (Blueprint $table){
|
|||
// $table->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; |
|||
} |
|||
} |
|||
@ -1,125 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class couponReport extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'command:couponReport {start?} {end?} {--ret=0}'; |
|||
|
|||
/** |
|||
* 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() |
|||
{ |
|||
$start = $this->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);
|
|||
} |
|||
} |
|||
} |
|||
@ -1,71 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class setStoreUsers extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:setStoreUsers'; |
|||
|
|||
/** |
|||
* 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. |
|||
* 店铺的登录账号,店长、店员 |
|||
* 将旧账号表的关联的店铺id和角色洗到新的店铺账号表 |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
// 如果表不存在则创建
|
|||
if(!Schema::hasTable('lanzu_store_users')){ |
|||
Schema::create('lanzu_store_users',function (Blueprint $table){ |
|||
$table->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; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue