117 lines
4.4 KiB
PHP
Executable File
117 lines
4.4 KiB
PHP
Executable File
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeshop开源商城系统
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||
// | github下载:https://github.com/likeshop-github
|
||
// | 访问官网:https://www.likeshop.cn
|
||
// | 访问社区:https://home.likeshop.cn
|
||
// | 访问手册:http://doc.likeshop.cn
|
||
// | 微信公众号:likeshop技术社区
|
||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||
// | likeshop团队版权所有并拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeshop.cn.team
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\api\lists;
|
||
|
||
|
||
use app\common\enum\AdEnum;
|
||
use app\common\enum\MenuEnum;
|
||
use app\common\enum\PayEnum;
|
||
use app\common\enum\shop\ShopEnum;
|
||
use app\common\lists\BaseDataLists;
|
||
use app\common\model\ad\Ad;
|
||
use app\common\model\goods\Goods;
|
||
use app\common\model\goods\GoodsCategory;
|
||
use app\common\model\order\Order;
|
||
use app\common\model\shop\Shop;
|
||
use app\common\model\shop\ShopCategoryIndex;
|
||
|
||
class ShopLists extends BaseDataLists
|
||
{
|
||
/**
|
||
* @notes 搜索条件
|
||
* @return array
|
||
* @author ljj
|
||
* @date 2022/3/25 9:54 上午
|
||
*/
|
||
public function where()
|
||
{
|
||
$where = [];
|
||
if(isset($this->params['keyword']) && $this->params['keyword']){
|
||
$where[] = ['name','like','%'.$this->params['keyword'].'%'];
|
||
}
|
||
if(isset($this->params['category_id']) && $this->params['category_id']){
|
||
$shopIds = ShopCategoryIndex::where(['category_id'=>$this->params['category_id']])->column('shop_id');
|
||
empty($shopIds) && $shopIds = [];
|
||
$where[] = ['id','in',$shopIds];
|
||
}
|
||
if(isset($this->params['city_id']) && $this->params['city_id']){
|
||
$where[] = ['city_id','=',$this->params['city_id']];
|
||
}
|
||
$where[] = ['audit_status','=',ShopEnum::AUDIT_STATUS_PASS];
|
||
$where[] = ['server_status','=',ShopEnum::SERVERSTATUSOPEN];
|
||
return $where;
|
||
}
|
||
|
||
/**
|
||
* @notes 广告列表
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @author ljj
|
||
* @date 2022/3/25 9:54 上午
|
||
*/
|
||
public function lists(): array
|
||
{
|
||
$field = 'id,name,good_comment,logo,work_status,0 as distance';
|
||
if (!empty($params['longitude']) && !empty($params['latitude'])) {
|
||
$field = 'id,name,good_comment,logo,work_status,round(st_distance_sphere(point('.$this->params['longitude'].','.$this->params['latitude'].'),point(longitude, latitude))/1000,2) as distance';
|
||
}
|
||
$lists = Shop::where($this->where())
|
||
->append(['distance_desc','categoryIds','work_status_desc'])
|
||
->order('distance asc')
|
||
->field($field)
|
||
->limit($this->limitOffset, $this->limitLength)
|
||
->select()
|
||
->toArray();
|
||
$categoryLists = GoodsCategory::where(['is_show'=>1])->column('name','id');
|
||
$consumptionLists = Order::where(['pay_status'=>PayEnum::ISPAID])
|
||
->where('shop_id','>',0)
|
||
->group('shop_id')
|
||
->column('round(sum(order_amount)/count(id),2) as consumption,shop_id');
|
||
$consumptionLists = array_column($consumptionLists,null,'shop_id');
|
||
foreach ($lists as $key => $shop)
|
||
{
|
||
$categoryNameLists = [];
|
||
foreach ($shop['categoryIds'] as $category){
|
||
$categoryNameLists[] = $categoryLists[$category['category_id']] ?? '';
|
||
}
|
||
$lists[$key]['consumption'] = $consumptionLists[$shop['id']]['consumption'] ?? 0;
|
||
$lists[$key]['category_name'] = $categoryNameLists;
|
||
|
||
}
|
||
|
||
return $lists;
|
||
|
||
}
|
||
|
||
/**
|
||
* @notes 广告数量
|
||
* @return int
|
||
* @author ljj
|
||
* @date 2022/3/25 9:55 上午
|
||
*/
|
||
public function count(): int
|
||
{
|
||
return Shop::where($this->where())
|
||
->count();
|
||
|
||
}
|
||
} |