Commit 6f917e07 authored by hangjun83's avatar hangjun83

后端:百化销售订单退货功能逻辑

parent e3e43c88
#标准树(有三种不同的树:未注册的树x主要用于本地或私有环境,个人树prs主要用于非商业发行的项目,供应商树vndvnd主要用于可公开获得和分发的项目。您使用的标准树将取决于您正在开发的项目。)
API_STANDARDS_TREE=x
#亚型(子类型通常是应用程序或项目的缩写全为小写。)
API_SUBTYPE=rhawn
#前缀
API_PREFIX=/
#域(也就是项目网址)
API_DOMAIN=localhost
#默认API版本
API_VERSION=v1
#API名称
API_NAME="rhawn tools"
#条件请求状态(默认情况下,条件请求处于启用状态,因为它将在可能的情况下利用客户端缓存功能来缓存API请求。
API_CONDITIONAL_REQUEST=false
......@@ -19,6 +25,7 @@ API_STRICT=true
#默认响应格式
API_DEFAULT_FORMAT=json
#调试模式
API_DEBUG=true
......@@ -31,10 +38,21 @@ APP_URL=http://localhost
APP_TIMEZONE=UTC
APP_LOCALE=en
# lumen日志配置
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
LOG_QUERY=false
LOG_REQUEST=false
LOG_QUERY=true
LOG_REQUEST=true
# 如果使用的是 mongo channel 需要配置
LOG_MONGODB_SEPARATE=daily
LOG_MONGODB_LEVEL=debug
LOG_MONGODB_HOST=127.0.0.1
LOG_MONGODB_PORT=27017
LOG_MONGODB_DATABASE=logs
LOG_MONGODB_USERNAME=
LOG_MONGODB_PASSWORD=
LOG_MONGODB_AUTHENTICATION_DATABASE=admin
# 数据库配置
DB_CONNECTION=mysql
......@@ -44,6 +62,7 @@ DB_DATABASE=rhawn_tools
DB_USERNAME=root
DB_PASSWORD=123456
# mongo数据库配置
#MONGODB_HOST=127.0.0.1
#MONGODB_PORT=27017
#MONGODB_USERNAME=homestead
......@@ -51,7 +70,9 @@ DB_PASSWORD=123456
#MONGODB_DATABASE=homestead
#MONGODB_AUTHENTICATION_DATABASE=admin
# 缓存配置
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
# jwt配置
JWT_SECRET=
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Http\Controllers\V1;
use App\Services\BhOrdersService;
use Illuminate\Http\Request;
use Jiannei\Enum\Laravel\Repositories\Enums\LogEnum;
use Jiannei\Response\Laravel\Support\Facades\Response;
use App\Http\Controllers\V1\Controller;
use App\Support\Traits\Helpers;
class BhOrdersController extends Controller
{
use Helpers;
protected $bhOrdersService = null;
public function __construct(BhOrdersService $bhOrdersService)
{
$this->bhOrdersService = $bhOrdersService;
}
/**
* 白化采购订单搜索
* @param Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function searchPorders(Request $request)
{
$message = [
'bhOrderNo.required' => "订单号必填",
];
$this->validateRequest($request, $message);
try{
$orderList = $this->bhOrdersService->searchPordersToPage($request);
return Response::success($orderList, '操作成功');
}catch(\Exception $exception){
return Response::fail($exception->getMessage(),500);
}
}
public function editBhPorders(Request $request)
{
$message = [
'poNo.required' => "订单号必填",
];
$this->validateRequest($request, $message);
try{
$order = $this->bhOrdersService->editBhPordersInfo($request);
return Response::success($order, '更新成功');
}catch(\Exception $exception){
return Response::fail($exception->getMessage(),500);
}
}
/**
* 添加一个订单退货人任务
* @param Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function addSorderRefundTask(Request $request)
{
$message = [
'name.required' => "任务名称必填",
'orderNo.required' => "订单号必填",
'itemId.required' => "订单购买项必填",
'refundNums.required' => "退货数量必填",
'handleFee.required' => "手续费费用必填",
'transferPre.required' => "是否转预存必选",
];
$this->validateRequest($request, $message);
try{
$order = $this->bhOrdersService->addSordersRefundTask($request);
return Response::success($order, '添加成功');
}catch(\Exception $exception){
return Response::fail($exception->getMessage(),500);
}
}
/**
* 获取订单退货任务列表
* @param Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function getBhSorderRefundTaskToPage(Request $request)
{
try{
$order = $this->bhOrdersService->getSordersRefundTask($request);
return Response::success($order, '添加成功');
}catch(\Exception $exception){
return Response::fail($exception->getMessage(),500);
}
}
/**
* 执行百化退货任务
* @param Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function execBhSorderRefundTask(Request $request)
{
$message = [
'taskId.required' => "任务id必填",
];
$this->validateRequest($request, $message);
try{
$this->bhOrdersService->execSordersRefundTask($request);
return Response::success([],'操作成功');
}catch(\Exception $exception){
return Response::fail($exception->getMessage(),500);
}
}
/**
* 查询订单详情
* @param Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function getBhSordersDetail(Request $request)
{
$message = [
'orderNo.required' => "订单号必填",
];
$this->validateRequest($request, $message);
try{
$order = $this->bhOrdersService->getBhSorderDetail($request);
return Response::success($this->formatKeysfromArray($order), '更新成功');
}catch(\Exception $exception){
return Response::fail($exception->getMessage(),500);
}
}
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Jobs;
use App\Repositories\Contracts\BhSorderRefundRepository;
use App\Services\BhOrdersService;
use Illuminate\Support\Facades\DB;
class BhSorderRefundJob extends Job
{
protected $refundInfo;
public function __construct($refundInfo)
{
$this->refundInfo = $refundInfo;
}
/**
* Execute the job.
*/
public function handle()
{
try{
app(BhSorderRefundRepository::class)->update(['status' => 'running'],$this->refundInfo['id']);
$refundInfo = json_decode($this->refundInfo['exec_content']);
$service = app(BhOrdersService::class);
$service->sOrderRefund($refundInfo);
//对任务进行更新
$update = [];
$update['status'] = 'finish';
$update['exec_nums'] = $this->refundInfo['exec_nums'] + 1;
$update['error_message'] = '';
}catch(\Exception $e){
//对任务进行更新
$update = [];
$update['status'] = 'error';
$update['error_message'] = $e->getMessage();
$update['exec_nums'] = intval($this->refundInfo['exec_nums'] + 1);
}
try{
$db = DB::connection('mysql');
$db->beginTransaction();
$update['updated_at'] = date('Y-m-d H:i:s',time());
app(BhSorderRefundRepository::class)->update($update,$this->refundInfo['id']);
$logInsert = [];
$logInsert['task_id'] = $this->refundInfo['id'];
if(isset($update['error_message']) && !empty($update['error_message'])){
$logInsert['content'] = $update['error_message'];
}else{
$logInsert['content'] = '执行完成';
}
$logInsert['created_at'] = date('Y-m-d H:i:s',time());
$logInsert['updated_at'] = date('Y-m-d H:i:s',time());
$db->table('task_log')->insertGetId($logInsert);
$db->commit();
}catch(\Exception $e){
$db->rollback();
throw $e;
}
}
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Contracts;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhPordersRepository extends RepositoryInterface
{
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Contracts;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhSoitemsRepository extends RepositoryInterface
{
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Contracts;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhSorderRefundRepository extends RepositoryInterface
{
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Contracts;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhSordersRepository extends RepositoryInterface
{
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Criteria;
use Illuminate\Database\Eloquent\Builder;
use App\Repositories\Criteria\Criteria;
class BhPordersCriteria extends Criteria
{
protected function condition(Builder $query): void
{
if ($orderNo = $this->request->get('bhOrderNo')) {
$query->where('po_no', '=', $orderNo);
}
}
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Criteria;
use Illuminate\Database\Eloquent\Builder;
use App\Repositories\Criteria\Criteria;
class BhSorderRefundCriteria extends Criteria
{
protected function condition(Builder $query): void
{
if($this->request->has('type')){
$query->where('type', '=', $this->request->get('type'));
}
}
}
<?php
namespace App\Repositories\Eloquent;
use App\Repositories\Contracts\BhPordersRepository;
use App\Repositories\Criteria\RequestCriteria;
use App\Repositories\Models\BhPorders;
use App\Repositories\Eloquent\BaseRepository;
use Illuminate\Support\Facades\DB;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhPordersRepositoryEloquent extends BaseRepository implements BhPordersRepository
{
protected $fieldSearchable = [
];
/**
* 定义validator的检索规则
* @var \string[][]
*/
public $rules = [
ValidatorInterface::RULE_CREATE => [
'menu_name' => 'required',
'title' => 'required',
'menu_path' => 'required',
'parent_id' => 'required',
'menu_type' => 'required',
'status' => 'required',
'sort' => 'required',
'is_show' => 'required',
'sys_default' => 'required'
],
ValidatorInterface::RULE_UPDATE => [
'menu_name' => 'required',
'title' => 'required',
'menu_path' => 'required',
'parent_id' => 'required',
'menu_type' => 'required',
'status' => 'required',
'sort' => 'required',
'is_show' => 'required',
'sys_default' => 'required'
]
];
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhPorders::class;
}
/**
* Boot up the repository, pushing criteria.
*
* @throws \Prettus\Repository\Exceptions\RepositoryException
*/
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
/**
* 获取采购订单详情
* @param $po_id
* @return array
*/
public function getPorderItemsFromPoId($po_id,$pi_id = null)
{
$pOrder = $this->findWhere(['po_id' => $po_id])->toArray();
$db = DB::connection('bh_mysql');
$rowQueryobj = $db->table('poitems')
->join('products','poitems.p_id','products.p_id')
->join('chemicals','products.c_id','chemicals.c_id')
->join('brands','products.b_id','brands.b_id');
$rowQueryobj->where('poitems.po_id',$po_id);
if(!is_null($pi_id)){
$rowQueryobj->where('poitems.pi_id',$pi_id);
}
$pOrder['poitems'] = $rowQueryobj->get()->toArray();
return $pOrder;
}
}
<?php
namespace App\Repositories\Eloquent;
use App\Repositories\Contracts\BhSoitemsRepository;
use App\Repositories\Contracts\BhSordersRepository;
use App\Repositories\Criteria\RequestCriteria;
use App\Repositories\Models\BhSoitems;
use App\Repositories\Eloquent\BaseRepository;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhSoitemsRepositoryEloquent extends BaseRepository implements BhSoitemsRepository
{
protected $fieldSearchable = [
];
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhSoitems::class;
}
/**
* Boot up the repository, pushing criteria.
*
* @throws \Prettus\Repository\Exceptions\RepositoryException
*/
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
/**
* 获取订单详情
* @param $orderId
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function getSorderItemsDetailFromOrderId($orderId)
{
$order = app(BhSordersRepository::class)->find($orderId);
if(!$order){
throw new \LogicException('该订单不存在!',500);
}
//查询订单的详情
$soItems = BhSoitems::query()
->join('products','soitems.p_id','products.p_id')
->join('chemicals','products.c_id','chemicals.c_id')
->join('brands','products.b_id','brands.b_id')
->where('soitems.so_id',$order->so_id)->get();
return $soItems;
}
/**
* 根据si_id获取订单明细项
* @param $si_id
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function getSorderItemFromItemId($si_id)
{
$item = $this->find($si_id);
if(!$item){
throw new \LogicException('该订单项不存在!',500);
}
//查询订单的详情
$soItems = BhSoitems::query()
->join('products','soitems.p_id','products.p_id')
->where('soitems.si_id',$si_id)->get();
return $soItems;
}
}
<?php
namespace App\Repositories\Eloquent;
use App\Repositories\Contracts\BhSorderRefundRepository;
use App\Repositories\Criteria\RequestCriteria;
use App\Repositories\Models\BhSorderRefund;
use App\Repositories\Eloquent\BaseRepository;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhSorderRefundRepositoryEloquent extends BaseRepository implements BhSorderRefundRepository
{
protected $fieldSearchable = [
];
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhSorderRefund::class;
}
/**
* Boot up the repository, pushing criteria.
*
* @throws \Prettus\Repository\Exceptions\RepositoryException
*/
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
/**
* 添加退款任务
* @param $request
*/
public function addRefundTask($params)
{
if(empty($params)){
throw new \LogicException('参数为空!',500);
}
$task = [];
$task['name'] = $params['name'];
unset($params['name']);
$task['exec_content'] = json_encode($params);
$task['create_by'] = auth()->user()->id;
$task['status'] = 'notexec';
$task['type'] = 'sorder_refund';
return $this->create($task);
}
}
<?php
namespace App\Repositories\Eloquent;
use App\Repositories\Contracts\BhSordersRepository;
use App\Repositories\Criteria\RequestCriteria;
use App\Repositories\Models\BhSorders;
use App\Repositories\Eloquent\BaseRepository;
use Illuminate\Support\Facades\DB;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhSordersRepositoryEloquent extends BaseRepository implements BhSordersRepository
{
protected $fieldSearchable = [
];
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhSorders::class;
}
/**
* Boot up the repository, pushing criteria.
*
* @throws \Prettus\Repository\Exceptions\RepositoryException
*/
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
/**
* 返回指定订单编号的订单信息
* @param $order_no
* @return mixed
*/
public function getSorderFromOrderNo($orderNo)
{
$where = [
'so_no' => $orderNo
];
return $this->findWhere($where)->first();
}
/**
* 获取订单详情
* @param $orderNo
* @return mixed
*/
public function getSorderItemsFromOrderNo($orderNo){
$soItems = $this
->join('soitems','soitems.so_id','sorders.so_id')
->where('sorders.so_no',$orderNo)->get();
return $soItems;
}
/**
* 获取订单相关信息(包括,产品,客户,品牌等)
* @param $so_id
* @return mixed
*/
public function getSorderDetailFromOrderId($so_id)
{
$sOrderInfo = $this
->join('customers','sorders.cus_id','customers.cus_id')
->where('sorders.so_id',$so_id)
->get();
if(!$sOrderInfo){
return ;
}
$sOrderInfo = current($sOrderInfo->toArray());
$items = DB::connection('bh_mysql')->table('soitems')
->join('products','soitems.p_id','products.p_id')
->join('chemicals','products.c_id','chemicals.c_id')
->join('brands','products.b_id','brands.b_id')
->where('soitems.so_id',$so_id)
->get();
if(!$items){
$sOrderInfo['items'] = [];
}
$sOrderInfo['items'] = $items->toArray();
return $sOrderInfo;
}
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Models;
class BhPorders extends Model
{
protected $table = 'porders';
protected $connection = 'bh_mysql';
protected $primaryKey = 'po_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'po_sup_order','po_if_direct'
];
protected $guarded = ['updated_at'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
];
/**
* update时不做自动更新时间操作
* @return null
*/
public function getUpdatedAtColumn()
{
return null;
}
}
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Models;
class BhSoitems extends Model
{
// 销售订单
protected $table = 'soitems';
protected $connection = 'bh_mysql';
protected $primaryKey = 'si_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
];
protected $guarded = ['created_at', 'updated_at'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
];
/**
* update时不做自动更新时间操作
* @return null
*/
public function getUpdatedAtColumn()
{
return null;
}
public function getCreatedAtColumn()
{
return null;
}
}
\ No newline at end of file
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Models;
class BhSorderRefund extends Model
{
protected $table = 'tools_task';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name','exec_content','status','error_message','type','exec_nums','create_by'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
];
}
\ No newline at end of file
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Repositories\Models;
class BhSorders extends Model
{
// 销售订单
protected $table = 'sorders';
protected $connection = 'bh_mysql';
protected $primaryKey = 'so_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
];
protected $guarded = ['created_at', 'updated_at'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
];
/**
* update时不做自动更新时间操作
* @return null
*/
public function getUpdatedAtColumn()
{
return null;
}
public function getCreatedAtColumn()
{
return null;
}
}
\ No newline at end of file
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Services;
use App\Jobs\BhSorderRefundJob;
use App\Repositories\Contracts\BhPordersRepository;
use App\Repositories\Contracts\BhSoitemsRepository;
use App\Repositories\Contracts\BhSorderRefundRepository;
use App\Repositories\Contracts\BhSordersRepository;
use App\Repositories\Criteria\BhPordersCriteria;
use App\Repositories\Criteria\BhSorderRefundCriteria;
use App\Repositories\Enums\ResponseCodeEnum;
use App\Repositories\Models\AdminUsers;
use App\Repositories\Models\BhPorders;
use App\Support\Traits\Helpers;
use http\Exception\BadQueryStringException;
use Illuminate\Support\Facades\DB;
class BhOrdersService
{
use Helpers;
protected $bhPordersRepository = null;
public function __construct(BhPordersRepository $bhPordersRepository)
{
$this->bhPordersRepository = $bhPordersRepository;
}
public function searchPordersToPage($request)
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
$this->bhPordersRepository->pushCriteria(new BhPordersCriteria($request));
$pOrdersList = $this->bhPordersRepository->paginate($params['page_size']);
$returnRecord = [];
if($pOrdersList){
$record = $this->procOrderResponseData($pOrdersList->items());
}
// 获取当前角色的所有权限
$returnRecord['data'] = $this->formatKeysfromArray($record);
$returnRecord['current_page'] = $pOrdersList->currentPage();
$returnRecord['total'] = $pOrdersList->total();
return $returnRecord;
}
/**
* 编辑订单信息
* @param $request
* @return bool|int
*/
public function editBhPordersInfo($request)
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
$order = BhPorders::query()->where('po_no',$params['po_no'])->get();
if(!$order){
throw new \LogicException('订单号不存在!',500);
}
$updateOrderArr = [];
if(isset($params['po_sup_order']) && !empty($params['po_sup_order'])){
$updateOrderArr['po_sup_order'] = $params['po_sup_order'];
}
$updateOrderArr['po_if_direct'] = 0;
if(isset($params['po_if_direct']) && !empty($params['po_if_direct'])){
if($params['po_if_direct'] == true){
$updateOrderArr['po_if_direct'] = 1;
}
}
$res = $order->first()->update($updateOrderArr);
return $this->procOrderResponseData($order);
}
/**
* 获取订单详情
* @param $request
*/
public function getBhSorderDetail($request)
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
if(!isset($params['order_no']) || empty($params['order_no'])){
throw new BadQueryStringException('订单编号错误',500);
}
$sOrder = app(BhSordersRepository::class)->getSorderFromOrderNo($params['order_no']);
if(!$sOrder){
throw new \LogicException('该订单编号不存在!',500);
}
//查询订单的详情
$soItems = app(BhSoitemsRepository::class)->getSorderItemsDetailFromOrderId($sOrder->so_id);
$soItems = $soItems->toArray();
if($soItems){
foreach($soItems as &$item){
$item['so_no'] = $sOrder->so_no;
}
}
return $soItems;
}
public function addSordersRefundTask($request)
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
$sOrder = app(BhSordersRepository::class)->getSorderFromOrderNo($params['order_no']);
if(!$sOrder){
throw new \LogicException('该订单编号不存在!',500);
}
return app(BhSorderRefundRepository::class)->addRefundTask($params);
}
/**
* 获取订单退货任务
* @param $request
* @return array
*/
public function getSordersRefundTask($request)
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
if(!$params['page_size'] || $params['page_size'] == 0){
$params['page_size'] = 10;
}
$request->attributes->add(['type' => 'sorder_refund']);
$service = app(BhSorderRefundRepository::class);
$service->pushCriteria(new BhSorderRefundCriteria($request));
$tasks = $service->paginate($params['page_size']);
$returnRecord = [];
if($tasks){
$allItems = $tasks->items();
$allItems = collect($allItems)->map(function($item){
$item = $item->toArray();
$contentArr= [];
$execArr = json_decode($item['exec_content'],true);
foreach($execArr as $key => $content){
switch($key){
case 'order_no' : $contentArr[] = '【订单号】:'.$content; break;
case 'refund_nums' : $contentArr[] = '【退货数量】:'.$content; break;
case 'handle_fee' : $contentArr[] = '【手续费费用】:'.$content; break;
case 'item_id' : $contentArr[] = '【订单购买项id】:'.$content; break;
case 'transfer_pre' :
$content = $content == '1' ? '是' : '否';
$contentArr[] = '【是否转预存】:'.$content; break;
}
}
$user = AdminUsers::find($item['create_by']);
$item['create_by'] = $user->username;
$item['content_string'] = implode(' . ',$contentArr);
$item = array_merge($item,$execArr);
return $item;
});
// 获取当前角色的所有权限
$returnRecord['data'] = $this->formatKeysfromArray($allItems);
$returnRecord['current_page'] = $tasks->currentPage();
$returnRecord['total'] = $tasks->total();
}
return $returnRecord;
}
/**
* 手动执行脚本
* @param $request
*/
public function execSordersRefundTask($request)
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
$orderRefund = app(BhSorderRefundRepository::class)->find($params['task_id']);
$refundJob = (new BhSorderRefundJob($orderRefund->toArray()))->delay(100)->onQueue('slow');
app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($refundJob);
}
/**
* 处理退货逻辑
* @param $refundInfo
*/
public function sOrderRefund($refundInfo)
{
$sOrder = app(BhSordersRepository::class)->getSorderItemsFromOrderNo($refundInfo->order_no);
if(!$sOrder){
throw new \LogicException('该订单号不存在!',500);
}
try{
$dbConnect = DB::connection('bh_mysql');
$dbConnect->beginTransaction();
// 处理订单退货项
foreach($sOrder->toArray() as $orderitem){
if($refundInfo->item_id == $orderitem['si_id']){
// 先处理源数据
$currentPrice = floatval($orderitem['si_discount']);
$currentAmount = floatval($orderitem['si_amount']);
// 减去退货数量,剩余的更新数量
$num = intval($orderitem['si_num']) - intval($refundInfo->refund_nums);
//查询是否已经开票,如果开票不能进行退货
$dpdetail = $dbConnect->table('dpdetail')
->where('si_id',$orderitem['si_id'])
->get();
$dpdetail = $dpdetail->toArray();
if(count($dpdetail) > 0){
foreach($dpdetail as $detail){
if(floatval($detail->dpd_invoiced) > 0) {
throw new \logicexception('以开票的数据不能退货!',500);
}
}
}
//修改item数据项
$service = app(BhSoitemsRepository::class);
$soItem = $service->findWhere(['si_id' => $orderitem['si_id'],'si_if_cancel' => 0]);
$soItem = current($soItem->toArray());
$updateArr = [];
$updateArr['si_num'] = $num == 0 ? 1 :$num; // 如果数量只有1,且退货数量相等
$updateArr['si_assigned_num'] = $updateArr['si_num'];
$updateArr['si_amount'] = bcmul(
$orderitem['si_discount'] ,
$updateArr['si_num'],
2
);
if(isset($refundInfo->handle_fee) && $refundInfo->handle_fee > 0){
$updateArr['si_amount'] = bcadd(
$updateArr['si_amount'] , $refundInfo->handle_fee,2
);
}
if($num > 1){
$updateArr['si_discount'] = bcdiv($updateArr['si_amount'] , $num, 2);
}else{
$updateArr['si_discount'] = $updateArr['si_amount'];
}
$service->update($updateArr,$soItem['si_id']);
//生成新记录
$createArr = $soItem;
unset($createArr['si_id']);
if(isset($refundInfo->handle_fee) && floatval($refundInfo->handle_fee) > 0){
if($num == 0){
$createArr['si_amount'] = $refundInfo->handle_fee;
}else{
$createArr['si_amount'] = bcsub($currentAmount, $updateArr['si_amount'], 2);
}
}
$createArr['si_num'] = $refundInfo->refund_nums;
$createArr['si_assigned_num'] = $createArr['si_num'];
$createArr['si_discount'] = bcdiv($createArr['si_amount'], $createArr['si_num'], 2);
if($createArr['si_amount'] < 0){
throw new \LogicException('手续费异常,处理失败!',500);
}
$newItem = $service->create($createArr);
//修改配货单记录
if($dpdetail){
$maxRecord = $minRecord = [];
$needUpdate = null;
$totalNums = $totalAmount = 0;
//针对多个dpdetail数据,进行数量判断
//默认都是没有开票过的
foreach($dpdetail as $detail){
$detailArr = [];
$totalNums += $detail->dpd_num;
$totalAmount += $detail->dpd_amount;
foreach($detail as $key => $val){
$detailArr[$key] = $val;
}
if($detail->dpd_num == $refundInfo->refund_nums){
$needUpdate = $detailArr;
break;
}
// 1 数量5, 2条记录 3/2 , 退货4瓶
// 2 数量5, 2条记录 4/1 , 退货3瓶
// 3 数量6 3条记录 4/1/1, 退货3瓶
// 4 数量8 3条记录 4/2/2, 退货4瓶
// 5 数量8 3条记录 4/3/1, 退货4瓶
// 6 数量11 3条记录 6/4/1, 退货5瓶
if($detail->dpd_num > $refundInfo->refund_nums){
$nums = $detail->dpd_num;
$maxRecord[$nums][$detail->dpd_id] = $detailArr;
}elseif($refundInfo->refund_nums > $detail->dpd_num){
$nums = $refundInfo->refund_nums - $detail->dpd_num;
$minRecord[$nums][$detail->dpd_id] = $detailArr;
}
}
$cancelRecord = [];
if(!is_null($needUpdate)){
$dpUpdateArr = [];
$dpUpdateArr['si_id'] = $newItem->toArray()['si_id'];
// 如果有手续费,对价格进行更新
if($refundInfo->handle_fee > 0){
// 如果有手续费,将价格进行修改
foreach($dpdetail as $detail){
if($detail->dpd_id != $needUpdate['dpd_id']){
$otherUpdate = [];
$otherUpdate['dpd_amount'] = bcmul($updateArr['si_discount'], $needUpdate['dpd_num'], 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$dpdetail->dpd_id)
->update($otherUpdate);
}
}
//将取消的记录价格进行更新
$dpUpdateArr['dpd_amount'] = bcmul($createArr['si_discount'], $needUpdate['dpd_num'], 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$dpdetail->dpd_id)
->update($dpUpdateArr);
} // 如果没有手续费,不对价格进行更新
else{
$dbConnect->table('dpdetail')
->where('dpd_id',$dpdetail->dpd_id)
->update($dpUpdateArr);
}
}else{
asort($maxRecord);
arsort($minRecord); // 降序排序
$num = $refundInfo->refund_nums;
// minrecord有值,只有退货数量大于此条记录的数量时
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$minRecord,$newItem->toArray()['si_id'],$createArr,$updateArr,$refundInfo,'asort'));
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$maxRecord,$newItem->toArray()['si_id'],$createArr,$updateArr,$refundInfo,'arsort'));
}
// 更新除了取消的记录以外的记录的价格
if(count($cancelRecord) > 0){
$dpdetailInfo = $dbConnect->table('dpdetail')
->where('si_id',$orderitem['si_id'])
->whereNotIn('dpd_id',$cancelRecord)->get();
$dpdetailInfo = $dpdetailInfo->toArray();
if(count($dpdetailInfo) > 0){
foreach($dpdetailInfo as $info){
$otherUpdate = [];
$otherUpdate['dpd_amount'] = bcmul($updateArr['si_discount'], $info->dpd_num, 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$info->dpd_id)
->update($otherUpdate);
}
}
}
}
//新增配货单数据
/*foreach($dpdetail as $key => $value){
$dpCreateArr[$key] = $value;
}
unset($dpCreateArr['dpd_id']);
$dpCreateArr['dpd_num'] = $refundInfo->refund_nums;
$dpCreateArr['dpd_amount'] = $createArr['si_amount'];
$dpId = $dbConnect->table('dpdetail')->insertGetId($dpCreateArr);*/
// 修改采购订单的详情数据
$soItemArr = $soItem;
$poItems = $dbConnect->table('poitems')
->where('p_id', $soItemArr['p_id'])
->where('pi_id', $soItemArr['pi_id'])
->where('pi_status','<>',3)
->get();
if($poItems){
foreach($poItems as $item){
// 如果不是取消状态的
if($item->pi_status != 3){
// 可能存在对应多个po的情况
if($item->pi_num < $refundInfo->refund_nums){
throw new \LogicException('采购订单数量不足,无法退货!',500);
}
// 如果退货数量小于采购订单数量
if($item->pi_num > $refundInfo->refund_nums){
// 修改当前的数量和金额
$poItemUpdateArr = [];
$poNums = bcsub($item->pi_num, $refundInfo->refund_nums);
$poItemUpdateArr['pi_num'] = $poNums;
$poItemUpdateArr['pi_amount'] = bcmul($item->pi_price, $poNums, 2);
$poItemUpdateArr['pi_rnum'] = $poItemUpdateArr['pi_num'];
if($poItemUpdateArr['pi_num'] == $item->pi_rnum && $item->pi_status == 1){
$poItemUpdateArr['pi_status'] = 2;
}
$dbConnect->table('poitems')
->where('pi_id',$item->pi_id)
->update($poItemUpdateArr);
// 新增退货的采购订单信息
$poItemCreateArr = [];
foreach($item as $key => $ite){
$poItemCreateArr[$key] = $ite;
}
unset($poItemCreateArr['pi_id']);
$poItemCreateArr['pi_num'] = $refundInfo->refund_nums;
$poItemCreateArr['pi_amount'] = bcmul($item->pi_price, $poItemCreateArr['pi_num'], 2);
$poItemCreateArr['pi_rnum'] = $refundInfo->refund_nums;
$poItemCreateArr['pi_status'] = $poItemCreateArr['pi_num'] == $poItemCreateArr['pi_rnum'] ? 2 : 1;
$poItemsId = $dbConnect->table('poitems')->insertGetId($poItemCreateArr);
//将soitems表中的新增记录中的pi_id修改为新值
$newItem->update([
'pi_id' => $poItemsId
]);
// 取消采购订单
$this->cancelPorderItems($dbConnect,$poItemCreateArr['po_id'],$poItemsId);
}
}
}
}
//将dpdetail表里的新记录的si_id改为新值
/*$newDpdetail = $dbConnect->table('dpdetail')->where('dpd_id',$dpId)->first();
if(!$newDpdetail){
throw new \LogicException('数据处理失败!',500);
}
$updateDpArr = [];
$updateDpArr['si_id'] = $newItem->si_id;
$dbConnect->table('dpdetail')
->where('dpd_id',$dpId)
->update($updateDpArr);
*/
//预存款和退款处理
$this->cancelAndTransPrePay($dbConnect,$newItem->toArray()['si_id'],$refundInfo);
}
}
$dbConnect->commit();
}catch(\Exception $e){
$dbConnect->rollBack();
throw $e;
}
}
/**
* 具体处理拆分dpdetail数据
* @param $dbConnect
* @param $recordsArr
* @param $si_id
* @param $createArr
* @param $updateArr
* @param $refundInfo
* @param string $sort
* @return array
*/
protected function handleDpdetailInfo($dbConnect, &$num, $recordsArr, $si_id, $createArr, $updateArr, $refundInfo, $sort = 'arsort')
{
$cancelRecord = [];
if(!empty($recordsArr) && count($recordsArr) > 0){
foreach($recordsArr as $records){
if(is_array(current($records))){
$sort($records);
foreach($records as $re){
if($num > 0){
// 退货数量 > 当前记录的数量 或者 退货数量 = 当前记录的数量
if(($num > $re['dpd_num']) || ($num == $re['dpd_num'])){
$num = $num - $re['dpd_num'];
$dpUpdateArr = [];
$dpUpdateArr['si_id'] = $si_id;
if($refundInfo->handle_fee > 0){
$dpUpdateArr['dpd_amount'] = bcmul($createArr['si_discount'], $re['dpd_num'], 2);
}
$dbConnect->table('dpdetail')
->where('dpd_id',$re['dpd_id'])
->update($dpUpdateArr);
$cancelRecord[] = $re['dpd_id'];
} // 如果退货数量 < 当前记录的数量
elseif($num < $re['dpd_num']){
// 更新当前记录
$dpUpdateArr = [];
$dpUpdateArr['dpd_num'] = $re['dpd_num'] - $num;
if($refundInfo->handle_fee > 0){
$dpUpdateArr['dpd_amount'] = bcmul($updateArr['si_discount'], $dpUpdateArr['dpd_num'], 2);
}
$dbConnect->table('dpdetail')
->where('dpd_id',$re['dpd_id'])
->update($dpUpdateArr);
$cancelRecord[] = $re['dpd_id'];
//添加新的取消记录
$dpCreateArr = $re;
unset($dpCreateArr['dpd_id']);
$dpCreateArr['dpd_num'] = $num;
if($refundInfo->handle_fee > 0){
$dpCreateArr['dpd_amount'] = bcmul($createArr['si_discount'], $num, 2);
}
$dpCreateArr['si_id'] = $si_id;
$dpId = $dbConnect->table('dpdetail')->insertGetId($dpCreateArr);
$num = 0;
$cancelRecord[] = $dpId;
}
}
}
}
}
}
return $cancelRecord;
}
/**
* 取消采购订单项
* @param $db
* @param $po_id
* @param $pi_id
*/
protected function cancelPorderItems($db,$po_id,$pi_id)
{
$pOrderItems = app(BhPordersRepository::class)->getPorderItemsFromPoId($po_id,$pi_id);
$total = $db->table('poitems')
->where('po_id',$po_id)
->where('pi_status','<>',3)
->where('pi_id','<>',$pi_id)
->sum('pi_amount');
//$row = $db->select("SELECT SUM(`pi_amount`) AS `total` FROM `poitems` WHERE `po_id` = ".$po_id." AND `pi_id` <> ".$pi_id." AND `pi_status` <> 3");
//$row = current($row);
//判断是否是最后一条非运费明细
if($total > 0){
$total += current($pOrderItems)['po_express'];
$db->table('porders')->where('po_id', $po_id)->update(['po_total'=>$total]);
$db->table('poitems')->where('pi_id', $pi_id)->update(['pi_status'=>'3']);
}else{
$db->table('porders')
->where('po_id', $po_id)
->update(
[
'po_total' => '0',
'po_review_status' => '2'
]
);
$db->table('poitems')->where('pi_id', $pi_id)->update(['pi_status'=>'3']);
}
//更新采购订单的开票状态
$pOrderItems = current($pOrderItems);
if($pOrderItems['po_invoiced_amount'] >= $pOrderItems['po_total']){
$db->table('porders')->where('po_id',$po_id)->update(['po_invoice_status' => 2]);
}elseif($pOrderItems['po_invoiced_amount'] > 0){
$db->table('porders')->where('po_id',$po_id)->update(['po_invoice_status' => 1]);
}else{
$db->table('porders')->where('po_id',$po_id)->update(['po_invoice_status' => 0]);
}
return true;
}
/**
* 取消并转预存
* @param $db
* @param $si_id
*/
protected function cancelAndTransPrePay($db,$si_id,$refundInfo)
{
//获取订单明细项
$sOrderItem = app(BhSoitemsRepository::class)->getSorderItemFromItemId($si_id);
$sOrderItem = current($sOrderItem->toArray());
if($sOrderItem['si_if_cancel'] == 1){
throw new \LogicException('已经取消过了,请不要重复操作!',500);
}
$sOrderDetail = app(BhSordersRepository::class)->getSorderDetailFromOrderId($sOrderItem['so_id']);
if(!$sOrderDetail){
throw new \LogicException('数据不存在!',500);
}
$sOrderDetail['express'] = 0;
foreach($sOrderDetail['items'] as $k=>$v){
if($v->p_id == 0){
$sOrderDetail['express'] = $v->si_amount;
unset($sOrderDetail['items'][$k]);
}
}
if($sOrderDetail['so_pay_status'] == 0){
throw new \LogicException('未完成付款的订单不能取消转预存款!',500);
}
if($sOrderDetail['so_pay_status'] == 1){
throw new \LogicException('部分付款的订单不能取消明细,请联系管理员!',500);
}
if($sOrderItem['pi_id'] > 0){
//判断对应的采购订单明细是否已经取消
$pOrderItems = $db->table('poitems')
->join('porders','poitems.po_id','porders.po_id')
->where('poitems.pi_id',$sOrderItem['pi_id'])
->first();
if(!$pOrderItems){
throw new \LogicException('查询采购订单明细 ['.$sOrderItem['pi_id'].'] 数据不存在!',500);
}
if($pOrderItems->pi_status != 3){
throw new \LogicException('请先取消采购订单:'.$pOrderItems->po_no.'中的对应采购订单明细!');
}
}
if($sOrderItem['si_assigned_num'] > 0){
$dp_status = array();
$invoiced_amount = 0;
$dpdetailInfos = $db->table('dpdetail')
->join('dispatch','dpdetail.dp_id','dispatch.dp_id')
->where('dpdetail.si_id',$sOrderItem['si_id'])
->get();
if(!$dpdetailInfos){
throw new \LogicException('dpdetail ['.$sOrderItem['si_id'].'] 配货单数据不存在!',500);
}
foreach($dpdetailInfos as $k=>$v){
$dp_status[] = $v->dp_status;
$invoiced_amount += $v->dpd_invoiced;
}
if($invoiced_amount != 0){
throw new \LogicException('已经开过发票,不能取消!',500);
}
$dp_status = array_unique($dp_status);
if(in_array('0',$dp_status) || in_array('1',$dp_status)){
throw new \LogicException('请物流部配合处理至已发货状态,再做取消操作!',500);
}
}
// 具体处理退货并转预存
$si_cancel_time = 0;
$siAmountTotal = $db->table('soitems')
->where('so_id',$sOrderItem['so_id'])
->where('si_id','<>',$si_id)
->where('si_if_cancel',0)
->sum('si_amount');
$siAmountTotalPid = $db->table('soitems')
->where('so_id',$sOrderItem['so_id'])
->where('si_id','<>',$si_id)
->where('si_if_cancel',0)
->where('p_id','>',0)
->sum('si_amount');
$soItem = app(BhSoitemsRepository::class)->find($si_id);
if($soItem){
if($soItem['si_assigned_num']){
$dp = $db->table('dpdetail')->where('si_id',$si_id)->get();
$dp = $dp->toArray();
foreach($dp as $k=>$v){
if($v->dp_id == 0 && $v->stk_id > 0){
//清除已配货记录
$stock = $db->table('stock')->where('stk_id',$v['stk_id'])->get();
$stock = current($stock->toArray());
$stock_data = array();
$stock_data['stk_lock_num'] = $stock->stk_lock_num - $v->dpd_num;
if($stock_data['stk_lock_num'] < 0){
$stock_data['stk_lock_num'] = 0;
}
$db->table('stock')
->where('stk_id',$v->stk_id)
->update($stock_data);
$db->table('dpdetail')
->delete($v->dpd_id);
$si_assigned_num = $soItem['si_assigned_num'] - $v->dpd_num;
app(BhSoitemsRepository::class)->update(['si_patch_status'=>'0','si_assigned_num'=>$si_assigned_num],$si_id);
}
}
}
}
$customer = $db->table('customers')
->where('cus_id',$sOrderDetail['cus_id'])
->first();
//判断是否是最后一条非运费明细
$note = $sOrderDetail['so_no'].'取消明细:'.$soItem['p_code'];
if($siAmountTotalPid > 0){
$refund_amount = $soItem['si_amount'];
// 退款
if($refundInfo->transfer_pre == 0){
$refund_data = [];
$refund_data['r_company'] = $customer->cus_company;
$refund_data['r_amount'] = $refund_amount;
$refund_data['r_ctime'] = time();
$refund_data['r_note'] = $note;
$db->table('refund')->insertGetId($refund_data);
}else{
$prepaylog_data = [];
$prepaylog_data['cus_id'] = $sOrderDetail['cus_id'];
$prepaylog_data['prepaylog_amount'] = $refund_amount;
$prepaylog_data['prepaylog_note'] = $note;
$prepaylog_data['prepaylog_date'] = time();
$prepaylog_data['prepaylog_time'] = time();
$prepaylog_data['prepaylog_operator'] = auth()->user()->id;
$prepayId = $db->table('prepaylog')->insertGetId($prepaylog_data);
$sum = $db->table('prepaylog')
->where('cus_id',$sOrderDetail['cus_id'])
->sum('prepaylog_amount');
$db->table('customers')
->where('cus_id',$sOrderDetail['cus_id'])
->update(['cus_prepay' => $sum]);
$si_cancel_time = time();
}
app(BhSordersRepository::class)->update(['so_total'=>$siAmountTotal],$sOrderItem['so_id']);
app(BhSoitemsRepository::class)->update(['si_if_cancel'=>'1','si_cancel_time'=>$si_cancel_time],$si_id);
}else {
//得到退款金额
$sOrder = app(BhSordersRepository::class)->find($sOrderItem['so_id']);
if (!$sOrder) {
throw new \LogicException('数据不存在!', 500);
}
$sOrder = $sOrder->toArray();
$refund_amount = $sOrder['so_total'];
if($refundInfo->transfer_pre == 0){
$refund_data = array();
$refund_data['r_company'] = $customer->cus_company;
$refund_data['r_amount'] = $refund_amount;
$refund_data['r_ctime'] = time();
$refund_data['r_note'] = $note;
$db->table('refund')->insertGetId($refund_data);
}else{
$prepaylog_data = [];
$prepaylog_data['cus_id'] = $sOrderDetail['cus_id'];
$prepaylog_data['prepaylog_amount'] = $refund_amount;
$prepaylog_data['prepaylog_note'] = $note;
$prepaylog_data['prepaylog_date'] = time();
$prepaylog_data['prepaylog_time'] = time();
$prepaylog_data['prepaylog_operator'] = auth()->user()->id;
$prepayId = $db->table('prepaylog')->insertGetId($prepaylog_data);
$sum = $db->table('prepaylog')
->where('cus_id', $sOrderDetail['cus_id'])
->sum('prepaylog_amount');
$db->table('customers')
->where('cus_id', $sOrderDetail['cus_id'])
->update(['cus_prepay' => $sum]);
$si_cancel_time = time();
}
app(BhSordersRepository::class)->update(['so_review_status' => '3', 'so_total' => '0'], $sOrderItem['so_id']);
app(BhSoitemsRepository::class)->update(['si_if_cancel' => '1', 'si_cancel_time' => $si_cancel_time], $sOrderItem['so_id']);
}
$db->table('logs')->insertGetId(
['l_obj'=>$sOrderItem['so_id'],'l_type'=>'sorders_mng','l_op'=>'cancelsi','l_op_name'=>'取消明细','l_note'=>$note,'l_timestamp'=>time(),'u_id'=>auth()->user()->id]
);
return true;
}
/**
* 处理需要返回的数据
* @param $pOrdersList
* @return array|\Illuminate\Support\Collection
*/
protected function procOrderResponseData($items)
{
$items = collect($items)->map(function($item){
$item = $item->toArray();
//开票状态
switch($item['po_invoice_status']){
case 0 : $item['po_invoice_status'] = '未开票';break;
case 1 : $item['po_invoice_status'] = '部分开票';break;
case 2 : $item['po_invoice_status'] = '全额开票';break;
}
//是否直发
switch($item['po_if_direct']){
case 0 : $item['po_if_direct_label'] = '否'; break;
case 1 : $item['po_if_direct_label'] = '是'; break;
}
//订单类型
switch($item['po_type']){
case 0 : $item['po_type'] = '备货'; break;
case 1 : $item['po_type'] = '订单'; break;
}
//审核状态
switch($item['po_review_status']){
case 0 : $item['po_review_status'] = '未付款'; break;
case 1 : $item['po_review_status'] = '部分付款'; break;
case 2 : $item['po_review_status'] = '全额付款'; break;
}
//付款类型
switch($item['po_pay_type']){
case 0 : $item['po_pay_type'] = '公账'; break;
case 1 : $item['po_pay_type'] = '私账'; break;
case 2 : $item['po_pay_type'] = '预付款'; break;
}
return $item;
});
return $items;
}
}
......@@ -9,4 +9,4 @@ $api = app('Dingo\Api\Routing\Router');
require __DIR__.'/../routes/api/auth.php';
require __DIR__.'/../routes/api/permissions.php';
//require __DIR__.'/../routes/api/tools.php';
require __DIR__.'/../routes/api/tools.php';
......@@ -61,6 +61,21 @@ return [
'engine' => env('DB_ENGINE', null),
'timezone' => env('DB_TIMEZONE', '+00:00'),
],
'bh_mysql' => [
'driver' => 'mysql',
'host' => env('BH_DB_HOST', '127.0.0.1'),
'port' => env('BH_DB_PORT', 3306),
'database' => env('BH_DB_DATABASE', 'forge'),
'username' => env('BH_DB_USERNAME', 'forge'),
'password' => env('BH_DB_PASSWORD', ''),
'unix_socket' => env('BH_DB_SOCKET', ''),
'charset' => env('BH_DB_CHARSET', 'utf8mb4'),
'collation' => env('BH_DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => env('BH_DB_PREFIX', ''),
'strict' => env('BH_DB_STRICT_MODE', true),
'engine' => env('BH_DB_ENGINE', null),
'timezone' => env('BH_DB_TIMEZONE', '+00:00'),
],
'pgsql' => [
'driver' => 'pgsql',
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class CreateToolsTaskTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$tableNames = 'tools_task';
Schema::create($tableNames, function (Blueprint $table) {
$table->id();
$table->string('name')->comment('任务名称');
$table->longText('exec_content')->comment('任务内容');
$table->enum('status',['notexec','running','error','finish'])->comment('任务状态');
$table->string('type')->comment('任务类型');
$table->longText('error_message')->nullable()->comment('错误信息');
$table->unsignedTinyInteger('create_by')->comment('创建人');
$table->unsignedTinyInteger('exec_nums')->default(0)->comment('执行次数');
$table->timestamps();
});
Schema::table($tableNames,function(Blueprint $table){
DB::statement('ALTER TABLE '.$table->getTable(). ' ROW_FORMAT=DYNAMIC;');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tools_task');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTaskLogTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('task_log', function (Blueprint $table) {
$table->id();
$table->string('task_id')->comment('任务id');
$table->longText('content')->comment('执行内容');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('task_log');
}
}
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