|
@@ -431,6 +431,7 @@ class Order extends Backend
|
|
|
$params = [
|
|
|
'refund_status' => $refund_status,
|
|
|
'updatetime' => time(),
|
|
|
+ 'refund_amount' => $refund_amount,
|
|
|
];
|
|
|
if($refund_status == 3) {
|
|
|
$params['had_refund'] = time();
|
|
@@ -511,6 +512,87 @@ class Order extends Backend
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 已支付未发货退款
|
|
|
+ */
|
|
|
+ public function cancelrefund($ids = null)
|
|
|
+ {
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ if ($row['status'] != \app\admin\model\unishop\Order::STATUS_CANCEL || $row['have_paid'] == 0 || $row['have_delivered'] != 0) {
|
|
|
+ $this->error('订单状态错误');
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $updatetime = $this->request->post('updatetime');
|
|
|
+ $refund_amount = $this->request->post('refund_amount');
|
|
|
+ $refund_status = $this->request->post('refund_status');
|
|
|
+
|
|
|
+ if ($refund_amount > $row['total_price']) {
|
|
|
+ $this->error('退款金额不能大于实际支付金额');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 退款
|
|
|
+ $params = [
|
|
|
+ 'refund_status' => $refund_status,
|
|
|
+ 'updatetime' => time(),
|
|
|
+ 'refund_amount' => $refund_amount,
|
|
|
+ ];
|
|
|
+ if($refund_status == 3) {
|
|
|
+ $params['had_refund'] = time();
|
|
|
+ }
|
|
|
+ // 乐观锁
|
|
|
+ $result = Db::name('unishop_order')->where(['id' => $ids, 'updatetime' => $updatetime])->update($params);
|
|
|
+ if (!$result) {
|
|
|
+ throw new Exception(__('Data had been update before saved, close windows and do it again'));
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改退款金额
|
|
|
+ /*$rs2 = Db::name('unishop_order_refund')->where('order_id',$ids)->update(['amount'=>$refund_amount]);
|
|
|
+ if ($rs2 === false) {
|
|
|
+ throw new Exception('操作失败');
|
|
|
+ }*/
|
|
|
+
|
|
|
+ //同意并执行退款
|
|
|
+ if($refund_status == 3 && $refund_amount > 0){
|
|
|
+ $order = Db::name('unishop_order')->where('id',$ids)->find();
|
|
|
+
|
|
|
+ if($order['pay_type'] == 2){
|
|
|
+ $wallet_rs = model('wallet')->lockChangeAccountRemain($order['user_id'],'money',$refund_amount,32,$remark='商城订单退款','unishop_order',$ids);
|
|
|
+ if($wallet_rs['status'] === false){
|
|
|
+ throw new Exception($wallet_rs['msg']);
|
|
|
+ }
|
|
|
+ }elseif($order['pay_type'] == 3 || $order['pay_type'] == 4){
|
|
|
+ $refund_result = $this->old_refund($order,$refund_amount);
|
|
|
+ if($refund_result !== true){
|
|
|
+ throw new Exception($refund_result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ } catch (ValidateException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->view->assign('row', $row);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
// 退款
|
|
|
public function old_refund($order, $refund_price)
|
|
|
{
|