Esempio n. 1
0
 public function payment($sum)
 {
     // На бете альфе включаем дебаг режим
     if (!is_release()) {
         //$sum = 0.1;// @debug
         $this->api->setDebug(true);
     }
     $result = $this->api->requestPayment(round((double) $sum, 2), $this->account->id);
     if ($result['status'] == API_Webmoney::STATUS_SUCCESS) {
         $process = $this->api->processPayment($this->api->merchant_transaction_id, $result['processor_transaction_id']);
         switch ($process['status']) {
             case API_Webmoney::STATUS_PAYMENT_PROGRESS:
             case API_Webmoney::STATUS_PAYMENT_SUCCESS:
                 // Зачисляем деньги на бете/альфе
                 //                    if(!is_release()) {
                 //                        $paymentDateTime = date('d.m.Y H:i');
                 //                        $orderNumber     = rand(1, 99999999);
                 //                        $descr = "WebMoney с кошелька {$this->data['wallet']} сумма - {$sum}, обработан {$paymentDateTime}, номер покупки - $orderNumber";
                 //
                 //                        $this->account->deposit($op_id, $this->account->id, $sum, $descr, 3, $sum, 12);
                 //                    }
                 return true;
                 break;
             case API_Webmoney::STATUS_PAYMENT_FAIL:
                 ob_start();
                 var_dump($result);
                 var_dump($process);
                 $content = ob_get_clean();
                 $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
                 $this->log->write("Request:\n " . $this->api->last_request->getBody());
                 $this->log->write("Result:\n {$content}");
                 return false;
                 break;
                 // Отложить платеж на пол часа
                 // @todo придумать как отложить запрос на потом
                 //case API_Webmoney::STATUS_PAYMENT_PROCESS:
             // Отложить платеж на пол часа
             // @todo придумать как отложить запрос на потом
             //case API_Webmoney::STATUS_PAYMENT_PROCESS:
             default:
                 return;
                 break;
         }
     } else {
         ob_start();
         var_dump($result);
         $content = ob_get_clean();
         $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
         $this->log->write("Request:\n " . $this->api->last_request->getBody());
         $this->log->write("Result:\n {$content}");
         return false;
     }
 }
Esempio n. 2
0
	public function query($sql){
		$rs = mysql_query($sql);
		log::write(date('Y-m-d H:i:s', time()).'--->'.$sql); //记录日志

		return $rs;

	}
Esempio n. 3
0
 public function query($sql)
 {
     $rs = mysqli_query($this->conn, $sql);
     log::write($sql);
     log::write(time());
     return $rs;
 }
Esempio n. 4
0
 public function query($sql)
 {
     $rs = mysqli_query($this->conn, $sql);
     log::write($sql);
     //log::write("  result:" . $rs);
     return $rs;
 }
Esempio n. 5
0
 public function clearMemcache()
 {
     $result = $this->memcached->flush();
     if (!$result) {
         log::write("MemDb::clearMemcach() failed", "log");
         return false;
     }
     return true;
 }
Esempio n. 6
0
function execute($sql)
{
    try {
        global $_conn;
        $_conn->execute($sql);
    } catch (Exception $e) {
        log::write($e->getMessage(), "execute");
    }
}
Esempio n. 7
0
 function test_writing_to_file()
 {
     log::write(array(VAR_DIR . '/tmp/', 'test.log'), 'wow');
     $this->assertTrue(file_exists(VAR_DIR . '/tmp/test.log'));
     $arr = file(VAR_DIR . '/tmp/test.log');
     $this->assertNotNull($arr[0]);
     if (isset($_SERVER['REQUEST_URI'])) {
         $this->assertWantedPattern('|' . preg_quote($_SERVER['REQUEST_URI']) . '|', $arr[1]);
     }
     $this->assertWantedPattern('|wow|', $arr[2]);
 }
Esempio n. 8
0
 /**
  * 获取账户信息
  *
  */
 public static function get($account_id)
 {
     $post_url = "http://manage.backstage-gateway.com/account";
     $post_var = "account_id=" . $account_id;
     $result = tool::curl_pay($post_url, $post_var);
     $res = @unserialize(stripcslashes($result));
     if (!is_array($res)) {
         log::write('data_error', $result, __FILE__, __LINE__);
     }
     return $res;
 }
