소스 검색

新增Cp管理

zqwang 2 년 전
부모
커밋
71f5d8d83e

+ 4 - 1
app/Exceptions/Handler.php

@@ -65,7 +65,10 @@ class Handler extends ExceptionHandler
     public function render($request, Throwable $e): JsonResponse|Response
     {
         $message = $e->getMessage();
-
+        echo "<pre><hr>";
+        var_export($message);
+        echo  "<hr>";
+        die();
         if (method_exists($e, 'getStatusCode')) {
             if ($e->getStatusCode() == Response::HTTP_NOT_FOUND) {
                 $message = '路由未找到或未注册';

+ 37 - 0
modules/Common/Models/BaseModel.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ *  模型公共部分
+ * @file:${FILE_NAME}
+ * @Created by gnitif
+ * @Date: 2023/5/6
+ * @Time: 15:21
+ */
+
+
+namespace Modules\Common\Models;
+
+use Catch\Base\CatchModel as Model;
+use Illuminate\Database\Eloquent\Builder;
+
+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);
+    }
+}

+ 148 - 0
modules/CpManage/Http/Controllers/CpListController.php

@@ -0,0 +1,148 @@
+<?php
+/**
+ * ${CARET}
+ * @file:CpListController.php
+ * @Created by gnitif
+ * @Date: 2023/3/20
+ * @Time: 16:25
+ */
+
+
+namespace Modules\CpManage\Http\Controllers;
+
+use Catch\Base\CatchController as Controller;
+use Catch\Exceptions\FailedException;
+use Illuminate\Http\Request;
+use Modules\CpManage\Http\Requests\CpRequest;
+use Modules\CpManage\Models\Cp\CpCollection;
+use Modules\CpManage\Models\Cp\Cps;
+use Modules\CpManage\Services\CpManage\CpService;
+
+class CpListController extends Controller
+{
+    /**
+     * @param Cps $model
+     */
+    public function __construct(protected readonly Cps $model,protected readonly CpCollection $cpCollectionModel)
+    {
+
+    }
+
+    /**
+     * cp列表
+     * name: index
+     * @param CpRequest $request
+     * @return mixed
+     * date 2023/03/20 16:26
+     */
+    public function index(Request $request)
+    {
+        $where =[ ['is_deleted','=',0]];
+        if (!empty($request->get("cp_name", ''))){
+            $where[] = ['cp_name','like',"%".$request->get("cp_name", ''). "%"];
+        }
+        if (!empty($request->get("cp_company", ''))) {
+            $where[] = ['cp_company','like',"%".$request->get("cp_company", ''). "%"];
+        }
+
+        return  CpService::getCpList($where,$request->get('limit',15));
+    }
+
+    /**
+     *  添加
+     * name: store
+     * @param CpRequest $request
+     * @return mixed
+     * date 2023/03/23 13:50
+     */
+    public function store(CpRequest $request)
+    {
+        $params = $request->all();
+        return $this->model->storeBy($params);
+    }
+
+    /**
+     *  获取cp信息
+     * name: show
+     * @param $id
+     * @return mixed
+     * date 2023/03/23 13:50
+     */
+    public function show($id)
+    {
+
+        $cp =  $this->model->where('cp_id', $id)->first();
+        // [$cp['share_per_before'],$cp['share_per_after']] = explode(':',$cp['share_per']);
+        return $cp;
+    }
+
+    /**
+     *  编辑
+     * name: update
+     * @param $id
+     * @param CpRequest $request
+     * @return mixed
+     * date 2023/03/23 13:51
+     */
+    public function update($id, CpRequest $request)
+    {
+        $params = $request->all();
+        // $params['share_per'] = $params['share_per_before'] .":" .$params['share_per_after'];
+        if(isset($params['cp_name'])){
+            unset($params['cp_name']);
+        }
+        return $this->model->updateBy($id, $params);
+    }
+
+    /**
+     *  删除
+     * name: destroy
+     * @param $id
+     * date 2023/03/23 13:51
+     */
+    public function destroy($id)
+    {
+        return $this->model->deleteBy($id);
+    }
+
+    /**
+     * 获取cp现在选
+     * name: selectOptions
+     * @param Request $request
+     * @return mixed
+     * date 2023/03/23 13:51
+     */
+    public function selectOptions(Request $request)
+    {
+        $cpName = $request->input('cp_name','');
+        return CpService::selectOptions($cpName);
+
+    }
+
+
+    /**
+     * 采集
+     * @param Request $request
+     * @return void
+     */
+    public function cpCollection(Request $request){
+        $cpName = $request->get('cp_name');
+        $cpId = $request->get('cp_id');
+
+        if(empty($cpName) || empty($cpId) ){
+            throw new FailedException('缺少参数');
+        }
+
+
+        $status = $this->cpCollectionModel->where('cp_id',$cpId)->whereIn('spider_status',[0,1])->count();
+        if($status >0){
+            throw new FailedException('正在采集中');
+        }
+
+        $this->cpCollectionModel->create(['cp_id'=>$cpId,'cp_name'=>$cpName,'spider_status'=>0,'spider_result'=>'']);
+
+        return [];
+
+    }
+
+}

