调整活动商品区域查询

This commit is contained in:
luofei 2024-01-24 10:14:09 +08:00 committed by mkm
parent b4ba989c37
commit 9ba73d596d
5 changed files with 49 additions and 0 deletions

View File

@ -19,6 +19,7 @@ use app\common\model\store\product\CloudProduct;
use app\common\model\store\StoreActivity;
use app\common\model\store\StoreActivityOrderProduct;
use app\common\repositories\store\product\SpuRepository;
use think\db\Query;
use think\exception\ValidateException;
use think\facade\Db;
@ -139,4 +140,27 @@ class StoreActivityDao extends BaseDao
}
}
/**
* 根据活动获取对应的镇街
* @param $activityId
* @return array
*/
public function district($activityId)
{
$merchants = CloudProduct::with(['merchant' => function (Query $query) {
$query->with(['street' => function (Query $query) {
$query->field('street_code,street_name');
}])->field('mer_id,street_id');
}])->where('activity_id', $activityId)->field('mer_id')->group('mer_id')->select()->toArray();
$result = [];
foreach ($merchants as $merchant) {
$streetCode = $merchant['merchant']['street']['street_code'] ?? '';
$streetName = $merchant['merchant']['street']['street_name'] ?? '';
if (!isset($result[$streetCode]) && !empty($streetCode)) {
$result[$streetCode] = ['street_code' => $streetCode, 'street_name' => $streetName];
}
}
return array_values($result);
}
}

View File

@ -13,6 +13,7 @@
namespace app\common\model\store\product;
use app\common\model\BaseModel;
use app\common\model\system\merchant\Merchant;
class CloudProduct extends BaseModel
{
@ -30,4 +31,9 @@ class CloudProduct extends BaseModel
return 'cloud_product';
}
public function merchant()
{
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
}
}

View File

@ -310,4 +310,10 @@ class Merchant extends BaseModel
{
$query->whereIn('mer_id',$value);
}
public function street()
{
return $this->hasOne(GeoStreet::class, 'street_code', 'street_id');
}
}

View File

@ -118,4 +118,16 @@ class StoreActivity extends BaseController
return app('json')->success($result);
}
/**
* 根据活动获取对应的镇街
* @param StoreActivityDao $dao
* @return mixed
*/
public function district(StoreActivityDao $dao)
{
$activityId = $this->request->get('activity_id', 2);
$result = $dao->district($activityId);
return app('json')->success($result);
}
}

View File

@ -468,6 +468,7 @@ Route::group('api/', function () {
Route::get('record', 'api.store.StoreActivity/record'); //活动红包获取记录
Route::get('total', 'api.store.StoreActivity/total'); //活动红包统计
Route::get('product', 'api.store.StoreActivity/product'); //活动商品专区
Route::get('district', 'api.store.StoreActivity/district'); //活动地区列表
});
})->middleware(UserTokenMiddleware::class, true);