public function balance_op() { $user_id = Filter::int(Req::args('user_id')); $type = Filter::int(Req::args('type')); $amount = Filter::float(Req::args('amount')); //事件类型: 0:订单支付 1:用户充值 2:管理员充值 3:提现 4:退款到余额 $model = new Model("customer"); $obj = $model->where("user_id={$user_id}")->find(); $info = array('status' => 'fail'); $range = 1000000000 - $obj['balance']; if ($obj && $amount > 0 && $amount <= $range) { if ($type == 2) { $model->data(array('balance' => "`balance`+" . $amount))->where("user_id={$user_id}")->update(); Log::balance($amount, $user_id, '管理员为您充值,充值的金额为:' . $amount, 2, $this->manager['id']); $info = array('status' => 'success', 'msg' => '充值成功。'); } else { if ($type == 4) { $model->data(array('balance' => "`balance`+" . $amount))->where("user_id={$user_id}")->update(); Log::balance($amount, $user_id, '管理员退款到您的余额中,退款金额为:' . $amount, 4, $this->manager['id']); $info = array('status' => 'success', 'msg' => '退款成功。'); } } } else { $info = array('status' => 'fail', 'msg' => '此用户可充值的金额范围0.01-' . sprintf("%01.2f", $range)); } echo JSON::encode($info); }
public function withdraw() { Filter::form(); $account = floatval(Req::args('account')); $name = Filter::txt(Req::args('name')); $type_name = Filter::txt(Req::args('type_name')); $account = Filter::txt(Req::args('account')); $amount = Filter::float(Req::args('amount')); $info = array('status' => 'success', 'msg' => '申请成功.'); $model = new Model('customer'); $customer = $model->where("user_id=" . $this->user['id'])->find(); if ($customer['balance'] < $amount) { $info = array('status' => 'fail', 'msg' => '提现金额超出的账户余额'); } $obj = $model->table("withdraw")->where("user_id=" . $this->user['id'] . ' and status=0')->find(); if ($obj) { $info = array('status' => 'fail', 'msg' => '上次申请的提现,还未处理,处理后才可再申请。'); } else { $data = array('name' => $name, 'type_name' => $type_name, 'account' => $account, 'amount' => $amount, 'time' => date('Y-m-d H:i:s'), 'user_id' => $this->user['id']); $model->table("withdraw")->data($data)->insert(); } echo JSON::encode($info); }
/** * @param string $value * @param int $round * @return float * * @deprecated See JBZoo\Utils\Filter */ public static function float($value, $round = 10) { return Filter::float($value, $round); }
/** * Converts the type of values like "true", "false", "null" or "123". * * @param string $value * @param int $options * @return mixed */ public static function convert($value, $options = self::VAR_STRING) { $options = (int) $options; if ($options & self::VAR_STRING && !empty($value)) { return trim(Filter::stripQuotes($value)); } if ($options & self::VAR_FLOAT) { return Filter::float($value, 12); } if ($options & self::VAR_INT) { return Filter::int($value); } if ($options & self::VAR_BOOL || $options & self::VAR_NULL) { if (null === $value || 'null' === strtolower(trim($value))) { return null; } return Filter::bool($value); } return (string) $value; }
public function doPay() { // 获得payment_id 获得相关参数 $payment_id = Filter::int(Req::args('payment_id')); $order_id = Filter::int(Req::args('order_id')); $recharge = Req::args('recharge'); $extendDatas = Req::args(); if ($payment_id) { $payment = new Payment($payment_id); $paymentPlugin = $payment->getPaymentPlugin(); //充值处理 if ($recharge != null) { $recharge = Filter::float($recharge); $paymentInfo = $payment->getPayment(); $data = array('account' => $recharge, 'paymentName' => $paymentInfo['name']); $packData = $payment->getPaymentInfo('recharge', $data); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); } else { if ($order_id != null) { $order = Order::getOrder($order_id); $model = new Model("order_goods"); if ($order) { //获取订单可能延时时长,0不限制 $config = Config::getInstance(); $config_other = $config->get('other'); // todo 修改方法 order type 去掉 详情表中记录 order type switch ($order['type']) { case '1': $order_delay = isset($config_other['other_order_delay_group']) ? intval($config_other['other_order_delay_group']) : 120; break; case '2': $order_delay = isset($config_other['other_order_delay_flash']) ? intval($config_other['other_order_delay_flash']) : 120; break; case '3': $order_delay = isset($config_other['other_order_delay_bund']) ? intval($config_other['other_order_delay_bund']) : 0; break; default: $order_delay = isset($config_other['other_order_delay']) ? intval($config_other['other_order_delay']) : 0; break; } $time = strtotime("-" . $order_delay . " Minute"); $create_time = strtotime($order['create_time']); if ($create_time >= $time || $order_delay == 0) { //取得所有订单商品 //$order_goods = $model->table('order_goods')->fields("product_id,goods_nums, prom_type")->where('order_id='.$order_id)->findAll(); $order_goods_inst = new OrderGoods(); $order_goods = $order_goods_inst->getOrderGoods($order_id); $product_ids = array(); $order_products = array(); // todo 这里判断 prom_type 类型 foreach ($order_goods as $value) { // 套餐不在这里检查商品库存 考虑在别的地方检查 // 如果订单详细表中行是由于捆绑促销 if ($value['prom_type'] == 'bundling') { continue; } else { $product_ids[] = $value['product_id']; $order_products[$value['product_id']] = $value['goods_nums']; } } $packData = $payment->getPaymentInfo('order', $order_id); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); /* 这里不需要验证库存量 提交订单时已经验证 if (!empty($product_ids)) { $product_ids = implode(',', $product_ids); $products = $model->table('products')->fields("id,store_nums")->where("id in ($product_ids)")->findAll(); $products_list = array(); foreach ($products as $value) { $products_list[$value['id']] = $value['store_nums']; } $flag = true; foreach ($order_goods as $value) { if ($order_products[$value['product_id']] > $products_list[$value['product_id']]) { $flag = false; break; } } //检测库存是否还能满足订单 if ($flag) { //团购订单 if ($order['type'] == 1 || $order['type'] == 2) { if ($order['type'] == 1) { $prom_name = '团购'; $prom_table = "groupbuy"; } else { $prom_name = '抢购'; $prom_table = "flash_sale"; } $prom = $model->table($prom_table)->where("id=" . $order['prom_id'])->find(); if ($prom) { if (time() > strtotime($prom['end_time']) || $prom['max_num'] <= $prom["goods_num"]) { $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,' . $prom_name . "活动已结束。")); exit; } } } $packData = $payment->getPaymentInfo('order', $order_id); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); } else { $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,库存已不足。')); exit; } } */ } else { $model->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '订单超出了规定时间内付款,已作废.')); exit; } } } } if (!empty($sendData)) { $this->assign("paymentPlugin", $paymentPlugin); $this->assign("sendData", $sendData); $this->redirect('pay_form', false); } else { $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '需要支付的订单已经不存在。')); } } else { echo "fail"; } }
/** * 记录加载css,js时间 * * @author mrmsl <*****@*****.**> * @date 2012-09-06 17:15:16 * @lastmodify 2013-01-21 16:52:19 by mrmsl * * @return object this */ public function logLoadTimeAction() { if (!$this->_admin_info) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('CONTROLLER_NAME_ADMIN,IS_EMPTY'); trigger_error($log, E_USER_ERROR); return $this; } $load_css_time = Filter::float('load_css_time'); //加载css样式时间 $load_ext_time = Filter::float('load_ext_time'); //加载extjs.js时间 $load_js_time = Filter::float('load_js_time'); //加载其它js时间 $app_launch_time = Filter::float('app_launch_time'); //创建应用程序时间 $total_time = $load_css_time + $load_ext_time + $load_js_time + $app_launch_time; $app_launch_time = $app_launch_time ? ', app_launch_time => ' . $app_launch_time : ''; //管理中心才会有 $log = get_method_line(__METHOD__, __LINE__, LOG_LOAD_SCRIPT_TIME) . "total_time => {$total_time}{$app_launch_time}, load_ext_time => {$load_ext_time}, load_css_time => {$load_css_time}, load_js_time => {$load_js_time}"; trigger_error($log, E_USER_ERROR); return $this; }
public function checkProductTax() { $ship_id = Req::args("ship_id"); $real_price = Filter::float(Req::args("real_price")); $tax_type_percent = Filter::float(Req::args("tax_type_percent")); $num = Filter::int(Req::args("num")); $tax_amount = $this->checkProductTax_p($ship_id, $real_price, $tax_type_percent, $num); $data = array('taxAmount' => $tax_amount); echo JSON::encode($data); }