Esempio n. 9
0
 public function GetOne($id)
 {
     $query = 'SELECT * FROM ' . $this->tableName . ' WHERE id=:id';
     $param[':id'] = $id;
     $res = $this->query($query, $param);
     if (empty($res)) {
         $log = new log();
         $log->write('Trying to get unexisting article');
         throw new E404Exception('The article with id=' . $id . ' was not found');
     }
     return $this->query($query, $param)[0];
 }
Esempio n. 10
0
 /**
  * Validates and optionally saves a new delivery category from an array.
  *
  * @param array value to check
  * @param boolean save the record when validation succeeds
  * @return boolean      
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('name', 'required', 'length[1,255]')->add_rules('ename', 'required', 'length[1,255]')->add_rules('description', 'length[1,1000]')->add_rules('edescription', 'length[1,1000]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         log::write('form_error', $errors, __FILE__, __LINE__);
         return FALSE;
     }
 }
Esempio n. 11
0
 public function query($sql)
 {
     //	if($this->conf->debug){
     //		log::write($sql);
     //	}
     $rs = $this->conn->query($sql);
     log::write($sql);
     if (!$rs) {
         //log::write($this->error());
         log::write("error");
     }
     return $rs;
 }
Esempio n. 12
0
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('status', 'numeric')->add_rules('manager_id', 'numeric')->add_rules('user_log_type', 'numeric')->add_rules('ip', 'length[0,255]')->add_rules('method', 'length[0,255]')->add_rules('memo', 'length[0,512]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         log::write('form_error', $errors, __FILE__, __LINE__);
         return FALSE;
     }
 }
Esempio n. 13
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('host', 'required', 'length[0,255]')->add_rules('port', 'required', 'numeric')->add_rules('username', 'required', 'length[0,255]')->add_rules('password', 'required', 'length[0,255]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         log::write('Smtp_queue_form_error', $errors, __FILE__, __LINE__);
         return FALSE;
     }
 }
Esempio n. 14
0
 public static function error($errno, $errstr, $errfile, $errline)
 {
     switch ($errno) {
         case E_ERROR:
         case E_USER_ERROR:
             $errormsg = "[" . L("exceptionhd_error1") . "]{$errstr}\t[" . L("exceptionhd_error2") . "]{$errfile}\t[" . L("exceptionhd_error3") . "]{$errline}";
             log::write($errormsg);
             error($errormsg);
             break;
         case E_USER_WARNING:
         case E_USER_NOTICE:
         default:
             $errormsg = "[" . L("exceptionhd_error4") . "] {$errstr}\t[" . L("exceptionhd_error5") . "]{$errfile}\t[" . L("exceptionhd_error6") . "]{$errline}";
             self::notice(func_get_args());
             log::set($errormsg);
     }
 }
Esempio n. 15
0
function customError($errno, $errstr, $errfile, $errline)
{
    global $_charset, $KYPHP, $kyphp_error_no, $kyphp_errors;
    switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
            $error = $_charset['notice'];
            break;
        case E_WARNING:
        case E_USER_WARNING:
            $error = $_charset['warning'];
            break;
        case E_ERROR:
        case E_USER_ERROR:
            $error = $_charset['fatal'];
            break;
        default:
            $error = $_charset['unknow'];
            break;
    }
    if (empty($KYPHP)) {
        if (!strstr($errstr, 'mysql_close')) {
            echo $error . ':' . $errstr . 'at:' . $errfile . ' line:' . $errline;
        }
        return;
    }
    $error_display = $KYPHP->config->get('error_display');
    $error_log = $KYPHP->config->get('error_log');
    if (!$error_display) {
        $error_display = 'on';
    }
    if (!$error_log) {
        $error_log = 'on';
    }
    $kyphp_errors[] = array($errno, $errstr, $errfile, $errline);
    $KYPHP->config->set('error', $kyphp_errors);
    if ($error_log == 'on') {
        $log = new log('error.txt');
        $log->write($error . ':' . $errstr . ' at:' . $errfile . ' line:' . $errline);
    }
    if ($error_display == 'on') {
        kyphp_display_error($errno, $errstr, $errfile, $errline, $kyphp_error_no);
        $kyphp_error_no++;
    }
    //die();
}
Esempio n. 16
0
 public function get_validate($apiKey = null)
 {
     $apiCheck = \Crm\Portal\Portal_Check::api_key($apiKey);
     if ($apiCheck === false) {
         $this->response(array('status' => 'FAIL', 'message' => 'Invalid API Key has been used, please contact your IT support!'));
     } else {
         $allFields = TRUE;
         $missingFields = array();
         $surveyChoice = $apiCheck->survey;
         $surveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->where('required', '1')->get();
         $allSurveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->get();
         foreach ($surveyQuestions as $surveyRequired) {
             $requiredFields[] = 'form-q' . $surveyRequired->id;
         }
         foreach ($allSurveyQuestions as $surveyQuestions) {
             $questionFields[] = 'form-q' . $surveyQuestions->id;
         }
         // Check and make a list of any missing fields
         foreach ($requiredFields as $field) {
             if (is_null(Input::get($field, null)) || strlen(Input::get($field, null)) < 1 && !is_integer(Input::get($field, null)) || Input::get($field, null) == "-- Select") {
                 $allFields = FALSE;
                 $missingFields[] = $field;
             }
         }
         // If we have everything we need then we do our logic
         if ($allFields) {
             // Get the client type from the given questions
             $questionPassOn = array();
             foreach ($questionFields as $singleQuestion) {
                 $questionPassOn[$singleQuestion] = Input::get($singleQuestion, null);
                 $questionPassOn[str_replace('form-q', 'form-e', $singleQuestion)] = Input::get(str_replace('form-q', 'form-e', $singleQuestion), null);
             }
             \log::write('PPI-DEBUG', \Format::forge($_GET)->to_json());
             $clientType = \Crm\Portal\Portal_Check::choice($questionPassOn, $_GET, $apiKey);
             // If we can decide on a client type
             if (!is_null($clientType)) {
                 $this->response(array('client_type' => $clientType));
             } else {
                 $this->response(array('status' => 'FAIL', 'message' => 'No client type could be decided. Please complete ALL the given questions.'));
             }
         } else {
             $this->response(array('status' => 'FAIL', 'code' => '101', 'message' => 'Not all required fields were submitted! Missing fields are ' . implode(", ", $missingFields), 'missing_fields' => $missingFields));
         }
     }
 }
Esempio n. 17
0
 public static function ucenter_order()
 {
     $siteConfig = new Config('site_config');
     $order_cancel_time = $siteConfig->order_cancel_time !== "" ? intval($siteConfig->order_cancel_time) : 7;
     $order_finish_time = $siteConfig->order_finish_time !== "" ? intval($siteConfig->order_finish_time) : 20;
     $orderModel = new IModel('order');
     $orderCancelData = $order_cancel_time >= 0 ? $orderModel->query(" if_del = 0 and pay_type != 0 and status in(1) and datediff(NOW(),create_time) >= {$order_cancel_time} ", "id,order_no,4 as type_data") : array();
     $orderCreateData = $order_finish_time >= 0 ? $orderModel->query(" if_del = 0 and distribution_status = 1 and status in(1,2) and datediff(NOW(),send_time) >= {$order_finish_time} ", "id,order_no,5 as type_data") : array();
     $resultData = array_merge($orderCreateData, $orderCancelData);
     if ($resultData) {
         foreach ($resultData as $key => $val) {
             $type = $val['type_data'];
             $order_id = $val['id'];
             $order_no = $val['order_no'];
             //oerder表的对象
             $tb_order = new IModel('order');
             $tb_order->setData(array('status' => $type, 'completion_time' => ITime::getDateTime()));
             $tb_order->update('id=' . $order_id);
             //生成订单日志
             $tb_order_log = new IModel('order_log');
             //订单自动完成
             if ($type == '5') {
                 $action = '完成';
                 $note = '订单【' . $order_no . '】完成成功';
                 //完成订单并且进行支付
                 Order_Class::updateOrderStatus($order_no);
                 //增加用户评论商品机会
                 Order_Class::addGoodsCommentChange($order_id);
                 $logObj = new log('db');
                 $logObj->write('operation', array("系统自动", "订单更新为完成", '订单号:' . $order_no));
             } else {
                 $action = '作废';
                 $note = '订单【' . $order_no . '】作废成功';
                 //订单重置取消
                 Order_class::resetOrderProp($order_id);
                 $logObj = new log('db');
                 $logObj->write('operation', array("系统自动", "订单更新为作废", '订单号:' . $order_no));
             }
             $tb_order_log->setData(array('order_id' => $order_id, 'user' => "系统自动", 'action' => $action, 'result' => '成功', 'note' => $note, 'addtime' => ITime::getDateTime()));
             $tb_order_log->add();
         }
     }
 }
Esempio n. 18
0
 /**
  * 写入日志并且更新账户余额
  * @param array $config config数据类型
  * @return string|bool
  */
 public function write($config)
 {
     if (isset($config['user_id'])) {
         $this->setUser($config['user_id']);
     } else {
         throw new IException("用户信息不存在");
     }
     isset($config['seller_id']) ? $this->setSeller($config['seller_id']) : "";
     isset($config['admin_id']) ? $this->setAdmin($config['admin_id']) : "";
     isset($config['event']) ? $this->setEvent($config['event']) : "";
     if (isset($config['num']) && is_numeric($config['num'])) {
         $this->amount = abs(round($config['num'], 2));
         //金额正负值处理
         if (in_array($this->allow_event[$this->event], array(2, 3))) {
             $this->amount = '-' . abs($this->amount);
         }
     } else {
         throw new IException("金额必须大于0元");
     }
     $this->config = $config;
     $this->noteData = isset($config['note']) ? $config['note'] : $this->note();
     //写入数据库
     $finnalAmount = $this->user['balance'] + $this->amount;
     if ($finnalAmount < 0) {
         throw new IException("用户余额不足");
     }
     $memberDB = new IModel('member');
     $memberDB->setData(array("balance" => $finnalAmount));
     $memberDB->update("user_id = " . $this->user['id']);
     $tb_account_log = new IModel("account_log");
     $insertData = array('admin_id' => $this->admin ? $this->admin['id'] : 0, 'user_id' => $this->user['id'], 'event' => $this->allow_event[$this->event], 'note' => $this->noteData, 'amount' => $this->amount, 'amount_log' => $finnalAmount, 'type' => $this->amount >= 0 ? 0 : 1, 'time' => ITime::getDateTime());
     $tb_account_log->setData($insertData);
     $result = $tb_account_log->add();
     //后台管理员操作记录
     if ($insertData['admin_id']) {
         $logObj = new log('db');
         $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "对账户金额进行了修改", $insertData['note']));
     }
     return $result;
 }