+ 234 - 0
modules/CpManage/Http/Controllers/CpSubscribeStatisticDataController.php

@@ -0,0 +1,234 @@
+<?php
+
+namespace Modules\CpManage\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+
+
+class CpSubscribeStatisticDataController extends CatchController
+{
+    use ValidatesRequests, UserTrait;
+
+
+    /**
+     * cp结算数据中心列表
+     * @param Request $request
+     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function list(Request $request) {
+        $this->validate($request, [
+            'book_name' => 'nullable|string|max:256',
+            'bid' => 'nullable|integer|min:1',
+            'cp_name' => 'nullable|string|min:1',
+            'start_date' => 'nullable|date_format:Y-m-d',
+            'end_date' => 'nullable|date_format:Y-m-d',
+            'page' => 'required|integer|min:1',
+            'limit' => 'integer|min:10|max:300',
+            'is_export' => 'nullable|integer|in:0,1',   // 是否导出全部, 1-是,0-否
+            'final_amount_gt0' => 'nullable|integer|in:0,1', // 应结算金额是否要大于0,
+            'book_settlement_type' => 'nullable|in:share,bottomline', // 书籍合作模式
+        ]);
+        $bookName = $request->input('book_name');
+        $bid = $request->input('bid');
+        $cpName = $request->input('cp_name');
+        $startDate = $request->input('start_date');
+        $endDate = $request->input('end_date');
+        $perPage = $request->input('limit', 15);
+        $isExport = $request->input('is_export', 0);
+        $finalAmountGt0 = $request->input('final_amount_gt0', 0);
+        $bookSettlementType = $request->input('book_settlement_type');
+        $settlementTypes = [
+            'buyout' => '买断', 'bottomline' => '保底', 'share' => '分成', 'zhuishuyun' => '追书云计算'
+        ];
+
+        $cpName = $this->getUserCpName() ?? $cpName;
+
+
+        $sql = DB::table('cp_subscribe_statistic_data as statistic')
+            ->leftJoin('books as book', 'statistic.bid' , 'book.id')
+            ->when($bookName, function ($query, $bookName) {
+                return $query->where('book.name', 'like', '%'.$bookName. '%');
+            })->when($bid , function ($query, $bid) {
+                return $query->where(['statistic.bid' => $bid]);
+            })->when($cpName, function ($query, $cpName) {
+                return $query->where(['statistic.cp_name' => $cpName]);
+            })->when($startDate, function ($query, $startDate) {
+                $realStartDate = date_add(date_create($startDate), date_interval_create_from_date_string('1 day'))
+                    ->format('Y-m-d');
+                return $query->where('statistic.calculate_date', '>=', $realStartDate);
+            })->when($endDate, function ($query, $endDate) {
+                $realEndDate = date_add(date_create($endDate), date_interval_create_from_date_string('1 day'))
+                    ->format('Y-m-d');
+                return $query->where('statistic.calculate_date', '<=', $realEndDate);
+            })->when($finalAmountGt0, function ($query) {
+                return $query->where('statistic.yesterday_final_amount', '>', 0);
+            })->when($bookSettlementType, function ($query, $bookSettlementType){
+                return $query->where('statistic.book_settlement_type', $bookSettlementType);
+            })
+            ->select('statistic.bid', 'book.name as book_name', 'statistic.cp_name',
+            'statistic.yesterday_total_coins', 'statistic.yesterday_available_amount', 'statistic.yesterday_final_amount',
+            'statistic.calculate_date', 'statistic.book_settlement_type')
+            ->orderBy('statistic.calculate_date', 'desc')
+            ->orderBy('statistic.bid', 'desc');
+
+
+        if($isExport) {
+            return $sql->get()->map(function ($item) use($settlementTypes) {
+                $item->date = date_sub(date_create($item->calculate_date), date_interval_create_from_date_string('1 day'))
+                    ->format('Y-m-d');
+                $item->book_settlement_type_str = $settlementTypes[$item->book_settlement_type] ?? '';
+                return $item;
+            });
+        } else {
+            return $sql->paginate($perPage)->through(function ($item) use ($settlementTypes) {
+                $item->date = date_sub(date_create($item->calculate_date), date_interval_create_from_date_string('1 day'))
+                    ->format('Y-m-d');
+                $item->book_settlement_type_str = $settlementTypes[$item->book_settlement_type] ?? '';
+                return $item;
+            });
+        }
+
+
+
+    }
+
+    public function listStatistic(Request $request) {
+        $this->validate($request, [
+            'book_name' => 'nullable|string|max:256',
+            'bid' => 'nullable|integer|min:1',
+            'cp_name' => 'nullable|string|min:1',
+            'start_date' => 'nullable|date_format:Y-m-d',
+            'end_date' => 'nullable|date_format:Y-m-d',
+            'book_settlement_type' => 'nullable|in:share,bottomline'
+        ]);
+        $bookName = $request->input('book_name');
+        $bid = $request->input('bid');
+        $cpName = $request->input('cp_name');
+        $startDate = $request->input('start_date');
+        $endDate = $request->input('end_date');
+        $bookSettlementType = $request->input('book_settlement_type');
+
+        $cpName = $this->getUserCpName() ?? $cpName;
+
+        $res = DB::table('cp_subscribe_statistic_data as statistic')
+            ->leftJoin('books as book', 'statistic.bid' , 'book.id')
+            ->when($bookName, function ($query, $bookName) {
+                return $query->where('book.name', 'like', '%'.$bookName. '%');
+            })->when($bid , function ($query, $bid) {
+                return $query->where(['statistic.bid' => $bid]);
+            })->when($cpName, function ($query, $cpName) {
+                return $query->where(['statistic.cp_name' => $cpName]);
+            })->when($startDate, function ($query, $startDate) {
+                $realStartDate = date_add(date_create($startDate), date_interval_create_from_date_string('1 day'))
+                    ->format('Y-m-d');
+                return $query->where('statistic.calculate_date', '>=', $realStartDate);
+            })->when($endDate, function ($query, $endDate) {
+                $realEndDate = date_add(date_create($endDate), date_interval_create_from_date_string('1 day'))
+                    ->format('Y-m-d');
+                return $query->where('statistic.calculate_date', '<=', $realEndDate);
+            })->when($bookSettlementType, function ($query, $bookSettlementType){
+                return $query->where('statistic.book_settlement_type', $bookSettlementType);
+            })
+            ->select(
+                DB::raw('sum(yesterday_total_coins) as yesterday_total_coins'),
+                DB::raw('sum(yesterday_available_amount) as yesterday_available_amount'),
+                DB::raw('sum(yesterday_final_amount) as yesterday_final_amount')
+            )->first();
+
+        return $res;
+    }
+
+    /**
+     * cp结算列表
+     * @param Request $request
+     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function monthList(Request $request) {
+        $this->validate($request, [
+            'cp_name' => 'nullable|string',
+            'start_month' => 'nullable|date_format:Y-m',
+            'end_month' => 'nullable|date_format:Y-m',
+            'page' => 'required|integer|min:1',
+            'limit' => 'integer|min:10',
+            'is_export' => 'integer|in:0,1'
+        ]);
+
+        $cpName = $request->input('cp_name');
+        $startMonth = $request->input('start_month');
+        $endMonth = $request->input('end_month');
+        $isExport = $request->input('is_export', 0);
+        $finalStateMap = ['notCheck' => '未结算', 'done' => '已结算'];
+
+        $cpName = $this->getUserCpName() ?? $cpName;
+        $sql =  DB::table('cp_subscribe_month_statistic_data as data')
+            ->leftJoin('cps as cp' , 'cp.cp_name', 'data.cp_name')
+            ->when($cpName, function ($query, $cpName){
+                return $query->where(['data.cp_name' => $cpName]);
+            })->when($startMonth, function ($query, $startMonth){
+                return $query->where('data.month', '>=', $startMonth);
+            })->when($endMonth, function ($query, $endMonth){
+                return $query->where('data.month', '<=', $endMonth);
+            })
+            ->select('data.id','data.month', 'cp.cp_id', 'cp.cp_name', 'cp.cp_company',
+            'data.book_num', 'data.final_amount', 'data.final_state', 'data.final_time')
+            ->orderBy('data.month', 'desc')
+            ->orderBy('cp.cp_id', 'desc');
+
+
+        if($isExport) {
+            return $sql->get()->map(function ($item) use ($finalStateMap){
+                $item->final_state_str = $finalStateMap[$item->final_state] ?? '';
+                return $item;
+            });
+        }else {
+            return $sql->paginate($request->integer('limit', 10));
+        }
+    }
+
+    public function saveFinalState(Request $request){
+        $this->validate($request, [
+            'id' => 'required|integer|min:1',
+            'final_state' => 'required|string|in:done'
+        ]);
+        $now = date('Y-m-d H:i:s');
+        DB::table('cp_subscribe_month_statistic_data')
+            ->where(['id' => $request->input('id'), 'final_state' => 'notCheck'])
+            ->update([
+                'final_state' => $request->input('final_state'),
+                'final_time' => $now,
+                'updated_at' => $now,
+            ]);
+        return 'ok';
+    }
+
+    /**
+     * 导出某个cp某个月的各个书籍的应结算金额
+     * @param Request $request
+     * @return \Illuminate\Support\Collection
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function listCpMonthFinalAmount(Request $request) {
+        $this->validate($request, [
+            'cp_name' => 'required|string',
+            'month' => 'required|date_format:Y-m'
+        ]);
+        $cpName = $request->input('cp_name');
+        $cpName = $this->getUserCpName() ?? $cpName;
+        return DB::table('cp_book_month_final_amounts as mfa')
+            ->leftJoin('books', 'books.id', 'mfa.bid')
+            ->where([
+                'mfa.is_enabled' => 1,
+                'mfa.cp_name' => $cpName,
+                'mfa.month' => $request->input('month')
+            ])
+            ->select('mfa.id', 'mfa.bid', 'books.name as book_name', 'mfa.final_amount', 'mfa.cp_name','mfa.month')
+            ->get();
+
+
+    }
+}

+ 0 - 28
modules/CpManage/Http/Controllers/DuanJuCpController.php

@@ -1,28 +0,0 @@
-<?php
-/**
- *  短剧cp管理
- * @file:CpList.php
- * @Created by gnitif
- * @Date: 2023/5/6
- * @Time: 14:06
- */
-
-
-namespace Modules\CpManage\Http\Controllers;
-
-use Catch\Base\CatchController as Controller;
-use Catch\Exceptions\FailedException;
-use Illuminate\Http\Request;
-use  Modules\CpManage\Services\DuanJuCpService;
-
-class DuanJuCpController extends Controller
-{
-
-    public function list(Request $request)
-    {
-       $param = $request->all();
-       return   DuanJuCpService::getCpList($param);
-    }
-
-
-}

+ 63 - 0
modules/CpManage/Http/Controllers/UserTrait.php

@@ -0,0 +1,63 @@
+<?php
+/**
+ * ${CARET}
+ * @file:${FILE_NAME}
+ * @Created by gnitif
+ * @Date: 2023/5/6
+ * @Time: 16:01
+ */
+
+
+namespace Modules\CpManage\Http\Controllers;
+
+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;
+        }
+    }
+}

