Bladeren bron

test1
test2

liuzejian 2 jaren geleden
bovenliggende
commit
0b2e20e6a5

+ 17 - 0
modules/Channel/Exceptions/ChannelBusinessException.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Modules\Channel\Exceptions;
+
+use Throwable;
+
+class ChannelBusinessException extends \RuntimeException
+{
+    public function __construct($message = "", $code = 0, Throwable $previous = null)
+    {
+        parent::__construct($message, $code, $previous);
+    }
+
+    public static function throwError($error, Throwable $previous = null) {
+        throw (new static($error[1], $error[0], $previous));
+    }
+}

+ 167 - 0
modules/Channel/Http/Controllers/AdvertiserController.php

@@ -0,0 +1,167 @@
+<?php
+
+namespace Modules\Channel\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Modules\Channel\Exceptions\ChannelBusinessException;
+use Modules\Common\Errors\Errors;
+use Modules\User\Models\User;
+
+class AdvertiserController extends CatchController
+{
+    use ValidatesRequests;
+    public function __construct(
+        protected readonly User $user
+    ) {
+    }
+
+    /**
+     * 添加投手
+     * @param Request $request
+     * @return int
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function addAdvertiser(Request $request) {
+        $this->validate($request, [
+            'email' => 'required|email',
+            'username' => 'required',
+            'password' => 'required',
+            'repassword' => 'required|same:password',
+            'status' => 'required',
+            'remark' => 'string|max:140',
+            'miniProgramIds' => 'required|array|min:1',
+            'miniProgramIds.*' => 'required|integer'
+        ]);
+        $this->user->emailUnique($request->input('email'));
+        // todo : 这里需要修改成投手角色的id
+        $request['roles'] = [3];
+        $this->user->storeBy($request->all());
+        $this->user->pid = $this->getLoginUserId();
+        $this->user->save();
+        $insertData = [];
+        $now = date('Y-m-d H:i:s');
+        foreach ($request->input('miniProgramIds') as $miniProgramId) {
+            $insertData[] = [
+                'uid' => $this->user->id,
+                'miniprogram_id' => $miniProgramId,
+                'created_at' => $now,
+                'updated_at' => $now,
+             ];
+        }
+        DB::table('user_has_miniprograms')
+            ->insert($insertData);
+        return 1;
+    }
+
+    /**
+     * 投手账号列表
+     * @param Request $request
+     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function listAdvertiser(Request $request) {
+        $this->validate($request, [
+            'email' => 'string|email',
+            'username' => 'string',
+            'miniProgramId' => 'integer',
+        ]);
+        $miniProgramId = $request->input('miniProgramId');
+        $email = $request->input('email');
+        $username = $request->input('username');
+        return  DB::table('users')
+            ->join('user_has_miniprograms', 'users.id', 'user_has_miniprograms.uid')
+            ->where([
+                'user_has_miniprograms.is_enabled' => 1,
+                'users.deleted_at' => 0,
+                'users.pid' => $this->getLoginUserId()
+            ])->when($email, function ($query, $email) {
+                return $query->where('users.email', $email);
+            })->when($miniProgramId, function ($query, $miniProgramId){
+                return $query->where('user_has_miniprograms.miniprogram_id', $miniProgramId);
+            })->when($username, function ($query, $username){
+                return $query->where('users.username', 'like', '%'.$username.'%');
+            })
+            ->select(
+                'users.id', 'users.username', 'users.email', 'users.status',
+                DB::raw("from_unixtime(users.created_at) as created_at"),
+                DB::raw("group_concat(distinct user_has_miniprograms.miniprogram_id separator ',') as miniProgramIds")
+            )->groupBy('users.id')
+            ->orderBy('users.id','desc')
+            ->paginate($request->input('per_page', 15));
+    }
+
+    /**
+     * 更新账号
+     * @param Request $request
+     * @return int
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function updateAdvertiser(Request $request) {
+        $this->validate($request, [
+            'id' => 'required',
+            'username' => 'required',
+            'miniProgramIds' => 'required|array|min:1',
+            'miniProgramIds.*' => 'required|integer',
+            'status' => 'required',
+            'remark' => 'string|max:140',
+        ]);
+
+        $this->user->updateBy($request->input('id'), $request->all());
+        $now = date('Y-m-d H:i:s');
+        DB::table('user_has_miniprograms')
+            ->where([
+                'uid' => $this->user->id,
+                'is_enabled' => 1
+            ])->update([
+                'is_enabled' => 0,
+                'updated_at' => $now,
+            ]);
+        $insertData = [];
+        foreach ($request->input('miniProgramIds') as $miniProgramId) {
+            $insertData[] = [
+                'uid' => $this->user->id,
+                'miniprogram_id' => $miniProgramId,
+                'created_at' => $now,
+                'updated_at' => $now,
+            ];
+        }
+        DB::table('user_has_miniprograms')
+            ->insert($insertData);
+
+        return 1;
+    }
+
+    /**
+     * 获取投手信息
+     * @param Request $request
+     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|object|null
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function getAdvertiser(Request $request) {
+        $this->validate($request, [
+            'id' => 'required'
+        ]);
+
+        $user = DB::table('users')
+            ->where([
+                'deleted_at' => 0,
+                'id' => $request->input('id')
+            ])->select('id','email', 'username', 'status', 'remark')
+            ->first();
+        if(!$user) {
+            ChannelBusinessException::throwError(Errors::USER_NOT_FOUND);
+        }
+        $miniProgramIds = DB::table('user_has_miniprograms')
+            ->where([
+                'is_enabled' => 1,
+                'uid' => $user->id,
+            ])->select('miniprogram_id')
+            ->get()->pluck('miniprogram_id')->toArray();
+
+        $user->miniProgramIds = $miniProgramIds;
+        return $user;
+    }
+}

+ 56 - 0
modules/Channel/Http/Controllers/UserTrait.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace Modules\ContentManage\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
+use Modules\User\Models\User;
+
+trait UserTrait
+{
+    // 当前登录用户
+    protected $currentUser;
+
+    /**
+     * 获取当前登录用户
+     * @return User
+     */
+    protected function getCurrentUser(): User {
+        if(!$this->currentUser) {
+            $this->currentUser = $this->getLoginUser();
+        }
+        return $this->currentUser;
+    }
+    /**
+     * 当前用户的所有的角色标识的结合
+     * @return Collection
+     */
+    protected function listUserRoles():Collection {
+        return $this->getCurrentUser()->roles->pluck('identify');
+    }
+
+    /**
+     * 当前用户是否是cp角色
+     * @return bool
+     */
+    public function userIsCp():bool {
+        return $this->listUserRoles()->contains('cp');
+    }
+
+    /**
+     * 如果当前用户是cp角色,返回cp_name,否则返回null
+     * @return string
+     */
+    public function getUserCpName():string|null {
+        if($this->userIsCp()) {
+            return DB::table('user_belong_to_cp')
+                ->where([
+                    'is_enabled' => 1,
+                    'user_id' => $this->getCurrentUser()->id,
+                ])->value('cp_name');
+        } else {
+            return null;
+        }
+    }
+}