Esempio n. 19
0
 /**
  * Автооплата услуги
  *
  * @param $sum
  * @return bool|mixed
  */
 public function payment($sum)
 {
     $this->createOrder($sum);
     $this->api->getAccessData('autopay');
     $result = $this->api->register($sum, $this->orderNumber, $this->account->id);
     if ($result['orderId'] != '') {
         walletAlpha::updateOrder($this->orderNumber, array('order_id' => $result['orderId'], 'state' => walletAlpha::STATE_NEW));
         $payment = $this->api->paymentOrderBinding($result['orderId']);
         switch ($payment['errorCode']) {
             case API_AlphaBank::STATUS_SUCCESS:
                 $status = $this->api->getOrderStatus($result['orderId']);
                 $update = array('pan' => $status['Pan'], 'expiration' => $status['expiration'], 'cardholder_name' => $status['cardholderName'], 'ip' => $status['Ip'], 'binding_id' => Wallet::des()->encrypt($status['bindingId']));
                 $update['state'] = $this->deposit($this->account, $this->account->id, $status, $this->data['wallet'], $this->orderNumber, $sum);
                 $this->updateOrder($this->orderNumber, $update);
                 break;
             default:
                 // Ошибка оплаты
                 ob_start();
                 var_dump($result);
                 var_dump($payment);
                 $content = ob_get_clean();
                 $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
                 $this->log->write("Request:\n " . $this->api->last_request->getBody());
                 $this->log->write("Result:\n {$content}");
                 return false;
                 break;
         }
     } else {
         ob_start();
         var_dump($result);
         $content = ob_get_clean();
         $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
         $this->log->write("Request:\n " . $this->api->last_request->getBody());
         $this->log->write("Result:\n {$content}");
         return false;
         //error
     }
 }
