From f279e9c9e320e05e30ee0bcbcaa88c46121afbac Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 29 Aug 2023 18:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B8=AD=E5=A5=96=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 13 ++++++++++++- app/controller/Index.php | 36 ++++++++++++++++++++++++++++++++++++ route/app.php | 3 +++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/app/common.php b/app/common.php index 8e842d1..40cd89d 100644 --- a/app/common.php +++ b/app/common.php @@ -76,7 +76,7 @@ function generate_random_str(int $length = 8): string /** * 返回图片路径 - * @param $image + * @param $imageUrl * @return string */ function get_image_url($imageUrl):string @@ -99,4 +99,15 @@ function get_image_url($imageUrl):string function give_symbol(&$value,$symbol = '+') { $value = $symbol . $value; +} + +/** + * 手机号处理 + * @param $phoneNumber + * @return string + */ +function format_phone_number($phoneNumber) { + $prefix = substr($phoneNumber, 0, 3); + $suffix = substr($phoneNumber, -4); + return $prefix . '****' . $suffix; } \ No newline at end of file diff --git a/app/controller/Index.php b/app/controller/Index.php index 81203ad..84343dc 100644 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -2,6 +2,9 @@ namespace app\controller; use app\BaseController; +use app\model\AwardsRecords; +use app\model\User as UserModel; +use think\facade\Request; class Index extends BaseController { @@ -14,4 +17,37 @@ class Index extends BaseController { return 'hello,' . $name; } + + /** + * 获取首页中间记录 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function awardRecords() + { + + $data = Request::param(); + + $limit = $data['limit'] ?: 10; + + $records = new AwardsRecords(); + + $list = $records->field('user_id,awards_amount')->order('create_time desc')->paginate($limit); + + $data = $list->toArray()['data']; + + foreach ($data as &$item) { + $item['user_id'] .= "XX"; + $user = UserModel::field('phone')->find($item['user_id']); + $item['phone'] = format_phone_number($user['phone']); + $item['awards_amount'] = number_format($item['awards_amount']); + } + + return $this->renderSuccess('数据返回成功',[ + 'list' => $data, + 'total' => $list->total() + ]); + } } diff --git a/route/app.php b/route/app.php index 7599049..e10b032 100644 --- a/route/app.php +++ b/route/app.php @@ -15,6 +15,9 @@ Route::get('think', function () { return 'hello,ThinkPHP6!'; }); +Route::group('index',function () { + Route::post('awardRecords','index/awardRecords')->allowCrossDomain(); +}); Route::group('passport',function (){ Route::post('register','passport/register')->allowCrossDomain();