123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\api\controller\h5;
- use app\hander\HelpHander;
- use EasyWeChat\Factory;
- use think\Db;
- class GOrders extends Base
- {
- //从购物车去结算生成订单
- public function create(){
- $cartId=input('cart_id/s');
- $addressId=input('address_id/d',0);
- $delivery_type=input('delivery_type/d',0);
- $delivery_date=input('delivery_date');
- $ret = model('GOrders')->add($cartId,$addressId,$this->userId,$this->orgId,$delivery_type,$delivery_date);
- if(!$ret){
- HelpHander::error(model('GOrders')->getError());
- }
- HelpHander::success(['id'=>$ret],'成功');
- }
- //立即购买生成订单
- public function createOne(){
- $goodsId=input('goods_id/d');
- $addressId=input('address_id/d',0);
- $nums=input('nums/d',0);
- $delivery_type=input('delivery_type/d',0);
- $delivery_date=input('delivery_date');
- $ret = model('GOrders')->addOne($goodsId,$addressId,$nums,$this->userId,$this->orgId,$delivery_type,$delivery_date);
- if(!$ret){
- HelpHander::error(model('GOrders')->getError());
- }
- HelpHander::success(['id'=>$ret],'成功');
- }
- //商城订单列表
- public function orderList(){
- $page=input('page/d',1);
- $size=input('size/d',20);
- $ret = model('GOrders')->lists($page,$size,$this->userId,$this->orgId);
- HelpHander::success($ret);
- }
- //订单详情
- public function orderDetails(){
- $orderId=input('order_id/d',0);
- $ret = model('GOrders')->details($orderId);
- HelpHander::success($ret);
- }
- //订单完成
- public function orderAccomplish(){
- $ordersId=input('order_id/d',0);
- model('GOrders')->accomplish($ordersId);
- HelpHander::success([],'订单已完成');
- }
- //取消订单
- public function cancelOrder(){
- $id = input('id',0);
- $data = [
- 'status'=>3,
- 'cancel_time'=>date('Y-m-d H:i:s')
- ];
- $ret = Db::name('g_orders')->where('id',$id)->update($data);
- //取消订单添加库存
- $orderGoods = Db::name('g_order_goods')
- ->where('order_id',$id)
- ->select();
- foreach ($orderGoods as $k=>$v){
- Db::name('g_goods')
- ->where('id',$v['goods_id'])
- ->inc('stock',$v['nums'])
- ->update();
- }
- if($ret){
- HelpHander::success([],'取消成功');
- }else{
- HelpHander::error([],'取消失败');
- }
- }
- //继续支付
- public function goPay(){
- $id = input('id',0);
- $order = Db::name('g_orders')->where('id',$id)->where('status',0)->find();
- if(!$order){
- HelpHander::error('订单不存在');
- }
- $config = config('app.wx_config');
- $notify = config("app.app_host").'/api/h5/notify/xshopOrder';
- $openid = Db::name('wxuser')->where('id',$this->userId)->where('type',1)->value('openid');
- $app = Factory::payment($config);
- $result = $app->order->unify([
- 'body' => '商城',
- 'out_trade_no' => $order['order_sn'],
- 'total_fee' => $order['amount']*100,
- 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
- 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
- 'openid' => $openid,
- ]);
- if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
- $jssdk = $app->jssdk;
- $ret = $jssdk->sdkConfig($result['prepay_id']); // 返回数组
- HelpHander::success($ret,'成功');
- }else{
- HelpHander::error('支付失败');
- }
- }
- }
|