+ 50 - 0
modules/Channel/Http/Requests/NoticeTypeRequest.php

@@ -0,0 +1,50 @@
+<?php
+/**
+ * ${CARET}
+ * @file:CpRequest.php
+ * @Created by gnitif
+ * @Date: 2023/3/22
+ * @Time: 17:06
+ */
+
+
+namespace Modules\System\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+use Modules\System\Models\NoticeTypes;
+
+
+class NoticeTypeRequest extends  FormRequest
+{
+
+    /**
+     * rules
+     *
+     * @return array
+     */
+    public function rules(): array
+    {
+        return [
+                'name' => [
+                'required',
+                function ($attribute, $value, $fail) {
+                    $has = NoticeTypes::where('is_deleted', 0)->where('name', $value)->value('id');
+                    if (!empty($has)) {
+                        $fail("分类已存在!");
+                    }
+                }
+            ]
+        ];
+    }
+    /**
+     * messages
+     *
+     * @return string[]
+     */
+    public function messages(): array
+    {
+        return [
+            'name.required' => '分类名称必须填写',
+        ];
+    }
+}

+ 32 - 0
modules/Channel/Installer.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Modules\ContentManage;
+
+use Catch\Support\Module\Installer as ModuleInstaller;
+use Modules\ContentManage\Providers\ContentManageServiceProvider;
+
+class Installer extends ModuleInstaller
+{
+    protected function info(): array
+    {
+        // TODO: Implement info() method.
+        return [
+            'title' => '内容中台',
+            'name' => 'contentManage',
+            'path' => 'contentManage',
+            'keywords' => '内容中台',
+            'description' => '内容中台管理模块',
+            'provider' => ContentManageServiceProvider::class
+        ];
+    }
+
+    protected function requirePackages(): void
+    {
+        // TODO: Implement requirePackages() method.
+    }
+
+    protected function removePackages(): void
+    {
+        // TODO: Implement removePackages() method.
+    }
+}

