用户服务订单模块联调门店返回坐标

pull/1/head
ztt 9 months ago
parent 800ad4ae4b
commit 47c55a1051
  1. 27
      app/api/controller/Active.php
  2. 42
      app/api/controller/Recovery.php
  3. 9
      app/api/controller/Store.php
  4. 3
      app/api/controller/User.php
  5. 8
      app/api/model/Agreement.php
  6. 16
      app/api/model/RecoveryOrder.php
  7. 2
      app/api/service/Store.php
  8. 29
      app/common.php
  9. 4
      app/common/model/Agreement.php

@ -6,6 +6,7 @@ use app\api\model\Goods as GoodsModel;
use app\common\model\ActiveMain;
use app\common\model\Goods;
use think\response\Json;
use app\common\library\helper;
/**
* 活动相关接口
@ -66,4 +67,30 @@ class Active extends Controller
$goods_list = $goodsModel->getList([], $limit);
return $this->renderSuccess($goods_list->toArray());
}
public function funTest() {
$data = [
[
'id' => 1,
'name' => 'ztt'
],
[
'id' => 2,
'name' => 'ztt2'
],
[
'id' => 3,
'name' => 'ztt3'
],
];
// $res = helper::getArrayColumns($data, ['id', 'name']);
$res = helper::getArrayColumn($data, 'id');
// $res = helper::arrayColumn2Key($data, 'id');
// $res = array_column($data, 'id'); // ==> helper::getArrayColumn
// $res = array_column($data, null, 'id'); // ==> helper::arrayColumn2Key
// $ids = array_keys($res);
// $res = array_column($data, 'name', 'id');
// $res = helper::getArrayColumnSum();
dd($res);
}
}

@ -152,11 +152,12 @@ class Recovery extends Controller
$info['is_edit'] = 1;
}
$images_list = helper::getArrayColumn($info['images'], 'file');
$arr = [];
foreach ($images_list as $image) {
$arr[] = $image['preview_url'];
}
$info['images_list'] = $arr;
// $arr = [];
// foreach ($images_list as $image) {
// $arr[] = $image['preview_url'];
// }
// $info['images_list'] = $arr;
$info['images_list'] = $images_list;
unset($info['images']);
//回收信息
$info['recovery_image'] = '';
@ -305,17 +306,20 @@ class Recovery extends Controller
$image_str = $this->request->post('image_ids');
$imageIds = [];
if ($image_str) {
if (!is_array($image_str)) {
$imageIds = explode(',', $image_str);
} else {
$imageIds = $image_str;
}
}
if ($imageIds && !is_array($imageIds)) {
$imageIds = explode(',', $imageIds);
} else {
$imageIds = [];
}
$imageIds = explode(',', $image_str);
}
// if ($image_str) {
// if (!is_array($image_str)) {
// $imageIds = explode(',', $image_str);
// } else {
// $imageIds = $image_str;
// }
// }
// if ($imageIds && !is_array($imageIds)) {
// $imageIds = explode(',', $imageIds);
// } else {
// $imageIds = [];
// }
$shop_id = intval($this->request->post('shop_id'));
if (!$shop_id) {
return $this->renderError('门店不能为空');
@ -384,10 +388,8 @@ class Recovery extends Controller
'house_number' => $house_number,
];
$model = new RecoveryOrder();
if ($model->edit($data, $order_id, $imageIds)) {
return $this->renderSuccess('操作成功');
}
return $this->renderError('操作失败');
$model->edit($data, $order_id, $imageIds);
return $this->renderSuccess('操作成功');
}
/**

@ -78,7 +78,14 @@ class Store extends Controller
public function getStore(): Json
{
$service = new StoreService;
return $this->renderSuccess($service->getStore());
$store = $service->getStore();
$userLatitude = $this->request->param('userLat', 32.919925); // 用户纬度
$userLongitude = $this->request->param('userLng', 118.825957); // 用户经度
foreach ($store as &$row) {
$distanceInKm = calculateDistance($userLatitude, $userLongitude, $row['latitude'], $row['longitude']);
$row['distance'] = $distanceInKm . "km";
}
return $this->renderSuccess($store);
}
public function editStore(): Json

@ -273,11 +273,10 @@ class User extends Controller
*/
public function getAgreement(): Json {
$params = $this->request->param();
$model = new AgreementModel();
if (empty($params['type'])) {
return $this->renderSuccess("参数错误");
}
$detail = $model->detail2($params);
$detail = AgreementModel::detail(['type' => $params['type']]);
return $this->renderSuccess(compact('detail'), 'success');
}

@ -36,13 +36,5 @@ class Agreement extends AgreementModel
'update_time'
];
/**
* 协议类型
* @param $params
* @return Agreement|array|null
*/
public function detail2($params) {
return self::where('type', $params['type'])->find();
}
}

@ -96,6 +96,7 @@ class RecoveryOrder extends BaseRecoveryOrder
{
if ($this->where(['order_id' => $orderId])->save($data)) {
if ($imageIds) {
log_record(['name'=>'服务订单图片', 'image_ids' => $imageIds]);
RecoveryImage::updates($orderId, $imageIds);
}
return true;
@ -125,4 +126,19 @@ class RecoveryOrder extends BaseRecoveryOrder
}
return false;
}
/**
* 获取回收单记录
* @return int
*/
public static function getCount() {
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
// 查询数据
return self::where('user_id', '=', $userId)
->where('order_status', '<>', 20)
->where('is_delete', '=', 0)
->count();
}
}

@ -186,7 +186,7 @@ class Store extends BaseService
public function getStore()
{
$storeList = Db::query('select shop_id,shop_name from yoshop_store_shop where status = 1 and is_delete= 0');
$storeList = Db::query('select shop_id,shop_name,longitude,latitude from yoshop_store_shop where status = 1 and is_delete= 0');
return $storeList;
}

@ -457,3 +457,32 @@ function getUrl($value, $host = ''){
$host = $host ? $host : getHost();
return $value ? $host."/".$value : "";
}
/**
* 计算用户和门店距离
* @param float $lat1 用户纬度
* @param float $lon1 用户经度
* @param float $lat2
* @param float $lon2
* @return float
*/
function calculateDistance($lat1, $lon1, $lat2, $lon2): float
{
// 将角度转换为弧度
$degToRad = M_PI / 180;
// 经纬度转换成弧度
$lat1 *= $degToRad;
$lon1 *= $degToRad;
$lat2 *= $degToRad;
$lon2 *= $degToRad;
// 应用Haversine Formula计算球体上两点之间的距离
$dLat = ($lat2 - $lat1);
$dLon = ($lon2 - $lon1);
$a = pow(sin($dLat/2), 2) + cos($lat1) * cos($lat2) * pow(sin($dLon/2), 2);
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
$distance = 6371 * $c; // 地球平均半径为6371km
return round($distance, 2); // 返回结果保留小数点后两位
}

@ -42,11 +42,11 @@ class Agreement extends BaseModel
/**
* 详情
* @param int $agreementId
* @param mixed $agreementId
* @param array $with
* @return static|array|null
*/
public static function detail(int $agreementId, array $with = [])
public static function detail($agreementId, array $with = [])
{
return self::get($agreementId, $with);
}

Loading…
Cancel
Save