聚水潭接口对接这段代码是一个控制器类,包含了聚水潭接口的一些方法,用于实现授权、订单同步、库存同步、取消订单、物流同步、售后收货等功能。主要方法:* auth(): 生成授权链接。* callback(): 接收服务商应用的授权回调并更新 access_tokenexpires_inrefresh_token。* shopcallback(): 接收自建应用的授权回调并更新 access_tokenexpires_inrefresh_token。* autoTask(): 定时执行订单同步和库存同步。* cancelOrderErp(): 将聚水潭订单状态改为已取消。* sendOrderErp(): 将聚水潭订单状态改为已发货。* updateStockErp(): 接收 ERP 的库存变化信息。* returnOrderErp(): 接收 ERP 的售后确认收货信息。**功能描述:**1. 授权: 通过 auth() 方法生成授权链接,用户访问该链接后授权应用访问聚水潭数据。2. 订单同步: 定时执行 autoTask() 方法,同步聚水潭订单信息到本地数据库。3. 库存同步: 定时执行 autoTask() 方法,同步聚水潭库存信息到本地数据库。4. 取消订单: 接收 ERP 取消订单信息后,调用 cancelOrderErp() 方法将聚水潭订单状态改为已取消。5. 物流同步: 接收 ERP 发货信息后,调用 sendOrderErp() 方法将聚水潭订单状态改为已发货。6. 售后收货: 接收 ERP 售后确认收货信息后,调用 returnOrderErp() 方法更新相关信息。代码示例:php// 授权public function auth(){ $aid = input('aid'); $jst = new JushuitanCustom(); $url = $jst->createUrl($aid); return redirect($url);}// 授权回调 服务商应用public function callback(){ $aid = input('aid'); $jushuitan_config = Db::name('shop_jushuitan')->where('aid',$aid)->find(); if($jushuitan_config['expires_in']<=time()) { $jst = new JushuitanCustom(); $data = $jst->getAccessToken(input('code')); if ($data['code'] == 0) { try { Db::name('shop_jushuitan')->where('jst_app_key', $jushuitan_config['jst_app_key']) ->where('co_name', $jushuitan_config['co_name']) ->update([ 'access_token' => $data['data']['access_token'], 'expires_in' => time() + intval($data['data']['expires_in']), 'refresh_token' => $data['data']['refresh_token'] ]); } catch (/Exception $e) { return $e->getMessage(); } } else { return $data['msg']; } }}// 取消订单:接收ERP取消订单信息(订单取消就触发)public function cancelOrderErp(){ // 将点大订单状态改为已取消 $aid = input('aid'); $so_id = input('so_id'); $shop_jushuitan_orders = Db::name('shop_jushuitan_orders')->where('so_id', $so_id)->find(); $orderinfo = Db::name('shop_order')->where('id', $shop_jushuitan_orders['order_id'])->find(); // 加库存 $oglist = Db::name('shop_order_goods')->where('aid',$aid)->where('orderid',$orderinfo['id'])->select()->toArray(); foreach($oglist as $og){ Db::name('shop_guige')->where('aid',$aid)->where('id',$og['ggid'])->update(['stock'=>Db::raw('stock+'.$og['num']),'sales'=>Db::raw('sales-'.$og['num'])]); Db::name('shop_product')->where('aid',$aid)->where('id',$og['proid'])->update(['stock'=>Db::raw('stock+'.$og['num']),'sales'=>Db::raw('sales-'.$og['num'])]); } // 优惠券抵扣的返还 if($orderinfo['coupon_rid']){ Db::name('coupon_record')->where('aid',$aid)->where('mid',$orderinfo['mid'])->where('id','in',$orderinfo['coupon_rid'])->update(['status'=>0,'usetime'=>'']); } Db::name('shop_order')->where('id',$orderinfo['id'])->where('aid',$aid)->update(['status'=>4]); Db::name('shop_order_goods')->where('orderid',$orderinfo['id'])->where('aid',$aid)->update(['status'=>4])

聚水潭接口对接 - 订单同步、库存同步、取消订单、物流同步、售后收货

原文地址: https://www.cveoy.top/t/topic/nu0p 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录