+ 26 - 0
modules/Channel/Middlewares/ContentManageGate.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace Modules\ContentManage\Middlewares;
+
+use Illuminate\Http\Request;
+use Modules\ContentManage\Exceptions\PermissionForbidden;
+use Modules\User\Models\User;
+
+class ContentManageGate
+{
+    public function handle(Request $request, \Closure $next)
+    {
+        if ($request->isMethod('get')) {
+            return $next($request);
+        }
+
+        /* @var User $user */
+        $user = $request->user(getGuardName());
+
+        if (! $user->can()) {
+            throw new PermissionForbidden();
+        }
+
+        return $next($request);
+    }
+}

+ 30 - 0
modules/Channel/Models/BaseModel.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace Modules\System\Models;
+
+use Catch\Base\CatchModel as Model;
+use Illuminate\Database\Eloquent\Builder;
+
+
+abstract class BaseModel extends Model
+{
+
+    protected array $defaultHidden = [];
+
+    protected array $defaultCasts = [
+        'created_at' => 'datetime:Y-m-d H:i:s',
+
+        'updated_at' => 'datetime:Y-m-d H:i:s',
+    ];
+    protected $dateFormat = '';
+
+    public static function bootSoftDeletes(): void{
+
+    }
+
+
+    public function scopeActive(Builder $query): void
+    {
+        $query->where($this->table.'.is_enabled', 1);
+    }
+}

+ 15 - 0
modules/Channel/Models/NoticeTypes.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace Modules\System\Models;
+
+
+
+class NoticeTypes extends BaseModel
+{
+    protected $table = 'notice_types';
+
+    protected $fillable = [
+        'id', 'name', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
+    ];
+
+}

