"彩色", "2" => "黑白"]; protected array $duplex = ["1" => "单面", "2" => "双面"]; protected array $type = ["1" => "文档", "2" => "复印"]; #[Route(path: "data",methods: "get")] public function getUserData(Request $request): Response { try { $param = $this->_valid([ "shop.require" => trans("empty.require"), ],$request->method()); if (!is_array($param)) return error($param); $user = $request->user; if (empty($user)) return errorTrans("empty.data"); $member = (new SaasUserOpen)->where("openid",$user['openid'])->with(['vip' => function($query) use($param){ $query->where("shop_id",$param['shop'])->field("openid,shop_id,ROUND(balance/100,2) as f_balance,ROUND(total_balance/100,2) as f_total_balance,ROUND(total_consume/100,2) as f_total_consume,card_no"); }])->field("openid,headimg,nickname")->append(["coupon"])->withAttr(['coupon' => function(){ return 0; }])->findOrEmpty(); return success("ok",$member->toArray()); } catch (\Throwable $th) { return error($th->getMessage()); } } /** * 价目表 */ #[Route(path: "price",methods: "get")] public function getPriceData(): Response { try { $param = $this->_valid([ "shop.require" => "参数错误" ]); if (!is_array($param)) return error($param); $data = (new SaasPrice)->where("shop_id",$param['shop'])->field("paper_size,source,duplex,price,color,type")->select(); if ($data->isEmpty()) return error("尚未配置价目表"); $resp = []; foreach ($data as $key=>$val) { $color = $this->color[$val['color']]; $type = $this->type[$val['type']]; $duplex = $this->duplex[$val['duplex']]; $resp[$val['paper_size']]['id'] = $val['paper_size']; $resp[$val['paper_size']]['child'][$key]['name'] = $type.$color.$duplex; $resp[$val['paper_size']]['child'][$key]['price'] = $val['price']; } return success("ok",$resp); } catch (\Throwable $exception) { return error($exception->getMessage()); } } }