Esempio n. 20
0
 function _write_file(&$log_file_data, $string, $verbosity_level)
 {
     if (!log::write($log_file_data, $string)) {
         $this->set_log_file_enabled(false, $verbosity_level);
     }
 }
Esempio n. 21
0
 public function log()
 {
     log::write('写入日志测试');
     echo '日志已写入,在SAE平台请在日志中心查看(选择debug类型);在本地环境请在' . LOG_PATH . '查看';
 }
Esempio n. 22
0
 function withdraw_status()
 {
     $id = IFilter::act(IReq::get('id'), 'int');
     $re_note = IFilter::act(IReq::get('re_note'), 'string');
     if ($id) {
         $withdrawObj = new IModel('withdraw');
         $dataArray = array('re_note' => $re_note);
         if (IReq::get('status') !== NULL) {
             $dataArray['status'] = IFilter::act(IReq::get('status'), 'int');
         }
         $withdrawObj->setData($dataArray);
         $where = "`id`= {$id} AND `status` = 0";
         $re = $withdrawObj->update($where);
         $this->withdraw_detail(true);
         if ($re != 0) {
             $logObj = new log('db');
             $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "修改了提现申请", "ID值为:" . $id));
         }
         Util::showMessage("更新成功");
     } else {
         $this->redirect('withdraw_list');
     }
 }