+ 73 - 0
modules/Channel/Models/Notices.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace Modules\System\Models;
+
+
+class Notices extends BaseModel
+{
+    protected $table = 'notices';
+
+    protected $fillable = [
+        'id', 'title', 'content', 'notice_type_id', "sort", 'type', 'notice_obj', 'is_popup', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
+    ];
+
+    /**
+     * @var array
+     */
+    protected array $fields = ['id', 'title', 'content', "sort", 'notice_type_id', 'type', 'notice_obj', 'is_popup', 'created_at', 'updated_at'];
+
+    /**
+     * @var array
+     */
+    protected array $form = ['title', 'content', 'notice_type_id',"sort", 'type', 'notice_obj', 'is_popup'];
+
+
+    protected $casts = ['notice_obj' => 'array'];
+
+    public array $searchable = [
+        'title' => 'like',
+        'notice_type_id' => '=',
+        'type' => '=',
+
+    ];
+
+    protected string $sortField = 'sort';
+
+
+
+    /**
+     *  添加通知
+     * @param array $data
+     * @return bool
+     * @throws \ReflectionException
+     */
+    public function storeBy(array $data): mixed
+    {
+        $result = '';
+        $this->beginTransaction();
+        try {
+            $result = $this->create($this->filterData($data));
+            if (isset($data['user_ids']) && !empty($data['user_ids'])) {
+                $this->addUserNotice($data['user_ids'], $result->id);
+            }
+            $this->commit();
+        } catch (\Exception $exception) {
+            $this->rollback();
+        }
+        return $result->id ?? 0;
+    }
+
+    private function addUserNotice(mixed $userIds, mixed $id)
+    {
+        $list = [];
+        foreach ($userIds as $val) {
+            $list[] = ['user_id' => $val, 'notice_id' => $id];
+        }
+        if (!empty($list)) {
+            UserNotice::insert($list);
+        }
+        return true;
+    }
+
+
+}

+ 14 - 0
modules/Channel/Models/UserNotice.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace Modules\System\Models;
+
+
+class UserNotice extends BaseModel
+{
+    protected $table = 'user_notice';
+
+    protected $fillable = [
+        'id', 'user_id', 'notice_id', 'is_deleted', 'is_read', 'created_at', 'updated_at', 'deleted_at',
+    ];
+
+}

+ 31 - 0
modules/Channel/Providers/ChannelServiceProvider.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace Modules\Channel\Providers;
+
+use Catch\CatchAdmin;
+use Catch\Providers\CatchModuleServiceProvider;
+use Modules\ContentManage\Middlewares\ContentManageGate;
+
+class ChannelServiceProvider extends CatchModuleServiceProvider
+{
+    /**
+     * middlewares
+     *
+     * @return string[]
+     */
+    protected function middlewares(): array
+    {
+       return [];
+    }
+
+    /**
+     * route path
+     *
+     * @return string|array
+     */
+    public function moduleName(): string|array
+    {
+        // TODO: Implement path() method.
+        return 'channel';
+    }
+}

+ 10 - 0
modules/Channel/README.md

@@ -0,0 +1,10 @@
+#内容中台管理模块
+关于内容中台 相关的后台接口,对外api接口,都写在这里
+配置文件放在: config目录下,读取配置文件示例:config('contentManage.zhushuyunpublicapi.public_domain');
+config("模块名.配置文件名.配置项");
+
+数据库模型文件放在:Models 目录下面
+服务层文件放在:Services 目录下面
+控制器放在:modules/ContentManage/Http/Controllers 目录下面
+中间件放在:modules/ContentManage/Middlewares 目录下面
+路由只能现在 modules/ContentManage/rout/route.php 文件里

+ 88 - 0
modules/Channel/Services/Notice/NoitceTypeService.php

@@ -0,0 +1,88 @@
+<?php
+/**
+ * ${CARET}
+ * @file:NoitceTypeService.php
+ * @Created by gnitif
+ * @Date: 2023/3/27
+ * @Time: 11:54
+ */
+
+
+namespace Modules\System\Services\Notice;
+
+use Illuminate\Support\Facades\DB;
+use Modules\ContentManage\Models\NoticeTypes;
+
+class NoitceTypeService
+{
+
+    /**
+     *  添加分类
+     * name: store
+     * @param array $param
+     * $param [
+     *      'name' => "平台通知"
+     * ];
+     * date 2023/03/27 18:14
+     */
+    public static function store(array $param)
+    {
+        return self::getModel()->storeBy($param);
+    }
+
+    protected static function getModel(){
+         return new NoticeTypes();
+    }
+
+    /**
+     *  获取通知分类列表分类
+     * name: list
+     * @param mixed $param
+     *  $param = [
+     *      'name' => '系统通知', // 分类名称模糊搜索
+     *      'page' => 1, //  页码
+     *      'limit' => 15, //  每页条数
+     * ]
+     * @param mixed $isAll // 是否获取所有数据 默认否
+     * date 2023/03/28 17:05
+     */
+    public static function list($param = [], $isAll = false)
+    {
+        $where = self::getCondition($param);
+        if ($isAll){
+            return   NoticeTypes::where($where)->select('id','name')->get();
+        }else {
+            $pageSize = $param['limit'] ?? 15;
+            return   NoticeTypes::where($where)->select('id', 'name', 'created_at')->paginate($pageSize);
+        }
+
+    }
+
+    /**
+     *  拼接查询条件
+     * name: getCondition
+     * @param mixed $param
+     * @return \string[][]
+     * date 2023/03/28 17:19
+     */
+    private static function getCondition(mixed $param)
+    {
+        $where = [['is_deleted', '=', '0']];
+        if (isset($param['name']) && !empty($param['name'])) {
+            $where[] = ['name', 'like', "%" . $param['name'] . "%"];
+        }
+        return $where;
+    }
+
+    /**
+     *  删除分类,软删除
+     * name: del
+     * @param $id
+     * @return mixed
+     * date 2023/03/29 11:05
+     */
+    public static function del($id)
+    {
+        return self::getModel()->updateBy($id,['is_deleted' => 1,'deleted_at' => date("Y-m-d H:i:s")]);
+    }
+}

+ 248 - 0
modules/Channel/Services/Notice/NoticesService.php

