123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\service\api\shop;
- use app\model\shop\Shop;
- use app\model\shop\ShopMember;
- use app\model\shop\ShopSite;
- use core\base\BaseApiService;
- use think\db\exception\DbException;
- /**
- * 店铺服务层(针对站点服务层扩展实现)
- * Class ShopService
- * @package addon\mall\app\service\admin\mall\shop
- */
- class ShopService extends BaseApiService
- {
- public function __construct()
- {
- parent::__construct();
- $this->model = new ShopSite();
- }
- /**
- * 获取站点列表
- * @param array $where
- * @return array
- * @throws DbException
- */
- public function getPage(array $where = [])
- {
- $field = 'shop.site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id,
- district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id';
- $condition = [
- [ 'app_type', '<>', 'admin' ],
- [ 'status', '=', 1 ]
- ];
- $search_model = $this->model->where($condition)->withSearch(['keyword', 'group_id', 'category_id', 'is_self' ], $where)
- ->withJoin( [
- 'shop' => [ 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName'])
- ->field($field)->order('create_time desc');
- return $this->pageQuery($search_model);
- }
- /**
- * 获取站点列表
- * @param array $where
- * @return array
- * @throws DbException
- */
- public function getAll(int $limit = 0)
- {
- $field = 'shop.site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id,
- district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id';
- $condition = [
- [ 'app_type', '<>', 'admin' ],
- [ 'status', '=', 1 ]
- ];
- $search_model = $this->model->where($condition)->withJoin( [ 'shop' => [ 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName'])
- ->field($field)->order('create_time desc')->limit($limit);
- return $search_model->select()->toArray();
- }
- /**
- * 站点信息
- * @param int $site_id
- * @return array
- */
- public function getInfo(int $site_id)
- {
- $field = 'shop.site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id,
- district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id';
- $condition = [
- [ 'shop_site.site_id', '=', $site_id ]
- ];
- $modelResult = $this->model->where($condition)
- ->withJoin( [
- 'shop'=> ['site_id', 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName'])
- ->field($field)->findOrEmpty()->toArray();
- if (!empty($this->member_id)) {
- $member_info = (new ShopMember())->field('is_follow')->where([['member_id', '=', $this->member_id], ['site_id', '=', $site_id]])->findOrEmpty()->toArray();
- $modelResult['member_info'] = $member_info ? ['is_follow' => $member_info['is_follow']] : ['is_follow' => 0];
- } else {
- $modelResult['member_info'] = ['is_follow' => 0];
- }
- return $modelResult;
- }
- /**
- * 更新店铺关注数
- * @param int $site_id
- * @param int $is_follow
- * @return void
- */
- public function editFollowNumber(int $site_id, int $is_follow)
- {
- $shop_model = new Shop();
- if ($is_follow == 1) {
- $shop_model->where(['site_id' => $site_id])->setInc('follow_number');
- } else if ($is_follow == 0) {
- $shop_model->where(['site_id' => $site_id])->setDec('follow_number');
- }
- }
- }
|