Esempio n. 23
0
 /**
  * @brief 彻底删除会员
  */
 function member_del()
 {
     $user_ids = IReq::get('check');
     $user_ids = is_array($user_ids) ? $user_ids : array($user_ids);
     $user_ids = IFilter::act($user_ids, 'int');
     if ($user_ids) {
         $ids = implode(',', $user_ids);
         if ($ids) {
             $tb_member = new IModel('member');
             $where = "user_id in (" . $ids . ")";
             $tb_member->del($where);
             $tb_user = new IModel('user');
             $where = "id in (" . $ids . ")";
             $tb_user->del($where);
             $logObj = new log('db');
             $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "删除了用户", "被删除的用户ID为:" . $ids));
         }
     }
     $this->redirect('member_list');
 }
Esempio n. 24
0
 function _write_file($file_name, $debug_info)
 {
     if (!log::write($file_name, debug::_parse_text_debug_info($debug_info))) {
         $this->set_log_file_enabled(false, $debug_info['level']);
     }
 }
Esempio n. 25
0
 /**
  * Покупка списка услуг ожидающих оплаты
  * 
  * @todo: рекомендуется не использовать данный метод
  * 
  * @param integer $gid     Ид пользователя
  * @param integer $op_code Ид услуги
  */
 public function buyOrdersList($gid, $op_code, $login = "")
 {
     $log = new log("billing/deposit-" . SERVER . '-%d%m%Y.log', 'a', "%d.%m.%Y %H:%M:%S:\r\n");
     $log->writeln("deposit: login:{$login}, uid:{$gid}, code:{$op_code}\r\n");
     if (!$gid) {
         return false;
     }
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/billing.php';
     session_start();
     $this->GetInfo($gid);
     $ac_sum = $this->sum;
     $log->write("start account_sum:{$ac_sum}\r\n");
     if (in_array($op_code, billing::$op_code_transfer_money)) {
         // Деньги поступают на счет смотрим что можно оплатить
         $bill = new billing($gid);
         $reserve_operations = $bill->getReserveOperationsByStatus();
         if (!empty($reserve_operations)) {
             ob_start();
             var_dump($reserve_operations);
             $out = ob_get_clean();
             $log->write($out . "\r\n");
             //$mail_reserved = array();
             $reserved_ids = array_map(create_function('$array', 'return $array["id"];'), $reserve_operations);
             $bill->startReserved($reserved_ids);
             // Блокируем услуги для изменений
             foreach ($reserve_operations as $reserve) {
                 //$ret[$reserve['id']] = $reserve;
                 $log->write("reserve {$reserve['id']} : {$ac_sum} >= {$reserve['ammount']}\r\n");
                 //if($ac_sum >= $reserve['ammount']) { // Пытаемся оплатить список услуг
                 //$mail_reserved[] = $reserve['id'];
                 $bill->transaction = $bill->account->start_transaction($bill->user['uid'], 0);
                 $success = $bill->completeOrders($reserve['id']);
                 $log->write("{$reserve['id']} ({$reserve['ammount']}) : {$success}\r\n");
                 if ($success) {
                     $bill->account->commit_transaction($bill->transaction, $bill->user['uid'], NULL);
                     $ac_sum = $ac_sum - $reserve['ammount'];
                 }
                 $log->write("set account_sum: {$ac_sum}\r\n---\r\n");
                 //}
             }
             $bill->stopReserved($reserved_ids);
             // Разблокируем услуги для изменений
             $log->write("done\r\n---------------------------------\r\n\r\n");
             /*
             require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/smail.php');
             if (substr($bill->user['subscr'], 15, 1) == 1) {
                 //$smail = new smail();
                 //$smail->sendReservedOrders($ret, $mail_reserved);
             }
             */
         }
         $_SESSION['ac_sum'] = $ac_sum;
     }
 }
