diff --git a/app/api/controller/Active.php b/app/api/controller/Active.php index 318bcada..b4657290 100644 --- a/app/api/controller/Active.php +++ b/app/api/controller/Active.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); + } } \ No newline at end of file diff --git a/app/api/controller/Recovery.php b/app/api/controller/Recovery.php index 7303eed3..a0473116 100644 --- a/app/api/controller/Recovery.php +++ b/app/api/controller/Recovery.php @@ -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('操作成功'); } /** diff --git a/app/api/controller/Store.php b/app/api/controller/Store.php index 776171b3..4ca9a36e 100644 --- a/app/api/controller/Store.php +++ b/app/api/controller/Store.php @@ -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 diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 2cc77400..a9f42bda 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -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'); } diff --git a/app/api/model/Agreement.php b/app/api/model/Agreement.php index 6da690db..73f7935c 100644 --- a/app/api/model/Agreement.php +++ b/app/api/model/Agreement.php @@ -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(); - } } diff --git a/app/api/model/RecoveryOrder.php b/app/api/model/RecoveryOrder.php index be5ba28a..a1591d63 100644 --- a/app/api/model/RecoveryOrder.php +++ b/app/api/model/RecoveryOrder.php @@ -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(); + } } \ No newline at end of file diff --git a/app/api/service/Store.php b/app/api/service/Store.php index d67c3f5e..21b11017 100644 --- a/app/api/service/Store.php +++ b/app/api/service/Store.php @@ -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; } diff --git a/app/common.php b/app/common.php index a970603c..9a17ebf6 100644 --- a/app/common.php +++ b/app/common.php @@ -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); // 返回结果保留小数点后两位 +} diff --git a/app/common/model/Agreement.php b/app/common/model/Agreement.php index 25683c2a..6241a646 100644 --- a/app/common/model/Agreement.php +++ b/app/common/model/Agreement.php @@ -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); }