ShopService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\api\shop;
  12. use app\model\shop\Shop;
  13. use app\model\shop\ShopMember;
  14. use app\model\shop\ShopSite;
  15. use core\base\BaseApiService;
  16. use think\db\exception\DbException;
  17. /**
  18. * 店铺服务层(针对站点服务层扩展实现)
  19. * Class ShopService
  20. * @package addon\mall\app\service\admin\mall\shop
  21. */
  22. class ShopService extends BaseApiService
  23. {
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. $this->model = new ShopSite();
  28. }
  29. /**
  30. * 获取站点列表
  31. * @param array $where
  32. * @return array
  33. * @throws DbException
  34. */
  35. public function getPage(array $where = [])
  36. {
  37. $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,
  38. district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id';
  39. $condition = [
  40. [ 'app_type', '<>', 'admin' ],
  41. [ 'status', '=', 1 ]
  42. ];
  43. $search_model = $this->model->where($condition)->withSearch(['keyword', 'group_id', 'category_id', 'is_self' ], $where)
  44. ->withJoin( [
  45. 'shop' => [ 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName'])
  46. ->field($field)->order('create_time desc');
  47. return $this->pageQuery($search_model);
  48. }
  49. /**
  50. * 获取站点列表
  51. * @param array $where
  52. * @return array
  53. * @throws DbException
  54. */
  55. public function getAll(int $limit = 0)
  56. {
  57. $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,
  58. district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id';
  59. $condition = [
  60. [ 'app_type', '<>', 'admin' ],
  61. [ 'status', '=', 1 ]
  62. ];
  63. $search_model = $this->model->where($condition)->withJoin( [ 'shop' => [ 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName'])
  64. ->field($field)->order('create_time desc')->limit($limit);
  65. return $search_model->select()->toArray();
  66. }
  67. /**
  68. * 站点信息
  69. * @param int $site_id
  70. * @return array
  71. */
  72. public function getInfo(int $site_id)
  73. {
  74. $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,
  75. district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id,is_recommend, is_self, follow_number, category_id';
  76. $condition = [
  77. [ 'shop_site.site_id', '=', $site_id ]
  78. ];
  79. $modelResult = $this->model->where($condition)
  80. ->withJoin( [
  81. 'shop'=> ['site_id', 'category_id', 'is_self', 'follow_number'] ])->with(['categoryName', 'groupName'])
  82. ->field($field)->findOrEmpty()->toArray();
  83. if (!empty($this->member_id)) {
  84. $member_info = (new ShopMember())->field('is_follow')->where([['member_id', '=', $this->member_id], ['site_id', '=', $site_id]])->findOrEmpty()->toArray();
  85. $modelResult['member_info'] = $member_info ? ['is_follow' => $member_info['is_follow']] : ['is_follow' => 0];
  86. } else {
  87. $modelResult['member_info'] = ['is_follow' => 0];
  88. }
  89. return $modelResult;
  90. }
  91. /**
  92. * 更新店铺关注数
  93. * @param int $site_id
  94. * @param int $is_follow
  95. * @return void
  96. */
  97. public function editFollowNumber(int $site_id, int $is_follow)
  98. {
  99. $shop_model = new Shop();
  100. if ($is_follow == 1) {
  101. $shop_model->where(['site_id' => $site_id])->setInc('follow_number');
  102. } else if ($is_follow == 0) {
  103. $shop_model->where(['site_id' => $site_id])->setDec('follow_number');
  104. }
  105. }
  106. }