Commit 40ab9604 authored by luhongguang's avatar luhongguang

update: 代码整理

parent 3115e349
......@@ -12,7 +12,7 @@ use App\Services\goods\GoodsService;
class MarketinggoodsController extends Base
{
const KS3_BASE_URL = 'ks3-cn-beijing.ksyun.com';
const KS3_BASE_URL = 'ks3-cn-beijing.ksyuncs.com';
/**
* 获取全部生效营销活动商品列表
*
......
......@@ -23,18 +23,19 @@ class TakePlaceService
public static function searchList($params)
{
$lifeAccountId = $params['life_account_id'] ?? 0;
$lifeAccountId = MarketingService::getPublicLifeAccountId();
$keywords = $params['keywords'] ?? '';
$takePlaceIds = $params['take_place_id'] ?? [];
$offset = $params['offset'] ?? 0;
$limit = $params['limit'] ?? 20;
if(!empty($takePlaceIds)) {
if (!empty($takePlaceIds)) {
$where['take_place_id'] = $takePlaceIds;
}
if($lifeAccountId) {
if ($lifeAccountId) {
$where['life_account_id'] = $lifeAccountId;
}
if($keywords) {
if ($keywords) {
$where['OR'] = [
'take_place_name[~]' => $keywords,
'contact_name[~]' => $keywords,
......@@ -45,7 +46,7 @@ class TakePlaceService
$where['LIMIT'] = [$offset, $limit];
$res['list'] = TakePlace::select('*', $where, []);
unset($where['ORDER'],$where['LIMIT']);
unset($where['ORDER'], $where['LIMIT']);
$res['total'] = TakePlace::count('*', $where);
return $res;
......@@ -85,27 +86,38 @@ class TakePlaceService
$data = [];
if (!empty($result)) {
$tagIds = array_unique(array_column($result, "tag_id"));
$businessCircleIds = array_unique(array_column($result, "business_circle_id"));
list ($tagArr, $businessCircleArr) = self::getTagAndBusinessCircle($tagIds, $businessCircleIds);
foreach ($result as $key => $item) {
$data[$item["take_place_id"]] = $item;
$data[$item["take_place_id"]]["tag_name"] = empty($tagArr[$item["tag_id"]]) ? "" : $tagArr[$item["tag_id"]]["tag_name"];
$data[$item["take_place_id"]]["business_circle_name"] = empty($businessCircleArr[$item["business_circle_id"]]) ? "" : $businessCircleArr[$item["business_circle_id"]]["business_circle_name"];
}
}
return $data;
}
/**
* @param $tagIds
* @param $businessCircleIds
* @return array
*/
private static function getTagAndBusinessCircle($tagIds, $businessCircleIds)
{
$tagList = Tag::getRecords(["tag_id" => $tagIds], ["tag_id", "tag_name"]);
$tagArr = [];
if (!empty($tagList)) {
$tagArr = array_column($tagList, null, "tag_id");
}
$businessCircleIds = array_unique(array_column($result, "business_circle_id"));
$businessCircleList = BusinessCircle::getRecords(["business_circle_id" => $businessCircleIds], ["business_circle_id", "business_circle_name"]);
$businessCircleArr = [];
if (!empty($businessCircleList)) {
$businessCircleArr = array_column($businessCircleList, null, "business_circle_id");
}
foreach ($result as $key => $item) {
$data[$item["take_place_id"]] = $item;
$data[$item["take_place_id"]]["tag_name"] = empty($tagArr[$item["tag_id"]]) ? "" : $tagArr[$item["tag_id"]]["tag_name"];
$data[$item["take_place_id"]]["business_circle_name"] = empty($businessCircleArr[$item["business_circle_id"]]) ? "" : $businessCircleArr[$item["business_circle_id"]]["business_circle_name"];
}
}
return $data;
return [$tagArr, $businessCircleArr];
}
/**
......@@ -118,7 +130,7 @@ class TakePlaceService
{
//验证life_account_id
$lifeAccountId = MarketingService::getPublicLifeAccountId();
if(isset($params['life_account_id']) && $params['life_account_id'] != $lifeAccountId) {
if (isset($params['life_account_id']) && $params['life_account_id'] != $lifeAccountId) {
$url = config('interface', 'merchant.lifeaccount.get_life_account_by_id');
$lifeAccountRes = (new Request())->get($url, ["life_account_id" => $params["life_account_id"]]);
......@@ -139,6 +151,9 @@ class TakePlaceService
$data['province'] = $params['province'];
$data['city'] = $params['city'];
$data['area'] = $params['area'];
$data['tag_id'] = $params['tag_id'];
$data['business_circle_id'] = $params['business_circle_id'];
$data['lunch_deliver_time'] = $params['lunch_deliver_time'];
return TakePlace::insert($data);
}
......@@ -147,15 +162,16 @@ class TakePlaceService
* 删除自提点
* @param $takePlaceId
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws MarketingException
*/
public static function delete($takePlaceId)
{
if(empty(self::detail($takePlaceId))) {
if (empty(self::detail($takePlaceId))) {
throw new MarketingException(['cus' => MarketingException::TAKE_PLACE_NOT_EXIST]);
}
return TakePlace::update(
['is_delete'=>TakePlace::STATUS_DELETE],
['take_place_id'=>$takePlaceId]
['is_delete' => TakePlace::STATUS_DELETE],
['take_place_id' => $takePlaceId]
);
}
......@@ -164,16 +180,17 @@ class TakePlaceService
* @param $marketingPindanId
* @param $takePlaceId
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws MarketingException
*/
public static function bindPindanTakePlace($marketingPindanId,$takePlaceId)
public static function bindPindanTakePlace($marketingPindanId, $takePlaceId)
{
$data = [
'marketing_pindan_id'=>$marketingPindanId,
'take_place_id'=>$takePlaceId,
'marketing_pindan_id' => $marketingPindanId,
'take_place_id' => $takePlaceId,
];
//检查关联是否已存在
if(!empty(MarketingTakePlace::get('*',$data))) {
if (!empty(MarketingTakePlace::get('*', $data))) {
throw new MarketingException(['cus' => MarketingException::RELATION_ALREADY_EXIST]);
}
......@@ -194,12 +211,12 @@ class TakePlaceService
$page = $params['page'] ?? 1;
$limit = $params['limit'] ?? 20;
$offset = ($page-1)*$limit;
$res = ['list'=>[],'total'=>0];
$offset = ($page - 1) * $limit;
$res = ['list' => [], 'total' => 0];
$where = ['marketing_id' => $marketingId];
if($keywords) {
if ($keywords) {
// $where['OR'] = [
// 'take_place_name[~]' => $keywords,
// 'address[~]' => $keywords,
......@@ -214,23 +231,23 @@ class TakePlaceService
// $where['LIMIT'] = [$offset, $limit];
$relations = MarketingTakePlace::select('*', $where);
if(empty($relations)) {
if (empty($relations)) {
return $res;
}
//获取自提点信息
$makePlaceIds = array_column($relations,'take_place_id');
$takePlaceWhere = ['take_place_id'=>$makePlaceIds];
$makePlaceIds = array_column($relations, 'take_place_id');
$takePlaceWhere = ['take_place_id' => $makePlaceIds];
if ( !isset($params['has_delete']) ) {
if (!isset($params['has_delete'])) {
$takePlaceWhere['is_delete'] = 0;
}
//本页按距离返回列表
$res['list'] = self::sortByDistance($latitude,$longitude,TakePlace::select('*', $takePlaceWhere));
$res['list'] = self::sortByDistance($latitude, $longitude, TakePlace::select('*', $takePlaceWhere));
unset($where['ORDER'],$where['LIMIT']);
unset($where['ORDER'], $where['LIMIT']);
$res['total'] = MarketingTakePlace::count('*', $where);
$res['total_page'] = ceil($res['total']/$limit);
$res['total_page'] = ceil($res['total'] / $limit);
return $res;
}
......@@ -245,17 +262,17 @@ class TakePlaceService
private static function sortByDistance($lat, $lng, $list)
{
//未传经纬度
if(empty($lat) || empty($lng)) {
if (empty($lat) || empty($lng)) {
return $list;
}
//按距离返回自提点列表
$sort = [];
if(!empty($list) && is_array($list)) {
if (!empty($list) && is_array($list)) {
foreach ($list as &$item) {
if($item['longitude'] && $item['latitude']) {
$item['distance'] = Geo::geoDistance($lat,$lng,$item['longitude'],$item['latitude'],true);
if ($item['longitude'] && $item['latitude']) {
$item['distance'] = Geo::geoDistance($lat, $lng, $item['longitude'], $item['latitude'], true);
$sort[] = $item['distance'];
}else {
} else {
$item['distance'] = '';
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment