/** * 同意支付尾款 * @author 李东 * @date 2015-08-07 */ public function due_pay() { if (IS_GET) { $gets = I('get.'); $order_id = $gets['order_id']; if ($order_id) { $result = pay_balance_due($order_id); if ($result) { $tips_msg = array('status' => '1', 'msg' => '操作成功'); } else { $tips_msg = array('status' => '0', 'msg' => '操作失败'); } } else { $tips_msg = array('status' => '0', 'msg' => '参数错误'); } } else { $tips_msg = array('status' => '0', 'msg' => '请求错误!'); } export: if ($tips_msg['status'] == 1) { $this->success($tips_msg['msg']); } else { $this->error($tips_msg['msg']); } }
/** * 退款操作 * 首先判断订单是否已付款 * 已付款订单才能进行退款处理 * 退款处理 * 1.对购买用户的余额账户进行余额增加 * 2.对店铺拥有者进行扣款 * 3.对订单状态做修改 * @param $id 退款订单ID * @param $refund_price 退款金额 * @param $description 退款备注 * @return bool 成功或失败 * * @author 李东 * @date 2015-06-23 */ function order_refund($id, $refund_price, $description) { $sql_arr = array(); /*查询出订单详情*/ $order_info = get_info('orders', array('id' => $id)); if ($order_info['status'] <= 0) { /* 判断是否已付款 */ return array('status' => '0', 'msg' => '未付款订单不可退款'); } elseif ($order_info['status'] == 5) { /* 判断是否已退款 */ return array('status' => '0', 'msg' => '该订单已经退款成功'); } if ($refund_price > $order_info['total_price']) { return array('status' => '0', 'msg' => '退款金额不能大于订单金额'); } /*查询出店铺信息*/ $shop_info = get_info(D('ShopView'), array('shop.id' => $order_info['shop_id'])); $buyer_id = $order_info['member_id']; /*购买人ID*/ $seller_id = $shop_info['seller_id']; /*出售人ID*/ $_POST = array('id' => $buyer_id, 'withdrawals' => $refund_price); /* 给客户账户增加余额 */ $sql_arr[] = "update __PREFIX__member set withdrawals = withdrawals+{$refund_price} where id = {$buyer_id}"; /* 添加资金记录*/ $sql_arr[] = "INSERT INTO __PREFIX__money_record (`type`, `frozen`, `member_id`, `money`,`description`, `order_num`, `from_member_id`, `status`) VALUES ('5', '2', '{$buyer_id}', '{$refund_price}', '商家退款', '{$order_info['order_num']}', '{$seller_id}', '3');"; /* 给商家账户减少余额 */ $sql_arr[] = "update __PREFIX__member set withdrawals = withdrawals-{$refund_price} where id = {$seller_id}"; /* 添加资金记录*/ //$sql_arr[] = "INSERT INTO __PREFIX__money_record (`type`, `frozen`, `member_id`, `money`,`description`, `order_num`, `from_member_id`, `status`) VALUES ('5', '2', '{$seller_id}', -'{$refund_price}', '订单退款', '{$order_info['order_num']}', '{$seller_id}', '3');"; /* 变更订单状态 */ $sql_arr[] = "update __PREFIX__orders set refund_price={$refund_price},agree_refund=1,status = 5 where id = {$id}"; /* 将订单操作记录到订单历史表中 */ $sql_arr[] = "INSERT INTO __PREFIX__order_history (`order_id`,`description`, `order_status`) VALUES ('{$id}', '{$description}', '5')"; $Model = M(); $Model->startTrans(); /*开启事务*/ foreach ($sql_arr as $key => $val) { $result = $Model->execute($val); if (!is_numeric($result)) { $status = 1; break; } } /*退款成功之后将剩余尾款支付给商家,并添加商家用户的资金记录*/ $result = pay_balance_due($id); if ($status == 1 && $result) { $Model->rollback(); /*事务回滚*/ return array('status' => '0', 'msg' => '操作失败'); } else { $Model->commit(); /*事务提交*/ return array('status' => '1', 'msg' => '操作成功'); } }