91 lines
3.0 KiB
PHP
91 lines
3.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2022年6月11日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\commands;
|
|
|
|
use app\models\BalanceLog;
|
|
use app\models\BallCart;
|
|
use app\models\common\union\CardFrom;
|
|
use app\models\common\union\CardUnionActionFrom;
|
|
use app\models\Model;
|
|
use app\models\Order;
|
|
use app\models\OrderDetail;
|
|
use app\models\OrderUnionMeta;
|
|
use app\models\PaymentOrder;
|
|
use app\models\PaymentOrderUnion;
|
|
use app\models\Store;
|
|
use app\models\StoreEarnings;
|
|
use app\models\User;
|
|
use app\models\UserCoupon;
|
|
use yii\console\Controller;
|
|
use yii\console\ExitCode;
|
|
/**
|
|
* This command echoes the first argument that you have entered.
|
|
*
|
|
* This command is provided as an example for you to learn how to create console commands.
|
|
*
|
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
* @since 2.0
|
|
*/
|
|
class OrderController extends Controller
|
|
{
|
|
|
|
#将未支付的订单变更为取消状态
|
|
public function actionOrderCancel()
|
|
{
|
|
echo '开始';
|
|
try {
|
|
$all = Order::find()->select('id,created_at')->where(['is_pay' => 0,'cancel_status' => 0,'is_delete' => 0])->asArray()->all();
|
|
if(!empty($all)){
|
|
foreach ($all as $index => $item){
|
|
$time = time() - $item['created_at'];
|
|
if($time >= 300){
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
$order = Order::findOne($item['id']);
|
|
$order->cancel_status = 1;
|
|
$order->status = 4;
|
|
if(!$order->save()){
|
|
$t->rollBack();
|
|
return false;
|
|
}
|
|
$order_detail = OrderDetail::findOne(['order_id' => $order->id]);
|
|
if(!empty($order_detail)){
|
|
$ball_cart = BallCart::find()->where(['status' => 3,'is_delete' => 0,'ball_number' => $order_detail->goods_id])->one();
|
|
if(!empty($ball_cart)){
|
|
$ball_cart->status = 0;
|
|
$ball_cart->save();
|
|
}
|
|
}
|
|
if(!empty($order->use_user_coupon_id)){
|
|
// 退回优惠券
|
|
UserCoupon::updateAll([
|
|
'status' => 0,
|
|
'updated_at' => time(),
|
|
],[
|
|
'id' => $order->use_user_coupon_id,
|
|
'is_delete' => 0,
|
|
]);
|
|
}
|
|
$t->commit();
|
|
}
|
|
}
|
|
}
|
|
echo '结束';
|
|
return ExitCode::OK;
|
|
}catch (\Exception $e){
|
|
echo "ERROR-Exception-{$e->getLine()}--{$e->getMessage()}--{$e->getFile()}".PHP_EOL;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} |