123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\service\api\shop;
- use app\dict\site\SiteDict;
- use app\model\shop\Shop;
- use app\model\shop\ShopMember;
- use app\model\shop\ShopSite;
- use app\service\core\sys\CoreSysConfigService;
- use app\service\core\web\CoreWebConfigService;
- use core\base\BaseApiService;
- use core\util\Barcode;
- 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);
- }
- /**
- * 获取甄选好店列表(web端)
- * @return array
- * @throws DbException
- */
- public function getSelectShopLists()
- {
- $config = (new CoreWebConfigService())->getWebConfig();
- $site_ids = $config['site_ids'] ?? [];
- $field = 'site_id,site_name,front_end_name,front_end_logo,icon';
- $condition = [
- [ 'app_type', '<>', 'admin' ],
- [ 'status', '=', 1 ],
- [ 'site_id', 'in', $site_ids ]
- ];
- $list = [];
- if ($config['is_show_shop']) {
- $list = $this->model->where($condition)->with( [ 'shop' => function($query) {
- $query->field('site_id,is_self');
- }])->field($field)->order('create_time desc')->select()->toArray();
- foreach ($list as &$v) {
- $goods_list = array_values(array_filter(event('MallShopGoodsList', [ 'site_id' => $v[ 'site_id' ], 'num' => 2 ])))[0] ?? [];
- $v['goods_list'] = $goods_list;
- }
- }
- return [
- 'list' => $list,
- 'config' => $config
- ];
- }
- /**
- * 获取站点列表(wap端)
- * @param array $where
- * @return array
- * @throws DbException
- */
- public function getShopPage(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');
- $res = $this->pageQuery($search_model);
- foreach ($res['data'] as &$v) {
- $goods_list = array_values(array_filter(event('MallShopGoodsList', [ 'site_id' => $v[ 'site_id' ], 'num' => 3 ])))[0] ?? [];
- $v['goods'] = $goods_list;
- }
- return $res;
- }
- /**
- * 获取站点列表
- * @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', 'business_license'] ])->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');
- }
- }
- /**
- * 获取商品列表供组件调用
- * @param array $where
- * @return array
- */
- public function getShopComponents(array $where = [])
- {
- $field = 'site_id,site_name,front_end_logo,front_end_name,icon';
- $condition = [
- [ 'app_type', '<>', 'admin' ],
- [ 'status', '=', SiteDict::ON ]
- ];
- if (!empty($where[ 'site_ids' ])) {
- $condition[] = [ 'shop_site.site_id', 'in', $where[ 'site_ids' ] ];
- }
- // 参数过滤
- if (!empty($where[ 'order' ]) && in_array($where[ 'order' ], [ 'follow_number' ])) {
- $order = $where[ 'order' ] . ' desc';
- } else {
- $order = 'follow_number desc,create_time desc';
- }
- $list = $this->model
- ->where($condition)->withSearch([ 'category_id' ], $where)
- ->field($field)
- ->withJoin([ 'shop' => function($query) {
- $query->field('category_id')->with(['categoryName']);
- } ])
- ->order($order)
- ->limit($where[ 'num' ])
- ->select()->toArray();
- foreach ($list as $k => &$v) {
- $goods_list = array_values(array_filter(event('MallShopGoodsList', [ 'site_id' => $v[ 'site_id' ], 'num' => 3 ])))[0] ?? [];
- $v[ 'goods_list' ] = $goods_list;
- if (empty($goods_list)) unset($list[$k]);
- }
- return $list;
- }
- /**
- * 获取店铺二维码
- */
- public function getQrcode(int $site_id){
- $url = ( new CoreSysConfigService() )->getSceneDomain($site_id)[ 'wap_url' ];
- $page = 'app/pages/site/index';
- $data = [
- [
- 'key' => 'sid',
- 'value' => $site_id
- ]
- ];
- $dir = 'upload/qrcode/' . $site_id . '/shop';
- $channel = 'weapp';
- return qrcode($url, $page, $data, $site_id, $dir, $channel);
- }
- }
|