Browse Source

checkredis

undefined
娄梦宁 4 years ago
parent
commit
99c727302f
1 changed files with 51 additions and 0 deletions
  1. +51
    -0
      application/admin/controller/unishop/Order.php

+ 51
- 0
application/admin/controller/unishop/Order.php View File

@@ -2,6 +2,9 @@

namespace app\admin\controller\unishop;

use addons\nzf\PayService;
use addons\unishop\extend\Hashids;
use addons\unishop\extend\Redis;
use app\admin\model\unishop\Area;
use app\admin\model\unishop\OrderRefund;
use app\common\controller\Backend;
@@ -627,4 +630,52 @@ class Order extends Backend
$this->success("提交成功", null);

}

public function doRefund(){
$order_id = $this->request->get('id');
$order = $this->model->where([
'id' => (int)$order_id,
'status'=>1,//订单状态正常
// 'have_paid'=>[">",0],//已支付
// 'had_refund'=>0
])->find();
if (!$order){
$this->error("订单已取消,请勿重复操作");
}
if ($order->have_paid>0){
//已支付
self::refundOrder($order);
}else{
$order->status = \addons\unishop\model\Order::STATUS_CANCEL;
$order->save();
}
// //回退虚拟活动库存
$redis = new Redis();
$flash = $this->model->alias("o")->
join("unishop_order_product","unishop_order_product.order_id =o.id")
->where(["o.id"=>(int)$order_id])
->field("flash_id,product_id")->find();

$sold = $redis->handler->hIncrBy('flash_sale_' . $flash->flash_id. '_' . $flash->flash_id, 'sold', -1);

$this->success("提交成功", null);

}

static function refundOrder($order){
$order->status = \addons\unishop\model\Order::STATUS_REFUND;
$order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_AGREE;
$result = $order->save();
if ($result !== false){
//order_id:订单ID name:订单名称 total_fee:总金额-元 refund_fee退款金额
$param = [
"order_id"=>$order['out_trade_no'],
"total_fee"=>$order['total_price'],
"refund_fee"=>$order['total_price'],
"memo"=>'订单退款',
];
PayService::cancel($param,$order["pay_type"]);
return;
}
}
}

Loading…
Cancel
Save