get(); if (empty($param['shop'])) { $param['shop'] = $request->user['shop_id']; } if (!empty($param['order'])) { $orderType = explode("-",$param['order']); if (count($orderType)>1) { // 搜索取件码 $param['sn'] = $param['order']; } else { $param['orderid'] = $param['order']; } } 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()); } } #[Route(path: "detail",methods: "get")] public function getOrderDetail(Request $request): Response { try { $param = $this->_valid([ "id.require" => trans("empty.require") ],$request->method()); if (!is_array($param)) return error($param); $detail = $this->model->where("id",$param['id'])->with(['detail','shop' => function($query){ $query->field("shop_id,shop_name"); }])->findOrEmpty(); if ($detail->isEmpty()) return errorTrans("error.data"); if ($detail['shop_id'] <> $request->user['shop_id']) return errorTrans("error.data"); $startTime = strtotime(date('Y-m-d 00:00:00')); $endTime = strtotime(date('Y-m-d 23:59:58')); $orderTime = strtotime($detail['create_at']); $detail['today'] = (($orderTime > $startTime && $orderTime < $endTime) ? 1 : 0); return success("ok",$detail->toArray()); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } #[Route(path: "refund",methods: "post")] public function orderRefund(Request $request): Response { try { $param = $this->_valid([ "id.require" => trans("empty.require") ],$request->method()); if (!is_array($param)) return error($param); $detail = $this->model->where("id",$param['id'])->findOrEmpty(); if ($detail->isEmpty()) return errorTrans("error.data"); if ($detail['shop_id'] <> $request->user['shop_id']) return errorTrans("error.data"); if (!in_array($detail['status'],[1,2,3])) return error("该订单不支持退款"); if ($detail['pay_type'] == 2) { $card = (new SaasUser)->where("openid",$detail['openid'])->where("shop_id",$detail['shop_id'])->findOrEmpty(); if ($card->isEmpty()) return error("会员卡失效"); $card->balance = ($card['balance'] + $detail['money']); $card->total_consume = ($card['total_consume'] - $detail['money']); $card->save(); (new SaasUserLog)->insertGetId([ "openid" => $detail['openid'], "shop_id" => $detail['shop_id'], "order_sn" => $detail['order_sn'], "money" => $detail['money'], "card_no" => strtoupper(md5($detail['openid'].$detail['shop_id'])), "type" => 2, "remark" => "订单退款", "balance" => $card['balance'] - $detail['money'], ]); $detail->status = 6; $detail->refund_at = getDateFull(); $detail->save(); (new SaasOrderDetail)->where("order_sn",$detail['order_sn'])->update(['status' => 6]); return success("退款成功"); } $respJhf = (new Pay)->config([ "appid" => sConf("wechat.jhf_appid"), "mch_id" => sConf("wechat.jhf_mch_id"), "aeskey" => sConf("wechat.jhf_aeskey"), "pubkey" => sConf("wechat.jhf_pubkey"), "prikey" => sConf("wechat.jhf_prikey"), ])->createRefund([ "payment_id" => $detail['payment_id'], "order_no" => $detail['order_sn'], "notify_url" => "https://panel.huiyinduo.cn/notify/refund", "refund_amt" => format_money($detail['money']/100,2) ]); if (isset($respJhf['code'])) { return error("发起退款失败"); } $detail->status = 4; $state = $detail->save(); if (!$state) return errorTrans("error.data"); (new SaasOrderDetail)->where("order_sn",$detail['order_sn'])->update(['status' => 4]); return successTrans("success.data"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } }