|
|
@@ -15,6 +15,7 @@ use App\Models\ActionLogModel;
|
|
|
use App\Models\MemberModel;
|
|
|
use App\Services\BaseService;
|
|
|
use App\Services\RedisService;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 会员管理-服务类
|
|
|
@@ -344,6 +345,61 @@ class MemberService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 修改推荐人
|
|
|
+ * @param $adminId
|
|
|
+ * @param $params
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function modifyParent($adminId, $params)
|
|
|
+ {
|
|
|
+ $id = isset($params['id'])?$params['id'] : 0;
|
|
|
+ $parentId = isset($params['parent_id'])?$params['parent_id'] : 0;
|
|
|
+
|
|
|
+ if($id<=0){
|
|
|
+ return message('用户参数错误', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($parentId<=0){
|
|
|
+ return message('请选择推荐人', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = $this->model->where(['id'=> $id])->first();
|
|
|
+ $memberParentId = isset($info['parent_id'])? $info['parent_id'] : 0;
|
|
|
+ if($memberParentId == $parentId){
|
|
|
+ return message('推荐人未修改', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $parent = $this->model->where(['id'=> $parentId])->first();
|
|
|
+ $parents = isset($parent['parents'])?$parent['parents'] : '';
|
|
|
+ $parents = $parents? explode(',', $parents) : [];
|
|
|
+ $parents = array_filter($parents);
|
|
|
+ $parents[] = $parentId;
|
|
|
+ $parents = ','.implode(',', $parents).',';
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ $info->parent_id = $parentId;
|
|
|
+ $info->parents = $parents;
|
|
|
+ $info->update_time = time();
|
|
|
+ if(!$info->save()){
|
|
|
+ DB::rollBack();
|
|
|
+ return message('修改失败', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改下级推荐参数
|
|
|
+ if(!$this->model->where(['parent_id'=> $id])->update(['parents'=> $parents.$id.',','update_time'=>time()])){
|
|
|
+ DB::rollBack();
|
|
|
+ return message('修改失败', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ // 设置日志
|
|
|
+ ActionLogModel::setRecord($adminId, ['type' => 1, 'title' => '修改会员推荐人', 'content' => json_encode($params, 256), 'module' => 'admin']);
|
|
|
+ ActionLogModel::record();
|
|
|
+
|
|
|
+ return message('修改成功', true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 添加会编辑会员
|
|
|
* @return array
|
|
|
* @since 2020/11/11
|