Commit e4d9fc08 authored by hangjun83's avatar hangjun83

罗恩测试工具

parent 916693e3
<?php
namespace App\Console\Commands;
use App\Services\ThirdPlatform\ZhenKhService;
use App\TestTools\Rhawn\RhawnToolsService;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
class RhawnToolsJobCommand extends Command
{
use ConfirmableTrait;
/**
* 命令行的名称及用法。
*
* @var string
*/
protected $signature = 'tools:job
{--action_type= : 任务操作类型}
{--params= : 任务参数}';
/**
* 命令行的概述。
*
* @var string
*/
protected $description = '罗恩任务命令行';
/**
* 创建新的命令实例。
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 运行命令。
* @throws \Exception
*/
public function handle()
{
if (! $this->confirmToProceed()) {
return 1;
}
if($this->hasArgument('help')){
$this->help();
}else{
$action_type = $this->option('action_type');
$params = $this->option('params');
if(empty($action_type)){
$this->error('缺少命令参数,请输入具体的参数命令.如需帮助请输入 --help');
exit;
}
list($cusCode,$discount) = explode(',',$params);
$service = app(RhawnToolsService::class);
switch($action_type){
case 'updateCustomerOrdersPricesByDiscount' :
$service->updateCustomerOrdersPricesByDiscount($cusCode,$discount);
break;
default:
}
/*$productUpdateJob = (new ZhenkhJob($action_type,$params))->delay(100);
app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($productUpdateJob);*/
}
}
public function help()
{
$helpStr = "参数帮助说明";
$this->comment($this->setHelp($helpStr)->getProcessedHelp());
$this->line("action_type: 具体动作参数\n\n initProductToExcel => 初始化批量商品 \n batchUpdateProduct => 批量更新商品\n\nparams : 操作需要传入的参数.非必填项");
}
}
...@@ -76,7 +76,8 @@ class AppServiceProvider extends ServiceProvider ...@@ -76,7 +76,8 @@ class AppServiceProvider extends ServiceProvider
\App\Console\Commands\LeyanJobCommand::class, \App\Console\Commands\LeyanJobCommand::class,
\App\Console\Commands\ThirdPlatformJobCommand::class, \App\Console\Commands\ThirdPlatformJobCommand::class,
\App\Console\Commands\KafkaConsumerCommand::class, \App\Console\Commands\KafkaConsumerCommand::class,
\App\Console\Commands\TestJobCommand::class \App\Console\Commands\TestJobCommand::class,
\App\Console\Commands\RhawnToolsJobCommand::class
]); ]);
} }
......
<?php
namespace App\TestTools\Rhawn;
use App\Rhawn\Repositories\Eloquent\RhawnSordersRepositoryEloquent;
use App\Rhawn\Services\RhawnCustomerService;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
class RhawnToolsService
{
public function __construct(\App\Rhawn\Services\RhawnOrdersService $rhawnOrdersService)
{
$this->rhawnOrdersService = $rhawnOrdersService;
$this->rhawnCustomerService = app(RhawnCustomerService::class);
}
/**
* 修改用户订单价格
*/
public function updateCustomerOrdersPricesByDiscount($cusCode, $discount)
{
$customer = $this->rhawnCustomerService->checkCustomerExist($cusCode);
if($customer){
$rhawnOrderRepository = app(RhawnSordersRepositoryEloquent::class);
$orderList = $rhawnOrderRepository->getOrdersListThroughtUserId($customer['cus_id'],1,1000);
if($orderList) {
$armedOrders = [];
foreach ($orderList as $order) {
if ($order['so_review_status'] == 0) {
array_push($armedOrders, $order);
}
}
$connection = DB::connection($rhawnOrderRepository->getConnectionName());
try {
$connection->beginTransaction();
//处理状态0的订单
if (count($armedOrders) > 0) {
foreach ($armedOrders as $order) {
$orderDetail = $this->rhawnOrdersService->getCustomerOrderItemsByOrderId($customer['cus_id'], $order['so_id']);
if ($orderDetail) {
foreach ($orderDetail as $detail) {
$si_discount = 0;
$si_amount = 0;
if ($detail['p_id'] > 0) {
$si_discount = round($detail['si_price'] * $discount);
$si_amount = bcadd($detail['si_num'], $si_discount);
$connection->table('soitems')
->where('si_id',$detail['si_id'])
->update([
'si_discount' => $si_discount,
'si_amount' => $si_amount
]);
}
}
//更新订单总价
$total = $connection->table('soitems')
->where('so_id',$order['so_id'])
->select(DB::raw('sum(si_amount) as amount'))
->get();
var_dump($total);
}
}
$connection->commit();
}
}catch(\Throwable $exception){
$connection->rollBack();
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':updateCustomerOrdersPricesByDiscount','error');
}
}
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment