get(); if (empty($param['shop'])) { $param['shop'] = $request->user['agent_id']; } if (empty($param['status'])) $param['statusGt'] = 1; $list = $this->service->getList($param); return successTrans("success.data",pageFormat($list),200); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 返回统计结果 * @param Request $request * @return Response */ #[Route(path: "fail",methods: "post")] public function setOrderFail(Request $request): Response { try { $param = $this->_valid(['order.require' => "error"],$request->method()); if (!is_array($param)) return error($param); $order = $this->model->where("order_sn",$param['order'])->findOrEmpty(); if ($order->isEmpty()) return errorTrans("empty.data"); $order->status = 2; $order->save(); (new SaasOrderDetail)->where("order_sn",$param['order'])->update(['status' => 3]); return successTrans("success.data"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 返回统计结果 * @param Request $request * @return Response */ #[Route(path: "total",methods: "get")] public function getTotalData(Request $request): Response { try { $param = $request->get(); if (empty($param['shop'])) { $param['shop'] = $request->user['agent_id']; } $total = $this->service->getTotal($param); return successTrans("success.data",compact("total")); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 申请退款 * @param Request $request * @return Response */ #[Route(path: "refund",methods: "post")] public function setRefund(Request $request): Response { try { $param = $this->_valid([ "id.require" => trans("empty.require") ],$request->method()); if (!is_array($param)) return error($param); $order = $this->model->where("id",$param['id'])->where("shop_id",$request->user['agent_id'])->findOrEmpty(); if ($order->isEmpty()) return errorTrans("empty.data"); if ($order['pay_type'] == 1) { // 微信退款 $wechat = new \WeChat\Pay($this->getWxConfig()); $resp = $wechat->createRefund([ "transaction_id" => $order['transaction_id'], "out_refund_no" => $order['order_sn']."-".date("is"), "total_fee" => $order['discount'], "refund_fee" => $order['discount'], "notify_url" => 'https://panel.huiyinduo.cn/notify/refund', ]); $order->status = 4; $state = $order->save(); (new SaasOrderDetail)->where("shop_id",$request->user['agent_id'])->where("order_sn",$order['order_sn'])->update(['status' => 4]); } else { // 会员卡退款 $card = (new SaasUser)->where("card_no",md5($order['openid'].$request->user['agent_id']))->findOrEmpty(); if ($card->isEmpty()) return error("会员不存在"); $card->balance = Db::raw("balance+".$order['discount']); $card->total_consume = Db::raw("total_consume-".$order['discount']); $card->save(); (new SaasUserLog)->insertGetId([ "order_sn" => $order['order_sn'], "openid" => $order['openid'], "shop_id" => $order['shop_id'], "card_no" => md5($order['openid'].$order['shop_id']), "money" => $order['discount'], "type" => 2, "balance" => $card->balance, "remark" => "订单退款" ]); $order->status = 6; $state = $order->save(); (new SaasOrderDetail)->where("shop_id",$request->user['agent_id'])->where("order_sn",$order['order_sn'])->update(['status' => 6]); } if (!$state) return error("申请失败"); return success("申请成功"); } catch (\Throwable $throwable) { echo $throwable->getLine()."\n"; echo $throwable->getFile()."\n"; return error($throwable->getMessage()); } } protected function getWxConfig(): array { return [ 'token' => 'test', 'appid' => sConf("wechat.mini_appid"), 'appsecret' => sConf("wechat.mini_secret"), 'encodingaeskey' => 'BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5', // 配置商户支付参数(可选,在使用支付功能时需要) 'mch_id' => sConf("wechat.mch_id"), 'mch_key' => sConf("wechat.mch_key"), "ssl_cer" => public_path().sConf("wechat.mch_ssl_cer"), "ssl_key" => public_path().sConf("wechat.mch_ssl_key"), ]; } }