+ 16 - 0
modules/CpManage/Http/Requests/CpRequest.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * ${CARET}
+ * @file:${FILE_NAME}
+ * @Created by gnitif
+ * @Date: 2023/5/6
+ * @Time: 15:16
+ */
+
+
+namespace Modules\CpManage\Http\Requests;
+
+class CpRequest
+{
+
+}

+ 34 - 0
modules/CpManage/Middlewares/CpManageGate.php

@@ -0,0 +1,34 @@
+<?php
+/**
+ * ${CARET}
+ * @file:${FILE_NAME}
+ * @Created by gnitif
+ * @Date: 2023/5/6
+ * @Time: 16:38
+ */
+
+
+namespace Modules\CpManage\Middlewares;
+
+use Illuminate\Http\Request;
+use Modules\Permissions\Exceptions\PermissionForbidden;
+use Modules\User\Models\User;
+
+class CpManageGate
+{
+    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);
+    }
+}

+ 13 - 0
modules/CpManage/Models/Cp/CpCollection.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace Modules\CpManage\Models\Cp;
+
+use Modules\Common\Models\BaseModel;
+
+class CpCollection extends BaseModel
+{
+    protected $table = 'cp_collections';
+    protected $dates = [];
+    protected $forceDeleting = true;
+    protected $fillable = ['cp_id','cp_name','spider_status','spider_result','created_at', 'updated_at'];
+}

