diff --git a/app/common/repositories/user/ExchangePickupPointRepository.php b/app/common/repositories/user/ExchangePickupPointRepository.php index 710fc6a..0e1ff14 100644 --- a/app/common/repositories/user/ExchangePickupPointRepository.php +++ b/app/common/repositories/user/ExchangePickupPointRepository.php @@ -26,6 +26,8 @@ class ExchangePickupPointRepository extends BaseRepository{ $info->address = $params['address']; $info->is_show = $params['is_show']; $info->uid_list = implode(',',$params['uid_list']); + $info->lat = $params['lat']; + $info->lng = $params['lng']; $info->save(); } @@ -42,7 +44,13 @@ class ExchangePickupPointRepository extends BaseRepository{ * @throws \think\db\exception\ModelNotFoundException */ public function getList(array $params,int $page,int $limit):array{ + // 查询 $query = $this->dao->getSearch([]) + ->when((isset($params['lng']) && $params['lng'] > 0) && (isset($params['lat']) && $params['lat'] > 0),function($query) use ($params){ + $distance = "ROUND((ST_DISTANCE(point(lng, lat), point({$params['lng']}, {$params['lat']})) * 111195),2)"; + $query->field("*,{$distance} as distance") + ->orderRaw("{$distance} ASC"); + }) ->when((int)$params['uid'] > 0,function($query) use ($params){ $query->where('find_in_set(' . $params['uid'] . ',`uid_list`)'); }) @@ -56,9 +64,16 @@ class ExchangePickupPointRepository extends BaseRepository{ $query->where('address', "like", "%{$params['address']}%") ->whereOr('title','like',"%{$params['address']}%"); }) - ->order('create_time DESC,id DESC'); + ->order("create_time DESC,id DESC"); $count = $query->count(); - $list = $query->page($page,$limit)->append(['user_list'])->select(); + $list = $query->page($page,$limit)->append(['user_list'])->select()->each(function($item){ + if($item->distance > 0){ + if ($item->distance < 100) $item->distance_text = '100m以内'; + else $item->distance_text = sprintf("%.2f",$item->distance / 1000).'km'; + } + + return $item; + }); return compact('count','list'); } diff --git a/app/controller/admin/Common.php b/app/controller/admin/Common.php index 106457f..7fb72a9 100644 --- a/app/controller/admin/Common.php +++ b/app/controller/admin/Common.php @@ -401,7 +401,7 @@ class Common extends BaseController public function config() { - $config = systemConfig(['delivery_type', 'delivery_status', 'sms_use_type', 'hot_ranking_lv', 'hot_ranking_switch']); + $config = systemConfig(['delivery_type', 'delivery_status', 'sms_use_type', 'hot_ranking_lv', 'hot_ranking_switch','tx_map_key']); return app('json')->success($config); } diff --git a/app/controller/admin/user/ExchangeQuota.php b/app/controller/admin/user/ExchangeQuota.php index f72eaed..4d4d647 100644 --- a/app/controller/admin/user/ExchangeQuota.php +++ b/app/controller/admin/user/ExchangeQuota.php @@ -127,10 +127,11 @@ class ExchangeQuota extends BaseController */ public function pickupPointEdit(){ // 参数获取 - $params = $this->request->params(['id','title','address','is_show','uid_list']); + $params = $this->request->params(['id','title','address','is_show','uid_list','lat','lng']); if(empty($params['title'])) return app('json')->fail('请输入提货点名称!'); if(empty($params['address'])) return app('json')->fail('请输入提货点地址!'); if(!is_array($params['uid_list']) || count($params['uid_list']) <= 0) return app('json')->fail('请至少选择一个负责人!'); + if(empty($params['lat']) || empty($params['lng'])) return app('json')->fail('请选择经纬度!'); // 判断:地址是否已经存在 $isHave = ExchangePickupPoint::where('address',$params['address']) ->when((int)$params['id'] > 0,function($query) use ($params){ diff --git a/app/controller/api/user/Exchange.php b/app/controller/api/user/Exchange.php index fb76485..c17f188 100644 --- a/app/controller/api/user/Exchange.php +++ b/app/controller/api/user/Exchange.php @@ -14,9 +14,7 @@ use app\common\repositories\user\ExchangeQuotaRepository; use app\common\repositories\user\UserRepository; use crmeb\basic\BaseController; use crmeb\services\QrcodeService; -use crmeb\services\wechat\MiniProgram; use think\App; -use think\exception\ValidateException; use think\facade\Db; class Exchange extends BaseController{ @@ -24,7 +22,6 @@ class Exchange extends BaseController{ public function __construct(App $app){ parent::__construct($app); - $this->user = $this->request->userInfo(); } /** * Common: 获取用户持有信息 @@ -35,6 +32,7 @@ class Exchange extends BaseController{ public function getUserHold(){ $params = $this->request->params(['consume_uid']); $uid = $this->request->uid(); + $user = $this->request->userInfo(); // 判断:是否存在指定消费者,不存在则使用当前登录用户 $uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid; // 获取额度 @@ -48,7 +46,7 @@ class Exchange extends BaseController{ ->where('uid',$uid) ->findOrEmpty(); $info->available = (float)$info->available; - $info->available_integral = (float)$this->user->exchange_integral; + $info->available_integral = (float)$user->exchange_integral; $info->diff_rate = 30;// 差价 应补金额,默认为30% return app('json')->success($info); @@ -60,9 +58,11 @@ class Exchange extends BaseController{ * @return mixed */ public function getPointList(){ - $search = $this->request->params(['uid', 'address', 'default_point_id']); + $search = $this->request->params(['uid', 'address', 'default_point_id','lng','lat']); $search['is_show'] = 1; - $data = app()->make(ExchangePickupPointRepository::class)->getList($search, 1, 30); + $make = app()->make(ExchangePickupPointRepository::class); + [$page, $limit] = $this->getPage(); + $data = $make->getList($search, $page, $limit); $list = $data['list']; return app('json')->success($list); diff --git a/route/api.php b/route/api.php index 5955b03..b28f8ed 100644 --- a/route/api.php +++ b/route/api.php @@ -349,7 +349,6 @@ Route::group('api/', function () { // 商品兑换 Route::group('exchange', function () { // 兑换相关 - Route::get('pointList', 'Exchange/getPointList'); Route::get('userHold', 'Exchange/getUserHold'); Route::get('exchangeHandle', 'Exchange/exchangeHandle'); Route::get('exchangeRecord', 'Exchange/exchangeRecord'); @@ -366,6 +365,10 @@ Route::group('api/', function () { //非强制登录 Route::group(function () { + // 商品兑换 + Route::get('exchange/pointList', 'api.user.Exchange/getPointList'); + + // 付费会员 Route::group('svip', function () { //价格列表