ShopMemberService.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\admin\shop\site;
  12. use app\model\shop\ShopMember;
  13. use core\base\BaseAdminService;
  14. /**
  15. * 店铺会员服务层
  16. * Class ShopService
  17. * @package app\service\admin\shop\site
  18. */
  19. class ShopMemberService extends BaseAdminService
  20. {
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->model = new ShopMember();
  25. }
  26. /**
  27. * 会员列表分页查询
  28. */
  29. public function getPage(array $where = []):array
  30. {
  31. $field = 'id, is_follow, first_consum_time, shop_member.last_consum_time, shop_member_label, member_no, mobile, nickname, username, headimg, register_channel';
  32. $order = 'create_time desc';
  33. $search_model = $this->model
  34. ->withJoin(['member' => ['member_no']])
  35. ->withSearch(['keyword', 'is_follow', 'register_channel', 'shop_member_label', 'create_time'], $where)
  36. ->where([['shop_member.site_id', '=', $this->site_id]])->append([ 'register_channel_name', 'is_follow_name' ])->field($field)->order($order);
  37. return $this->pageQuery($search_model, function ($item, $key) {
  38. $item = $this->makeUp($item);
  39. });
  40. }
  41. /**
  42. * 会员详情
  43. * @param int $member_id
  44. * @return array|null
  45. */
  46. public function getInfo(int $member_id)
  47. {
  48. $field = 'id, is_follow, first_consum_time, shop_member.last_consum_time, comsum_num, comsum_money, shop_member_label, member_no, mobile, nickname, username, headimg, register_channel';
  49. return $this->makeUp($this->model
  50. ->withJoin(['member' => ['member_id', 'member_no']])
  51. ->where([['shop_member.member_id', '=', $member_id], ['shop_member.site_id', '=', $this->site_id]])->field($field)->append(['register_channel_name'])->findOrEmpty()->toArray());
  52. }
  53. /**
  54. * 组合整理数据
  55. * @param $data
  56. */
  57. public function makeUp($data){
  58. //会员标签
  59. if(!empty($data['shop_member_label'])){
  60. $data['shop_member_label_array'] = (new ShopMemberLabelService())->getMemberLabelListByLabelIds($data['shop_member_label']);
  61. }
  62. return $data;
  63. }
  64. /**
  65. * 修改
  66. * @param int $member_id
  67. * @param string $field
  68. * @param $data
  69. * @return ShopMember
  70. */
  71. public function modify(int $member_id, string $field, $data)
  72. {
  73. $field_name = match ($field) {
  74. 'shop_member_label' => 'shop_member_label',
  75. };
  76. $where = [
  77. ['member_id', '=', $member_id],
  78. ];
  79. return $this->model->where($where)->update([$field_name => $data]);
  80. }
  81. }