+ 11 - 0
modules/CpManage/Models/Cp/CpSubscribeStatisticDataModel.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace Modules\CpManage\Models\Cp;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CpSubscribeStatisticDataModel extends Model
+{
+    protected $table = 'cp_subscribe_statistic_data';
+    protected $guarded = [];
+}

+ 81 - 0
modules/CpManage/Models/Cp/Cps.php

@@ -0,0 +1,81 @@
+<?php
+/**
+ *cp管理
+ * @file:Cps.php
+ * @Created by gnitif
+ * @Date: 2023/3/20
+ * @Time: 13:57
+ */
+
+
+namespace Modules\CpManage\Models\Cp;
+
+use Catch\Exceptions\FailedException;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+use Modules\ContentManage\Services\CpManage\CpService;
+
+class Cps extends Model
+{
+    protected $table = "cps";
+    protected $primaryKey = "cp_id";
+    protected $fillable = [
+        'cp_id', 'cp_nick', 'cp_name', 'cp_company', 'manager', 'phone', 'email', 'share_per', 'settlement_type', 'address', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
+    ];
+    protected array $fields = ['cp_id', 'cp_nick', 'cp_name', 'cp_company', 'manager', 'phone', 'email', 'share_per','address', 'created_at', 'updated_at'];
+    protected array $form =  ['cp_nick',  'cp_name',  'cp_company',  'manager',  'phone',  'email',  'settlement_type','share_per',   'address'];
+
+    public function storeBy(array $data): mixed
+    {
+        DB::beginTransaction();
+        try {
+            if ($this->create($this->filterData($data))){
+                DB::commit();
+                return  $this->getKey();
+            }else{
+                throw new \Exception("添加失效");
+            }
+
+        }catch (\Exception $exception){
+            DB::rollBack();
+            throw new FailedException('添加失败!请刷新重试');
+        }
+        return false;
+    }
+
+    public function updateBy($id, array $data)
+    {
+
+        $updated = $this->where($this->getKeyName(), $id)->update($this->filterData($data));
+        return $updated;
+    }
+
+    public function deleteBy($id)
+    {
+        $this->where($this->getKeyName(), $id)->update(['is_deleted' => 1,'deleted_at' => date("Y-m-d H:i:s")]);
+    }
+
+    protected function filterData(array $data): array
+    {
+        // 表单保存的数据集合
+        $fillable = array_unique(array_merge($this->getFillable(), property_exists($this, 'form') ? $this->form : []));
+
+        foreach ($data as $k => $val) {
+            if (is_null($val) || (is_string($val) && ! $val)) {
+                unset($data[$k]);
+            }
+
+            if (! empty($fillable) && ! in_array($k, $fillable)) {
+                unset($data[$k]);
+            }
+
+            if (in_array($k, [$this->getUpdatedAtColumn(), $this->getCreatedAtColumn()])) {
+                unset($data[$k]);
+            }
+        }
+
+        return $data;
+    }
+
+
+}