@@ -0,0 +1,248 @@
+<?php
+/**
+ * ${CARET}
+ * @file:NoitceService.php
+ * @Created by gnitif
+ * @Date: 2023/3/27
+ * @Time: 11:54
+ */
+
+
+namespace Modules\System\Services\Notice;
+
+use Catch\Exceptions\FailedException;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\DB;
+use Modules\System\Models\Notices;
+use Modules\System\Models\UserNotice;
+use Modules\Permissions\Models\Roles;
+use Modules\User\Models\User;
+use PharIo\Manifest\Author;
+
+class NoticesService
+{
+
+    protected static function getModel()
+    {
+        return new Notices();
+    }
+
+    /**
+     *  添加通知
+     * name: addNotice
+     * @param array $param
+     *  $param = [
+     *      'title' => '测试', // 通知标题
+     *      'notice_type_id' =>  2, // 通知分类id
+     *      'type' => '2', // 通知人群 1全部 2,指定人,3指定角色
+     *      'notice_obj' => [['id' =>  1,'name' => "超管"]] , // 通知对象
+     *      'is_popup' => '1', // 是否是弹窗 1弹窗  0 普通
+     *       'content' => '312312', // 通知内容
+     * ];
+     *
+     * date 2023/03/29 14:25
+     */
+    public static function addNotice(array $param)
+    {
+
+        if ($param['type'] != 1 && (!isset($param['notice_obj']) || empty($param['notice_obj']))) {
+            throw new FailedException('通知对象不能为空!');
+        }
+
+        if ($param['type'] == 3) {
+            $roleIds = array_column($param['notice_obj'], 'id');
+            $userIds = DB::table('user_has_roles')->whereIn('role_id', $roleIds)->pluck('user_id')->toArray();
+        } else if ($param['type'] == 2) {
+            $userIds = array_column($param['notice_obj'], 'id');
+        } else {
+            $userIds = User::pluck('id')->toArray();
+            $param['notice_obj'] = [];
+        }
+        $param['user_ids'] = $userIds;
+        return self::getModel()->storeBy($param);
+    }
+
+    public static function delete($id)
+    {
+        return self::getModel()->updateBy($id, ['is_deleted' => 1, 'deleted_at' => get_date()]);
+    }
+
+    /**
+     *  获取通知详情
+     * name: getDetail
+     * @param $id
+     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|Notices[]
+     * date 2023/03/29 15:12
+     */
+    public static function getDetail($id)
+    {
+        $info = Notices::leftJoin('notice_types', 'notice_types.id', 'notices.notice_type_id')
+            ->select('notices.*', 'notice_types.name as notice_type_name')->where('notices.id', $id)->first();
+        return $info;
+    }
+
+    /**
+     *  更新
+     * name: update
+     * @param $id
+     * @param array $param
+     * date 2023/03/29 18:32
+     */
+    public static function update($id, array $param)
+    {
+       return  self::getModel()->updateBy($id, $param);
+    }
+
+    /**
+     *  管理员操作通知列表
+     * name: list
+     * @return mixed
+     * date 2023/03/29 22:49
+     */
+    public static function  list()
+    {
+        $list = self::getModel()->setBeforeGetList(function ($query) {
+            return $query->where('is_deleted', 0)->orderBy('created_at','desc');
+        })->getList();
+        if (!$list->isEmpty()) {
+            $cate = NoitceTypeService::list([], true);
+            if ($cate->isEmpty()) {
+                $cate = [];
+            } else {
+                $cate = array_column($cate->toArray(), null, 'id');
+            }
+
+            foreach ($list as $value) {
+                $value->notice_type_txt = $cate[$value->notice_type_id]['name'] ?? "";
+                $value->type_txt = $value->type == 1 ? "全部" : ($value->type == 2 ? "指定用户" : "指定角色");
+            }
+        }
+        return $list;
+    }
+
+    /**
+     * 我的通知
+     * name: myNoticesList
+     * date 2023/03/29 22:49
+     */
+    public static function myNoticesList($param = [])
+    {
+        $type = $param['type'] ?? "";
+        $noticeTypeId = $param['notice_type_id'] ?? 0;
+        $title = $param['title'] ?? "";
+        $pageSize = $param['limit'] ?? 0;
+        $pageSize = $pageSize < 1 ? 15 : $pageSize;
+        $userId = Auth::guard(getGuardName())->id();
+        $where = [
+            ['user_notice.is_deleted', '=', 0],
+            ['user_notice.user_id', '=', $userId],
+            ['notices.is_deleted', '=', 0],
+            ['user_notice.is_deleted', '=', 0],
+        ];
+        if ($type) {
+            $where[] = ['notices.type', '=', $type];
+        }
+        if ($noticeTypeId) {
+            $where[] = ['notices.notice_type_id', '=', $noticeTypeId];
+        }
+        if ($title) {
+            $where[] = ['notices.title', 'like', "%" . $title . "%"];
+        }
+
+        $list = UserNotice::leftJoin('notices', 'notices.id', "user_notice.notice_id")->where($where)->select('notices.id', 'notices.title', 'notices.is_popup', "user_notice.is_read", 'notices.created_at')
+            ->orderBy('notices.created_at', 'desc')->orderBy('sort', 'desc')->paginate($pageSize);
+        if (!$list->isEmpty()) {
+            foreach ($list as $val) {
+                $val->is_read_txt = $val->is_read == 1 ? "已读" : "未读";
+            }
+        }
+        return $list;
+    }
+
+    /**
+     *  设置已读
+     * name: setRead
+     * @param $id
+     * date 2023/03/29 23:51
+     */
+    public static function setRead($id)
+    {
+        $userId = Auth::guard(getGuardName())->id();
+        return UserNotice::where('user_id', $userId)->where('notice_id', $id)->update(['is_read' => 1, 'read_at' => get_date()]);
+    }
+
+    /**
+     *  用户删除
+     * name: userDel
+     * @param $id
+     * date 2023/03/29 23:55
+     */
+    public static function userDel($id)
+    {
+        $userId = Auth::guard(getGuardName())->id();
+        return UserNotice::where('user_id', $userId)->where('notice_id', $id)->update(['is_deleted' => 1, 'deleted_at' => get_date()]);
+    }
+
+    /**
+     *  阅读详情
+     * name: detail
+     * @param $id
+     * @return Notices
+     * date 2023/03/30 00:09
+     */
+    public static function detail($id)
+    {
+        return Notices::where('id', $id)->where('is_deleted', 0)->select('title', 'id', 'is_popup', 'content')->first();
+    }
+
+    /**
+     *  获取指定对象选择项
+     * name: objOption
+     * @param $type
+     * @param string $name
+     * @return array
+     * date 2023/03/30 10:23
+     */
+    public static function objOption($type, $name = ""): mixed
+    {
+        if ($type == 'user') {
+            if ($name) {
+                return  User::where("username", 'like', "%" . $name . "%")->without(['roles','jobs'])->select('id','username as name')->get();
+            }
+            return User::select('id','username as name')->without(['roles','jobs'])->get();
+        } else if ($type == "role") {
+            if ($name) {
+                return Roles::where("role_name", 'like', "%" . $name . "%")->select('id','role_name as name')->get();
+            }
+            return Roles::select('id','role_name as name')->get();
+        }
+        return [];
+    }
+
+    /**
+     *  一条获取弹窗信息
+     * name: getPopup
+     * @return Model|UserNotice|object|null
+     * date 2023/03/30 16:45
+     */
+    public static function getPopup()
+    {
+        $where = [
+            ['user_notice.is_deleted', '=', 0],
+            ['user_notice.user_id', '=',  Auth::guard(getGuardName())->id()],
+            ['notices.is_deleted', '=', 0],
+            ['notices.is_popup', '=', 1],
+            ['user_notice.is_read', '=', 0],
+        ];
+
+         $info =  UserNotice::leftJoin('notices', 'notices.id', "user_notice.notice_id")->where($where)->select('notices.id', 'notices.title', 'notices.content')
+             ->orderBy('notices.created_at', 'desc')->orderBy('sort', 'desc')->first();
+         if (empty($info)){
+             return  [];
+         }
+         return  $info;
+    }
+
+
+}

