diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index b4c5f0c..aa6398a 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -392,9 +392,9 @@ class OrderController extends Controller { $id = (int)request()->input('id'); - $fields = ['id', 'order_no', 'agent_product_id', 'num', 'price', 'title', 'picture', 'status', + $fields = ['id', 'agent_id', 'order_no', 'agent_product_id', 'num', 'price', 'title', 'picture', 'status', 'pay_type', 'coupon_id', 'paid_money', 'paid_at', 'refund_info', 'verify_code', 'created_at']; - $order = Order::query() + $order = Order::with('agent:id,appid,appsecret') ->where('user_id', $this->user_id) ->find($id, $fields); @@ -405,6 +405,24 @@ class OrderController extends Controller //订单ID和核销码拼接,查询时通过订单ID和核销码来查询,这样核销码不用建索引 $order->verify_code = $order->verify_code ? $order->id . '-' . $order->verify_code : ''; + //如果有核销码,生成核销二维码 + if ($order->verify_code) { + $config = [ + 'app_id' => $order->agent->appid, + 'secret' => $order->agent->appsecret, + ]; + $app = Factory::miniProgram($config); + + $response = $app->app_code->getUnlimit($order->verify_code, ['path' => 'pages/verification/index']); + + if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { + $filename = $response->saveAs(storage_path('app/public/verify_code'), $order->verify_code); + $order->verify_qrcode = Storage::disk('public')->url('verify_code/' . $filename); + } + } + + unset($order->agent, $order->agent_id); //必须unset掉$order->agent,否则会造成appsecret泄漏 + $order->coupon = Coupon::query() ->whereIn('id', $order->coupon_id) ->where(['agent_id' => $this->agent_id, 'agent_product_id' => $order->agent_product_id,]) diff --git a/app/Http/Controllers/Api/VerificationController.php b/app/Http/Controllers/Api/VerificationController.php index d63a3a5..ecc2f8e 100644 --- a/app/Http/Controllers/Api/VerificationController.php +++ b/app/Http/Controllers/Api/VerificationController.php @@ -47,38 +47,4 @@ class VerificationController extends Controller return $this->success(); } - - //生成核销二维码 - public function qrcode() - { - $id = request()->input('id'); //订单ID - - $order = Order::where(['agent_id' => $this->agent_id, 'user_id' => $this->user_id])->find($id); - if (!$order) { - return $this->error('订单不存在!'); - } else if (!in_array($order->status, [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, OrderStatus::REFUSED_REFUND])) { - return $this->error('当前订单状态不允许核销!'); - } else if (!$order->verify_code) { - $order->verify_code = uniqid(); - $order->save(); - } - - $verify_code = $order->id . '-' . $order->verify_code; - - $agent = Agent::find($this->agent_id); - $config = [ - 'app_id' => $agent->appid, - 'secret' => $agent->appsecret, - ]; - $app = Factory::miniProgram($config); - - $response = $app->app_code->getUnlimit($verify_code, ['path' => 'pages/verification/index']); - - if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { - $filename = $response->saveAs(storage_path('app/public/verify_code'), $verify_code); - } - - $prefix = Storage::disk('public')->url('verify_code/'); - return $this->success(['qrcode' => $prefix . $filename]); - } }