+ 0 - 16
modules/CpManage/Models/DaunJuCpSubscribeStatisticData.php

@@ -1,16 +0,0 @@
-<?php
-
-namespace Modules\CpManage\Models;
-
-use Catch\Base\CatchModel as Model;
-
-
-class DaunJuCpSubscribeStatisticData extends Model
-{
-    protected $table = 'daunju_cp_subscribe_statistic_data';
-
-    protected $fillable = [
-        'id', 'bid', 'calculate_date', 'settlement_date', 'month', 'cp_name', 'yesterday_available_amount', 'yesterday_final_amount', 'yesterday_total_coins', 'book_settlement_type', 'data_source_id', 'data_source_from', 'data_source_bid', 'created_at', 'updated_at',
-    ];
-
-}

+ 0 - 16
modules/CpManage/Models/DuanJuCpBookMonthFinalAmounts.php

@@ -1,16 +0,0 @@
-<?php
-
-namespace Modules\CpManage\Models;
-
-use Catch\Base\CatchModel as Model;
-
-
-class DuanJuCpBookMonthFinalAmounts extends Model
-{
-    protected $table = 'duanju_cp_book_month_final_amounts';
-
-    protected $fillable = [
-        'id', 'bid', 'cp_name', 'month', 'final_amount', 'is_enabled', 'created_at', 'updated_at',
-    ];
-
-}