+ 13 - 0
modules/Channel/routes/route.php

@@ -0,0 +1,13 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+use Modules\Channel\Http\Controllers\AdvertiserController;
+use Modules\System\Http\Controllers\NoticesController;
+use Modules\System\Http\Controllers\NoticeTypesController;
+
+Route::prefix('channel')->group(function () {
+    Route::post('advertiser/add', [AdvertiserController::class, 'addAdvertiser']);
+    Route::get('advertiser/listAdvertiser', [AdvertiserController::class, 'listAdvertiser']);
+    Route::get('advertiser/getAdvertiser', [AdvertiserController::class, 'getAdvertiser']);
+});
+

+ 9 - 0
modules/Common/Errors/Errors.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace Modules\Common\Errors;
+
+class Errors
+{
+    public const  EMAIL_EXISTS= [500001, '邮箱已经被使用'];
+    public const  USER_NOT_FOUND= [500002, '用户不存在'];
+}

+ 3 - 3
modules/ContentManage/Services/CpManage/SyncSubscribe.php

@@ -5,7 +5,7 @@ namespace Modules\ContentManage\Services\CpManage;
 use GuzzleHttp\Client;
 use Modules\Common\Support\Trace\CustomizeLogger;
 use Modules\Common\Support\Trace\TraceContext;
-use Modules\ContentManage\Exceptions\ContentBusinessException;
+use Modules\ContentManage\Exceptions\ChannelBusinessException;
 use Modules\ContentManage\Exceptions\Errors;
 use Modules\ContentManage\Models\Cp\CpSubscribeStatisticDataModel;
 