Esempio n. 26
0
  function _writeFile($file_name, $debug_info)
  {
    include_once(LIMB_DIR . '/core/util/Log.class.php');

    if (!log :: write($file_name, Debug :: _parseTextDebugInfo($debug_info)))
      $this->setLogFileEnabled(false, $debug_info['level']);
  }
Esempio n. 27
0
 /**
  * 添加订单
  */
 function do_add()
 {
     /*权限检查*/
     role::check('order_add');
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim');
         $post->add_rules('shipping_firstname', 'required', 'length[1,200]');
         $post->add_rules('shipping_lastname', 'required', 'length[1,200]');
         $post->add_rules('shipping_country', 'required', 'length[1,200]');
         $post->add_rules('shipping_state', 'length[1,200]');
         $post->add_rules('shipping_city', 'required', 'length[1,200]');
         $post->add_rules('shipping_address', 'required', 'length[1,200]');
         $post->add_rules('shipping_zip', 'required', 'length[1,200]');
         $post->add_rules('shipping_phone', 'required', 'length[1,200]');
         $post->add_rules('shipping_mobile', 'length[1,200]');
         $post->add_rules('billing_firstname', 'length[1,200]');
         $post->add_rules('billing_lastname', 'length[1,200]');
         $post->add_rules('billing_country', 'length[1,200]');
         $post->add_rules('billing_state', 'length[1,200]');
         $post->add_rules('billing_city', 'length[1,200]');
         $post->add_rules('billing_address', 'length[1,200]');
         $post->add_rules('billing_zip', 'length[1,200]');
         $post->add_rules('billing_phone', 'length[1,200]');
         $post->add_rules('billing_mobile', 'length[1,200]');
         $post->add_rules('good_price', 'required', 'length[1,200]');
         $post->add_rules('shipping_price', 'required', 'length[1,200]');
         if (!$post->validate()) {
             $errors = $post->errors();
             log::write('form_error', $errors, __FILE__, __LINE__);
             remind::set(Kohana::lang('o_order.user_address_wrong'), 'order/order_add/add_again', 'error');
         }
         /* 添加主订单详情*/
         $order_data = array();
         $user_id = $this->input->post('user_id');
         $email = $this->input->post('email');
         $carrier = $this->input->post('carrier');
         $currency_code = $this->input->post('code');
         if ($user_id && $email && $currency_code) {
             /* 订单用户信息*/
             $order_data['user_id'] = $user_id;
             $order_data['email'] = $email;
             /* 订单币种信息*/
             $currency = Mycurrency::instance()->get_by_code($currency_code);
             $order_data['currency'] = $currency_code;
             $order_data['conversion_rate'] = $currency['conversion_rate'];
             /* 订单国家*/
             $order_data['shipping_country'] = Mycountry::instance($post->shipping_country)->get('iso_code');
             $order_data['billing_country'] = Mycountry::instance($post->billing_country)->get('iso_code');
             /* 订单时间和IP信息*/
             $order_data['data_add'] = date('Y-m-d H:i:s', time());
             $order_data['IP'] = tool::get_long_ip();
             /* 订单号生成*/
             $order_num = '';
             do {
                 $temp = sprintf("%14.0f", date('ymd') . "00000" + rand(0, 99999) . "0000");
                 $exist_data = array();
                 $exist_data['order_num'] = $temp;
                 if (!Myorder::instance()->exist($exist_data)) {
                     $order_num = $temp;
                     break;
                 }
             } while (1);
             $order_data['order_num'] = $order_num;
             $order_data['order_status'] = '1';
             $order_data['pay_status'] = '1';
             $order_data['ship_status'] = '1';
             $order_data['user_status'] = 'NULL';
             $order_data['order_source'] = 'manual';
             $order_data['total'] = $post->good_price + $post->shipping_price;
             $order_data['total_products'] = $post->good_price;
             $order_data['total_shipping'] = $post->shipping_price;
             $order_data['total_real'] = $order_data['total'] / $order_data['conversion_rate'];
             $order_data['total_discount'] = '0.00';
             $order_data['total_paid'] = '0.00';
             $order_data['shipping_firstname'] = $post->shipping_firstname;
             $order_data['shipping_lastname'] = $post->shipping_lastname;
             $order_data['shipping_state'] = $post->shipping_state;
             $order_data['shipping_city'] = $post->shipping_city;
             $order_data['shipping_address'] = $post->shipping_address;
             $order_data['shipping_zip'] = $post->shipping_zip;
             $order_data['shipping_phone'] = $post->shipping_phone;
             $order_data['shipping_mobile'] = $post->shipping_mobile;
             $order_data['billing_firstname'] = $post->billing_firstname;
             $order_data['billing_lastname'] = $post->billing_lastname;
             $order_data['billing_state'] = $post->billing_state;
             $order_data['billing_city'] = $post->billing_city;
             $order_data['billing_address'] = $post->billing_address;
             $order_data['billing_zip'] = $post->billing_zip;
             $order_data['billing_phone'] = $post->billing_phone;
             $order_data['billing_mobile'] = $post->billing_mobile;
             $order_data['carrier'] = $carrier;
             $order_data['active'] = 1;
         } else {
             remind::set(Kohana::lang('o_order.data_trans_wrong'), 'order/order_add', 'error');
         }
         /* 添加订单,返回订单数据*/
         $order_id = Myorder::instance()->add($order_data);
         $order = Myorder::instance($order_id)->get();
         /* 添加订单产品信息*/
         $session = Session::instance();
         $cart_data = $session->get('cart_data');
         if (isset($cart_data) && is_array($cart_data) && count($cart_data) && !empty($order['order_num'])) {
             foreach ($cart_data as $key => $rs) {
                 $good_full_data = ProductService::get_instance()->get($key);
                 $order_product_detail_data = array();
                 $order_product_detail_data['order_id'] = $order['id'];
                 $order_product_detail_data['product_type'] = ProductService::PRODUCT_TYPE_GOODS;
                 $order_product_detail_data['dly_status'] = 'storage';
                 //$order_product_detail_data['product_id']            = $good_full_data['product_id'];
                 $order_product_detail_data['good_id'] = $key;
                 $order_product_detail_data['quantity'] = $rs;
                 $order_product_detail_data['sendnum'] = '0';
                 $order_product_detail_data['price'] = $good_full_data['price'];
                 $order_product_detail_data['discount_price'] = $good_full_data['price'];
                 $order_product_detail_data['weight'] = $good_full_data['weight'];
                 //$order_product_detail_data['name']                = $good_full_data['name_manage'];
                 $order_product_detail_data['name'] = $good_full_data['title'];
                 $order_product_detail_data['SKU'] = $good_full_data['sku'];
                 $order_product_detail_data['brief'] = $good_full_data['brief'];
                 $order_product_detail_data['date_add'] = date('Y-m-d H:i:s', time());
                 $order_product_detail_data['link'] = product::permalink($good_full_data);
                 order::do_order_product_detail_data_by_good(&$order_product_detail_data, $good_full_data, $good_full_data['default_image_id']);
                 $order_product_detail = Myorder_product::instance()->add($order_product_detail_data);
             }
         }
         /*验证是否添加成功,添加成功返回订单号*/
         if (!empty($order['order_num']) && $order_product_detail) {
             remind::set(Kohana::lang('o_order.add_order_success') . $order['order_num'], 'order/order', 'success');
         } else {
             remind::set(Kohana::lang('o_order.add_order_wrong'), 'order/order_add', 'error');
         }
     }
 }
