diff --git a/php/bullshitClass.php b/php/bullshitClass.php index 6aff38c0ac321317b400a9ee2f80f48853a3658c..8cdc2f429d6b09312c374d390503368fef46c7d4 100644 --- a/php/bullshitClass.php +++ b/php/bullshitClass.php @@ -1,10 +1,15 @@ find($productData['product_id']); + if (!$product || ($product->is_on_sell === 'F')) return ['status' => 'error', 'msg' => '商品不存在或已下架']; + + // 判断库存是否充足 TODO + + $orderData = [ + 'user_id' => 'xx',// 当前登录用户 id + 'product_id' => $productData['product_id'], + 'order_sn' => generateOrderSn(), // 生成唯一订单号 + 'product_price' => $productData['product_price'] * $productData['product_num'], + 'status' => 0,// 新订单 + 'create_time' => time() + ]; + // 拉取微信支付数据 + $result = $this->wxpay->order->unify([ + 'body' => '博彩投注', + 'out_trade_no' => $orderData['order_sn'], + 'total_fee' => $orderData['product_price'] * 100, + 'spbill_create_ip' => $_SERVER["REMOTE_ADDR"], // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址 + 'notify_url' => 'http://xxxxxx', // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + 'trade_type' => 'APP', + ]); + + if ($result['return_code'] == 'FAIL') { + return ['status' => 'error', 'msg' => $result['return_msg']]; } + + // 生成预支付订单 + Db::name('wx_order')->insert($orderData); + return ['status' => 'success', 'msg' => $result]; } } \ No newline at end of file