作者 王晓刚
1 个管道 的构建 通过 耗费 6 秒

下单模块,微信支付,支付宝支付

... ... @@ -62,11 +62,13 @@ class HomeBase extends Controller
if(!empty($token)){
$user_token = Db::name('user_token')->where(['token'=>$token])->find();
if(empty($user_token)){
session('token',null);
$this->error('令牌失效','','','');
}
$userModel = new User();
$user = $userModel->findData(['id'=>$user_token['user_id']]);
if(empty($user)){
session('token',null);
$this->error('查无此人','','','');
}
$this->token = $token;
... ...
... ... @@ -7,16 +7,19 @@
*/
return [
//应用ID,您的APPID。
'app_id' => "2021001152619507",
'app_id' => "2021001162623530",
//商户私钥, 请把生成的私钥文件中字符串拷贝在此
'merchant_private_key' => "MIIEowIBAAKCAQEArXpRzOlEmxeBRMvjaFsrXtH/SRDY3y2iXaJURw0cu1VRyRHdI//Ob6RSlfeUut9VPkjUbeHT5uqesEsouLuxCX3Ji2xJFVnG217KOEIAQ08ps4rlyK1me4tVCS3aEWdpIEqpRo25o4+OsIyqdr9CCRFIWWhcnFrpgWfrRnkNHexELXRILA7BhzmAeY59mO47DSBzAy27W5lPQIIUm7Z5XKEjrxW4f9TDPxTWrGHzGIX9wEIOYU2aOKUFp1IObtEyZaueUVuxi0K+v+E1moffymmIVybKM8avXYm9BJTHFYYpPu/UhFD3y6zhGmXYAJPBgBdpsbuwghOL/0BcZPRQ3wIDAQABAoIBAD6nrR+rKIIzbRbh5NJuCy4F/oPvN8TzgG79EB9RVw059X3/m7VC0NZ1rPZJI0iTHQCP4VmGdLg0CPh3TM/bykc5TS+z/nldoXrds3+6Jsoor1EPW4qtRhRc8GuOSfJ7PPbSwGyhB2lRkiGlzHNzBHCt80mHbdty4l9AnzMmyVwCvrcuucIjuDPr9KeshYZom1Trhm8xbfKx+pANmRGi9f+hpGMKEKNFFXcGqB34r1IKExoKrhK0Fj3t5dgk7XcyjsDukjREcPOQvkPnlM3Taq1a1+6Up2eLhJ2f4YFVVR+vw1wJ6DfjIVyK1lCj4Hujw6WNPWyQU4k4s+XuSHJytRECgYEA46AfhioONLhYPSrWjAxZ2o2eldLJy5ZW1RqJ7c0HE0/IntiFG5MMPfeZJ8oGerSbFIjEsEhW65nnFioaMNWsMbKSueLFbRHdYO9prxHP80/2eeGk2AjoE5TWxFxTTU8sIyjFdnfgwYwg5im4WUXlxoi0FYk9afyNgK285yMZjd0CgYEAwxpC8g/fhCNYqJCocWYCslUUgYKWtplfJVr8DfvI8tEVeWNaxwwWBAM8nfvZ7mvn6eLUTOLXevc10MttO6AyJ55s7+ip+0aRJiE3VuNOQIbvgYTsiuDh5Qj1bi+GhB/629gHPHrZR9ZrTvs1tqDZjWn6aLWi+1aEc/uYHH+Tg+sCgYAT5tIaxt6LGXsNjgtIH2RTyYIOE2n1VOWuqC1bD0wJEja2PLQWnxq46EcJxY4feF7+wp5/0zNWUhR0SaYUkvoFNlnByuP8D03NxeD1n5cQ7PLd4S6qfMzduWu1q2TVI5D2WgA5xW1vPrM5rHgjxgq6+wTTxTYLaDtu/sG/a8A2OQKBgAkuVzAk5xPExgtIo2SStFXIAysFBiqZlQyg93OBAbfLdwM7Va5AN1kA/f1BOMQrd8Jd1je4BQPYVkP5Dq7bnwCWR/ISNM2KSJJOxdfk4m3O675gjvEKHBc3ELWaru3Qw3FM/SovbcIfqPUShTiO4S3yasI6qezB6YG7uTC+ICb5AoGBAKNV8QLvuFuA/wVC9keZQJREbtcR9gztOIlGOlJX2O1ve0jw/j8u7nlUHds3L4QSx/h0j5/R41m51zVMVpihQr9bf9mHStP1uVHggzRVRjYbZkzZXEgvCjSnfbSApLTWW09xJosf9zznJgkS2EpIqqgen+rupDecK4abw4jcttuO",
'merchant_private_key' => "MIIEowIBAAKCAQEAgtM3ikYMpn5Omyc0sm90/yIov5ANB6jOehOL+tk9xHL+R6zWR/90hQyz4VCYZU4mt68zYd7nvW1wubgyWduZVI77e1P2UI/D9OKL47T+v7Q9+k1+sFQWt4GgYksQp4RHVj+q2/Osnxk90ukJPRXgr/qujYjBSvocuh1Fo0YGCOkE46WMOvKogsF2/kmIk/l060zchnTvqZka8EDWpE+E4aMbOlR4SxETxRnma8PNldWdBfl/gdx2Bj6d0/Eyg1u2dLEsG+RB59zZBu2vGGTZJBSoQzLbhJtB0KEWouEIOq6FTGkolCTZ/h/BsZ/+xioYlEqTbi7eeIpHIecDo4WFRQIDAQABAoIBAEQAJ+Fesdqk0pUBFvocxxKKneWcqbkufEyl9l+oJdwD7box05vO47D4vlNCgkQ+EA/wKGQZ6hjjVvGiFcHxTEzQmVUsel67q56RVydAAB6DQKfnOg/LVZeC8GvHGtwH/NCO/W+gxDxacXE8ogm3Ynf2dF6rE9W2FdKDvpu0nRRpyh9H4JwQnXKOSrGc8n9qay4biEy435Ro4wmSy/j+SLds3mOA9sK78NUkdO7lCRRnE96CBObA0OH75l4omg/htr08luLeRPNWfP30J3JrNcvRW4x8OuK27Q2YCNOOIY7p5w/wWiJwCNI19OkCgaSdplovXtTzRFMbrPdiuhXrMMECgYEA/aiA0FXhUDDzef+Re7HvAmCjo8ud2Ox+l+G7v3u7WIp4+SwzlY21HaQhvxw/TnMiN1zH3SX/mlZTBBsjdHK/C1A/RRhwVV7Ouq4b7Ua9JpZ+tRqhSOkSOq9GHrYfi+lqsiqy8/xjiwJIItKU5LujSzjJsPMcCUNOWet1NwSer3ECgYEAhAho0Eap+MHH4GxrM11iyETyNGRJwjUT5yGQcvitDNjcwnA/75XNYbqDutu9s4rMSO8bcHAnzQjLfG2EqC9Zpvbg9XQ3BBFjyZ53uztCUWIh8eHQ788/aYdEJk2h78VPDWl8HRRtrd3rRYKXFF3IltCB3IyJrHdQWhkCqcx0sRUCgYEAhMasTuF1ZGWLPUQC4k28f3EYl0ehI4h/p38YqN3arjklo8B4bANWV+Kva3scxDLOKU6eq+sVBbPEFrUh9PWPfRuPUtq9CmLrMZqrsaNCpa1HPANpg2HFEgTnXnIUx0bye7qQG9j0PjJ+kgPKvoRdsKVUJhTLiym5HKZ8n8UCT3ECgYAUfimmihE/pvQbBTjuVARNCUZ+k0JPfmWEblU5Qxe48r/w/fMugJXMIWLo0cpz34stls8veHj0/fR3b5gzcoX7wD3SWyNe4kQWux3iVaRJdW3HWUFQt14kRvZw64PC72EBt+mnqdAMOHGX7Fj+tD+6CMrfLIEB39L86Pzc1fsWsQKBgBZMT0qSv9vR7TPddvuQjUOFGdv61XUg4rZjTLtiwkquBM3pO3Eq7s1FGTKpSQetiuQw69HvPj2FAiILkQ0tPSiAs49W9D2FIq9V77wukCJpyKNNqW0vEAmtmJlTQBS5lf9iGmKvU+aH2h1OSUPHv/f8u4T312PTnYPAXmx4r9U+",
//异步通知地址(购买会员)
'notify_url1' => 'http://gongpinda.com/index/notify/index1',
//异步通知地址(购买商品)
'notify_url' => 'http://gongpinda.com/index/notify/index',//url('home/order/notify',true,true),
'notify_url2' => 'http://gongpinda.com/index/notify/index2',
//同步跳转
'return_url' => 'http://gongpinda.com/',//url('home/index/index',true,true),
'return_url' => 'http://gongpinda.com/',
//编码格式
'charset' => "UTF-8",
... ... @@ -28,5 +31,5 @@ return [
'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
//支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAh+0orFb0qY5kghDBypXs1gp5u1/x0L8ZTwgvqTH58B1zzCuExWFuiX1su2rcBwZyJolROGfurgxMbySC7bNJZ+RH0iUik6yeyQZ1MfkWWwyV/raFggtGbcd16jowwY/qgfY87DZYu6AV6ebLdB6a1Yzf59Q5b2hFyMpXTbI45AQ/vsTyOKWvyVHunUsXW90w5cDVme0m8x6vrWPI7FJE/bXA+nP+iD9KRjGEwbsJ3oK9uNYFj0eBbbyLA8b3uUdYUWIpdpSzY5gD/8AYadAMtIKB2lVWpCPvEpL12qqo8uF+HSJ/lMo3kD8RL9RnUmYfgLBCGDqxtZ4+iIy5MBauoQIDAQAB",
'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkuQaS+vm7yyvfKqchzqLaOcIEd1o00Nym0T2rLsPNTfcAXlwrb6NAQdG8J9iLUykuy4yjX4m1+LrKFhGCT+tzl6Muory5zb/ixTv9hpfvL2NVHXafzlREjFQC2EjrhWDVoTjG+1ugTV//81rKNcSGXFDeIesBFLij4gJL4KJcGS/gKMh6edClvVT7jU9Y3o4sTgibtkZyQU7Ve6TWL/gfP+l+H9K/LvXndKKfJnMmUi36P3630YBaUhxKj827Kcj5ejIPxqGB63nSrnqRGE4Wi3OEiczS6dKQxcKv7exh2HOx7vycEliL44jIviggXlAP0Ougb6o8zt6jS0846bLPQIDAQAB",
];
\ No newline at end of file
... ...
... ... @@ -15,8 +15,8 @@ return [
/**
* 账号基本信息,请从微信公众平台/开放平台获取
*/
'app_id' => '', // AppID H5支付必须
'secret' => '', // AppSecret
'app_id' => 'wx954f9f2f5a77d86b', // AppID H5支付必须
'secret' => '6d14f4a6c74678e3e2520bd10f62e00c', // AppSecret
'token' => 'bronet', // Token
'aes_key' => 'qblu4O3peCTWjLLEqKqLjQhJNNeCTi2se2EPeVARsbk', // EncodingAESKey,安全模式下请一定要填写!!!
/**
... ... @@ -62,6 +62,6 @@ return [
*/
'guzzle' => [
'timeout' => 3.0, // 超时时间(秒)
'verify' => false, // 关掉 SSL 认证(强烈不建议!!!)
'verify' => true, // 关掉 SSL 认证(强烈不建议!!!)
],
];
\ No newline at end of file
... ...
... ... @@ -95,4 +95,17 @@ class Address extends HomeBase
$data = $addressModel->findData(['id'=>$address_id]);
$this->success('SUCCESS','',$data);
}
public function del(){
$id = $this->request->param('id',0,'intval');
if(empty($id)){
$this->error('缺少必要参数');
}
$user_id = $this->getUserId();
$addressModel = new \app\index\model\Address();
$result = $addressModel->where(['user_id'=>$user_id,'id'=>$id])->delete();
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS');
}
}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,7 @@ namespace app\api\controller;
use app\common\controller\Api;
use app\common\controller\HomeBase;
use app\index\model\OrderDetail;
use app\index\model\Viporder;
use think\Db;
... ... @@ -19,7 +20,7 @@ class Notify extends HomeBase
* 购买会员
* @return bool
*/
public function index(){
public function index1(){
$param = $this->request->param();
if(empty($param)){
$this->error('缺少必要参数');
... ... @@ -64,4 +65,50 @@ class Notify extends HomeBase
}
return true; // 返回处理完成
}
/**
* 购买商品
* @return bool
*/
public function index2(){
$param = $this->request->param();
if(empty($param)){
$this->error('缺少必要参数');
}
cache('param',$param);
$result = \alipay\Notify::check($param);
cache('result',$result);
$out_trade_no = $param['out_trade_no'];
$identification = substr($out_trade_no, -1);
$orderModel = new \app\index\model\Order();
$orderDetailModel = new OrderDetail();
if($identification == 1){
$data = $orderModel->findData(['num'=>$out_trade_no]);
}else{
$data = $orderDetailModel->findData(['num'=>$out_trade_no]);
}
if (empty($data)) { // 如果订单不存在
return false;
}
// 如果订单存在
if (!empty($data['paytime'])) {
return true;
}
$userModel = new \app\index\model\User();
$user = $userModel->findData(['id'=>$data['user_id']]);
// 用户是否支付成功
if(!empty($result)){
if($identification == 1){
$orderModel->updateData(['id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
$orderDetailModel->updateData(['order_id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
}else{
$orderDetailModel->updateData(['id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
$order_detail_status1_count = $orderDetailModel->findData(['order_id'=>$data['order_id'],'status'=>'1']);
if($order_detail_status1_count == 0){
$orderModel->updateData(['id'=>$data['order_id']],['paytime'=>time(),'status'=>'2']);
}
}
}
return true; // 返回处理完成
}
}
\ No newline at end of file
... ...
... ... @@ -12,10 +12,20 @@ namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Address;
use app\index\model\Area;
use app\index\model\OrderDetail;
use app\index\model\OrderInfo;
use app\index\model\Store;
use think\Db;
class Order extends HomeBase
{
/**
* 确认订单
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function confirm(){
$user_id = $this->getUserId();
// $car_ids = $this->request->param('car_ids');
... ... @@ -77,19 +87,19 @@ class Order extends HomeBase
//配送价格
$postage_price = 0;
if($goods_total < $s['money']){
$postage_price = $store['freight'];
$postage_price = $s['freight'];
}
$store[$key2]['postage_price'] = $postage_price;
$store[$key2]['goods'] = $goods_arr;
}
//总合计
$goods_total1 = 0;
$postage_price1 = 0;
$postage_total1 = 0;
foreach($store as $key => $vo3){
$goods_total1 = $goods_total1 + $vo3['goods_total'];
$postage_price1 = $postage_price1 + $vo3['postage_price'];
$postage_total1 = $postage_total1 + $vo3['postage_price'];
}
$total = $goods_total1 + $postage_price1;
$total = $goods_total1 + $postage_total1;
//收货地址
$addressModel = new Address();
$address = $addressModel->selectData(['user_id'=>$user_id]);
... ... @@ -104,9 +114,347 @@ class Order extends HomeBase
$this->assign('city',$city);
$this->assign('county',$county);
$this->assign('store',$store);
// dump(collection($store)->toArray());
$this->assign('total',$total);
$this->assign('goods_total',$goods_total1);
$this->assign('postage_total',$postage_total1);
$this->assign('address',$address);
$this->assign('data',json_encode($data));
$this->assign('province_id',$province_id);
$this->assign('title','确认订单');
return $this->fetch();
}
/**
* 计算价格
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function confirm_ajax(){
$user_id = $this->getUserId();
// $car_ids = $this->request->param('car_ids');
$data = $this->request->param('data');
$province_id = $this->request->param('province_id',0,'intval');
$express = $this->request->param('express',0,'intval');
if(empty($data) || empty($province_id) || empty($express)){
$this->error('缺少必要参数');
}
$data = json_decode($data,true);
/*if(!empty($car_ids)){
$car_ids = explode(',',$car_ids);
$carModel = new \app\index\model\Car();
$result = $carModel->where(['id'=>$car_ids])->delete();
if(empty($result)){
$this->error('sql执行失败');
}
}*/
$goodsModel = new \app\index\model\Goods();
$goods_price = [];
$store_ids = [];
foreach($data as $key1 => $vo){
//获取店铺id
$goods = $goodsModel->findData(['g.id'=>$vo['goods_id']]);
$data[$key1]['store_id'] = $goods['store_id'];
$store_ids[] = $goods['store_id'];
}
$storeModel = new Store();
$store = $storeModel->selectData(['id'=>['in',$store_ids]]);
foreach($store as $key2 => $s){
if($s['is_svip'] != '1'){
if($s['is_vip'] != '1' && !in_array($province_id,$s['province_ids'])){
$this->error("店铺 【$s[name]】 不可以进行购买~");
}
}
$goods_ids = [];
$number = [];
foreach($data as $key3 => $vo){
if($vo['store_id'] == $s['id']){
$goods_ids[] = $vo['goods_id'];
$number[] = $vo['number'];
}
}
$store[$key2]['goods_ids'] = $goods_ids;
$goods_arr = [];
foreach($goods_ids as $key4 => $goods_id){
$goods = $goodsModel->findData(['g.id'=>$goods_id]);
if($goods['inventory'] < $number[$key4]){
$this->error("商品 【$goods[goodsname]】 库存不足~");
}
$goods['number'] = $number[$key4];
$goods_price[] = $goods['price']*$number[$key4];
$goods_arr[] = $goods;
}
//商品总价格
$store[$key2]['sum_goods_price'] = array_sum($goods_price);
//商品实际支付价格
$goods_total = $store[$key2]['sum_goods_price'];
$store[$key2]['goods_total'] = $goods_total;
//配送价格
$postage_price = 0;
if($express == 1){
if($goods_total < $s['money']){
$postage_price = $s['freight'];
}
}
$store[$key2]['postage_price'] = $postage_price;
$store[$key2]['goods'] = $goods_arr;
}
//总合计
$goods_total1 = 0;
$postage_total1 = 0;
foreach($store as $key => $vo3){
$goods_total1 = $goods_total1 + $vo3['goods_total'];
$postage_total1 = $postage_total1 + $vo3['postage_price'];
}
$total = $goods_total1 + $postage_total1;
$this->success('SUCCESS','',['total'=>$total,'postage_total'=>$postage_total1,'goods_total'=>$goods_total1]);
}
/**
* 创建订单
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function create_order(){
$user_id = $this->getUserId();
$data = $this->request->param('data');
$express = $this->request->param('express',0,'intval');
$address_id = $this->request->param('address_id',0,'intval');
$pay_type = $this->request->param('pay_type',0,'intval');
$car_ids = $this->request->param('car_ids');
$province_id = $this->request->param('province_id',0,'intval');
if(empty($data) || empty($express) || empty($pay_type) || empty($province_id)){
$this->error('缺少必要参数');
}
if($express == 1){
if(empty($address_id)){
$this->error('缺少必要参数');
}
$addressModel = new Address();
$address = $addressModel->findData(['id'=>$address_id]);
}
$data = json_decode($data,true);
Db::startTrans();
if(!empty($car_ids)){
$car_ids = explode(',',$car_ids);
$carModel = new \app\index\model\Car();
$result = $carModel->where(['id'=>$car_ids])->delete();
if(empty($result)){
$this->error('sql执行失败');
}
}
$goodsModel = new \app\index\model\Goods();
$goods_price = [];
$store_ids = [];
foreach($data as $key1 => $vo){
//获取店铺id
$goods = $goodsModel->findData(['g.id'=>$vo['goods_id']]);
$data[$key1]['store_id'] = $goods['store_id'];
$store_ids[] = $goods['store_id'];
}
$storeModel = new Store();
$store = $storeModel->selectData(['id'=>['in',$store_ids]]);
foreach($store as $key2 => $s){
if($s['is_svip'] != '1'){
if($s['is_vip'] != '1' && !in_array($province_id,$s['province_ids'])){
$this->error("店铺 【$s[name]】 不可以进行购买~");
}
}
$goods_ids = [];
$number = [];
foreach($data as $key3 => $vo){
if($vo['store_id'] == $s['id']){
$goods_ids[] = $vo['goods_id'];
$number[] = $vo['number'];
}
}
$store[$key2]['goods_ids'] = $goods_ids;
$goods_arr = [];
foreach($goods_ids as $key4 => $goods_id){
$goods = $goodsModel->findData(['g.id'=>$goods_id]);
if($goods['inventory'] < $number[$key4]){
$this->error("商品 【$goods[goodsname]】 库存不足~");
}
$goods['number'] = $number[$key4];
$goods_price[] = $goods['price']*$number[$key4];
$goods_arr[] = $goods;
}
//商品总价格
$store[$key2]['sum_goods_price'] = array_sum($goods_price);
//商品实际支付价格
$goods_total = $store[$key2]['sum_goods_price'];
$store[$key2]['goods_total'] = $goods_total;
//配送价格
$postage_price = 0;
if($express == 1){
if($goods_total < $s['money']){
$postage_price = $s['freight'];
}
}
$store[$key2]['postage_price'] = $postage_price;
$store[$key2]['goods'] = $goods_arr;
}
//总合计
$goods_total1 = 0;
$postage_total1 = 0;
foreach($store as $key => $vo3){
$goods_total1 = $goods_total1 + $vo3['goods_total'];
$postage_total1 = $postage_total1 + $vo3['postage_price'];
}
$total = $goods_total1 + $postage_total1;
//创建主订单
$order_num = get_order_sn();
$arr1['num'] = $order_num."1";
$arr1['user_id'] = $user_id;
$arr1['pay_type'] = $pay_type;
$arr1['express'] = $express;
$arr1['total'] = $total;
$arr1['goods_total'] = $goods_total1;
$arr1['postage_total'] = $postage_total1;
$arr1['createtime'] = time();
$arr1['status'] = '1';
$orderModel = new \app\index\model\Order();
$result1 = $orderModel->insertData($arr1);
if(empty($result1)){
Db::rollback();
$this->error('sql执行失败');
}
//创建子订单
$orderDetailModel = new OrderDetail();
$orderInfoModel = new OrderInfo();
foreach($store as $key => $s){
$order_detail_num = get_order_sn();
$arr2['num'] = $order_detail_num."2";
$arr2['user_id'] = $user_id;
$arr2['store_id'] = $s['id'];
$arr2['order_id'] = $result1;
$arr2['pay_type'] = $pay_type;
$arr2['express'] = $express;
$arr2['total'] = $s['goods_total']+$s['postage_price'];
$arr2['goods_total'] = $s['goods_total'];
$arr2['postage_total'] = $s['postage_price'];
if(!empty($address)){
$arr2['name'] = $address['name'];
$arr2['mobile'] = $address['phone'];
$arr2['province_name'] = $address['province_name'];
$arr2['city_name'] = $address['city_name'];
$arr2['county_name'] = $address['county_name'];
$arr2['address'] = $address['address'];
}
$arr2['createtime'] = time();
$arr2['status'] = '1';
$result2 = $orderDetailModel->insertData($arr2);
if(empty($result2)){
Db::rollback();
$this->error('sql执行失败');
}
//创建订单详情
foreach($s['goods'] as $key2 => $g){
$arr3 = [];
$arr3['order_id'] = $result1;
$arr3['order_detail_id'] = $result2;
$arr3['user_id'] = $user_id;
$arr3['goods_id'] = $g['id'];
$arr3['goodsname'] = $g['goodsname'];
$arr3['goods_image'] = $g['thumbnail'];
$arr3['goods_price'] = $g['price'];
$arr3['number'] = $g['number'];
$arr3['createtime'] = time();
$result3 = $orderInfoModel->insertData($arr3);
if(empty($result3)){
Db::rollback();
$this->error('sql执行失败');
}
}
}
Db::commit();
$this->success('SUCCESS','',['order_id'=>$result1,'url'=>url("index/order/pay",array('order_id'=>$result1),false,true)]);
}
/**
* 唤起支付
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function pay(){
$user_id = $this->getUserId();
$order_id = $this->request->param('order_id',0,'intval');
$order_detail_id = $this->request->param('order_detail_id',0,'intval');
if(empty($order_id) && empty($order_detail_id)){
$this->error('缺少必要参数');
}
$orderInfoModel = new OrderInfo();
if(!empty($order_id)){
$orderModel = new \app\index\model\Order();
$data = $orderModel->findData(['id'=>$order_id,'user_id'=>$user_id]);
$order_info = $orderInfoModel->selectData(['order_id'=>$order_id,'user_id'=>$user_id]);
}else{
$orderDetailModel = new OrderDetail();
$data = $orderDetailModel->findData(['id'=>$order_detail_id,'user_id'=>$user_id]);
$order_info = $orderInfoModel->selectData(['order_detail_id'=>$order_detail_id,'user_id'=>$user_id]);
}
if(empty($data)){
$this->error('查询为空');
}
if($data['status'] != '1'){
$this->error('订单状态不合法');
}
$goodsModel = new \app\index\model\Goods();
foreach($order_info as $key => $o_i){
$goods = $goodsModel->findData(['g.id'=>$o_i['goods_id']]);
if($goods['inventory'] < $o_i['number']){
$this->error("商品 【$goods[goodsname]】 库存不足~");
}
}
if($data['pay_type'] == '1'){
//微信支付
$wechatPay = new WechatPay();
$code_url = $wechatPay->index2($data);
if(empty($code_url)){
$this->error('生成二维码失败');
}
\PHPQRCode\QRcode::png($code_url);
}else if($data['pay_type'] == '2'){
//支付宝支付
$params['subject'] = "购买商品";
$params['out_trade_no'] = $data['num'];
$params['total_amount'] = $data['total'];
$result = \alipay\Pagepay::pay2($params);
echo $result;
}else{
$this->error('未知的支付类型');
}
}
/**
* 检测订单支付状态
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function order_pay(){
$user_id = $this->getUserId();
$order_id = $this->request->param('order_id',0,'intval');
$order_detail_id = $this->request->param('order_detail_id',0,'intval');
if(empty($order_id) && empty($order_detail_id)){
$this->error('缺少必要参数');
}
if(!empty($order_id)){
$orderModel = new \app\index\model\Order();
$data = $orderModel->findData(['id'=>$order_id,'user_id'=>$user_id]);
}else{
$orderDetailModel = new OrderDetail();
$data = $orderDetailModel->findData(['id'=>$order_detail_id,'user_id'=>$user_id]);
}
if(empty($data)){
$this->error('查询为空');
}
if($data['status'] != '1'){
$this->success('SUCCESS',url("index/index/index"));
}
$this->error('尚未支付');
}
}
\ No newline at end of file
... ...
... ... @@ -104,7 +104,7 @@ class Vip extends HomeBase
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS','',['viporder_id'=>$result]);
$this->success('SUCCESS','',['viporder_id'=>$result,'url'=>url("index/vip/pay",array('viporder_id'=>$result),false,true)]);
}
/**
... ... @@ -131,6 +131,38 @@ class Vip extends HomeBase
$this->error('生成二维码失败','','','');
}
\PHPQRCode\QRcode::png($code_url);
}else if($data['pay_type'] == '2'){
//支付宝支付
$params['subject'] = "购买商品";
$params['out_trade_no'] = $data['num'];
$params['total_amount'] = $data['money'];
$result = \alipay\Pagepay::pay($params);
echo $result;
}else{
$this->error('未知的支付类型');
}
}
/**
* 检测订单支付状态
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function order_pay(){
$user_id = $this->getUserId();
$order_id = $this->request->param('order_id',0,'intval');
if(empty($order_id)){
$this->error('缺少必要参数');
}
$viporderModel = new Viporder();
$data = $viporderModel->findData(['id'=>$order_id]);
if(empty($data)){
$this->error('查询为空');
}
if($data['status'] != '1'){
$this->success('SUCCESS',url("index/index/index"));
}
$this->error('尚未支付');
}
}
\ No newline at end of file
... ...
... ... @@ -3,6 +3,7 @@
namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\OrderDetail;
use app\index\model\Viporder;
use EasyWeChat\Foundation\Application;
//use EasyWeChat\Payment\Order;
... ... @@ -21,7 +22,7 @@ class WechatPay extends HomeBase
$this->options = config('wechat');
}
/**
* 微信支付
* 微信支付(购买会员)
* @param $data
* @return mixed
*/
... ... @@ -46,11 +47,37 @@ class WechatPay extends HomeBase
} else {
$this->error('支付参数错误', '', $result);
}
}
/**
* 微信支付(购买商品)
* @param $data
* @return mixed
*/
public function index2($data){
$attributes = [
'trade_type' => 'NATIVE',
'body' => '工品达',
'detail' => '购买商品',
'out_trade_no' => $data['num'],
'total_fee' => 1,//$data['pay_total'] * 100, // 单位:分
'notify_url' => url('wechat_pay/notify2', '', '', true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'openid' => '', // trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识,
];
$order = new \EasyWeChat\Payment\Order($attributes);
$app = new Application($this->options);
$payment = $app->payment;
$result = $payment->prepare($order);
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
return $result->code_url;
} else {
$this->error('支付参数错误', '', $result);
}
}
/**
* 支付回调
* 支付回调(购买会员)
* @throws \EasyWeChat\Core\Exceptions\FaultException
*/
public function notify()
... ... @@ -103,6 +130,51 @@ class WechatPay extends HomeBase
}
/**
* 支付回调(购买商品)
* @throws \EasyWeChat\Core\Exceptions\FaultException
*/
public function notify2()
{
$app = new Application($this->options);
$response = $app->payment->handleNotify(function ($notify, $successful) {
// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
$out_trade_no=$notify->out_trade_no;
$identification = substr($out_trade_no, -1);
$orderModel = new \app\index\model\Order();
$orderDetailModel = new OrderDetail();
if($identification == 1){
$data = $orderModel->findData(['num'=>$out_trade_no]);
}else{
$data = $orderDetailModel->findData(['num'=>$out_trade_no]);
}
if (empty($data)) { // 如果订单不存在
return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
}
// 如果订单存在
// 检查订单是否已经更新过支付状态
if (!empty($data['paytime'])) {
return true;
}
// 用户是否支付成功
if($successful){
if($identification == 1){
$orderModel->updateData(['id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
$orderDetailModel->updateData(['order_id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
}else{
$orderDetailModel->updateData(['id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
$order_detail_status1_count = $orderDetailModel->findData(['order_id'=>$data['order_id'],'status'=>'1']);
if($order_detail_status1_count == 0){
$orderModel->updateData(['id'=>$data['order_id']],['paytime'=>time(),'status'=>'2']);
}
}
}
return true; // 返回处理完成
});
$response->send();
}
/**
* 查询订单
*/
public function checkOrder()
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/14
* Time: 11:45
*/
namespace app\index\model;
use think\Model;
class Order extends Model
{
public function insertData($data){
$result = $this->insertGetId($data);
return $result;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
public function updateData($where,$data){
$result = $this->where($where)->update($data);
return $result;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/14
* Time: 11:51
*/
namespace app\index\model;
use think\Model;
class OrderDetail extends Model
{
public function insertData($data){
$result = $this->insertGetId($data);
return $result;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
public function updateData($where,$data){
$result = $this->where($where)->update($data);
return $result;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/14
* Time: 11:53
*/
namespace app\index\model;
use think\Model;
class OrderInfo extends Model
{
public function insertData($data){
$result = $this->insertGetId($data);
return $result;
}
public function selectData($where){
$data = $this->where($where)->order('id desc')->select();
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -324,7 +324,7 @@
.content .orderInfoBox .errandsBox ul li {
list-style-type: none;
width: 100%;
height: 116px;
/*height: 116px;*/
cursor: pointer;
}
... ... @@ -477,6 +477,97 @@
margin-top: -12px;
}
</style>
<style>
#payModal{
display: none;
}
.modal-box {
width: 716px;
height: 438px;
top: 25%;
left: 50%;
transform: translateX(-50%);
z-index: 666;
overflow: hidden;
position: fixed;
border: 6px solid #bbb;
background-color: #fff;
-webkit-animation: scale-in both cubic-bezier(.4, 0, 0, 1.5) .3s;
animation: scale-in both cubic-bezier(.4, 0, 0, 1.5) .3s;
}
.modal-left {
float: left;
width: 333px;
padding: 20px 50px 25px 45px;
}
#payModal .modal-qrcode {
width: 210px;
height: 210px;
display: block;
margin: 0 auto 20px;
}
.icon-qrcode {
width: 16px;
height: 16px;
margin-right: 3px;
position: relative;
display: inline-block;
vertical-align: middle;
background-position: 0 -88px;
}
.modal-left .icon {
font-size: 0;
background-image: url(https://mpay.meituan.com/resource/cashier/img/icon-common@2x.rcJBe.png);
background-size: 168px;
}
#payModal .modal-info {
color: #f80;
font-size: 12px;
padding: 13px 0;
text-align: center;
background-color: #f7f7f7;
}
.modal-right {
float: left;
}
#payModal p{
font-size: 18px;
text-align: center;
line-height: 32px;
margin-bottom: 16px;
}
#payModal .orange {
color: #f80;
}
#payModal .modal-qr{
padding-top: 20px;
border: 1px solid #ddd;
}
.icon-clock {
width: 12px;
height: 12px;
margin-right: 5px;
}
.icon-close {
top: 13px;
right: 13px;
width: 13px;
height: 13px;
z-index: 5;
cursor: pointer;
position: absolute;
background-position: -17px -88px;
}
.modal-right .icon {
font-size: 0;
background-image: url(https://mpay.meituan.com/resource/cashier/img/icon-common@2x.rcJBe.png);
background-size: 168px;
}
#payModal .model-right img {
width: 371px;
height: 438px;
}
</style>
<body>
{include file="public/header"/}
<!--主要内容-->
... ... @@ -503,11 +594,11 @@
<div class="sendModeBox">
<p class="title">物流方式</p>
<ul>
<li onclick="changeSendMode('express')"><img id="expressImg" src="__CDN__/assets/store/images/checkbox_orange.png" alt="img">快递运输
<li onclick="changeSendMode(1)"><img id="expressImg" src="__CDN__/assets/store/images/checkbox_orange.png" alt="img">快递运输
</li>
<li onclick="changeSendMode('dada')"><img id="dadaImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">达达快递
<li onclick="changeSendMode(2)"><img id="dadaImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">达达快递
</li>
<li onclick="changeSendMode('meiTuan')"><img id="meiTuanImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">美团跑腿
<li onclick="changeSendMode(3)"><img id="meiTuanImg" src="__CDN__/assets/store/images/radioUnSelect.png" alt="img">美团跑腿
</li>
</ul>
</div>
... ... @@ -542,7 +633,7 @@
<span data-county_id="{$a.county_id}">{$a.county_name}</span>
<span>{$a.address}</span>
</p>
<span class="btnSpan" onclick="del(this)"><img src="__CDN__/assets/store/images/icon_del.png" alt="">
<span class="btnSpan" onclick="del(this,'{$a.id}')"><img src="__CDN__/assets/store/images/icon_del.png" alt="">
<span>删除</span>
</span>
</div>
... ... @@ -573,6 +664,12 @@
<span>{$s.address}</span>
</span>
</p>
{foreach name="$s.goods" item="g"}
<p>
<span>商品:{$g.goodsname}</span>
<span>数量:{$g.number}</span>
</p>
{/foreach}
</div>
</li>
{/foreach}
... ... @@ -627,9 +724,9 @@
<!--提交订单部分-->
<div class="submitBox">
<p>商品金额:<span>¥150.00</span></p>
<p>物流费用:<span>¥0.00</span></p>
<p>应付总额:<span>¥198.00</span></p>
<p>商品金额:<span>¥{$goods_total}</span></p>
<p>物流费用:<span>¥{$postage_total}</span></p>
<p>应付总额:<span>¥{$total}</span></p>
<button id="submitBtn" type="button" class="btn" onclick="submitOrder()">提交订单</button>
</div>
</div>
... ... @@ -695,11 +792,41 @@
</div>
</div>
</div>
<!--支付窗口-->
<div id="payModal">
<div class="modal-box">
<div class="modal-left">
<p>
<span>请使用 </span>
<span class="orange">微信 </span>
<i class="icon icon-qrcode"></i>
<span class="orange"> 扫一扫</span><br>扫描二维码支付
</p>
<div class="modal-qr">
<img class="modal-qrcode"
src=""
alt="您的浏览器版本太低, 请升级您的浏览器">
<div class="modal-info">
<img class="icon-clock" src="__CDN__/assets/store/images/clock.png">
<span>二维码有效时长为2小时, 请尽快支付</span>
</div>
</div>
</div>
<div class="modal-right"><i class="icon icon-close"></i><img
src="https://mpay.meituan.com/resource/cashier/img/weixin-qrcode.1xf1oN.jpg" alt="微信扫码">
</div>
</div>
</div>
{include file="public/footer"/}
{include file="public/js"/}
<script>
var sendMode = 'express';
var payMode = 'weChat';
var order_id = '';//用于判断订单状态
var order_status = 1;//用于判断订单状态
var sendMode = 1;//配送方式
var payMode = 1;//支付方式
var data = '{$data}';
var province_id = "{$province_id}";
$(function () {
var source = window.location.href.split('source=')[1];
if (source){
... ... @@ -710,24 +837,44 @@
//更换运输方式
function changeSendMode(type) {
$('.sendModeBox ul li img').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
sendMode = type;
if (type == 'express') {
//快递
$('.errandsBox,.downloadBox').hide();
$('.consigneeBox').show();
$('#expressImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
} else if (type == 'dada') {
//达达
$('.consigneeBox').hide();
$('.errandsBox,.downloadBox').show();
$('#dadaImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
} else {
//美团
$('.consigneeBox').hide();
$('.errandsBox,.downloadBox').show();
$('#meiTuanImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
}
$.ajax({
url:"{:url('index/order/confirm_ajax')}",
type:"POST",
data:{'data':data,'province_id':province_id,'express':type},
success:function (res) {
if(res.code == 1){
$('.sendModeBox ul li img').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
if (type == 1) {
//快递
$('.errandsBox,.downloadBox').hide();
$('.consigneeBox').show();
$('#expressImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
} else if (type == 2) {
//达达
$('.consigneeBox').hide();
$('.errandsBox,.downloadBox').show();
$('.downloadBox').find('div').eq(0).show();
$('.downloadBox').find('div').eq(1).hide();
$('#dadaImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
} else {
//美团
$('.consigneeBox').hide();
$('.errandsBox,.downloadBox').show();
$('.downloadBox').find('div').eq(0).hide();
$('.downloadBox').find('div').eq(1).show();
$('#meiTuanImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
}
$('.submitBox').find('p').eq(0).find('span').html("¥"+res.data.goods_total);
$('.submitBox').find('p').eq(1).find('span').html("¥"+res.data.postage_total);
$('.submitBox').find('p').eq(2).find('span').html("¥"+res.data.total);
}
},
error:function (res) {
toast('与服务器断开连接');
}
})
}
//新增收货信息
... ... @@ -800,7 +947,7 @@
" <span data-county_id=\""+data.county_id+"\">"+data.county_name+"</span>\n" +
" <span>"+data.address+"</span>\n" +
" </p>\n" +
" <span class=\"btnSpan\" onclick=\"del(this)\"><img src=\"__CDN__/assets/store/images/icon_del.png\" alt=\"\">\n" +
" <span class=\"btnSpan\" onclick=\"del(this,"+data.id+")\"><img src=\"__CDN__/assets/store/images/icon_del.png\" alt=\"\">\n" +
" <span>删除</span>\n" +
" </span>\n" +
" </div>";
... ... @@ -829,7 +976,7 @@
" <span data-county_id=\""+data.county_id+"\">"+data.county_name+"</span>\n" +
" <span>"+data.address+"</span>\n" +
" </p>\n" +
" <span class=\"btnSpan\" onclick=\"del(this)\"><img src=\"__CDN__/assets/store/images/icon_del.png\" alt=\"\">\n" +
" <span class=\"btnSpan\" onclick=\"del(this,"+data.id+")\"><img src=\"__CDN__/assets/store/images/icon_del.png\" alt=\"\">\n" +
" <span>删除</span>\n" +
" </span>\n" +
" </div>\n" +
... ... @@ -853,18 +1000,12 @@
function changeConsignee(obj) {
$('.content .orderInfoBox .consigneeBox ul li .checkImg').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
$(obj).find('.checkImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
var name = $(obj).find('.name').html();
var phone = $(obj).find('.phone').html();
var address = $(obj).find('.address').html();
}
//更改跑腿收货人
function changeErrands(obj) {
$('.content .orderInfoBox .errandsBox ul li .checkImg').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
$(obj).find('.checkImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
var name = $(obj).find('.shopName').html().split('<span')[0];
var phone = $(obj).find('.phone').html();
var address = $(obj).find('.address').html();
}
//修改收件信息
... ... @@ -903,8 +1044,21 @@
}
//删除收件信息
function del(obj) {
$(obj).parent().parent().parent('li').remove();
function del(obj,id) {
$.ajax({
url:"{:url('index/address/del')}",
type:"POST",
data:{'id':id},
success:function (res) {
if(res.code == 1){
$(obj).parent().parent().parent('li').remove();
toast('操作成功');
}
},
error:function (res) {
toast('与服务器断开连接');
}
});
}
//修改支付方式
... ... @@ -913,19 +1067,83 @@
$(obj).find('.checkImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
if (type == 'weChat') {
//微信支付
payMode = 'weChat';
payMode = 1;
} else if (type == 'aliPay') {
//支付宝支付
payMode = 'aliPay';
payMode = 2;
} else {
//云闪付
payMode = 'yunPay';
payMode = 3;
}
}
//提交订单
function submitOrder() {
if(sendMode == 1){
var address_id = '';
for(var i=0;$('.address_box .imgBox').length;i++){
if($('.address_box .imgBox').eq(i).find('img').attr('src') == '__CDN__/assets/store/images/checkbox_orange.png'){
address_id = $('.address_box .imgBox').eq(i).parent().attr('data-address_id');
console.log(address_id);
break;
}
}
if(address_id == ''){
toast('请选择收货地址');
return false;
}
}
$.ajax({
url:"{:url('index/order/create_order')}",
type:"POST",
data:{"data":data,"pay_type":payMode,'address_id':address_id,"express":sendMode,'province_id':province_id},
success:function (res) {
console.log(res);
if(res.code == 1){
if(payMode == 1){
//微信支付
order_id = res.data.order_id;
$('#payModal').show();
$('.modal-left .modal-qrcode').attr('src',res.data.url);
}else if(payMode == 2){
//支付宝支付
order_id = res.data.order_id;
window.open(res.data.url);
}
}
},
error:function (res) {
toast('与服务器断开连接');
}
})
}
setInterval(function(){order_pay()},3000);
//检测订单支付状态
function order_pay() {
console.log(order_id);console.log(order_status);
if(order_id != '' && order_status != 2){
$.ajax({
url:"{:url('index/order/order_pay')}",
type:"POST",
data:{'order_id':order_id},
success:function(res){
console.log(res);
if(res.code == 1){
order_id = '';
order_status = 2;
toast('支付成功');
setTimeout(function(){
window.location.href = res.url;
},3000);
// window.location.href = res.url;
}
},
error:function(res){
toast('与服务器断开连接')
}
})
}
}
//更换省份
... ...
... ... @@ -579,13 +579,11 @@
{include file="public/footer"/}
{include file="public/js"/}
<script>
var payMode = 'weChat';//默认支付方式
var unitPrice = {$price.vipprice
}
;
var svipPrice = {$price.svipprice
}
;
var order_id = '';//用于判断订单状态
var order_status = 1;//用于判断订单状态
var payMode = 1;//默认支付方式
var unitPrice = {$price.vipprice};
var svipPrice = {$price.svipprice};
var selectCity = '';
function cityClick(obj) {
... ... @@ -625,12 +623,12 @@
$(obj).addClass('check_pay_type');
$(obj).find('.checkImg').attr('src', '__CDN__/assets/store/images/checkbox_orange.png');
$(obj).siblings('li').find('.checkImg').attr('src', '__CDN__/assets/store/images/radioUnSelect.png');
if (type == 'weChat') {
payMode = 'weChat';
} else if (type == 'aliPay') {
payMode = 'aliPay';
if (type == 1) {
payMode = 1;
} else if (type == 2) {
payMode = 2;
} else {
payMode = 'yunPay';
payMode = 3;
}
}
... ... @@ -652,7 +650,7 @@
province_ids = province_ids.toString();
}
console.log(province_ids);
var pay_type = $('.check_pay_type').attr('data-pay_type');
var pay_type = payMode;
if (pay_type == '' || pay_type == undefined) {
toast('请选择支付方式');
return false;
... ... @@ -667,16 +665,13 @@
if (res.code == 1) {
if (pay_type == 1) {
//微信支付
var url = "{:url('vip/pay',array('viporder_id'=>'VIPORDER_ID'),'',true)}".replace('VIPORDER_ID',res.data.viporder_id);
console.log(url);
order_id = res.data.viporder_id;
$('#payModal').show();
$('.modal-left .model-prcode').attr('src',url);
$('.modal-left .modal-qrcode').attr('src',res.data.url);
} else if (pay_type == 2) {
//支付宝支付
} else if (pay_type == 3) {
//银联支付
order_id = res.data.viporder_id;
window.open(res.data.url);
}
} else {
toast(res.msg);
... ... @@ -692,6 +687,34 @@
$("#payModal").hide();
})
}
setInterval(function(){order_pay()},3000);
//检测订单支付状态
function order_pay() {
console.log(order_id);console.log(order_status);
if(order_id != '' && order_status != 2){
$.ajax({
url:"{:url('index/vip/order_pay')}",
type:"POST",
data:{'order_id':order_id},
success:function(res){
console.log(res);
if(res.code == 1){
order_id = '';
order_status = 2;
toast('支付成功');
setTimeout(function(){
window.location.href = res.url;
},3000);
// window.location.href = res.url;
}
},
error:function(res){
toast('与服务器断开连接')
}
})
}
}
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -16,7 +16,7 @@ loader::import('alipay.pay.buildermodel.AlipayTradePagePayContentBuilder');
class Pagepay
{
/**
* 主入口
* 主入口(购买会员)
* @param array $params 支付参数, 具体如下
* @param string $params['subject'] 订单标题
* @param string $params['out_trade_no'] 订单商户号
... ... @@ -44,7 +44,39 @@ class Pagepay
* @param $notify_url 异步通知地址,公网可以访问
* @return $response 支付宝返回的信息
*/
return $aop->pagePay($payRequestBuilder, $config['return_url'],$config['notify_url']);
return $aop->pagePay($payRequestBuilder, $config['return_url'],$config['notify_url1']);
}
/**
* 主入口(购买商品)
* @param array $params 支付参数, 具体如下
* @param string $params['subject'] 订单标题
* @param string $params['out_trade_no'] 订单商户号
* @param float $params['total_amount'] 订单金额
*/
public static function pay2($params)
{
// 1.校检参数
self::checkParams($params);
// 2.构造参数
$payRequestBuilder = new \AlipayTradePagePayContentBuilder();
$payRequestBuilder->setSubject($params['subject']);
$payRequestBuilder->setTotalAmount($params['total_amount']);
$payRequestBuilder->setOutTradeNo($params['out_trade_no']);
// 3.获取配置
$config = config('alipay');
$aop = new \AlipayTradeService($config);
/**
* 4.电脑网站支付请求(会自动跳转到支付页面)
* @param $builder 业务参数,使用buildmodel中的对象生成。
* @param $return_url 同步跳转地址,公网可以访问
* @param $notify_url 异步通知地址,公网可以访问
* @return $response 支付宝返回的信息
*/
return $aop->pagePay($payRequestBuilder, $config['return_url'],$config['notify_url2']);
}
... ...