+ 0 - 17
modules/CpManage/Models/DuanJuCpSubscribeMonthStatisticData.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace Modules\CpManage\Models;
-
-use Catch\Base\CatchModel as Model;
-
-
-class DuanJuCpSubscribeMonthStatisticData extends Model
-{
-    protected $table = 'duanju_cp_subscribe_month_statistic_data';
-
-    protected $fillable = [
-        'id', 'month', 'book_num', 'final_amount', 'cp_name', 'final_state', 'final_time', 'created_at', 'updated_at',
-    ];
-
-}
-

+ 0 - 16
modules/CpManage/Models/DuanJuCps.php

@@ -1,16 +0,0 @@
-<?php
-
-namespace Modules\CpManage\Models;
-
-use Catch\Base\CatchModel as Model;
-
-
-class DuanJuCps extends Model
-{
-    protected $table = 'duanju_cps';
-
-    protected $fillable = [
-        'cp_id', 'cp_nick', 'cp_name', 'cp_company', 'manager', 'phone', 'email', 'share_per', 'settlement_type', 'address', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
-    ];
-
-}

+ 0 - 17
modules/CpManage/Models/DuanJuUserBelongToCp.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace Modules\CpManage\Models;
-
-use Catch\Base\CatchModel as Model;
-
-
-class DuanJuUserBelongToCp extends Model
-{
-    protected $table = 'duanju_user_belong_to_cp';
-
-    protected $fillable = [
-        'id', 'user_id', 'cp_name', 'is_enabled',
-    ];
-
-}
-

+ 18 - 6
modules/CpManage/Providers/CpManageServiceProvider.php

@@ -1,20 +1,32 @@
 <?php
 
-namespace Modules\Cpmanage\Providers;
+namespace Modules\CpManage\Providers;
+
 
-use Catch\CatchAdmin;
 use Catch\Providers\CatchModuleServiceProvider;
+use Modules\CpManage\Middlewares\CpManageGate;
 
