|
|
@@ -226,13 +226,23 @@ class Order extends Base |
|
|
|
if ($order['have_paid'] != \addons\unishop\model\Order::PAID_NO) { |
|
|
|
$this->error('此订单已支付,无法取消'); |
|
|
|
} |
|
|
|
$redis = new Redis(); |
|
|
|
$flash = (new \addons\unishop\model\Order)->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(); |
|
|
|
if ($flash){ |
|
|
|
$redis->handler->hIncrBy('flash_sale_' . $flash->flash_id. '_' . $flash->product_id, 'sold', -1); |
|
|
|
// $redis = new Redis(); |
|
|
|
// $flash = (new \addons\unishop\model\Order)->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(); |
|
|
|
// if ($flash){ |
|
|
|
// $redis->handler->hIncrBy('flash_sale_' . $flash->flash_id. '_' . $flash->product_id, 'sold', -1); |
|
|
|
// } |
|
|
|
$orderProduct = new OrderProduct(); |
|
|
|
|
|
|
|
$list =$orderProduct->where([ |
|
|
|
'order_id' => $order_id |
|
|
|
])->select(); |
|
|
|
$list = collection($list)->toArray(); |
|
|
|
$product = new \app\admin\model\unishop\Product(); |
|
|
|
foreach ($list as $val){ |
|
|
|
$product->where(["id"=>$val['product_id']])->setInc("stock",$val["number"]); |
|
|
|
} |
|
|
|
|
|
|
|
if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_paid'] == \addons\unishop\model\Order::PAID_NO) { |
|
|
@@ -598,6 +608,8 @@ class Order extends Base |
|
|
|
} |
|
|
|
|
|
|
|
public function doRefund(){ |
|
|
|
$this->error("暂不支持"); |
|
|
|
|
|
|
|
$order_id = $this->request->post('order_id'); |
|
|
|
$order_id = Hashids::decodeHex($order_id); |
|
|
|
$orderModel = new \addons\unishop\model\Order(); |
|
|
@@ -612,16 +624,16 @@ class Order extends Base |
|
|
|
if (!$order){ |
|
|
|
$this->error("订单信息错误"); |
|
|
|
} |
|
|
|
$redis = new Redis(); |
|
|
|
$flash = $orderModel->alias("o")-> |
|
|
|
join("unishop_order_product","unishop_order_product.order_id =o.id") |
|
|
|
->join("unishop_flash_sale","unishop_order_product.flash_id=unishop_flash_sale.id") |
|
|
|
->where(["o.id"=>(int)$order_id,"unishop_flash_sale.status"=>0,"unishop_flash_sale.switch"=>1,"unishop_flash_sale.deletetime"=>0]) |
|
|
|
->field("flash_id,product_id,endtime")->find(); |
|
|
|
if (!$flash || $flash->endtime < time()){ |
|
|
|
$this->error("活动已结束,不支持退款"); |
|
|
|
} |
|
|
|
$sold = $redis->handler->hIncrBy('flash_sale_' . $flash->flash_id. '_' . $flash->product_id, 'sold', -1); |
|
|
|
// $redis = new Redis(); |
|
|
|
// $flash = $orderModel->alias("o")-> |
|
|
|
// join("unishop_order_product","unishop_order_product.order_id =o.id") |
|
|
|
// ->join("unishop_flash_sale","unishop_order_product.flash_id=unishop_flash_sale.id") |
|
|
|
// ->where(["o.id"=>(int)$order_id,"unishop_flash_sale.status"=>0,"unishop_flash_sale.switch"=>1,"unishop_flash_sale.deletetime"=>0]) |
|
|
|
// ->field("flash_id,product_id,endtime")->find(); |
|
|
|
// if (!$flash || $flash->endtime < time()){ |
|
|
|
// $this->error("活动已结束,不支持退款"); |
|
|
|
// } |
|
|
|
// $sold = $redis->handler->hIncrBy('flash_sale_' . $flash->flash_id. '_' . $flash->product_id, 'sold', -1); |
|
|
|
$order->status = \addons\unishop\model\Order::STATUS_REFUND; |
|
|
|
$order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_AGREE; |
|
|
|
$result = $order->save(); |
|
|
@@ -636,6 +648,8 @@ class Order extends Base |
|
|
|
PayService::cancel($param,$order["pay_type"]); |
|
|
|
$this->success("success",[]); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->error("订单信息错误"); |
|
|
|
} |
|
|
|
|
|
|
|