其余文件
This commit is contained in:
80
app/common/command/AwardIntegral.php
Normal file
80
app/common/command/AwardIntegral.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?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\logic\AccountLogLogic;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\user\User;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class AwardIntegral extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('award_integral')
|
||||
->setDescription('结算消费赠送积分');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$time = time();
|
||||
$config = ConfigServer::get('transaction', 'order_after_sale_days', 7);
|
||||
|
||||
$finish_limit = $config * 24 * 60 * 60;
|
||||
$orders = Order::field(true)->where([
|
||||
['del', '=', 0],
|
||||
['award_integral_status', '>', 0],
|
||||
['is_award_integral', '=', 0],
|
||||
['pay_status', '=', 1]
|
||||
])->select()->toArray();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
if ($order['award_integral'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($order['award_integral_status'] == OrderEnum::ORDER_DELIVERY && $order['order_status'] < OrderEnum::ORDER_STATUS_GOODS) {
|
||||
continue;
|
||||
}
|
||||
if ($order['award_integral_status'] == OrderEnum::ORDER_FINISH && $order['order_status'] < OrderEnum::ORDER_STATUS_COMPLETE) {
|
||||
continue;
|
||||
}
|
||||
if ($order['award_integral_status'] == OrderEnum::ORDER_AFTER_SALE_OVER && ($order['order_status'] < OrderEnum::ORDER_STATUS_COMPLETE || ($finish_limit + $order['confirm_take_time']) > $time)) {
|
||||
continue;
|
||||
}
|
||||
User::where('id',$order['user_id'])->inc('user_integral', $order['award_integral'])->update();
|
||||
Order::update(['is_award_integral'=>1,'update_time'=>$time],['id'=>$order['id']]);
|
||||
AccountLogLogic::AccountRecord($order['user_id'], $order['award_integral'], 1, AccountLog::consume_award_integral, '', $order['id'], $order['order_sn']);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('结算消费赠送积分异常:'.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
74
app/common/command/BargainClose.php
Normal file
74
app/common/command/BargainClose.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\model\bargain\BargainLaunch;
|
||||
use app\common\model\bargain\Bargain;
|
||||
use app\common\enum\BargainEnum;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class BargainClose extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('bargain_close')
|
||||
->setDescription('关闭砍价记录');
|
||||
}
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$now = time();
|
||||
$bargainModel = new Bargain();
|
||||
$bargainLaunchModel = new BargainLaunch();
|
||||
|
||||
$succeed_ids = [];
|
||||
$defeat_ids = [];
|
||||
//砍价成功后的下单时间
|
||||
$payment_limit_time = ConfigServer::get('bargain', 'payment_limit_time', 0) * 60;
|
||||
if($payment_limit_time > 0){
|
||||
$payment_limit_time = $now + $payment_limit_time;
|
||||
}
|
||||
//找出所有超时未关掉的订单
|
||||
$bargainLaunchModel->where([['status','=',BargainLaunch::conductStatus],['launch_end_time','<=',$now]])
|
||||
->chunk(100, function($launchs) use(&$succeed_ids,&$defeat_ids) {
|
||||
|
||||
foreach ($launchs as $launch){
|
||||
$launch = $launch->toarray();
|
||||
//任意金额购买时,更新砍价成功
|
||||
if(2 == $launch['bargain_snap']['payment_where']){
|
||||
$succeed_ids[] = $launch['id'];
|
||||
}else{
|
||||
$defeat_ids[] = $launch['id'];
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
//标记成功
|
||||
if($succeed_ids){
|
||||
$bargainLaunchModel->where(['id'=>$succeed_ids])->update(['status'=>BargainLaunch::successStatus,'payment_limit_time'=>$payment_limit_time,'bargain_end_time'=>$now]);
|
||||
}
|
||||
//标记失败
|
||||
if($defeat_ids){
|
||||
$bargainLaunchModel->where(['id'=>$defeat_ids])->update(['status'=>BargainLaunch::failStatus,'bargain_end_time'=>$now]);
|
||||
}
|
||||
|
||||
// 查询出要关闭的砍价活动
|
||||
$bargain_ids = $bargainModel->where([
|
||||
['activity_end_time', '<', $now],
|
||||
['del', '=', 0],
|
||||
['status', '=', 1]
|
||||
])->column('id');
|
||||
|
||||
// 结束砍价活动(结束时间 < 当前时间)
|
||||
$bargainModel->whereIn('id', $bargain_ids)
|
||||
->update(['status' => 0]);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::write('结束砍价活动失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
103
app/common/command/Crontab.php
Normal file
103
app/common/command/Crontab.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?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 Cron\CronExpression;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Console;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
class Crontab extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('crontab')
|
||||
->setDescription('定时任务');
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动定时任务守护进程
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
Log::close();
|
||||
|
||||
$time = time();
|
||||
|
||||
$crons = Db::name('dev_crontab')
|
||||
->where(['status' => 1])
|
||||
->select();
|
||||
if (empty($crons)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($crons as $cron) {
|
||||
//规则错误,不执行
|
||||
if (CronExpression::isValidExpression($cron['expression']) === false) {
|
||||
continue;
|
||||
}
|
||||
//未到时间,不执行
|
||||
$cron_expression = CronExpression::factory($cron['expression']);
|
||||
$next_time = $cron_expression->getNextRunDate(date('Y-m-d H:i:s', $cron['last_time']))->getTimestamp();
|
||||
if ($next_time >= $time) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//开始执行
|
||||
try {
|
||||
// Debug::remark('begin');
|
||||
$parameter = explode(' ', $cron['parameter']);
|
||||
if (is_array($parameter) && !empty($cron['parameter'])) {
|
||||
Console::call($cron['command'], $parameter);
|
||||
} else {
|
||||
Console::call($cron['command']);
|
||||
}
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => '']);
|
||||
} catch (\Exception $e) {
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => $e->getMessage(), 'status' => 3]);
|
||||
} finally {
|
||||
// Debug::remark('end');
|
||||
// $range_time = Debug::getRangeTime('begin', 'end');
|
||||
// $max_time = max($cron['max_time'], $range_time);
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['last_time' => $time]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
156
app/common/command/DistributionOrder.php
Normal file
156
app/common/command/DistributionOrder.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\admin\logic\distribution\DistributionLevelLogic;
|
||||
use app\common\enum\DistributionOrderGoodsEnum;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\after_sale\AfterSale;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\user\User;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class DistributionOrder extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('distribution_order')
|
||||
->setDescription('结算分销订单');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 1、获取结算时间
|
||||
$time = time();
|
||||
$afterSaleTime = ConfigServer::get('distribution', 'settlement_days', 7);
|
||||
$afterSaleTime = intval($afterSaleTime * 24 * 60 * 60);
|
||||
|
||||
// 2、查询可以结算的订单
|
||||
$model = new DistributionOrderGoods();
|
||||
$orders = $model->alias('DOG')->field([
|
||||
'O.id as order_id, O.order_status, O.confirm_take_time',
|
||||
'DOG.id as distribution_id, DOG.sn, DOG.money',
|
||||
'DOG.user_id, DOG.order_goods_id'
|
||||
])
|
||||
->join('order_goods OG', 'OG.id = DOG.order_goods_id')
|
||||
->join('order O', 'O.id = OG.order_id')
|
||||
->whereRaw("O.confirm_take_time+$afterSaleTime < $time")
|
||||
->where([
|
||||
['DOG.status', '=', DistributionOrderGoodsEnum::STATUS_WAIT_HANDLE],
|
||||
])
|
||||
->limit(100)
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($orders as &$order) {
|
||||
//当前分佣订单是否可结算
|
||||
if (false === self::isSettle($order)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 增加用户佣金
|
||||
$earnings = User::where('id', $order['user_id'])->value('earnings');
|
||||
User::update([
|
||||
'earnings' => $earnings + $order['money'],
|
||||
'update_time' => $time,
|
||||
'id' => $order['user_id']
|
||||
]);
|
||||
|
||||
// 记录流水
|
||||
AccountLog::create([
|
||||
'log_sn' => createSn('account_log', 'log_sn', '', 4),
|
||||
'user_id' => $order['user_id'],
|
||||
'source_type' => AccountLog::distribution_inc_earnings,
|
||||
'source_id' => $order['distribution_id'],
|
||||
'source_sn' => $order['sn'],
|
||||
'change_amount' => $order['money'],
|
||||
'left_amount' => $earnings+$order['money'],
|
||||
'change_type' => 1,
|
||||
'remark' => '分销佣金增加'
|
||||
]);
|
||||
|
||||
// 更新分销订单状态
|
||||
DistributionOrderGoods::update([
|
||||
'status' => DistributionOrderGoodsEnum::STATUS_SUCCESS,
|
||||
'update_time' => $time,
|
||||
'settlement_time' => $time,
|
||||
'id'=>$order['distribution_id']
|
||||
]);
|
||||
|
||||
// 更新订单分销佣金
|
||||
$orderModel = Order::findOrEmpty($order['order_id']);
|
||||
$orderModel->distribution_money = $orderModel->distribution_money + $order['money'];
|
||||
$orderModel->update_time = $time;
|
||||
$orderModel->save();
|
||||
|
||||
// 更新分销会员等级
|
||||
DistributionLevelLogic::updateDistributionLevel($order['user_id']);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('分销结算异常:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 是否可以结算分佣订单 (检查是否有售后记录 没有则可结算, 有则需要检查售后记录状态)
|
||||
* @Author: 张无忌
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSettle($order)
|
||||
{
|
||||
// 订单是否在售后(正在退款或已退款)
|
||||
$check = (new AfterSale())->where([
|
||||
'order_id' => $order['order_id'],
|
||||
'order_goods_id' => $order['order_goods_id'],
|
||||
'del'=>0
|
||||
])->findOrEmpty()->toArray();
|
||||
|
||||
if (!$check) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 有售后订单记录且状态 $no_settlement中的 不结算分佣订单
|
||||
$no_settlement = [
|
||||
AfterSale::STATUS_APPLY_REFUND, //申请退款
|
||||
AfterSale::STATUS_WAIT_RETURN_GOODS, //商品待退货
|
||||
AfterSale::STATUS_WAIT_RECEIVE_GOODS, //商家待收货
|
||||
];
|
||||
|
||||
// 不结算且分佣订单改为已失效
|
||||
$set_fail = [
|
||||
AfterSale::STATUS_WAIT_REFUND, //等待退款
|
||||
AfterSale::STATUS_SUCCESS_REFUND, //退款成功
|
||||
];
|
||||
|
||||
// 售后情况不明 不结算
|
||||
if (in_array($check['status'], $no_settlement)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 分佣订单更新为已失效 不结算
|
||||
if (in_array($check['status'], $set_fail)) {
|
||||
DistributionOrderGoods::update([
|
||||
'status' => DistributionOrderGoodsEnum::STATUS_ERROR,
|
||||
'update_time' => time()
|
||||
], ['id'=>$order['distribution_id']]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
55
app/common/command/IntegralOrderFinish.php
Normal file
55
app/common/command/IntegralOrderFinish.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\IntegralOrderEnum;
|
||||
use app\common\model\integral\IntegralOrder;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class IntegralOrderFinish extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('integral_order_finish')
|
||||
->setDescription('积分订单自动确认收货');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$time = time();
|
||||
$config = ConfigServer::get('transaction', 'order_auto_receipt_days', 7);
|
||||
if ($config == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$finish_limit = $config * 24 * 60 * 60;
|
||||
$model = new IntegralOrder();
|
||||
$orders = $model->field(true)->where([
|
||||
['order_status', '=', IntegralOrderEnum::ORDER_STATUS_GOODS],
|
||||
['del', '=', 0]
|
||||
])->whereRaw("shipping_time+$finish_limit < $time")
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$model->where(['id' => $order['id']])
|
||||
->update([
|
||||
'order_status' => IntegralOrderEnum::ORDER_STATUS_COMPLETE,
|
||||
'update_time' => $time,
|
||||
'confirm_time' => $time,
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('积分订单自动确认收货异常:'.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
121
app/common/command/OrderClose.php
Normal file
121
app/common/command/OrderClose.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\CouponList;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsItem;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderClose extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_close')
|
||||
->setDescription('关闭订单');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$time = time();
|
||||
$order_cancel_time = ConfigServer::get('transaction', 'unpaid_order_cancel_time', 60);
|
||||
// 配置0或为空时不取消订单
|
||||
if (empty($order_cancel_time)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$order_cancel_time = $order_cancel_time * 60;
|
||||
|
||||
$model = new Order();
|
||||
$order_list = $model->field(true)
|
||||
->whereRaw("create_time+$order_cancel_time < $time")
|
||||
->where([
|
||||
['order_type', '<>', OrderEnum::TEAM_ORDER],
|
||||
['order_status', '=', OrderEnum::ORDER_STATUS_NO_PAID],
|
||||
['pay_status', '=', OrderEnum::PAY_STATUS_NO_PAID]
|
||||
])->with(['orderGoods'])
|
||||
->select()->toArray();
|
||||
|
||||
$order_ids = []; //更新的订单
|
||||
$update_total_stock = []; //更新总库存
|
||||
$update_stock = []; //更新规格库存
|
||||
$total_stock_num = []; //总库存
|
||||
$stock_num = []; //规格库存
|
||||
$update_coupon_ids = []; //更新优惠券状态
|
||||
foreach ($order_list as $order) {
|
||||
$order_ids[] = $order['id'];
|
||||
//返回优惠券
|
||||
if ($order['coupon_list_id']) {
|
||||
$update_coupon_ids[] = $order['coupon_list_id'];
|
||||
}
|
||||
|
||||
foreach ($order['orderGoods'] as $order_goods) {
|
||||
//更新商品总库存数据
|
||||
if (isset($update_total_stock[$order_goods['goods_id']])) {
|
||||
$total_stock_num[$order_goods['goods_id']] = $total_stock_num[$order_goods['goods_id']] + $order_goods['goods_num'];
|
||||
$update_total_stock[$order_goods['goods_id']]['stock'] = Db::raw('stock+' . $total_stock_num[$order_goods['goods_id']]);
|
||||
} else {
|
||||
$total_stock_num[$order_goods['goods_id']] = $order_goods['goods_num'];
|
||||
$update_total_stock[$order_goods['goods_id']] = [
|
||||
'id' => $order_goods['goods_id'],
|
||||
'stock' => Db::raw('stock+' . $total_stock_num[$order_goods['goods_id']])
|
||||
];
|
||||
}
|
||||
//更新商品规格库存数据
|
||||
if (isset($update_stock[$order_goods['item_id']])) {
|
||||
$stock_num[$order_goods['item_id']] = $stock_num[$order_goods['item_id']] + $order_goods['goods_num'];
|
||||
$update_stock[$order_goods['item_id']]['stock'] = Db::raw('stock+' . $stock_num[$order_goods['item_id']]);
|
||||
} else {
|
||||
$stock_num[$order_goods['item_id']] = $order_goods['goods_num'];
|
||||
$update_stock[$order_goods['item_id']] = [
|
||||
'id' => $order_goods['item_id'],
|
||||
'stock' => Db::raw('stock+' . $stock_num[$order_goods['item_id']])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新订单状态为关闭
|
||||
if ($order_ids) {
|
||||
$update_data = [
|
||||
'order_status' => OrderEnum::ORDER_STATUS_DOWN,
|
||||
'update_time' => $time,
|
||||
];
|
||||
|
||||
$model->where(['id' => $order_ids])->update($update_data);
|
||||
}
|
||||
|
||||
|
||||
//批量更新库存
|
||||
if($update_total_stock){
|
||||
(new Goods())->saveAll(array_values($update_total_stock));
|
||||
(new GoodsItem())->saveAll(array_values($update_stock));
|
||||
}
|
||||
|
||||
if($update_coupon_ids){
|
||||
$update_coupon = [
|
||||
'status' => 0,
|
||||
'use_time' => '',
|
||||
'order_id' => '',
|
||||
'update_time' => $time,
|
||||
];
|
||||
(new CouponList())->where(['id'=>$update_coupon_ids])->update($update_coupon);
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('自动关闭订单异常:'.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
68
app/common/command/OrderFinish.php
Normal file
68
app/common/command/OrderFinish.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderFinish extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_finish')
|
||||
->setDescription('普通订单自动确认收货');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$time = time();
|
||||
$config = ConfigServer::get('transaction', 'order_auto_receipt_days', 7);
|
||||
if ($config == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$finish_limit = $config * 24 * 60 * 60;
|
||||
$model = new Order();
|
||||
$orders = $model->field(true)->where([
|
||||
['order_status', '=', OrderEnum::ORDER_STATUS_GOODS],
|
||||
['pay_status', '=', OrderEnum::PAY_STATUS_PAID],
|
||||
['delivery_type', '<>', OrderEnum::DELIVERY_TYPE_SELF],
|
||||
['del', '=', 0]
|
||||
])->whereRaw("shipping_time+$finish_limit < $time")
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$model->where(['id' => $order['id']])
|
||||
->update([
|
||||
'order_status' => OrderEnum::ORDER_STATUS_COMPLETE,
|
||||
'update_time' => $time,
|
||||
'confirm_take_time' => $time,
|
||||
]);
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLogEnum::TYPE_SYSTEM,
|
||||
OrderLogEnum::SYSTEM_CONFIRM_ORDER,
|
||||
$order['id'],
|
||||
0,
|
||||
OrderLogEnum::SYSTEM_CONFIRM_ORDER
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('自动确认收货异常:'.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
app/common/command/Password.php
Normal file
58
app/common/command/Password.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\admin\logic\AdminLogic;
|
||||
use app\common\model\Admin;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
|
||||
class Password extends Command
|
||||
{
|
||||
/**
|
||||
* @notes
|
||||
* @author 令狐冲
|
||||
* @date 2021/11/24 10:56
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('password')
|
||||
->addArgument('password', Argument::OPTIONAL, "your name")
|
||||
->setDescription('修改超级管理密码');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
* @author 令狐冲
|
||||
* @date 2021/11/22 17:15
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$password = trim($input->getArgument('password'));
|
||||
if (empty($password)) {
|
||||
$output->error('请输入密码');
|
||||
return;
|
||||
}
|
||||
|
||||
$adminInfo = Admin::where(['root' => 1])->findOrEmpty();
|
||||
|
||||
if (empty($adminInfo)) {
|
||||
$output->info('超级管理员账号不存在');
|
||||
} else {
|
||||
AdminLogic::updatePassword($password, $adminInfo['id']);
|
||||
$output->info('超级管理修改密码成功!');
|
||||
$output->info('账号:' . $adminInfo['account']);
|
||||
$output->info('密码:' . $password);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
162
app/common/command/TeamEnd.php
Normal file
162
app/common/command/TeamEnd.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\enum\TeamEnum;
|
||||
use app\common\logic\OrderRefundLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\team\TeamActivity;
|
||||
use app\common\model\team\TeamFound;
|
||||
use app\common\model\team\TeamJoin;
|
||||
use app\common\server\ConfigServer;
|
||||
use Exception;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class TeamEnd extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('team_end')
|
||||
->setDescription('结束已超时的拼团');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$time = time();
|
||||
$automatic = ConfigServer::get('team', 'automatic', 0);
|
||||
|
||||
// 获取并关闭已结束的活动
|
||||
$team_ids = (new TeamActivity())->where([['activity_end_time', '<=', $time]])->column('id');
|
||||
(new TeamActivity())->whereIn('id', $team_ids)->update(['status'=>0, 'update_time'=>$time]);
|
||||
|
||||
// 找出拼团中&&拼团有效期结束的拼团记录
|
||||
$map1 = array(
|
||||
['invalid_time', '<=', $time],
|
||||
['status', '=', 0]
|
||||
);
|
||||
$map2 = array(
|
||||
['team_activity_id', 'in', $team_ids],
|
||||
['status', '=', 0]
|
||||
);
|
||||
$teamFound1 = (new TeamFound())->whereOr([$map1, $map2])->select()->toArray();
|
||||
$teamFound2 = (new TeamFound())->alias('TF')
|
||||
->where('TF.people','exp',' <= TF.join ')
|
||||
->where('status', '=', 0)
|
||||
->select()->toArray();
|
||||
|
||||
$teamFound = $teamFound1;
|
||||
if (empty($teamFound1)) {
|
||||
$teamFound = array_merge($teamFound1, $teamFound2);
|
||||
} else {
|
||||
$found_ids = array_column($teamFound1, "id");
|
||||
if (!empty($teamFound2)) {
|
||||
foreach ($teamFound2 as $item) {
|
||||
if (!in_array($item['id'], $found_ids)) {
|
||||
$teamFound[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 结束拼团时间到的团
|
||||
$teamJoinModel = new TeamJoin();
|
||||
foreach ($teamFound as $found) {
|
||||
$teamJoin = $teamJoinModel->alias('TJ')
|
||||
->field(['TJ.*,O.order_sn,O.order_status,O.pay_status,O.refund_status,O.order_amount'])
|
||||
->where(['team_id' => $found['id']])
|
||||
->join('order O', 'O.id=TJ.order_id')
|
||||
->select()->toArray();
|
||||
|
||||
// 已支付的数量
|
||||
$payNums = array_column($teamJoin, 'pay_status');
|
||||
$payCount = 0;
|
||||
foreach ($payNums as $i) {
|
||||
if ($i == 1) {
|
||||
$payCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 此团有未支付订单: 关闭拼团,关闭订单,给已支付的退款
|
||||
if (in_array(1, array_column($teamJoin, 'pay_status'))) {
|
||||
if ($automatic == 1 || ($found['people'] == $found['join'] && $found['join'] == $payCount)) {
|
||||
$this->teamSuccess($teamJoin, $found, $time);
|
||||
} else {
|
||||
$this->teamFail($teamJoin, $found, $time);
|
||||
}
|
||||
} else {
|
||||
$this->teamFail($teamJoin, $found, $time);
|
||||
// $this->teamSuccess($teamJoin, $found, $time);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::write('拼团关闭异常'.$e->getMessage());
|
||||
throw new \think\Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 拼团失败
|
||||
* @Author: 张无忌
|
||||
* @param $teamJoin (参团列表数据)
|
||||
* @param $found (开团的数据)
|
||||
* @param $time (时间)
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
private function teamFail($teamJoin, $found, $time)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
TeamFound::update(['status'=>TeamEnum::TEAM_STATUS_FAIL, 'team_end_time'=>$time], ['id'=>$found['id']]);
|
||||
foreach ($teamJoin as $item) {
|
||||
TeamJoin::update(['status' => TeamEnum::TEAM_STATUS_FAIL, 'update_time' => $time], ['id' => $item['id']]);
|
||||
if ($item['order_status'] == OrderEnum::ORDER_STATUS_DOWN) continue;
|
||||
if ($item['refund_status'] != OrderEnum::REFUND_STATUS_NO_REFUND) continue;
|
||||
$order = (new Order())->findOrEmpty($item['order_id'])->toArray();
|
||||
// 取消订单
|
||||
OrderRefundLogic::cancelOrder($order['id'], OrderLogEnum::TYPE_SYSTEM);
|
||||
if ($order['pay_status'] == OrderEnum::PAY_STATUS_PAID) {
|
||||
// 更新订单状态
|
||||
OrderRefundLogic::cancelOrderRefundUpdate($order);
|
||||
// 订单退款
|
||||
OrderRefundLogic::refund($order, $order['order_amount'], $order['order_amount']);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
throw new \think\Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 拼团成功
|
||||
* @Author: 张无忌
|
||||
* @param $teamJoin (该团的,参团数据)
|
||||
* @param $found (该团的, 开团时间)
|
||||
* @param $time (时间)
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
private function teamSuccess($teamJoin, $found, $time)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
TeamFound::update(['status'=>TeamEnum::TEAM_STATUS_SUCCESS, 'team_end_time'=>$time], ['id'=>$found['id']]);
|
||||
foreach ($teamJoin as $item) {
|
||||
TeamJoin::update(['status'=>TeamEnum::TEAM_STATUS_SUCCESS, 'update_time'=>$time], ['id'=>$item['id']]);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
throw new \think\Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
97
app/common/command/UserDistribution.php
Normal file
97
app/common/command/UserDistribution.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?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\PayEnum;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\user\User;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use app\common\model\order\Order;
|
||||
use think\facade\Log;
|
||||
|
||||
class UserDistribution extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('user_distribution')
|
||||
->setDescription('更新会员分销信息');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$userModel = new User();
|
||||
$users = $userModel->alias('u')
|
||||
->field('d.*')
|
||||
->join('user_distribution d', 'd.user_id = u.id')
|
||||
->where(['u.del' => 0])
|
||||
->select()->toArray();
|
||||
|
||||
if (!$users) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
//粉丝数量
|
||||
$where1 = [
|
||||
['first_leader', '=', $user['user_id']],
|
||||
];
|
||||
$where2 = [
|
||||
['second_leader', '=', $user['user_id']],
|
||||
];
|
||||
$fans = User::whereOr([$where1, $where2])->count();
|
||||
|
||||
//分销订单信息
|
||||
$distribution = DistributionOrderGoods::where(['user_id' => $user['user_id']])
|
||||
->field('sum(money) as money, count(id) as order_num')
|
||||
->find();
|
||||
|
||||
//订单信息
|
||||
$order = Order::where([
|
||||
'user_id' => $user['user_id'],
|
||||
'pay_status' => PayEnum::ISPAID,
|
||||
'refund_status' => 0
|
||||
])
|
||||
->field('sum(order_amount) as order_amount, count(id) as order_num')
|
||||
->find();
|
||||
|
||||
$data = [
|
||||
'distribution_order_num' => $distribution['order_num'] ?? 0,
|
||||
'distribution_money' => $distribution['money'] ?? 0,
|
||||
'order_num' => $order['order_num'] ?? 0,
|
||||
'order_amount' => $order['order_amount'] ?? 0,
|
||||
'fans' => $fans,
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
//更新会员分销信息表
|
||||
\app\common\model\user\UserDistribution::where('user_id', $user['user_id'])->update($data);
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('自动更新会员分销信息异常:'.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
116
app/common/command/WechatLiveGoods.php
Normal file
116
app/common/command/WechatLiveGoods.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?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\LiveGoodsEnum;
|
||||
use app\common\model\live\LiveGoods;
|
||||
use app\common\server\WxMnpLiveServer;
|
||||
use think\console\Command;
|
||||
use think\console\Output;
|
||||
use think\console\Input;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
class WechatLiveGoods extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('wechat_live_goods')
|
||||
->setDescription('微信小程序直播商品状态同步');
|
||||
}
|
||||
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$liveGoodsModel = new LiveGoods();
|
||||
// 系统待微信审核的商品
|
||||
$localGoods = $liveGoodsModel->where([
|
||||
'del' => 0,
|
||||
'sys_audit_status' => LiveGoodsEnum::SYS_AUDIT_STATUS_WAIT_WECHAT
|
||||
])
|
||||
->select()->toArray();
|
||||
|
||||
if (empty($localGoods)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 切分为20个一组,获取每组的商品状态更新
|
||||
$localGoods = array_chunk($localGoods, 20);
|
||||
foreach ($localGoods as $localGoodsItem) {
|
||||
$goodsIds = array_column($localGoodsItem, 'wx_goods_id');
|
||||
$wxGoodsData = $this->getGoods($goodsIds);
|
||||
$wxGoodsData = $wxGoodsData['goods'] ?? [];
|
||||
$wxGoodsDataColumn = array_column($wxGoodsData, null,'goods_id');
|
||||
|
||||
$updateData = [];
|
||||
foreach ($localGoodsItem as $goods) {
|
||||
$wxGoodsId = $goods['wx_goods_id'];
|
||||
if (!isset($wxGoodsDataColumn[$wxGoodsId])) {
|
||||
continue;
|
||||
}
|
||||
$wxGoods = $wxGoodsDataColumn[$wxGoodsId];
|
||||
$data = [
|
||||
'id' => $goods['id'],
|
||||
'wx_audit_status' => $wxGoods['audit_status'],
|
||||
'audit_remark' => LiveGoodsEnum::getWxAuditStatusDesc($wxGoods['audit_status']),
|
||||
];
|
||||
if ($wxGoods['audit_status'] == LiveGoodsEnum::WX_AUDIT_STATUS_SUCCESS) {
|
||||
$data['sys_audit_status'] = LiveGoodsEnum::SYS_AUDIT_STATUS_SUCCESS;
|
||||
}
|
||||
if ($wxGoods['audit_status'] == LiveGoodsEnum::WX_AUDIT_STATUS_FAIL) {
|
||||
$data['sys_audit_status'] = LiveGoodsEnum::SYS_AUDIT_STATUS_FAIL;
|
||||
}
|
||||
$updateData[] = $data;
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$liveGoodsModel->saveAll($updateData);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('更新直播商品状态失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品
|
||||
* @param $goodsIds
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2023/2/17 19:24
|
||||
*/
|
||||
protected function getGoods($goodsIds)
|
||||
{
|
||||
$result = (new WxMnpLiveServer())->handle('getGoodsWarehouse', $goodsIds);
|
||||
if (0 != $result['errcode']) {
|
||||
return [];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
129
app/common/command/WechatLiveRoom.php
Normal file
129
app/common/command/WechatLiveRoom.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?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\LiveRoomEnum;
|
||||
use app\common\model\live\LiveRoom;
|
||||
use app\common\server\WxMnpLiveServer;
|
||||
use think\console\Command;
|
||||
use think\console\Output;
|
||||
use think\console\Input;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
class WechatLiveRoom extends Command
|
||||
{
|
||||
// 直播间数据
|
||||
protected $roomData = [];
|
||||
|
||||
// 获取次数限制
|
||||
protected $requestlimit = 5;
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('wechat_live_room')
|
||||
->setDescription('微信小程序直播状态同步');
|
||||
}
|
||||
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$liveStatus = [
|
||||
LiveRoomEnum::LIVE_STATUS_WAIT,
|
||||
LiveRoomEnum::LIVE_STATUS_ING,
|
||||
LiveRoomEnum::LIVE_STATUS_STOP,
|
||||
LiveRoomEnum::LIVE_STATUS_ERROR,
|
||||
];
|
||||
$localRooms = LiveRoom::where('wx_room_id', '>', 0)
|
||||
->where(['audit_status' => LiveRoomEnum::AUDIT_STATUS_SUCCESS, 'del' => 0])
|
||||
->whereIn('live_status', $liveStatus)
|
||||
->select()->toArray();
|
||||
|
||||
if (empty($localRooms)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$wxRooms = $this->getRooms();
|
||||
if (empty($wxRooms)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$updateData = [];
|
||||
$wxRooms = array_column($wxRooms, null, 'roomid');
|
||||
foreach ($localRooms as $localRoom) {
|
||||
$localRoomId = $localRoom['wx_room_id'];
|
||||
if (!isset($wxRooms[$localRoomId])) {
|
||||
continue;
|
||||
}
|
||||
$wxRoomData = $wxRooms[$localRoomId];
|
||||
$updateData[] = [
|
||||
'id' => $localRoom['id'],
|
||||
'goods_num' => count($wxRoomData['goods']),
|
||||
'live_status' => $wxRoomData['live_status'],
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
(new LiveRoom())->saveAll($updateData);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('更新直播间信息失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取直播间
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2023/2/17 18:45
|
||||
*/
|
||||
protected function getRooms($start = 0, $limit = 100)
|
||||
{
|
||||
$result = (new WxMnpLiveServer())->handle('getRooms', [
|
||||
'start' => $start,
|
||||
'limit' => $limit,
|
||||
]);
|
||||
|
||||
if (0 != $result['errcode']) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->requestlimit -= 1;
|
||||
$this->roomData = array_merge($result['room_info'], $this->roomData);
|
||||
|
||||
if ($result['total'] == $limit && $this->requestlimit > 0) {
|
||||
return $this->getRooms($limit + 1, $limit);
|
||||
}
|
||||
|
||||
return $this->roomData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
95
app/common/command/WechatMerchantTransfer.php
Normal file
95
app/common/command/WechatMerchantTransfer.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?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\admin\logic\WechatMerchantTransferLogic;
|
||||
use app\common\enum\WithdrawEnum;
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\WithdrawApply;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Output;
|
||||
use think\console\Input;
|
||||
use think\facade\Log;
|
||||
|
||||
class WechatMerchantTransfer extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('wechat_merchant_transfer')
|
||||
->setDescription('商家转账到零钱查询');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
//微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
|
||||
$transfer_way = ConfigServer::get('withdraw', 'transfer_way',1);
|
||||
//选择了商家转账到零钱再进行查询
|
||||
if ($transfer_way == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lists = WithdrawApply::where(['type'=>WithdrawEnum::TYPE_WECHAT_CHANGE,'status'=>WithdrawEnum::STATUS_ING])
|
||||
->field('id,sn,batch_no,user_id,money')
|
||||
->select();
|
||||
|
||||
foreach ($lists as $list) {
|
||||
$result = WechatMerchantTransferLogic::details($list);
|
||||
// 记录查询结果
|
||||
WithdrawApply::update(['update_time'=>time(),'pay_search_desc'=>json_encode($result, JSON_UNESCAPED_UNICODE)],['id'=>$list['id']]);
|
||||
if(isset($result['state'])) {
|
||||
if ($result['state'] == 'SUCCESS') {
|
||||
// 转账成功,标记提现申请单为提现成功,记录支付信息
|
||||
WithdrawApply::update(['status'=>3,'payment_no'=>$result['transfer_bill_no'],'payment_time'=>strtotime($result['update_time'])],['id'=>$list['id']]);
|
||||
}
|
||||
if ($result['state'] == 'FAIL') {
|
||||
// 转账失败
|
||||
WithdrawApply::update(['status'=>4],['id'=>$list['id']]);
|
||||
//回退佣金
|
||||
$user = User::find($list['user_id']);
|
||||
$user->earnings = ['inc', $list['money']];
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$list['user_id'],
|
||||
$list['money'],
|
||||
1,
|
||||
AccountLog::withdraw_back_earnings,
|
||||
'',
|
||||
$list['id'],
|
||||
$list['sn']
|
||||
);
|
||||
}
|
||||
if ($result['state'] == 'PROCESSING') {
|
||||
return ['code' => 0, 'msg' => '正在处理中'];
|
||||
}
|
||||
}else{
|
||||
Log::write($result['message'] ?? '商家转账到零钱查询失败');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
89
app/common/command/WechatMiniExpressSendSync.php
Normal file
89
app/common/command/WechatMiniExpressSendSync.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\RechargeOrder;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\WechatMiniExpressSendSyncServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
class WechatMiniExpressSendSync extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('wechat_mini_express_send_sync')->setDescription('微信小程序发货同步');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
// 未开启发货同步
|
||||
if (! ConfigServer::get('mnp', 'express_send_sync', 1)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
// 订单
|
||||
static::order();
|
||||
// 用户充值
|
||||
static::user_recharge();
|
||||
}
|
||||
|
||||
private static function order()
|
||||
{
|
||||
// 快递
|
||||
$list = Order::where('delivery_type', OrderEnum::DELIVERY_TYPE_EXPRESS)
|
||||
->where('shipping_status', 1)
|
||||
->where('pay_status', 1)
|
||||
->where('pay_way', PayEnum::WECHAT_PAY)
|
||||
->where('wechat_mini_express_sync', 0)
|
||||
->where('order_status', 'in', [ OrderEnum::ORDER_STATUS_GOODS, OrderEnum::ORDER_STATUS_COMPLETE ])
|
||||
->limit(60)
|
||||
->order('id desc')
|
||||
->select()->toArray();
|
||||
// 自提
|
||||
$list2 = Order::where('delivery_type', OrderEnum::DELIVERY_TYPE_SELF)
|
||||
->where('pay_status', 1)
|
||||
->where('pay_way', PayEnum::WECHAT_PAY)
|
||||
->where('wechat_mini_express_sync', 0)
|
||||
->where('order_status', 'in', [ OrderEnum::ORDER_STATUS_DELIVERY, OrderEnum::ORDER_STATUS_GOODS, OrderEnum::ORDER_STATUS_COMPLETE ])
|
||||
->limit(20)
|
||||
->order('id desc')
|
||||
->select()->toArray();
|
||||
// 虚拟发货
|
||||
$list3 = Order::where('delivery_type', OrderEnum::DELIVERY_TYPE_VIRTUAL)
|
||||
->where('pay_status', 1)
|
||||
->where('pay_way', PayEnum::WECHAT_PAY)
|
||||
->where('wechat_mini_express_sync', 0)
|
||||
->where('order_status', 'in', [ OrderEnum::ORDER_STATUS_GOODS, OrderEnum::ORDER_STATUS_COMPLETE ])
|
||||
->limit(20)
|
||||
->order('id desc')
|
||||
->select()->toArray();
|
||||
// dump([ $list, $list2, $list3 ]);
|
||||
|
||||
foreach ([ $list, $list2, $list3 ] as $items) {
|
||||
foreach ($items as $item) {
|
||||
WechatMiniExpressSendSyncServer::_sync_order($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function user_recharge()
|
||||
{
|
||||
$list = RechargeOrder::where('pay_status', 1)
|
||||
->where('pay_way', PayEnum::WECHAT_PAY)
|
||||
->where('wechat_mini_express_sync', 0)
|
||||
->limit(60)
|
||||
->order('id desc')
|
||||
->select()->toArray();
|
||||
// dump($list);
|
||||
|
||||
foreach ($list as $item) {
|
||||
WechatMiniExpressSendSyncServer::_sync_recharge($item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user