/** * 下订单 * 判断是否是POST提交 * 如果是POST提交则进行下单操作 * 否则 提示错误 * * * @author 李东 * @date 2015-07-09 */ public function add_order() { if (IS_POST) { $posts = I('post.'); // print_r($posts);exit; /* 获取当前登录的用户的ID */ $member_id = session('home_member_id'); $rules = array(array('qty', '/^[1-9]\\d*(\\.\\d+)?$/', '数量必须大于1', 'regex')); // 默认情况下用正则进行验证 if (!$posts['agree']) { $tips_msg = array('status' => '0', 'msg' => '请同意保密协议'); goto export; /* 直接跳转到输出位置 */ } /* 如果需要发票,判断发票信息是否填写 */ if ($posts['need_invoice']) { if (empty(trim($posts['invoice']))) { $tips_msg = array('status' => '0', 'msg' => '请填写发票抬头'); goto export; } if (intval($posts['address_id']) < 1) { $tips_msg = array('status' => '0', 'msg' => '请选择发票寄送地址'); goto export; } } $product_info = get_info($this->product_table, array('id' => $posts['product_id'])); $shop_id = $product_info['shop_id']; /* 获取店铺ID */ $product_type = $product_info['type']; /* 获取产品类型 */ $address_path = ''; $area_detail = ''; $product_title = $product_info['title']; /*获取产品title*/ $product_description = array(); if (empty($posts['expected_start_time']) || empty($posts['expected_end_time'])) { $tips_msg = array('status' => '0', 'msg' => '请填写完整预约服务时间'); goto export; } if ($posts['expected_start_time'] >= $posts['expected_end_time']) { $tips_msg = array('status' => '0', 'msg' => '结束时间必须大于开始时间'); goto export; } if ($product_type == 37) { /* 判断是否填写了详细信息 */ if (empty(trim($posts['area_detail']))) { $tips_msg = array('status' => '0', 'msg' => '请填写详细地址'); goto export; } elseif (empty($posts['addpath'])) { $tips_msg = array('status' => '0', 'msg' => '请选择服务地址'); goto export; } else { /* 选择服务地址的path */ $address_path = $posts['addpath'] . $posts['area']; $area_detail = $posts['area_detail']; } } else { if (!$posts['language_sbt']) { $tips_msg = array('status' => '0', 'msg' => '请选择翻译模式'); goto export; } /* 判断文件用途 */ if ($posts['ability_id'] == 'other') { $description = $posts['ability_other']; $product_description['ability_other'] = $description; } elseif (is_numeric($posts['ability_id'])) { $product_description['ability_id'] = $posts['ability_id']; } else { $tips_msg = array('status' => '0', 'msg' => '请选择服务领域或文件领域'); goto export; } } /* 判断专业领域 */ if ($posts['industry_id'] == 'other') { $description = $posts['industry_other']; $product_description['industry_other'] = $description; } elseif (is_numeric($posts['industry_id'])) { $product_description['industry_id'] = $posts['industry_id']; } else { $tips_msg = array('status' => '0', 'msg' => '请选择服务领域或文件领域'); goto export; } $expired_time = date('Y-m-d H-i-s', time() + intval(C('TIME_LEFT')) * 24 * 3600); /* 计算失效时间 */ /* 判断音频翻译是否填网址或者上传文件 */ if ($product_type != 37) { if (empty($posts['save_path']) && !$posts['files_url']) { $tips_msg = array('status' => '0', 'msg' => '请上传要翻译的文件'); goto export; } } /* 计算数量(千字/小时) */ $qty = floatval($posts['qty']); $total_price = $qty * $product_info['price']; /* 计算总价 */ $order_num = get_order_num(intval($shop_id), intval($member_id)); // dump($address_path);die; $_POST = array('title' => $product_title, 'order_num' => $order_num, 'member_id' => $member_id, 'shop_id' => $posts['shop_id'], 'product_id' => $posts['product_id'], 'qty' => $qty, 'product_type' => $product_type, 'total_price' => $total_price, 'status' => '1', 'expired_time' => $expired_time, 'description' => $posts['description'], 'product_description' => json_encode($product_description), 'address_id' => $posts['address_id'], 'requirements' => $posts['language_sbt'], 'is_need_invoice' => $posts['need_invoice'], 'step' => 1, 'address_path' => $address_path, 'area_detail' => $area_detail, 'expected_start_time' => $posts['expected_start_time'], 'expected_end_time' => $posts['expected_end_time'], 'invoice' => $posts['invoice'], 'address_id' => $posts['address_id'], 'files_url' => $posts['files_url'], 'is_confirm_price' => '1'); /* 开启事务 */ $Model = M(); $Model->startTrans(); $result1 = update_data($this->table, $rules); if (is_numeric($result1)) { $_POST = array('order_id' => $result1, 'order_status' => 1, 'description' => '下单成功'); $result2 = update_data($this->history_table); if (!empty($posts['save_path'])) { /* 判断是否提交了文件 */ //multi_file_upload($posts['save_path'],'Uploads/UserFiles/'.$member_id,'files','order_id',$result1,'save_path'); $data_array = array(); foreach ($posts['save_path'] as $val) { if (!empty(intval($val))) { $data_array[$val] = array("title" => $posts["filename_" . $val], "order_id" => $result1, "member_id" => $member_id, "shop_id" => $posts['shop_id'], "description" => $posts['description']); } } multi_file_uploads($posts['save_path'], 'Uploads/UserFiles/' . $member_id, 'files', $data_array, 'save_path'); } /*发送订单消息*/ $result3 = order_msg_send($member_id, $result1, $order_num, $shop_id); if (is_numeric($result1) && is_numeric($result2) && is_numeric($result3)) { /*提交事务*/ $Model->commit(); /*@刘巧 给订单用户发送短信 */ $shop_info = get_info('shop', array('shop_id' => $posts['shop_id']), array('title')); $content = C('ORDSUCCESS'); $content2 = C('MESSAGE_SHOP'); $content = str_replace("(0)", $total_price, $content); //替换金额; $content = str_replace("(1)", $shop_info['title'], $content); //替换商家电铺字符串 $content2 = str_replace("(0)", $total_price, $content2); //替换订单用户字符串 $content2 = str_replace("(2)", session('username'), $content2); //替换订单用户字符串 $account = session('home_member_tel'); $stauts1 = send_code($content, $account); /*@liuqiao 给商家用户发送短信*/ $stauts2 = send_code($content1, $account1); $tips_msg = array('status' => '1', 'msg' => '下单成功', 'order_id' => $result1); } else { /*事务回滚*/ $Model->rollback(); $tips_msg = array('status' => '0', 'msg' => '下单失败'); } } else { $tips_msg = array('status' => '0', 'msg' => $result1); } } else { $tips_msg = array('status' => '0', 'msg' => '错误请求'); } export: /*判断需要展示的web提示信息*/ if ($tips_msg['status']) { $this->success($tips_msg['msg'], U('/Home/Buy/confirm_quote', array('order_id' => $tips_msg['order_id']))); } else { $this->error($tips_msg['msg']); } }
/** * 在线支付 * 先判断是否是在线充值,在线支付订单需要有订单号; * 查询出订单信息之后将必需信息提交到支付宝; * * 在线充值需在先生成订单信息,然后再将必需信息提交到支付宝; * */ public function index() { if (IS_POST) { $member_id = session('home_member_id'); /*获取充值用户ID*/ if (!$member_id) { $this->error('请登录后在操作', U('/User/Login/index')); } /*接收参数*/ $posts = I('post.'); $order_id = $posts['order_id']; /*获取订单ID*/ $paytype = $posts['pay_type']; /*获取支付方式*/ if ($order_id) { /*判断是订单支付还是在线充值*/ /* 如果有订单ID则是订单支付 */ /*获取即将被支付的订单*/ $info = get_info($this->table, array('id' => $order_id, 'status' => 1)); if (!$info) { $this->error('订单不存在或已经支付'); } /*获取订单号*/ $order_no = $info['order_num']; $title = $info['title']; // $title = '商品一'; $total_price = $info['total_price']; $param = array('order_id' => $order_id, 'shop_id' => $info['shop_id'], 'member_id' => $info['member_id']); } else { /* 没有订单ID则是在线充值 */ $total_price = $posts['recharge_money']; /*获取充值金额*/ if (floatval($total_price) <= 0) { $this->error('充值金额必须大于0'); } $order_no = get_order_num(C('PLATFORM_ID'), $member_id); $title = '账户余额充值'; $_POST = array('title' => $title, 'qty' => '1', 'shop_id' => 0, 'order_num' => $order_no, 'member_id' => $member_id, 'total_price' => $total_price, 'status' => '1', 'pay_type' => '2', 'description' => '账户余额充值', 'type' => '1'); $res = update_data($this->table); if (is_numeric($res)) { /*@liuqiao 购买商品后增加积分*/ $get_coin = get_coin_points($total_price, $member_id); } $param = array('order_id' => $res, 'shop_id' => 0, 'member_id' => $member_id); if (!is_numeric($res)) { $this->error('订单生成失败'); } } if ($paytype == 'alipay') { $callBack = "Pay/pay"; //$total_price=0.01;//测试完后 删除 //$param['test']='1'; // echo $paytype,' -- ',$order_no,' -- ',$title,' -- ',$callBack,' -- ',$param;exit; $callBack = "Pay/pay"; $vo = new \Think\Pay\PayVo(); $vo->setType($paytype)->setBody("支付成功后请不要关闭窗口,等待自动跳转")->setFee($total_price)->setOrderNo($order_no)->setTitle($title)->setCallback($callBack)->setUrl(U('/Pay/success'))->setParam($param); //必要的一些信息,用来产生动态时调用相关数据 $payment_conf = C('payment.' . $paytype); $pay = new \Think\Pay($paytype, $payment_conf); echo $pay->buildRequestForm($vo); } } else { $paytype = 'alipay'; $callBack = "Pay/pay"; $title = '异步通知支付测试'; $total_price = 0.01; $param['test'] = '1'; $order_no = get_order_num(1, 1); $callBack = "Pay/pay"; $vo = new \Think\Pay\PayVo(); $vo->setType($paytype)->setBody("支付成功后请不要关闭窗口,等待自动跳转")->setFee($total_price)->setOrderNo($order_no)->setTitle($title)->setCallback($callBack)->setUrl(U('/Pay/success'))->setParam($param); //必要的一些信息,用来产生动态时调用相关数据 $payment_conf = C('payment.' . $paytype); $pay = new \Think\Pay($paytype, $payment_conf); echo $pay->buildRequestForm($vo); } }
protected function update_money_record() { if (IS_POST) { $posts = I(); $member_id = session('home_member_id'); $money = $posts['drawals_money']; /*提现金额*/ $cards_id = $posts['cards_id']; /*选择提现的账户在卡包中的信息ID*/ $order_num = get_order_num(intval($shop_id), intval($member_id)); /*生成订单号*/ if (!trim($posts['dealpassword'])) { return array('status' => '0', 'msg' => '请输入支付密码'); } if (floatval($money) <= 0) { return array('status' => '0', 'msg' => '提现金额必须大于0'); } if (intval($cards_id) <= 0) { return array('status' => '0', 'msg' => '请选择提现账户'); } /*查询当前登录用户信息*/ $info = get_info($this->member_table, array('id' => $member_id)); /*判断用户可提现余额状态*/ if ($info['wallet_status'] == 0) { return array('status' => '0', 'msg' => '账户已被冻结,请联系管理员'); } /*判断用户可提现余额是否充足*/ if ($info['withdrawals'] < $money) { return array('status' => '0', 'msg' => '可提现余额不足' . $money . ',请重新输入'); } /*判断支付密码是否正确*/ if (md5(md5($posts['dealpassword'])) == $info['deal_password']) { $_POST = array('type' => '3', 'frozen' => '2', 'member_id' => $member_id, 'money' => -$money, 'cards_id' => $cards_id, 'order_num' => $order_num, 'from_member_id' => $member_id, 'status' => '0'); /*开启事务*/ $Model = M(); $Model->startTrans(); /*更新资金流动记录*/ $result1 = update_data($this->table); /*计算提现后余额*/ $new_withdrawals = $info['withdrawals'] - $money; $_POST = array('id' => $member_id, 'withdrawals' => $new_withdrawals); /*更新用户可提现余额*/ $result2 = update_data($this->member_table); if (is_numeric($result1) && is_numeric($result2)) { /*如果数据都更新成功,提交事务*/ $Model->commit(); return array('status' => '1', 'msg' => '申请成功'); } else { /*如果有其中一个失败,执行事务回滚*/ $Model->rollback(); return array('status' => '0', 'msg' => '申请失败'); } } else { return array('status' => '0', 'msg' => '支付密码错误'); } } else { return array('status' => '0', 'msg' => '错误请求'); } }