@@ -145,7 +145,7 @@ class SyncSubscribe
     {
         $httpStatus = $rawResult->getStatusCode();
         if (200 != $httpStatus) {
-            ContentBusinessException::throwError(Errors::REQUEST_HTTP_STATUS_ERROR);
+            ChannelBusinessException::throwError(Errors::REQUEST_HTTP_STATUS_ERROR);
         }
         $rawContent = $rawResult->getBody()->getContents();
         $parsedContent = \json_decode($rawContent, true);
@@ -157,7 +157,7 @@ class SyncSubscribe
 
         $code = $parsedContent['code'] ?? -1;
         if (0 != $code) {
-            ContentBusinessException::throwError(Errors::REQUEST_CODE_STATUS_ERROR);
+            ChannelBusinessException::throwError(Errors::REQUEST_CODE_STATUS_ERROR);
         }
 
         return [

+ 19 - 1
modules/User/Models/User.php

@@ -6,6 +6,8 @@ use Catch\Base\CatchModel as Model;
 use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
 use Illuminate\Database\Eloquent\Casts\Attribute;
 use Laravel\Sanctum\HasApiTokens;
+use Modules\Channel\Exceptions\ChannelBusinessException;
+use Modules\Common\Errors\Errors;
 use Modules\Common\Repository\Options\Modules;
 use Modules\User\Models\Traits\UserRelations;
 use Illuminate\Auth\Authenticatable;
@@ -29,7 +31,9 @@ class User extends Model implements AuthenticatableContract
     use Authenticatable, UserRelations, HasApiTokens;
 
     protected $fillable = [
-        'id', 'username', 'email', 'avatar', 'password', 'remember_token', 'creator_id', 'status', 'department_id', 'login_ip', 'login_at', 'created_at', 'updated_at', 'deleted_at'
+        'id', 'username', 'email', 'avatar', 'password', 'remember_token', 'creator_id',
+        'status', 'department_id', 'login_ip', 'login_at', 'created_at', 'updated_at', 'deleted_at',
+        'remark'
     ];
 
     /**
@@ -120,4 +124,18 @@ class User extends Model implements AuthenticatableContract
         })->values()->all();
         $this->setAttribute('permissions', $enablePermissions);
     }
+
+    /**
+     * 保证邮箱没有被使用
+     * @param $email
+     */
+    public function emailUnique($email) {
+        $user = $this->where([
+            'email' => $email,
+            'deleted_at' => 0,
+        ])->first();
+        if($user) {
+            ChannelBusinessException::throwError(Errors::EMAIL_EXISTS);
+        }
+    }
 }

+ 49 - 0
tests/Channel/Http/Controllers/AdvertiserControllerTest.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace Tests\Channel\Http\Controllers;
+
+use Modules\Channel\Http\Controllers\AdvertiserController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class AdvertiserControllerTest extends UsedTestCase
+{
+
+    public function testAddAdvertiser()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/channel/advertiser/add', [
+            'email' => 'aa1@test.com',
+            'password' => '123',
+            'repassword' => '123',
+            'status' => 1,
+            'remark' => 'kljlkjkj',
+            'miniProgramIds'=> [1,2,3],
+            'username' => 'aa1@test'
+        ]);
+        $res->dump();
+    }
+
+    public function testlistAdvertiser() {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/channel/advertiser/listAdvertiser?'.http_build_query([
+//                'email' => 'aa1@test.com',
+//                'miniProgramId' => 3,
+            'username' => 'aa'
+            ]));
+        $res->dump();
+    }
+
+    public function testgetAdvertiser() {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/channel/advertiser/getAdvertiser?'.http_build_query([
+//                'email' => 'aa1@test.com',
+//                'miniProgramId' => 3,
+                'username' => 'aa'
+            ]));
+        $res->dump();
+    }
+}

+ 1 - 1
tests/User/Http/Controllers/UserControllerTest.php

@@ -36,7 +36,7 @@ class UserControllerTest extends \Tests\UsedTestCase
     public function testOnline() {
         $res = $this->withHeaders([
             'Authorization' => 'Bearer '. $this->token,
-        ])->json('get','http://localhost/api/user/online?app=contentManage');
+        ])->json('get','http://localhost/api/user/online');
         $res->dump();
     }
 }