all(); if (!empty($param['size'])) { $param['pageSize'] = $param['size']; } $param['openid'] = $request->user['openid']; $data = $this->service->setModel()->getList($param,['product' => function($query){ $query->field("product_id,product_name"); }]); return successTrans("success.data",pageFormat($data)); } catch (\Throwable $th) { return error($th->getMessage()); } } #[PostMapping("del")] public function delOrderData(Request $request): Response { try { $param = $this->_valid([ "order.require" => trans("empty.require"), "type.require" => trans("empty.require"), ],$request->method()); if (!is_array($param)) return error($param); $order = $this->model->where("order_sn",$param['order'])->with(['product','poi'])->findOrEmpty(); if ($order->isEmpty()) return errorTrans("empty.data"); if ($order['openid'] <> $request->user['openid']) return errorTrans("empty.data"); switch ($param['type']) { case "del": // 删除订单 if ($order['status'] <> 5) return error("该订单不支持删除"); $state = $order->delete(); break; case "cancel": // 取消订单 if ($order['status'] <> 0) return error("该订单不支持取消"); $order->status = 5; $state = $order->save(); break; default: $state = false; break; } if (!$state) return errorTrans("error.data"); return successTrans("success.data"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } #[PostMapping("refund")] public function orderRefund(Request $request): Response { try { $param = $this->_valid([ "order.require" => trans("empty.require"), "refund.require" => trans("empty.require"), ],$request->method()); if (!is_array($param)) return error($param); $order = $this->model->where("order_sn",$param['order'])->with(['product','poi'])->findOrEmpty(); if ($order->isEmpty()) return errorTrans("empty.data"); if ($order['openid'] <> $request->user['openid']) return errorTrans("empty.data"); if ($order['status'] <> 1) return error("当前订单不支持退款"); $reason = explode(",",$param['refund']); $payParam = [ "order_sn" => $order['order_sn'], "total" => $order['pay_money'], "reason" => $reason[0]??'不想要了', "out_refund_no" => $order['pay_sn'], "notify_url" => "https://tran.jsshuita.cn/notify/refund" ]; $byteAuthorization = (new Pay)->config([ "appid" => sConf("wechat.mini_appid"), "secret" => sConf("wechat.mini_secret"), "salt" => sConf("wechat.mch_salt"), ])->createRefund($payParam); if (!$byteAuthorization) return error("发起退款失败"); $order->status = 4; $order->refund_apply = getDateFull(); $state = $order->save(); if (!$state) return errorTrans("error.data"); return successTrans("提交申请成功"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } #[GetMapping('detail')] public function getDataDetail(Request $request): Response { try { $param = $this->_valid([ "order.require" => trans("empty.require") ],$request->method()); if (!is_array($param)) return error($param); $order = $this->model->where("out_order_no",$param['order'])->with(['product','poi'])->findOrEmpty(); if ($order->isEmpty()) return errorTrans("empty.data"); $order['end_time'] = timeDiff(strtotime("+30 minutes",strtotime($order['create_at'])),time()); return $this->encode("ok",$order->toArray()); } catch (\Throwable $th) { return error($th->getMessage()); } } #[GetMapping("confirm")] public function confirmOrder(Request $request): Response { try { $param = $this->_valid([ "order.require" => trans("empty.require") ],$request->method()); if (!is_array($param)) return error($param); $order = $this->model->where("order_sn",$param['order'])->with(['product','poi'])->findOrEmpty(); if ($order->isEmpty()) return errorTrans("empty.data"); if ($order['status'] <> 0) return errorTrans("empty.data"); return $this->encode("ok",$order->toArray()); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 差价支付 * @param Request $request * @return Response */ #[PostMapping("pricePay")] public function orderPricePay(Request $request): Response { try { $param = $this->_valid([ "order.require" => trans("empty.require") ],$request->method()); if (!is_array($param)) return error($param); $order = (new SaasOrderPrice)->where("order_sn",$param['order'])->findOrEmpty(); $payParam = [ "order_sn" => $order['order_sn'], "total" => $order['price'], "name" => $order['name'], "notify_url" => "https://tran.jsshuita.cn/notify/price" ]; $byteAuthorization = (new Pay)->config([ "appid" => sConf("wechat.mini_appid"), "secret" => sConf("wechat.mini_secret"), "salt" => sConf("wechat.mch_salt"), ])->createOrder($payParam); return success("ok",['pay' => $byteAuthorization]); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 发起支付 * @param Request $request * @return Response */ #[PostMapping("toPay")] public function orderPay(Request $request): Response { try { $param = $this->_valid([ "order.require" => trans("empty.require"), "mobile.default" => "" ],$request->method()); if (!is_array($param)) return error($param); $order = $this->model->where("order_sn",$param['order'])->with(['product','poi'])->findOrEmpty(); $payParam = [ "order_sn" => $order['order_sn'], "total" => $order['price'], "name" => $order['product']['product_name'], "notify_url" => "https://tran.jsshuita.cn/notify/douyin" ]; $byteAuthorization = (new Pay)->config([ "appid" => sConf("wechat.mini_appid"), "secret" => sConf("wechat.mini_secret"), "salt" => sConf("wechat.mch_salt"), ])->createOrder($payParam); if (!empty($param['mobile'])) { $order->mobile = $param['mobile']; $order->save(); } return success("ok",['pay' => $byteAuthorization]); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } #[PostMapping("mobile")] public function getOrderMobile(Request $request) { try { $param = $request->post(); $mobile = []; if (!empty($param['code'])) { $mobileStr = (new Crypt)->config($this->getDyConfig())->token()->getMobile($param['code']); if (!empty($mobileStr)) { $mobile = $this->decrypt2code(sConf('wechat.min_private_key'), $mobileStr); } } $mobileStr = ""; if (!empty($mobile['purePhoneNumber'])) { $mobileStr = $mobile['purePhoneNumber']; } return success("ok",['mobile' => $mobileStr]); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } protected function decrypt2code($private_key, $ciphertext_str) { // 解码 base64 密文 $ciphertext = base64_decode($ciphertext_str); // 使用私钥解密 openssl_private_decrypt($ciphertext, $plaintext, $private_key, OPENSSL_PKCS1_PADDING); if ($plaintext === false) { return []; } return json_decode($plaintext,true); } protected function decrypt($encrypted_data, $session_key, $iv) { $data = base64_decode($encrypted_data); $key = base64_decode($session_key); $iv_decoded = base64_decode($iv); // 使用 AES-256-CBC 模式解密 $decrypted = openssl_decrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv_decoded); return $decrypted; } }