shop-php/app/common/dao/store/StoreActivityDao.php

108 lines
3.7 KiB
PHP
Raw Normal View History

2023-05-10 13:38:51 +08:00
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\store;
use app\common\dao\BaseDao;
2024-01-23 10:24:39 +08:00
use app\common\dao\store\product\CloudProductDao;
2023-05-10 13:38:51 +08:00
use app\common\model\BaseModel;
2024-01-23 10:24:39 +08:00
use app\common\model\store\GeoStreet;
2023-05-10 13:38:51 +08:00
use app\common\model\store\StoreActivity;
2024-01-23 10:24:39 +08:00
use app\common\repositories\store\product\SpuRepository;
2023-05-10 13:38:51 +08:00
use app\common\repositories\system\RelevanceRepository;
2024-01-23 10:24:39 +08:00
use think\facade\Db;
2023-05-10 13:38:51 +08:00
/**
*
* Class StoreActivityDao
* @package app\common\dao\system\merchant
*/
class StoreActivityDao extends BaseDao
{
protected function getModel(): string
{
return StoreActivity::class;
}
public function search(array $where = [])
{
$where['is_del'] = 0;
return $this->getSearch($where);
}
2024-01-23 10:24:39 +08:00
/**
* 活动商品专区
* @param $location
* @param $streetCode
* @param $activityId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function product($location, $streetCode, $activityId)
{
if (!empty($location) && $location != ',') {
[$lat, $lng] = explode(',', $location);
} elseif (!empty($streetCode)) {
$location = GeoStreet::where('street_code', $streetCode)->field('lng,lat')->find();
if (!empty($location)) {
[$lat, $lng] = [$location['lat'], $location['lng']];
}
}
if (empty($lat) || empty($lng)) {
[$lat, $lng] = ['28.889137', '105.443352'];
}
$cloud_product_arr = (new CloudProductDao())->getByDistance($lat, $lng, ['activity_id' => $activityId], 4);
$cloud_product = [];
foreach ($cloud_product_arr as $key => $value) {
$cloud_product[] = $value['product_id'];
}
$where = [
'is_show' => 1,
'is_used' => 1,
'status' => 1,
'is_del' => 0,
'mer_status' => 1,
'product_id' => $cloud_product
];
if (!$cloud_product) {
return app('json')->success(['count' => 0, 'list' => []]);
}
$query = Db::name('cloud_product')->where('status', 1);
$count = $query->where(function($query){
$query->whereOr('mer_labels', '')
->whereOr('mer_labels',',5,');
})->count();
/** @var SpuRepository $spuRep */
$spuRep = app()->make(SpuRepository::class);
$products = $spuRep->getApiSearch($where, 1, 4, false, true);
if ($products['list']) {
$list = $products['list'];
foreach ($cloud_product_arr as $key => $value) {
foreach ($list as $k => $v) {
if ($value['product_id'] == $v['product_id']) {
if ($value['mer_labels'] == ',5,') {
$list[$k]['mer_labels_name'] = '五日达';
} else {
$list[$k]['mer_labels_name'] = '同城';
}
}
}
}
}
return ['count' => $count, 'list' => $list ?? []];
}
2023-05-10 13:38:51 +08:00
}