初始版本
This commit is contained in:
85
server/app/common/command/AppointOrderClose.php
Executable file
85
server/app/common/command/AppointOrderClose.php
Executable file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\enum\OrderRefundEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\logic\RefundLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderLog;
|
||||
use app\common\service\ConfigService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 关闭超过预约时间的订单
|
||||
* Class AppointOrderClose
|
||||
* @package app\common\command
|
||||
*/
|
||||
class AppointOrderClose extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('appoint_order_close')
|
||||
->setDescription('关闭超过预约时间的订单');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$time = time();
|
||||
|
||||
$orders = Order::where(['order_status' => OrderEnum::ORDER_STATUS_WAIT_RECEIVING,'pay_status' => PayEnum::ISPAID])
|
||||
->where('appoint_time','<',$time)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($orders)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try{
|
||||
foreach ($orders as $order) {
|
||||
//更新订单状态
|
||||
Order::update(['order_status' => OrderEnum::ORDER_STATUS_CLOSE,'cancel_time'=>time()], ['id' => $order['id']]);
|
||||
|
||||
//原路退款
|
||||
(new RefundLogic())->refund($order,$order['order_amount'],0,OrderRefundEnum::TYPE_SYSTEM,1,0);
|
||||
|
||||
//添加订单日志
|
||||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_SYSTEM,OrderLogEnum::SYSTEM_CANCEL_APPOINT_ORDER,$order['id'],0);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('关闭超过预约时间的订单失败,失败原因:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
92
server/app/common/command/Crontab.php
Executable file
92
server/app/common/command/Crontab.php
Executable file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\enum\CrontabEnum;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use Cron\CronExpression;
|
||||
use think\facade\Console;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
* Class Crontab
|
||||
* @package app\command
|
||||
*/
|
||||
class Crontab extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('crontab')
|
||||
->setDescription('定时任务');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$lists = \app\common\model\Crontab::where('status', CrontabEnum::START)->select()->toArray();
|
||||
if(empty($lists)) {
|
||||
return false;
|
||||
}
|
||||
foreach($lists as $item) {
|
||||
$nextTime = (new CronExpression($item['expression']))
|
||||
->getNextRunDate($item['last_time'])
|
||||
->getTimestamp();
|
||||
if($nextTime > time()) {
|
||||
// 未到时间,不执行
|
||||
continue;
|
||||
}
|
||||
// 开始执行
|
||||
self::start($item);
|
||||
}
|
||||
}
|
||||
|
||||
public static function start($item)
|
||||
{
|
||||
// 开始执行
|
||||
$startTime = microtime(true);
|
||||
$error = '';
|
||||
$status = CrontabEnum::START;
|
||||
try {
|
||||
$params = explode(' ', $item['params']);
|
||||
if (is_array($params) && !empty($item['params'])) {
|
||||
Console::call($item['command'], $params);
|
||||
} else {
|
||||
Console::call($item['command']);
|
||||
}
|
||||
// 清除错误信息
|
||||
// \app\common\model\Crontab::where('id', $item['id'])->update(['error' => '']);
|
||||
} catch(\Exception $e) {
|
||||
// 记录错误信息
|
||||
// \app\common\model\Crontab::where('id', $item['id'])->update(['error' => $e->getMessage(), 'status' => CrontabEnum::ERROR]);
|
||||
$error = $e->getMessage();
|
||||
$status = CrontabEnum::ERROR;
|
||||
} finally {
|
||||
$endTime = microtime(true);
|
||||
// 本次执行时间
|
||||
$useTime = round(($endTime - $startTime), 2);
|
||||
// 最大执行时间
|
||||
$maxTime = max($useTime, $item['max_time']);
|
||||
// 更新最后执行时间
|
||||
\app\common\model\Crontab::where('id', $item['id'])
|
||||
->update(['last_time' => time(), 'time' => $useTime, 'max_time' => $maxTime,'error' => $error, 'status' => $status]);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
server/app/common/command/MapKeyReset.php
Executable file
53
server/app/common/command/MapKeyReset.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\MapKeyEnum;
|
||||
use app\common\model\MapKey;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class MapKeyReset extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('map_key_reset')
|
||||
->setDescription('重置地图异常key');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
MapKey::where(['status'=>MapKeyEnum::STATUS_ABNORMAL])->update(['status'=>MapKeyEnum::STATUS_WAIT,'error_info'=>'']);
|
||||
|
||||
Db::commit();
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('重置地图异常key失败,失败原因:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
81
server/app/common/command/OrderAbnormalNotice.php
Executable file
81
server/app/common/command/OrderAbnormalNotice.php
Executable file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\service\ConfigService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderAbnormalNotice extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_abnormal_notice')
|
||||
->setDescription('订单异常通知');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
//当前时间
|
||||
$currentTime = time();
|
||||
$mobile = ConfigService::get('platform', 'mobile','');
|
||||
if(empty($mobile)){
|
||||
return true;
|
||||
}
|
||||
$orders = Order::where(['order_status'=>[OrderEnum::ORDER_STATUS_WAIT_RECEIVING, OrderEnum::ORDER_STATUS_SERVER_FINISH]])
|
||||
->whereRaw("appoint_time+86400 < $currentTime")
|
||||
->field('id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($orders)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Db::startTrans();
|
||||
try{
|
||||
|
||||
foreach ($orders as $order) {
|
||||
// 订单异常通知平台
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::ORDER_ABNORMAL_NOTICE_PLATFORM,
|
||||
'params' => [
|
||||
'mobile' => $mobile,
|
||||
'order_id' => $order['id']
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// Db::commit();
|
||||
} catch(\Exception $e) {
|
||||
// Db::rollback();
|
||||
Log::write('订单异常通知失败,失败原因:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
98
server/app/common/command/OrderClose.php
Executable file
98
server/app/common/command/OrderClose.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderLog;
|
||||
use app\common\service\ConfigService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 关闭超时待付款订单
|
||||
* Class OrderClose
|
||||
* @package app\common\command
|
||||
*/
|
||||
class OrderClose extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_close')
|
||||
->setDescription('系统关闭超时未付款订单');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$now = time();
|
||||
$ableClose = ConfigService::get('transaction', 'cancel_unpaid_orders',1);
|
||||
$cancelTime = ConfigService::get('transaction', 'cancel_unpaid_orders_times',30) * 60;
|
||||
|
||||
if ($ableClose == YesNoEnum::NO) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$orders = Order::with('order_goods')
|
||||
->whereRaw("create_time+$cancelTime < $now")
|
||||
->where(['order_status'=>OrderEnum::ORDER_STATUS_WAIT_PAY,'pay_status'=>PayEnum::UNPAID])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($orders)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try{
|
||||
foreach ($orders as $order) {
|
||||
//更新订单状态
|
||||
Order::update(['order_status' => OrderEnum::ORDER_STATUS_CLOSE,'cancel_time'=>time()], ['id' => $order['id']]);
|
||||
|
||||
//添加订单日志
|
||||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_SYSTEM,OrderLogEnum::SYSTEM_CANCEL_ORDER,$order['id'],0);
|
||||
|
||||
// 系统取消订单 - 通知买家
|
||||
// event('Notice', [
|
||||
// 'scene_id' => NoticeEnum::SYSTEM_CANCEL_ORDER_NOTICE,
|
||||
// 'params' => [
|
||||
// 'user_id' => $order['user_id'],
|
||||
// 'order_id' => $order['id']
|
||||
// ]
|
||||
// ]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('订单自动关闭失败,失败原因:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
84
server/app/common/command/OrderComment.php
Executable file
84
server/app/common/command/OrderComment.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderGoods;
|
||||
use app\common\service\ConfigService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderComment extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_comment')
|
||||
->setDescription('订单自动评论');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
|
||||
$overTimeComment = ConfigService::get('order_setting', 'over_time_comment') * 60 * 60 * 60;
|
||||
$now = time();
|
||||
$lists = Order::alias('O')
|
||||
->join('order_goods OG','O.id = OG.order_id')
|
||||
->whereRaw("true_server_finish_time+$overTimeComment < $now")
|
||||
->where(['order_status'=>OrderEnum::ORDER_STATUS_SERVER_FINISH,'is_comment'=>0])
|
||||
->where('true_server_finish_time','>',0)
|
||||
->field('O.user_id,O.shop_id,O.coach_id,OG.*')
|
||||
->select()
|
||||
->toArray();
|
||||
if (empty($lists)) {
|
||||
return true;
|
||||
}
|
||||
$overTimeCommentContent = ConfigService::get('order_setting', 'over_time_comment_content');
|
||||
foreach ($lists as $order) {
|
||||
Db::startTrans();
|
||||
try{
|
||||
GoodsComment::create([
|
||||
'goods_id' => $order['goods_id'],
|
||||
'user_id' => $order['user_id'],
|
||||
'order_goods_id' => $order['id'],
|
||||
'service_comment' => 5,
|
||||
'comment' => $overTimeCommentContent,
|
||||
'reply' => '',
|
||||
'coach_id' => $order['coach_id'],
|
||||
'shop_id' => $order['shop_id'],
|
||||
]);
|
||||
\app\common\logic\CoachLogic::updateCoachComment($order['coach_id']);
|
||||
if($order['shop_id']){
|
||||
\app\common\logic\ShopLogic::updateShopComment($order['shop_id']);
|
||||
}
|
||||
OrderGoods::where(['id'=>$order['id']])->update(['is_comment' => 1]);
|
||||
Db::commit();
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('订单评论失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
180
server/app/common/command/OrderRefund.php
Executable file
180
server/app/common/command/OrderRefund.php
Executable file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\accountLog\AccountLogEnum;
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\OrderRefundEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\model\order\OrderRefundLog;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\AliPayService;
|
||||
use app\common\service\WeChatConfigService;
|
||||
use app\common\service\WeChatPayService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderRefund extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_refund')
|
||||
->setDescription('订单退款');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$lists = OrderRefundLog::alias('orl')
|
||||
->join('order_refund or', 'or.id = orl.refund_id')
|
||||
->join('order o', 'o.id = or.order_id')
|
||||
->field('or.order_terminal,or.transaction_id,orl.sn,or.order_amount,or.refund_amount + or.refund_car_amount as refund_amount,orl.refund_id,orl.id as refund_log_id,or.user_id,or.order_id,o.pay_way as refund_way,o.sn as order_sn')
|
||||
->where(['orl.refund_status'=>OrderRefundEnum::STATUS_ING])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($lists)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($lists as $val) {
|
||||
Db::startTrans();
|
||||
try{
|
||||
switch ($val['refund_way']) {
|
||||
//微信退款
|
||||
case PayEnum::WECHAT_PAY:
|
||||
//微信配置信息
|
||||
$wechatConfig = WeChatConfigService::getWechatConfigByTerminal($val['order_terminal']);
|
||||
if (!file_exists($wechatConfig['cert_path']) || !file_exists($wechatConfig['key_path'])) {
|
||||
throw new \Exception('微信证书不存在,请联系管理员!');
|
||||
}
|
||||
|
||||
//发起退款
|
||||
$result = (new WeChatPayService($val['order_terminal']))->refund([
|
||||
'transaction_id' => $val['transaction_id'],
|
||||
'refund_sn' => $val['sn'],
|
||||
'total_fee' => $val['order_amount'] * 100,//订单金额,单位为分
|
||||
'refund_fee' => intval($val['refund_amount'] * 100),//退款金额
|
||||
]);
|
||||
|
||||
if (isset($result['return_code']) && $result['return_code'] == 'FAIL') {
|
||||
throw new \Exception($result['return_msg']);
|
||||
}
|
||||
|
||||
if (isset($result['err_code_des'])) {
|
||||
throw new \Exception($result['err_code_des']);
|
||||
}
|
||||
|
||||
//更新退款日志记录
|
||||
OrderRefundLog::update([
|
||||
'wechat_refund_id' => $result['refund_id'] ?? 0,
|
||||
'refund_status' => (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') ? 1 : 2,
|
||||
'refund_msg' => json_encode($result, JSON_UNESCAPED_UNICODE),
|
||||
], ['id'=>$val['refund_log_id']]);
|
||||
|
||||
//更新订单退款状态
|
||||
\app\common\model\order\OrderRefund::update([
|
||||
'refund_status' => (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') ? 1 : 2,
|
||||
], ['id'=>$val['refund_id']]);
|
||||
|
||||
if (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') {
|
||||
// 订单退款成功 - 通知买家
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::ORDER_REFUND_NOTICE,
|
||||
'params' => [
|
||||
'user_id' => $val['user_id'],
|
||||
'order_id' => $val['order_id'],
|
||||
'refund_amount' => $val['refund_amount']
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
break;
|
||||
//余额退款
|
||||
case PayEnum::BALANCE_PAY:
|
||||
//退回余额
|
||||
User::update(['user_money'=>['inc', $val['refund_amount']]],['id'=>$val['user_id']]);
|
||||
//流水记录
|
||||
AccountLogLogic::add($val['user_id'], AccountLogEnum::MONEY,AccountLogEnum::CANCEL_ORDER_ADD_MONEY,AccountLogEnum::INC, $val['refund_amount'], $val['order_sn']);
|
||||
|
||||
//更新订单退款状态
|
||||
\app\common\model\order\OrderRefund::update([
|
||||
'refund_status' => 1,
|
||||
], ['id'=>$val['refund_id']]);
|
||||
//更新退款日志记录
|
||||
OrderRefundLog::update([
|
||||
'refund_status' => 1,
|
||||
], ['id'=>$val['refund_log_id']]);
|
||||
|
||||
// 订单退款成功 - 通知买家
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::ORDER_REFUND_NOTICE,
|
||||
'params' => [
|
||||
'user_id' => $val['user_id'],
|
||||
'order_id' => $val['order_id'],
|
||||
'refund_amount' => $val['refund_amount']
|
||||
]
|
||||
]);
|
||||
|
||||
break;
|
||||
//支付宝退款
|
||||
case PayEnum::ALI_PAY:
|
||||
//原路退回到支付宝的情况
|
||||
$result = (new AliPayService())->refund($val['order_sn'], $val['refund_amount'], $val['sn']);
|
||||
$result = (array)$result;
|
||||
|
||||
//更新退款日志记录
|
||||
OrderRefundLog::update([
|
||||
'refund_status' => ($result['code'] == '10000' && $result['msg'] == 'Success' && $result['fundChange'] == 'Y') ? 1 : 2,
|
||||
'refund_msg' => json_encode($result, JSON_UNESCAPED_UNICODE),
|
||||
], ['id'=>$val['refund_log_id']]);
|
||||
|
||||
//更新订单退款状态
|
||||
\app\common\model\order\OrderRefund::update([
|
||||
'refund_status' => ($result['code'] == '10000' && $result['msg'] == 'Success' && $result['fundChange'] == 'Y') ? 1 : 2,
|
||||
], ['id'=>$val['refund_id']]);
|
||||
|
||||
if ($result['code'] == '10000' && $result['msg'] == 'Success' && $result['fundChange'] == 'Y') {
|
||||
// 订单退款成功 - 通知买家
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::ORDER_REFUND_NOTICE,
|
||||
'params' => [
|
||||
'user_id' => $val['user_id'],
|
||||
'order_id' => $val['order_id'],
|
||||
'refund_amount' => $val['refund_amount']
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('订单退款失败,失败原因:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
125
server/app/common/command/OrderRefundQuery.php
Executable file
125
server/app/common/command/OrderRefundQuery.php
Executable file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\OrderRefundEnum;
|
||||
use app\common\model\order\OrderRefundLog;
|
||||
use app\common\service\WeChatConfigService;
|
||||
use EasyWeChat\Factory;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderRefundQuery extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_refund_query')
|
||||
->setDescription('订单退款查询');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$lists = OrderRefundLog::alias('orl')
|
||||
->join('order_refund or', 'or.id = orl.refund_id')
|
||||
->field('orl.sn as refund_log_sn,orl.id as refund_log_id,or.id refund_id,or.order_terminal,or.user_id,or.order_id')
|
||||
->where(['orl.refund_status'=>OrderRefundEnum::STATUS_ING])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($lists)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try{
|
||||
foreach ($lists as $val) {
|
||||
|
||||
//微信配置信息
|
||||
$wechatConfig = WeChatConfigService::getWechatConfigByTerminal($val['order_terminal']);
|
||||
if (!file_exists($wechatConfig['cert_path']) || !file_exists($wechatConfig['key_path'])) {
|
||||
throw new \Exception('微信证书不存在,请联系管理员!');
|
||||
}
|
||||
|
||||
$app = Factory::payment($wechatConfig);
|
||||
//通过商户退款单号查询退款状态
|
||||
$result = $app->refund->queryByOutRefundNumber($val['refund_log_sn']);
|
||||
|
||||
if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
|
||||
$refund_status = OrderRefundEnum::STATUS_ING;
|
||||
|
||||
if ($result['refund_status_0'] == 'SUCCESS') {
|
||||
$refund_status = OrderRefundEnum::STATUS_SUCCESS;
|
||||
|
||||
//更新订单退款状态
|
||||
\app\common\model\order\OrderRefund::update([
|
||||
'refund_status' => OrderRefundEnum::STATUS_SUCCESS,
|
||||
], ['id'=>$val['refund_id']]);
|
||||
|
||||
if (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') {
|
||||
// 订单退款成功 - 通知买家
|
||||
// event('Notice', [
|
||||
// 'scene_id' => NoticeEnum::REFUND_SUCCESS_NOTICE,
|
||||
// 'params' => [
|
||||
// 'user_id' => $val['user_id'],
|
||||
// 'order_id' => $val['order_id']
|
||||
// ]
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
if ($result['refund_status_0'] == 'REFUNDCLOSE') {
|
||||
$refund_status = OrderRefundEnum::STATUS_FAIL;
|
||||
|
||||
//更新订单退款状态
|
||||
\app\common\model\order\OrderRefund::update([
|
||||
'refund_status' => OrderRefundEnum::STATUS_FAIL,
|
||||
], ['id'=>$val['refund_id']]);
|
||||
}
|
||||
|
||||
//更新退款日志记录
|
||||
OrderRefundLog::update([
|
||||
'wechat_refund_id' => $result['refund_id_0'],
|
||||
'refund_status' => $refund_status,
|
||||
'refund_msg' => json_encode($result, JSON_UNESCAPED_UNICODE),
|
||||
], ['id'=>$val['refund_log_id']]);
|
||||
} else {
|
||||
if (isset($result['return_code']) && $result['return_code'] == 'FAIL') {
|
||||
throw new \Exception($result['return_msg']);
|
||||
}
|
||||
|
||||
if (isset($result['err_code_des'])) {
|
||||
throw new \Exception($result['err_code_des']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('订单退款查询失败,失败原因:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
89
server/app/common/command/OrderVerification.php
Executable file
89
server/app/common/command/OrderVerification.php
Executable file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\service\ConfigService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 系统自动核销服务中订单
|
||||
* Class OrderVerification
|
||||
* @package app\common\command
|
||||
*/
|
||||
class OrderVerification extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_verification')
|
||||
->setDescription('系统自动核销服务中订单');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$now = time();
|
||||
$ableAuto = ConfigService::get('transaction', 'verification_orders',1);
|
||||
$confirmTime = ConfigService::get('transaction', 'verification_orders_times',24) * 60 * 60;
|
||||
|
||||
if ($ableAuto == YesNoEnum::NO) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$orders = Order::where([
|
||||
'order_status' => OrderEnum::ORDER_STATUS_SERVICE,
|
||||
'pay_status' => PayEnum::ISPAID
|
||||
])->whereRaw("create_time+$confirmTime < $now")->select();
|
||||
|
||||
if (empty($orders)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($orders as $order) {
|
||||
//更新订单状态
|
||||
Order::update([
|
||||
'order_status' => OrderEnum::ORDER_STATUS_FINISH,
|
||||
'verification_status' => OrderEnum::VERIFICATION,
|
||||
'finish_time' => time(),
|
||||
], ['id' => $order['id']]);
|
||||
|
||||
//添加订单日志
|
||||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_SYSTEM,OrderLogEnum::SYSTEM_CONFIRM_ORDER,$order['id'],0);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('订单自动核销失败,失败原因:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
62
server/app/common/command/Password.php
Executable file
62
server/app/common/command/Password.php
Executable file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\model\auth\Admin;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 修改超级管理员密码
|
||||
*/
|
||||
class Password extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('password')
|
||||
->addArgument('password', Argument::OPTIONAL, "please input new password")
|
||||
->setDescription('修改超级管理员密码');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$password = trim($input->getArgument('password'));
|
||||
if (empty($password)) {
|
||||
$output->error('请输入密码');
|
||||
return;
|
||||
}
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$newPassword = create_password($password, $passwordSalt);
|
||||
$rootAdmin = Admin::where('root', 1)->findOrEmpty();
|
||||
if ($rootAdmin->isEmpty()) {
|
||||
$output->error('超级管理员不存在');
|
||||
return;
|
||||
}
|
||||
$rootAdmin->password = $newPassword;
|
||||
$rootAdmin->save();
|
||||
$output->info('超级管理修改密码成功!');
|
||||
$output->info('账号:' . $rootAdmin->account);
|
||||
$output->info('密码:' . $password);
|
||||
}
|
||||
}
|
||||
289
server/app/common/command/SettleOrder.php
Executable file
289
server/app/common/command/SettleOrder.php
Executable file
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\accountLog\CoachAccountLogEnum;
|
||||
use app\common\enum\accountLog\ShopAccountLogEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\CoachAccountLogLogic;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\logic\ShopAccountLogLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\settle\Settle;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\service\ConfigService;
|
||||
use Exception;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 结算订单
|
||||
* Class SettleOrder
|
||||
* @package app\common\command
|
||||
*/
|
||||
class SettleOrder extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('settle_order')
|
||||
->setDescription('结算订单');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$settleSettingConfig = [
|
||||
//结算方式(包含车费)
|
||||
'commission_settle' => ConfigService::get('settle_setting', 'commission_settle'),
|
||||
//结算周期
|
||||
'commission_settle_cycle' => ConfigService::get('settle_setting', 'commission_settle_cycle'),
|
||||
//结算类型
|
||||
'commission_settle_cycle_type' => ConfigService::get('settle_setting', 'commission_settle_cycle_type'),
|
||||
//结算天
|
||||
'commission_settle_cycle_day' => ConfigService::get('settle_setting', 'commission_settle_cycle_day'),
|
||||
];
|
||||
$whereRaw = '((order_status = '.OrderEnum::ORDER_STATUS_SERVER_FINISH.') or (order_status = '.OrderEnum::ORDER_STATUS_CLOSE.' and total_order_amount > total_refund_amount and pay_status = '.PayEnum::ISPAID.')) and is_settle = 0';
|
||||
$now = time();
|
||||
//结算周期:1-按状态;2-周期
|
||||
if(1 == $settleSettingConfig['commission_settle_cycle']){
|
||||
//订单结束后X天
|
||||
$overTime = $settleSettingConfig['commission_settle_cycle_day'] * 60 * 60 * 24;
|
||||
$whereRaw .= ' and true_server_finish_time + '.$overTime.' < '.$now;
|
||||
}else{
|
||||
//按周期:1-每周、2-每月
|
||||
if( 1== $settleSettingConfig['commission_settle_cycle_type']){
|
||||
$date = date('N');
|
||||
}else{
|
||||
$date = date('j');
|
||||
}
|
||||
if($date != $settleSettingConfig['commission_settle_cycle_day']){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$lists = Order::whereRaw($whereRaw)
|
||||
->append(['order_goods'])
|
||||
->select()
|
||||
->toArray();
|
||||
if(empty($lists)){
|
||||
return true;
|
||||
}
|
||||
$settleData = [
|
||||
'total_order_amount' => 0,
|
||||
'total_car_amount' => 0,
|
||||
'total_gap_amount' => 0,
|
||||
'total_append_amount' => 0,
|
||||
'total_commission' => 0,
|
||||
'total_car_commission' => 0,
|
||||
'total_car_coach_commission'=> 0,
|
||||
'total_car_shop_commission' => 0,
|
||||
'total_coach_commission' => 0,
|
||||
'total_shop_commission' => 0,
|
||||
'settle_num' => 0,
|
||||
'settle_config' => $settleSettingConfig,
|
||||
];
|
||||
$settleOrderData = [];
|
||||
|
||||
Db::startTrans();
|
||||
$settle = Settle::create($settleData);
|
||||
|
||||
foreach ($lists as $order){
|
||||
$goods = $order['order_goods'][0]->toArray();
|
||||
$commissionRatio = $goods['goods_snap']['commission_ratio'] ?? 0;
|
||||
$shopRatio = $goods['goods_snap']['shop_ratio'] ?? 0;
|
||||
$totalAmount = $order['total_order_amount'];
|
||||
$refundAmount = round($order['total_refund_amount'] - $order['refund_car_amount'],2);
|
||||
$totalAmount = round($totalAmount-$refundAmount-$order['car_amount'],2);
|
||||
$orderCarAmount = round($order['car_amount'] - $order['refund_car_amount'],2);
|
||||
$coachCarAmount = 0;
|
||||
$shopCarAmount = 0;
|
||||
$shopCommission = 0;
|
||||
$coachCommission = 0;
|
||||
//用于判断是否商家商品
|
||||
$goodsShopId = $goods['goods_snap']['shop_id'] ?? $order['shop_id'];
|
||||
if($goodsShopId){
|
||||
$shopRatio = round(100 - $commissionRatio,2);
|
||||
}
|
||||
//技师佣金
|
||||
if($totalAmount > 0 && $commissionRatio > 0){
|
||||
$coachCommission = round($totalAmount * ($commissionRatio / 100),2);
|
||||
}
|
||||
//商家佣金
|
||||
if($totalAmount > 0 && $shopRatio > 0 && $order['shop_id']){
|
||||
$shopCommission = round($totalAmount * ($shopRatio / 100),2);
|
||||
}
|
||||
//如果是包含车费
|
||||
if(1 == $settleSettingConfig['commission_settle']){
|
||||
if($orderCarAmount > 0){
|
||||
if($commissionRatio > 0){
|
||||
$coachCarAmount = round($orderCarAmount * ($commissionRatio / 100),2);
|
||||
}
|
||||
//商家车佣金
|
||||
if($shopRatio > 0 && $order['shop_id']){
|
||||
$shopCarAmount = round($orderCarAmount * ($shopRatio / 100),2);
|
||||
}
|
||||
}
|
||||
//
|
||||
}else{
|
||||
$coachCarAmount = $orderCarAmount;
|
||||
// $coachCommission = round($coachCommission+$coachCarAmount,2);
|
||||
}
|
||||
|
||||
if($coachCommission > 0){
|
||||
Coach::where(['id'=>$order['coach_id']])->update([
|
||||
'money'=> Db::raw('money+'.$coachCommission)
|
||||
]);
|
||||
CoachAccountLogLogic::add(
|
||||
$order['coach_id'],
|
||||
CoachAccountLogEnum::MONEY,
|
||||
CoachAccountLogEnum::ORDER_ADD_MONEY,
|
||||
1,
|
||||
$coachCommission,
|
||||
$order['sn']
|
||||
);
|
||||
|
||||
}
|
||||
//车费技师
|
||||
if($coachCarAmount > 0){
|
||||
Coach::where(['id'=>$order['coach_id']])->update([
|
||||
'money'=> Db::raw('money+'.$coachCarAmount)
|
||||
]);
|
||||
CoachAccountLogLogic::add(
|
||||
$order['coach_id'],
|
||||
CoachAccountLogEnum::MONEY,
|
||||
CoachAccountLogEnum::ORDER_ADD_CART_MONEY,
|
||||
1,
|
||||
$coachCarAmount,
|
||||
$order['sn']
|
||||
);
|
||||
|
||||
}
|
||||
if($shopCommission > 0){
|
||||
Shop::where(['id'=>$order['shop_id']])->update([
|
||||
'money'=> Db::raw('money+'.$shopCommission)
|
||||
]);
|
||||
ShopAccountLogLogic::add(
|
||||
$order['shop_id'],
|
||||
ShopAccountLogEnum::MONEY,
|
||||
ShopAccountLogEnum::ORDER_ADD_MONEY,
|
||||
1,
|
||||
$shopCommission,
|
||||
$order['sn']
|
||||
);
|
||||
}
|
||||
//结算商家车费
|
||||
if($shopCarAmount > 0){
|
||||
Shop::where(['id'=>$order['shop_id']])->update([
|
||||
'money'=> Db::raw('money+'.$shopCarAmount)
|
||||
]);
|
||||
ShopAccountLogLogic::add(
|
||||
$order['shop_id'],
|
||||
ShopAccountLogEnum::MONEY,
|
||||
ShopAccountLogEnum::ORDER_ADD_CART_MONEY,
|
||||
1,
|
||||
$shopCarAmount,
|
||||
$order['sn']
|
||||
);
|
||||
}
|
||||
|
||||
$coachCommission = round($coachCommission+$coachCarAmount,2);
|
||||
$shopCommission = round($shopCommission+$shopCarAmount,2);
|
||||
|
||||
$totalCommissionAmount = round($coachCommission+$shopCommission,2);
|
||||
$totalCarCommissionAmount = round($coachCarAmount+$shopCarAmount,2);
|
||||
//标记已结算
|
||||
Order::where(['id'=>$order['id']])->update([
|
||||
'is_settle' => 1,
|
||||
'settle_coach_amount' => $coachCommission,
|
||||
'settle_shop_amount' => $shopCommission,
|
||||
'settle_commission_amount' => $totalCommissionAmount,
|
||||
'settle_coach_car_amount' => $coachCarAmount,
|
||||
'settle_shop_car_amount' => $shopCarAmount,
|
||||
'settle_car_commission_amount' => $totalCarCommissionAmount,
|
||||
'settle_total_commission_amount' => round($totalCommissionAmount+$totalCarCommissionAmount,2),
|
||||
]);
|
||||
(new OrderLogLogic())
|
||||
->record(OrderLogEnum::TYPE_SYSTEM,OrderLogEnum::SYSTEM_SETTLEMENT_ORDER,$order['id']);
|
||||
//结算订单表
|
||||
$settleOrderData[] = [
|
||||
'order_id' => $order['id'],
|
||||
'settle_id' => $settle['id'],
|
||||
//订单总金额
|
||||
'total_order_amount'=> $order['total_order_amount'],
|
||||
'order_amount' => $totalAmount,
|
||||
//订单车费
|
||||
'car_amount' => $orderCarAmount,
|
||||
//技师车费佣金
|
||||
'coach_car_amount' => $coachCarAmount,
|
||||
//商家车费佣金
|
||||
'shop_car_amount' => $shopCarAmount,
|
||||
//总车费佣金
|
||||
'total_car_amount' => round($coachCarAmount+$shopCarAmount,2),
|
||||
'gap_amount' => $order['total_gap_amount'],
|
||||
'append_amount' => $order['total_append_amount'],
|
||||
//技师佣金
|
||||
'coach_commission' => $coachCommission,
|
||||
//商家佣金
|
||||
'shop_commission' => $shopCommission,
|
||||
//总佣金
|
||||
'total_commission' => $totalCommissionAmount,
|
||||
//技师佣金比例和商家佣金比例
|
||||
'commission_ratio' => $goods['goods_snap']['commission_ratio'] ?? 0,
|
||||
'shop_ratio' => $goods['goods_snap']['shop_ratio'] ?? 0,
|
||||
];
|
||||
//结算表
|
||||
$settleData['total_car_amount'] += $order['car_amount'];
|
||||
$settleData['total_gap_amount'] += $order['total_gap_amount'];
|
||||
$settleData['total_append_amount'] += $order['total_append_amount'];
|
||||
$settleData['total_order_amount'] += $order['total_order_amount'];
|
||||
//总技师和商家佣金,总佣金
|
||||
$settleData['total_coach_commission'] += $coachCommission;
|
||||
$settleData['total_shop_commission'] += $shopCommission;
|
||||
$settleData['total_commission'] += $totalCommissionAmount;
|
||||
//总技师和商家车费佣金,总佣金
|
||||
$settleData['total_car_coach_commission'] += $coachCarAmount;
|
||||
$settleData['total_car_shop_commission'] += $shopCarAmount;
|
||||
$settleData['total_car_commission'] += $totalCarCommissionAmount;
|
||||
|
||||
$settleData['settle_num']++;
|
||||
}
|
||||
Settle::where(['id'=>$settle->id])->update($settleData);
|
||||
(new \app\common\model\settle\SettleOrder())->saveAll($settleOrderData);
|
||||
Db::commit();
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
Log::write('结算订单计划任务执行失败:'.implode('-', [
|
||||
__CLASS__,
|
||||
__FUNCTION__,
|
||||
$e->getFile(),
|
||||
$e->getLine(),
|
||||
$e->getMessage()
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user