Esempio n. 28
0
 /**
  * 连接Redis
  * @access private
  */
 private function connectRedis()
 {
     $host = $this->options['server'];
     $hostArr = is_array(current($host)) ? $host : array($host);
     foreach ($hostArr as $h) {
         $_host = isset($h['host']) ? $h['host'] : "127.0.0.1";
         //主机
         $_port = isset($h['port']) ? $h['port'] : 6379;
         //端口
         $_pconnect = isset($h['pconnect']) ? $h['pconnect'] : 1;
         //持久连接
         $_password = isset($h['password']) ? $h['password'] : null;
         //密码
         $_timeout = isset($h['timeout']) ? $h['timeout'] : 1;
         //连接超时
         $_db = isset($h['Db']) ? $h['Db'] : 0;
         //数据库
         try {
             $this->RedisObj[$_host] = new Redis();
             $linkFunc = $_pconnect ? "pconnect" : "connect";
             //是否持久连接
             $this->RedisObj[$_host]->{$linkFunc}($_host, $_port, $_timeout);
             if ($_password) {
                 if (!$this->RedisObj[$_host]->auth($_password)) {
                     throw new Exception();
                 }
             }
             $this->RedisObj[$_host]->select($_db);
         } catch (Exception $e) {
             if (C("DEBUG")) {
                 throw_exception("Redis{$_host} connection fails");
             }
             log::write($e->getMessage());
         }
     }
 }
