From dd7176a4fdeb2f6afb448065fefa2fdfc0ba7657 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Tue, 27 Feb 2024 11:42:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E8=A1=8C?= =?UTF-8?q?=E6=94=BF=E5=8C=BA=E5=9F=9F=EF=BC=8C=E7=94=A8=E6=88=B7=E9=82=80?= =?UTF-8?q?=E8=AF=B7=E5=95=86=E6=88=B7=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Common.php | 100 +++++++++++++++++++++++++++++++ app/controller/api/user/User.php | 38 ++++++++++++ route/api.php | 7 +++ 3 files changed, 145 insertions(+) diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 04e73c0e..545ca14f 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -44,8 +44,10 @@ use crmeb\services\WechatService; use Exception; use Joypack\Tencent\Map\Bundle\Location; use Joypack\Tencent\Map\Bundle\LocationOption; +use Overtrue\Pinyin\Pinyin; use think\exception\ValidateException; use think\facade\Cache; +use think\facade\Db; use think\facade\Log; use think\Response; @@ -563,4 +565,102 @@ class Common extends BaseController $data['config'] = systemConfig(['open_screen_switch','open_screen_time','open_screen_space']); return app('json')->success($data); } + + + /** + * 小程序版本 + */ + public function applet() + { + $group_id = Db::name('system_group')->where('group_key', 'applet')->value('group_id'); + $list = []; + if ($group_id) { + $select = Db::name('system_group_data')->where('group_id', $group_id)->field('value')->limit(30)->where('status',1)->select(); + foreach ($select as $key => $value) { + $list[] = json_decode($value['value'], true); + } + } + return app('json')->success($list); + } + + /** + * 获取省级行政区 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getProvince() + { + $select = Db::name('geo_province')->field('province_id id,province_code code,province_name name')->select(); + return app('json')->success($select); + } + + /** + * 获取市级行政区 + * @param $code + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getCity($code) + { + $select = Db::name('geo_city')->where('province_code', $code)->field('city_id id,city_code code,city_name name')->select(); + return app('json')->success($select); + } + + /** + * 获取县级行政区 + * @param $code + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getArea($code) + { + $select = Db::name('geo_area')->where('city_code', $code)->field('area_id id,area_code code,area_name name')->select(); + return app('json')->success($select); + } + + /** + * 获取街道 + * @param $code + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getStreet($code) + { + $select = Db::name('geo_street')->where('area_code', $code)->field('street_id id,street_code code,street_name name')->select()->toArray(); + foreach ($select as $k => &$item) { + $first_char = mb_str_split($item['name']); + if ($first_char[0]) { + $pinyin = new Pinyin(); + $string = $first_char[0]; + $pinyin = $pinyin->abbr($string); + $item['pinyin'] = $pinyin; + } else { + $item['pinyin'] = ''; + } + } + return app('json')->success($select); + } + + /** + * 获取社区 + * @param $code + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getVillage($code) + { + $select = Db::name('geo_village')->where('street_code', $code)->field('village_id id,village_code code,village_name name')->select(); + return app('json')->success($select); + } + } diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 5d103a9d..3a111584 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -14,7 +14,11 @@ namespace app\controller\api\user; +use app\common\dao\store\order\StoreOrderDao; +use app\common\model\system\merchant\Merchant; +use app\common\model\user\User as UserModel; use app\common\repositories\store\IntegralRepository; +use app\common\repositories\store\order\PresellOrderRepository; use app\common\repositories\store\service\StoreServiceRepository; use app\common\repositories\system\CacheRepository; use app\common\repositories\user\MemberinterestsRepository; @@ -537,4 +541,38 @@ class User extends BaseController return app('json')->success('修改成功'); } + /** + * 邀请的商户记录 + * @return mixed + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function merchantRecord() + { + [$page, $limit] = $this->getPage(); + $userIds = UserModel::where('spread_uid', $this->user->uid)->column('uid'); + $query = Merchant::whereIn('uid', $userIds) + ->where('status', 1) + ->where('is_del', 0) + ->where('mer_state', 1); + $count = $query->count(); + $result = $query->page($page, $limit) + ->field('mer_id,mer_name,uid,real_name') + ->select()->toArray(); + $dao = new StoreOrderDao(); + /** @var PresellOrderRepository $preSellDao */ + $preSellRepo = app()->make(PresellOrderRepository::class); + foreach ($result as &$item) { + $saleOrderQuery = $dao->search(['mer_id' => $item['mer_id']])->whereIn('StoreOrder.status', [0, 1, 2, 3, 9, 10])->where('paid', 1); + $saleOrderIds = $saleOrderQuery->column('order_id'); + $saleAmount1 = $saleOrderQuery->sum('StoreOrder.pay_price'); + $saleAmount2 = $preSellRepo->search(['paid' => 1, 'order_ids' => $saleOrderIds])->sum('pay_price'); + $item['sale_amount'] = bcadd($saleAmount1, $saleAmount2, 2); + $item['buy_amount'] = StoreOrderOther::where('uid', $item['uid'])->whereIn('status', [0, 1, 2, 3, 9, 10])->where('paid', 1)->sum('pay_price'); + $item['buy_amount'] = bcadd($item['buy_amount'], 0, 2); + } + return app('json')->success(['count' => $count, 'list' => $result]); + } + } diff --git a/route/api.php b/route/api.php index a64f9a2c..3f2c8767 100644 --- a/route/api.php +++ b/route/api.php @@ -21,6 +21,7 @@ use think\facade\Route; Route::group('api/', function () { Route::any('test', 'api.Auth/test'); + Route::any('applet', 'api.Common/applet'); //强制登录 Route::group(function () { Route::group('v2', function () { @@ -203,6 +204,7 @@ Route::group('api/', function () { Route::get('fields/info', 'UserFields/info'); Route::post('fields/save', 'UserFields/save'); Route::delete('fields/delete', 'UserFields/delete'); + Route::get('merchantRecord', 'User/merchantRecord'); })->prefix('api.user.'); @@ -683,6 +685,11 @@ Route::group('api/', function () { Route::post('ajcheck', 'api.Auth/ajcheck'); Route::get('open_screen', 'api.Common/open_screen'); + Route::get('city/get_province', 'api.Common/getProvince'); + Route::get('city/get_city', 'api.Common/getCity'); + Route::get('city/get_area', 'api.Common/getArea'); + Route::get('city/get_street', 'api.Common/getStreet'); + Route::get('city/get_Village', 'api.Common/getVillage'); })->middleware(AllowOriginMiddleware::class) ->middleware(InstallMiddleware::class) ->middleware(CheckSiteOpenMiddleware::class)