| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\MemberModel;
- use App\Services\BaseService;
- /**
- * 会员管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class MemberService
- * @package App\Services\Common
- */
- class MemberService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * MemberService constructor.
- */
- public function __construct()
- {
- $this->model = new MemberModel();
- }
- /**
- * 获取列表
- * @param $params 参数
- * @param int $pageSize 分页大小:默认 15
- * @return array
- */
- public function getDataList($params, $pageSize = 10, $field=[])
- {
- $where = ['a.mark' => 1];
- $status = isset($params['status'])? $params['status'] : 0;
- if($status>0){
- $where['a.status'] = $status;
- }
- $list = $this->model->with(['level','parent','point'])
- ->from('member as a')
- ->leftJoin('member as b','b.id','a.parent_id')
- ->where($where)
- ->where(function($query) use($params){
- $trcUrl = isset($params['trc_url'])? trim($params['trc_url']) : '';
- if($trcUrl){
- $query->where('a.trc_url','like',"%{$trcUrl}%");
- }
- $parentUrl = isset($params['parent_trc_url'])? trim($params['parent_trc_url']) : '';
- if($parentUrl){
- $query->where('b.trc_url','like',"%{$parentUrl}%");
- }
- })
- ->where(function($query) use($params){
- $account = isset($params['account'])? trim($params['account']) : '';
- if($account){
- $query->where('a.username','like',"%{$account}%")->orWhere('a.nickname','like',"%{$account}%");
- }
- })
- ->select($field? $field : ['a.*','b.trc_url as parent_trc_url'])
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list? $list->toArray() :[];
- if($list){
- foreach($list['data'] as &$item){
- $item['create_time_text'] = $item['create_time']? datetime($item['create_time']):'';
- $item['avatar'] = $item['avatar']? get_image_url($item['avatar']): get_image_url('/images/member/logo.png');
- $item['invite_num'] = $this->model->where(['parent_id'=> $item['id'],'mark'=>1])->count('id');
- $item['team_num'] = $this->model->where(['mark'=>1])->whereRaw('FIND_IN_SET(?,parents)', $item['id'])->count('id');
- $item['point_num'] = $this->model->where(['point_id'=>$item['id'],'mark'=>1])->count('id');
- }
- }
- return [
- 'pageSize'=> $pageSize,
- 'total'=>isset($list['total'])? $list['total'] : 0,
- 'list'=> isset($list['data'])? $list['data'] : []
- ];
- }
- /**
- * 添加会编辑会员
- * @return array
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function edit()
- {
- // 请求参数
- $data = request()->all();
- // 头像处理
- $avatar = trim($data['avatar']);
- if (strpos($avatar, "temp")) {
- $data['avatar'] = save_image($avatar, 'member');
- } else {
- $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
- }
- // 出生日期
- if ($data['birthday']) {
- $data['birthday'] = strtotime($data['birthday']);
- }
- // 城市处理
- $city = isset($data['city']) ? $data['city'] : [3];
- if (!empty($data['city'])) {
- // 省份
- $data['province_id'] = $city[0];
- // 城市
- $data['city_id'] = $city[1];
- // 县区
- $data['district_id'] = $city[2];
- }
- unset($data['city']);
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- }
|