Esempio n. 29
0
 /**
  * Оплачиваем услуг
  *
  * @param float   $sum          Сумма услуги
  * @return bool|mixed|null
  */
 public function payment($sum)
 {
     // На бете альфе включаем дебаг режим
     if (!is_release()) {
         $this->api->setDebug(true);
     }
     $result = $this->api->requestPayment(round((double) $sum, 2), $this->account->id);
     if ($result['status'] == API_Yandex::STATUS_SUCCESS) {
         // не откуда взять csc
         //            foreach($result['money_source'] as $name=>$value) {
         //                // Первый доступный метод оплаты
         //                if($value['allowed'] == true) {
         //                    $money_source = $name;
         //                    break;
         //                }
         //            }
         // Для беты сумму баланса не проверяем
         if (($result['balance'] > $sum || !is_release()) && $result['request_id'] != '') {
             $process = $this->api->processPayment($result['request_id']);
             switch ($process['status']) {
                 case API_Yandex::STATUS_SUCCESS:
                     // Зачисляем деньги на бете/альфе
                     if (!is_release()) {
                         $paymentDateTime = date('d.m.Y H:i');
                         $orderNumber = rand(1, 99999999);
                         $descr = "ЯД с кошелька {$this->data['wallet']} сумма - {$sum}, обработан {$paymentDateTime}, номер покупки - {$orderNumber}";
                         $this->account->deposit($op_id, $this->account->id, $sum, $descr, 3, $sum, 12);
                     }
                     return true;
                     break;
                 case API_Yandex::STATUS_FAIL:
                     ob_start();
                     var_dump($result);
                     var_dump($process);
                     $content = ob_get_clean();
                     $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
                     $this->log->write("Request:\n " . $this->api->last_request->getBody());
                     $this->log->write("Result:\n {$content}");
                     return false;
                     break;
                     // Отложить платеж на пол часа
                     // @todo придумать как отложить запрос на потом
                 // Отложить платеж на пол часа
                 // @todo придумать как отложить запрос на потом
                 case API_Yandex::STATUS_PROCESS:
                 default:
                     return null;
                     break;
             }
         } else {
             ob_start();
             var_dump($result);
             $content = ob_get_clean();
             $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
             $this->log->write("Request:\n " . $this->api->last_request->getBody());
             $this->log->write("Result:\n {$content}");
             return false;
             //error
         }
     } else {
         ob_start();
         var_dump($result);
         $content = ob_get_clean();
         $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
         $this->log->write("Request:\n " . $this->api->last_request->getBody());
         $this->log->write("Result:\n {$content}");
         return false;
     }
 }
Esempio n. 30
0
 public function delete($request_data)
 {
     $id = is_array($request_data) ? $request_data['id'] : $request_data;
     $orm_instance = ORM::factory($this->object_name, $id);
     //if($orm_instance->loaded && $orm_instance->disabled)
     if ($orm_instance->loaded) {
         //$orm_instance->disabled     = true;
         //$orm_instance->save();
         $orm_instance->delete();
         return TRUE;
     } else {
         $error = 'Data load failed , object : ' . $this->object_name . ' , id : ' . $id;
         log::write('alert', $error, __FILE__, __LINE__);
         return FALSE;
     }
 }