public function expire() { $sql = "select *from reservation"; $query = $this->db->query($sql); $res = $query->result_array(); $date = date("F j, Y, g:i a"); $date = get_gmt_time(strtotime($date)); foreach ($res as $reservation) { $timestamp = $reservation['book_date']; $book_date = date("F j, Y, g:i a", $timestamp); $book_date = strtotime($book_date); $gmtTime = get_gmt_time(strtotime('+1 day', $timestamp)); if ($gmtTime <= $date && $reservation['status'] == 1) { $reservation_id = $reservation['id']; $admin_email = $this->dx_auth->get_site_sadmin(); $admin_name = $this->dx_auth->get_site_title(); $conditions = array('reservation.id' => $reservation_id); $row = $this->Trips_model->get_reservation($conditions); if ($row->num_rows() != 0) { $row = $row->row(); $query1 = $this->Users_model->get_user_by_id($row->userby); $traveler_name = $query1->row()->username; $traveler_email = $query1->row()->email; $query2 = $this->Users_model->get_user_by_id($row->userto); $host_name = $query2->row()->username; $host_email = $query2->row()->email; $list_title = $this->Common_model->getTableData('list', array('id' => $row->list_id))->row()->title; $updateKey = array('id' => $reservation_id); $updateData = array(); $updateData['status '] = 2; $this->Trips_model->update_reservation($updateKey, $updateData); // payment_helper called for refund amount for host and guest as per host and guest cancellation policy refund($reservation_id); $currency = $this->Common_model->getTableData('currency', array('currency_code' => $row->currency))->row()->currency_symbol; $price = $row->price; //echo $currency;exit; $checkin = date('m/d/Y', $row->checkin); $checkout = date('m/d/Y', $row->checkout); //Send Mail To Traveller $email_name = 'traveler_reservation_expire'; $splVars = array("{checkout}" => $checkout, "{checkin}" => $checkin, "{currency}" => $currency, "{price}" => $price, "{site_name}" => $this->dx_auth->get_site_title(), "{traveler_name}" => ucfirst($traveler_name), "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name)); $this->Email_model->sendMail($traveler_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); //Send Mail To Host $email_name = 'host_reservation_expire'; $splVars = array("{checkout}" => $checkout, "{checkin}" => $checkin, "{currency}" => $currency, "{price}" => $price, "{site_name}" => $this->dx_auth->get_site_title(), "{traveler_name}" => ucfirst($traveler_name), "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name)); $this->Email_model->sendMail($host_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); //if($host_email != $admin_email && $traveler_email != $admin_email) // { //Send Mail To Administrator $email_name = 'admin_reservation_expire'; $splVars = array("{traveler_email}" => $traveler_email, "{host_email}" => $host_email, "{checkout}" => $checkout, "{checkin}" => $checkin, "{currency}" => $currency, "{price}" => $price, "{site_name}" => $this->dx_auth->get_site_title(), "{traveler_name}" => ucfirst($traveler_name), "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name)); $this->Email_model->sendMail($admin_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); // } } } } echo '<h2>Cron Successfully Runned.</h2>'; }
/** * 订单退款 */ function autorefund() { // //$_GET['show_sql'] $list = M('bao')->where(array('state' => 2, 'addtime' => array('lt', time() - 259200), 'is_refund' => 0))->select(); if ($list) { foreach ($list as $hongbao) { $total_amount = M('bao_order')->where(array('bao_id' => $hongbao['id'], 'user_id' => '0', 'state' => 1))->sum('amount'); $refund_amount = 0; if ($total_amount > 0) { $total_num = M('bao_order')->where(array('bao_id' => $hongbao['id'], 'user_id' => '0', 'state' => 1))->count(); if ($total_num == $hongbao['total_num']) { $refund_amount = $hongbao['total_amount']; } else { $refund_amount = $total_amount; } } if ($refund_amount > 0) { $rs = refund(array('out_trade_no' => $hongbao['order_sn'], 'total_fee' => $hongbao['total_amount'] * 100, 'refund_fee' => $refund_amount * 100)); if ($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS') { M('bao')->where(array("id" => $hongbao['id']))->save(array('is_refund' => 1, 'state' => 3, 'refund_time' => time())); M('bao_order')->where(array("bao_id" => $hongbao['id'], 'state' => 1, 'user_id' => 0))->save(array('state' => 3, 'user_id' => '-1')); $log = "订单退款成功, 红包编号:{$hongbao['id']},订单编号:{$hongbao['order_sn']}"; f_log($log, ROOT_PATH . 'Runtime/Logs/refund.log'); echo $log . "<br/>"; } else { print_r($rs); $log = "订单退款失败, 红包编号:{$hongbao['id']},退款订单编号:{$hongbao['order_sn']}"; f_log($log, ROOT_PATH . 'Runtime/Logs/refund.log'); echo $log . "<br/>"; } } sleep(5); // } } die('ok'); }
public function checkin($param = '') { if ($this->input->post()) { $reservation_id = $this->input->post('reservation_id'); $updateKey = array('id' => $reservation_id); $updateData = array(); $updateData['status '] = 7; $this->Trips_model->update_reservation($updateKey, $updateData); /*if(!$this->Trips_model->update_reservation($updateKey,$updateData)) { $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('success',translate('You are successfully checked in. Enjoy the trip.'))); redirect('travelling/your_trips'); } else { $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error',translate('Your List was deleted.'))); redirect('travelling/your_trips'); }*/ // payment_helper called for refund amount for host and guest as per host and guest cancellation policy refund($reservation_id); $conditions = array('reservation.id' => $reservation_id); $row = $this->Trips_model->get_reservation($conditions)->row(); if ($this->Users_model->get_user_by_id($row->userby)) { $query1 = $this->Users_model->get_user_by_id($row->userby); } else { $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', translate('Your List was deleted.'))); redirect('travelling/your_trips'); } $traveler_name = $query1->row()->username; $traveler_email = $query1->row()->email; $query2 = $this->Users_model->get_user_by_id($row->userto); $host_name = $query2->row()->username; $host_email = $query2->row()->email; $admin_email = $this->dx_auth->get_site_sadmin(); $admin_name = $this->dx_auth->get_site_title(); $list_title = $this->Common_model->getTableData('list', array('id' => $row->list_id))->row()->title; $username = ucfirst($this->dx_auth->get_username()); $checkin = date('m/d/Y', $row->checkin); $checkout = date('m/d/Y', $row->checkout); $price = $row->price; $currency = $this->db->where('currency_code', $row->currency)->get('currency')->row()->currency_symbol; $conversation = $this->db->where('userto', $row->userto)->where('userby', $row->userby)->order_by('id', 'desc')->get('messages'); if ($conversation->num_rows() != 0) { foreach ($conversation->result() as $row3) { if ($row3->conversation_id != 0) { $conversation_id = $row3->conversation_id; } else { $conversation1 = $this->db->where('userto', $row->userby)->where('userby', $row->userto)->order_by('id', 'desc')->get('messages'); if ($conversation1->num_rows() != 0) { foreach ($conversation1->result() as $row2) { if ($row2->conversation_id != 0) { $conversation_id = $row2->conversation_id; } } } else { $conversation_id = 0; } } } } else { $conversation1 = $this->db->where('userto', $row->userby)->where('userby', $row->userto)->order_by('id', 'desc')->get('messages'); if ($conversation1->num_rows() != 0) { foreach ($conversation1->result() as $row1) { if ($row1->conversation_id != 0) { $conversation_id = $row1->conversation_id; } } } else { $conversation_id = 0; } } if (!isset($conversation_id)) { $insertData = array('list_id' => $row->list_id, 'reservation_id' => $reservation_id, 'userby' => $row->userby, 'userto' => $row->userto, 'message' => "{$username} checkin to {$list_title}.", 'created' => date('m/d/Y g:i A'), 'message_type ' => 3); } else { $insertData = array('list_id' => $row->list_id, 'reservation_id' => $reservation_id, 'conversation_id' => $conversation_id, 'userby' => $row->userby, 'userto' => $row->userto, 'message' => "{$username} checkin to {$list_title}.", 'created' => date('m/d/Y g:i A'), 'message_type ' => 3); } if ($row->list_id) { $this->Message_model->sentMessage($insertData); //Send Mail To Traveller $email_name = 'checkin_traveller'; $splVars = array("{site_name}" => $this->dx_auth->get_site_title(), "{currency}" => $currency, "{traveler_email}" => $traveler_email, "{host_email}" => $host_email, "{traveler_name}" => ucfirst($traveler_name), "{checkin}" => $checkin, "{checkout}" => $checkout, "{price}" => $price, "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name)); $this->Email_model->sendMail($traveler_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); //Send Mail To Host $email_name = 'checkin_host'; $splVars = array("{site_name}" => $this->dx_auth->get_site_title(), "{currency}" => $currency, "{traveler_email}" => $traveler_email, "{host_email}" => $host_email, "{traveler_name}" => ucfirst($traveler_name), "{checkin}" => $checkin, "{checkout}" => $checkout, "{price}" => $price, "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name)); $this->Email_model->sendMail($host_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); $admin_to_email = $this->db->where('id', 1)->get('users')->row()->email; //Send Mail To Administrator $email_name = 'checkin_admin'; $splVars = array("{site_name}" => $this->dx_auth->get_site_title(), "{currency}" => $currency, "{traveler_email}" => $traveler_email, "{host_email}" => $host_email, "{traveler_name}" => ucfirst($traveler_name), "{checkin}" => $checkin, "{checkout}" => $checkout, "{price}" => $price, "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name)); $this->Email_model->sendMail($admin_to_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('success', translate('You are successfully checkin.'))); redirect('travelling/your_trips'); } else { $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', translate('Your List was deleted.'))); redirect('travelling/your_trips'); } } $data['reservation_id'] = $param; $this->load->view(THEME_FOLDER . '/travelling/view_checkin', $data); }
update_order($f['order_id'], $arr); $user_id = $f['user_id']; $wxch_order_name = 'refund'; $team_sign = $f['team_sign']; $order_id = $f['order_id']; require_once ROOT_PATH . 'wxch_order.php'; } } } } if ($v['team_status'] == 3) { $sql = "select * from " . $GLOBALS['hhs']->table('order_info') . " where team_sign=" . $v['team_sign']; $team_list = $GLOBALS['db']->getAll($sql); foreach ($team_list as $f) { $order_sn = $f['order_sn']; $r = refund($order_sn, $f['money_paid'] * 100); if ($r) { $arr = array(); $arr['order_status'] = OS_RETURNED; $arr['pay_status'] = PS_REFUNDED; $arr['shipping_status'] = 0; $arr['team_status'] = 3; $arr['money_paid'] = 0; $arr['order_amount'] = $f['money_paid'] + $f['order_amount']; update_order($f['order_id'], $arr); $user_id = $f['user_id']; $wxch_order_name = 'refund'; $team_sign = $f['team_sign']; $order_id = $f['order_id']; require_once ROOT_PATH . 'wxch_order.php'; }
/** * 订单退款 */ function autorefund() { // $list = M('hongbao')->where(array('state' => 3, ' is_refund' => 0))->select(); if ($list) { foreach ($list as $hongbao) { $order_list = M('hongbao_order')->where(array('hongbao_id' => $hongbao['id'], 'state' => 2, 'is_refund' => 0))->select(); if ($order_list) { foreach ($order_list as $order) { $rs = refund(array('out_trade_no' => $order['order_sn'], 'total_fee' => $order['total_amount'] * 100, 'refund_fee' => $order['total_amount'] * 100)); if ($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS') { M('hongbao_order')->where(array("id" => $order['id']))->save(array('is_refund' => 1, 'refund_time' => time())); $log = "订单退款成功, 红包编号:{$hongbao['id']},订单编号:{$order['id']}"; f_log($log, ROOT_PATH . 'Runtime/Logs/refund.log'); echo $log . "<br/>"; } else { $log = "订单退款失败, 红包编号:{$hongbao['id']},订单编号:{$order['id']}"; f_log($log, ROOT_PATH . 'Runtime/Logs/refund.log'); echo $log . "<br/>"; } sleep(5); } } M('hongbao')->where(array('id' => $hongbao['id']))->save(array('is_refund' => 1)); } } die('ok'); }
/** * 订单退款 */ function refund() { refund(array('transaction_id' => '1007370008201601132684551338', 'total_fee' => 1, 'refund_fee' => 1)); }
public function expire($id) { $admin_email = $this->dx_auth->get_site_sadmin(); $admin_name = $this->dx_auth->get_site_title(); $reservation_id = $id; $conditions = array('reservation.id' => $reservation_id); $row = $this->Trips_model->get_reservation($conditions)->row(); $date = date("F j, Y, g:i a"); $date = get_gmt_time(strtotime($date)); $timestamp = $row->book_date; $book_date = date("F j, Y, g:i a", $timestamp); $book_date = strtotime($book_date); $gmtTime = get_gmt_time(strtotime('+1 day', $timestamp)); if ($gmtTime <= $date && $row->status == 1) { $query1 = $this->Users_model->get_user_by_id($row->userby); $traveler_name = $query1->row()->username; $traveler_email = $query1->row()->email; $query2 = $this->Users_model->get_user_by_id($row->userto); $host_name = $query2->row()->username; $host_email = $query2->row()->email; $list_title = $this->Common_model->getTableData('list', array('id' => $row->list_id))->row()->title; //Send Message Notification $insertData = array('list_id' => $row->list_id, 'reservation_id' => $reservation_id, 'userby' => $row->userto, 'userto' => $row->userby, 'message' => "Sorry, Your reservation request is expired by {$host_name} for {$list_title}.", 'created' => local_to_gmt(), 'message_type ' => 2); $this->Message_model->sentMessage($insertData); $message_id = $this->db->insert_id(); $updateData1['is_respond'] = 1; $updateKey1['reservation_id'] = $reservation_id; $updateKey1['userto'] = $row->userto; $this->Message_model->updateMessage($updateKey1, $updateData1); $updateKey = array('id' => $reservation_id); $updateData = array(); $updateData['status '] = 2; $this->Trips_model->update_reservation($updateKey, $updateData); // payment_helper called for refund amount for host and guest as per host and guest cancellation policy refund($reservation_id); $price = $x->row()->price; $currencycode = $x->row()->currency; $currency = $this->Common_model->getTableData('currency', array('currency_code' => $currencycode))->row()->currency_symbol; $checki = $x->row()->checkin; $checkin = date("F j, Y", $checki); $checko = $x->row()->checkout; $checkout = date("F j, Y", $checko); //Send Mail To Traveller $email_name = 'traveler_reservation_expire'; $splVars = array("{site_name}" => $this->dx_auth->get_site_title(), "{traveler_name}" => ucfirst($traveler_name), "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name), "{price}" => $price, "{currency}" => $currency, "{checkin}" => $checkin, "{checkout}" => $checkout, "{type}" => 'Reservation'); $this->Email_model->sendMail($traveler_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); //Send Mail To Host $email_name = 'host_reservation_expire'; $splVars = array("{site_name}" => $this->dx_auth->get_site_title(), "{traveler_name}" => ucfirst($traveler_name), "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name), "{price}" => $price, "{currency}" => $currency, "{checkin}" => $checkin, "{checkout}" => $checkout, "{type}" => 'Reservation'); $this->Email_model->sendMail($host_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); if ($host_email != $admin_email && $traveler_email != $admin_email) { //Send Mail To Administrator $email_name = 'admin_reservation_expire'; $splVars = array("{site_name}" => $this->dx_auth->get_site_title(), "{traveler_name}" => ucfirst($traveler_name), "{list_title}" => $list_title, "{host_name}" => ucfirst($host_name), "{price}" => $price, "{currency}" => $currency, "{checkin}" => $checkin, "{checkout}" => $checkout, "{type}" => 'Reservation'); $this->Email_model->sendMail($admin_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); } } }
function pay_team_action($orsn) { /*是团购改变订单*/ $sql = "select * from " . $GLOBALS['hhs']->table('order_info') . " where order_sn='" . $orsn . "'"; $order_info = $GLOBALS['db']->getRow($sql); include_once ROOT_PATH . "languages/zh_cn/wx_msg.php"; if (!empty($order_info) && $order_info['extension_code'] == 'team_goods') { $team_sign = $order_info['team_sign']; $weixin = new class_weixin($GLOBALS['appid'], $GLOBALS['appsecret']); $openid = $GLOBALS['db']->getOne("select openid from " . $GLOBALS['hhs']->table('users') . " where user_id=" . $order_info['user_id']); $t_openid = $GLOBALS['db']->getOne("select u.openid from " . $GLOBALS['hhs']->table('order_info') . " as oi left join " . $GLOBALS['hhs']->table('users') . " as u on oi.user_id=u.user_id where oi.team_first=1 and oi.team_sign=" . $team_sign); $sql = "select team_num,discount_type,discount_amount from " . $GLOBALS['hhs']->table('goods') . " where goods_id=" . $order_info['extension_id']; $rs = $GLOBALS['db']->getRow($sql); $team_num = $rs['team_num']; $discount_type = $rs['discount_type']; $discount_amount = $rs['discount_amount']; if ($order_info['team_first'] == 1) { //若是团长记录下团的人数 if ($discount_type == 1 && $order_info['refund_sign'] == 0) { $sql = "UPDATE " . $GLOBALS['hhs']->table('order_info') . " SET team_num='{$team_num}',discount_type ='{$discount_type}',discount_amount=money_paid+order_amount WHERE order_id=" . $order_info['order_id']; } elseif ($discount_type == 2 && $order_info['refund_sign'] == 0) { $sql = "UPDATE " . $GLOBALS['hhs']->table('order_info') . " SET team_num='{$team_num}',discount_type ='{$discount_type}', discount_amount='{$discount_amount}' WHERE order_id=" . $order_info['order_id']; } else { $sql = "UPDATE " . $GLOBALS['hhs']->table('order_info') . " SET team_num='{$team_num}', discount_amount=0 WHERE order_id=" . $order_info['order_id']; } $GLOBALS['db']->query($sql); } $sql = "select team_num from " . $GLOBALS['hhs']->table('order_info') . " where order_id=" . $order_info['team_sign']; $team_num = $GLOBALS['db']->getOne($sql); //团共需人数和状态 $sql = "UPDATE " . $GLOBALS['hhs']->table('order_info') . " SET team_status=1,team_num='{$team_num}' WHERE order_id=" . $order_info['order_id']; $GLOBALS['db']->query($sql); //实际人数 $sql = "select count(*) from " . $GLOBALS['hhs']->table('order_info') . " where team_sign=" . $team_sign . " and team_status>0 "; $rel_num = $GLOBALS['db']->getOne($sql); //存储实际人数 $sql = "update " . $GLOBALS['hhs']->table('order_info') . " set teammen_num='{$rel_num}' where team_sign=" . $team_sign; $GLOBALS['db']->query($sql); if ($team_num <= $rel_num) { $sql = "UPDATE " . $GLOBALS['hhs']->table('order_info') . " SET team_status=2 WHERE team_status=1 and team_sign=" . $team_sign; $GLOBALS['db']->query($sql); //取消未参团订单 $sql = "UPDATE " . $GLOBALS['hhs']->table('order_info') . " SET order_status=2 WHERE team_status=0 and team_sign=" . $team_sign; $GLOBALS['db']->query($sql); //判断团长是否有优惠,要重新取数据 $sql = "select order_id,user_id,refund_sign,discount_type, discount_amount, money_paid,order_amount,order_sn from " . $GLOBALS['hhs']->table('order_info') . " where order_id=" . $team_sign; $r = $GLOBALS['db']->getRow($sql); //目前只有微信可以退款 $payment = payment_info($order_info['pay_id']); if ($payment['pay_code'] == 'wxpay') { if ($r['discount_type'] == 1 && $r['refund_sign'] == 0) { //团长免单 $f = refund($r['order_sn'], $r['money_paid'] * 100); if ($f) { $arr['pay_status'] = 3; $arr['refund_sign'] = 1; $arr['money_paid'] = 0; $arr['order_amount'] = $r['money_paid'] + $r['order_amount']; update_order($team_sign, $arr); $weixin->send_wxmsg($t_openid, $_team_msg['refund_team_first']['title'], 'share.php?team_sign=' . $team_sign, $_team_msg['refund_team_first']['desc']); } } elseif ($r['discount_type'] == 2 && $r['refund_sign'] == 0) { $f = refund($r['order_sn'], $r['discount_amount'] * 100); if ($f) { $arr['refund_sign'] = 1; $arr['money_paid'] = $r['money_paid'] - $r['discount_amount']; $arr['order_amount'] = $r['discount_amount'] + $r['order_amount']; update_order($team_sign, $arr); $weixin->send_wxmsg($t_openid, $_team_msg['refund_team_discount']['title'], 'share.php?team_sign=' . $team_sign, $_team_msg['refund_team_discount']['desc']); } } } } if ($order_info['team_first'] == 1) { $weixin->send_wxmsg($openid, $_team_msg['pay']['title'], 'share.php?team_sign=' . $team_sign, $_team_msg['pay']['desc']); //$weixin->send_wxmsg($t_openid, $_team_msg['team_suc_first']['title'] , 'share.php?team_sign='.$team_sign , $_team_msg['team_suc_first']['title'] ); } elseif ($order_info['team_first'] == 2) { if ($team_num <= $rel_num) { $weixin->send_wxmsg($openid, $_team_msg['team_suc_mem']['title'], 'share.php?team_sign=' . $team_sign, $_team_msg['team_suc_mem']['desc']); $weixin->send_wxmsg($t_openid, $_team_msg['team_suc_first']['title'], 'share.php?team_sign=' . $team_sign, $_team_msg['team_suc_first']['title']); } else { $weixin->send_wxmsg($openid, $_team_msg['mem_pay']['title'], 'share.php?team_sign=' . $team_sign, $_team_msg['mem_pay']['title']); } } } }
$team_sign = $order['team_sign']; $wxch_order_name = 'pay'; include_once ROOT_PATH . 'wxch_order.php'; } } } elseif ('refund' == $operation) { /* 检查权限 */ require_once ROOT_PATH . 'includes/lib_payment.php'; require_once ROOT_PATH . 'includes/modules/payment/wxpay.php'; $arr['order_status'] = OS_RETURNED; $arr['pay_status'] = PS_REFUNDED; $arr['shipping_status'] = 0; $arr['money_paid'] = 0; $arr['order_amount'] = $order['money_paid'] + $order['order_amount']; $order['shipping_status'] = 0; $r = refund($order['order_sn'], $order['money_paid'] * 100); if ($r) { update_order($order_id, $arr); /* 记录log */ order_action($order['order_sn'], 4, $order['shipping_status'], 3, $action_note); $user_id = $order['user_id']; $order_id = $order['order_id']; $wxch_order_name = 'refund'; include_once ROOT_PATH . 'wxch_order.php'; /* 操作失败 */ $links[] = array('text' => $_LANG['order_info'], 'href' => 'order.php?act=info&order_id=' . $order_id); sys_msg('退款成功', 1, $links); } else { $links[] = array('text' => $_LANG['order_info'], 'href' => 'order.php?act=info&order_id=' . $order_id); sys_msg('退款失败', 1, $links); }