-class CpmanageServiceProvider extends CatchModuleServiceProvider
+class CpManageServiceProvider extends CatchModuleServiceProvider
 {
     /**
+     * middlewares
+     *
+     * @return string[]
+     */
+    protected function middlewares(): array
+    {
+        return [CpManageGate::class];
+    }
+
+    /**
      * route path
      *
-     * @return string
+     * @return string|array
      */
-    public function moduleName(): string
+    public function moduleName(): string|array
     {
         // TODO: Implement path() method.
-        return 'cpmanage';
+        return 'cpManage';
     }
 }
+

+ 49 - 0
modules/CpManage/Services/CpManage/CpService.php

@@ -0,0 +1,49 @@
+<?php
+/**
+ * ${CARET}
+ * @file:CpService.php
+ * @Created by gnitif
+ * @Date: 2023/3/21
+ * @Time: 20:24
+ */
+
+
+namespace Modules\CpManage\Services\CpManage;
+
+use Illuminate\Contracts\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Facades\DB;
+use Modules\CpManage\Models\Cp\Cps;
+
+class CpService
+{
+
+    public static function selectOptions($cpName = "")
+    {
+        $list = Cps::select('cp_id','cp_name','cp_nick','cp_company');
+        if (!empty($cpName)){
+            $list->where('cp_name','like',"%{$cpName}%");
+        }
+        return $list->get();
+    }
+
+    /**
+     *  查询产品列表
+     * name: getCpList
+     * @param  $where
+     * @param int $pageSize
+     * @return LengthAwarePaginator
+     * date 2023/03/22 20:49
+     */
+    public static function getCpList($where , int $pageSize = 20)
+    {
+        $list =  DB::table('cps')->where($where)->orderBy('cp_id','desc')->paginate($pageSize);
+        if(!$list->isEmpty()){
+            foreach ($list as  $value){
+                $value->book_count = 0;
+            }
+        }
+        return  $list;
+    }
+
+
+}

+ 0 - 19
modules/CpManage/Services/DuanJuCpService.php

@@ -1,19 +0,0 @@
-<?php
-/**
- * 短剧cp管理
- * @file:DuanJuCpService.php
- * @Created by gnitif
- * @Date: 2023/5/6
- * @Time: 14:11
- */
-namespace Modules\CpManage\Services;
-
-class DuanJuCpService
-{
-
-    public function getCpList($param){
-
-
-    }
-
-}

+ 35 - 3
modules/CpManage/routes/route.php

@@ -1,7 +1,39 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
+use Modules\CpManage\Http\Controllers\CpListController;
+use Modules\CpManage\Http\Controllers\CpSubscribeStatisticDataController;
 
-Route::prefix('{module}')->group(function(){
-    //next
-});
+
+Route::prefix('cpManage')->group(function () {
+    Route::prefix('cp')->group(function () {
+        Route::apiResource('manage/cp_list', CpListController::class);
+        // cp选择项
+        Route::any('options',[CpListController::class,"selectOptions"]);
+        /**
+         * cp结算数据中心
+         */
+        Route::get('subscribeStatisticData/list', [CpSubscribeStatisticDataController::class, 'list']);
+        /**
+         * cp结算数据中心统计数据
+         */
+        Route::get('subscribeStatisticData/listStatistic', [CpSubscribeStatisticDataController::class, 'listStatistic']);
+        /**
+         * cp结算
+         */
+        Route::get('subscribeStatisticData/monthList', [CpSubscribeStatisticDataController::class, 'monthList']);
+        /**
+         * 导出某个cp某个月的各个书籍的应结算金额
+         */
+        Route::get('subscribeStatisticData/listCpMonthFinalAmount', [CpSubscribeStatisticDataController::class, 'listCpMonthFinalAmount']);
+        /**
+         * 修改cp结算状态
+         */
+        Route::post('subscribeStatisticData/saveFinalState',
+            [CpSubscribeStatisticDataController::class, 'saveFinalState']);
+
+        Route::post('test/test1', [TestController::class, 'test1'])->withoutMiddleware(config('catch.route.middlewares'));
+
+        Route::get('cpCollection',[CpListController::class,"cpCollection"])->withoutMiddleware(config('catch.route.middlewares'));
+    });
+});