WIN-2308041133\Administrator 5 hónapja
szülő
commit
d8756a6c0a

+ 51 - 0
app/common/dao/user/AwardLakeDao.php

@@ -0,0 +1,51 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+
+namespace app\common\dao\user;
+
+
+use app\common\dao\BaseDao;
+use app\common\model\BaseModel;
+use app\common\model\user\AwardIntegralPrice;
+use app\common\model\user\AwardLake;
+
+/**
+ * Class AwardLakeDao
+ * @package app\common\dao\user
+ * @author xaboy
+ * @day 2020-05-07
+ */
+class AwardLakeDao extends BaseDao
+{
+
+    /**
+     * @return BaseModel
+     * @author xaboy
+     * @day 2020-03-30
+     */
+    protected function getModel(): string
+    {
+        return AwardLake::class;
+    }
+
+    public function search($where)
+    {
+//        return $this->getModel()::getDB()->where($where);
+        $query = $this->getModel()::getDB()
+            ->when(isset($where['type']) && $where['type'] !== '',function($query) use($where){
+                $query->where('type',$where['type']);
+            });
+        return $query;
+    }
+
+}

+ 48 - 0
app/common/dao/user/OilLevelDao.php

@@ -0,0 +1,48 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+
+namespace app\common\dao\user;
+
+
+use app\common\dao\BaseDao;
+use app\common\model\BaseModel;
+use app\common\model\user\AwardIntegralPrice;
+use app\common\model\user\OilLevel;
+
+/**
+ * Class OilLevelDao
+ * @package app\common\dao\user
+ * @author xaboy
+ * @day 2020-05-07
+ */
+class OilLevelDao extends BaseDao
+{
+
+    /**
+     * @return BaseModel
+     * @author xaboy
+     * @day 2020-03-30
+     */
+    protected function getModel(): string
+    {
+        return OilLevel::class;
+    }
+
+    public function search($where)
+    {
+//        return $this->getModel()::getDB()->where($where);
+        $query = $this->getModel()::getDB();
+        return $query;
+    }
+
+}

+ 25 - 1
app/common/repositories/user/AwardIntegralPriceRepository.php

@@ -15,6 +15,7 @@ namespace app\common\repositories\user;
 
 
 use app\common\dao\user\AwardIntegralPriceDao;
+use app\common\dao\user\AwardLakeDao;
 use app\common\model\store\order\StoreOrder;
 use app\common\model\user\AwardIntegralPrice;
 use app\common\model\user\UserExtract;
@@ -100,7 +101,7 @@ class AwardIntegralPriceRepository extends BaseRepository
     /**
      * 根据条件获取列表数据
      *
-     * 奖池列表
+     *  每日分红价格列表
      * @param array $where 查询条件数组,用于指定数据库查询的条件。
      * @param int $page 当前页码,用于指定要返回的页码。
      * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
@@ -114,6 +115,29 @@ class AwardIntegralPriceRepository extends BaseRepository
         // 统计满足条件的数据总数
         $count = $query->count();
 
+        // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
+        // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
+        $list = $query->page($page, $limit)->select()->toArray();
+        // 返回包含数据总数和数据列表的数组
+        return compact('count', 'list');
+    }
+    /**
+     * 根据条件获取列表数据
+     *
+     *  每日奖池列表
+     * @param array $where 查询条件数组,用于指定数据库查询的条件。
+     * @param int $page 当前页码,用于指定要返回的页码。
+     * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
+     * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
+     */
+    public function getLakeList(array $where, $page, $limit)
+    {
+        // 根据条件查询数据,$where 为查询条件数组
+        $query = AwardLakeDao::search($where);
+
+        // 统计满足条件的数据总数
+        $count = $query->count();
+
         // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
         // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
         $list = $query->page($page, $limit)->select()->toArray();

+ 113 - 0
app/common/repositories/user/OilLevelRepository.php

@@ -0,0 +1,113 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+
+namespace app\common\repositories\user;
+
+use app\common\dao\user\OilLevelDao;
+use app\common\repositories\BaseRepository;
+use FormBuilder\Exception\FormBuilderException;
+use FormBuilder\Factory\Elm;
+use FormBuilder\Form;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+use think\facade\Route;
+
+/**
+ * Class OilLevelRepository
+ * @package app\common\repositories\user
+ * @author xaboy
+ * @day 2020-05-07
+ * @mixin OilLevelDao
+ */
+class OilLevelRepository extends BaseRepository
+{
+    /**
+     * @var OilLevelDao
+     */
+    protected $dao;
+
+    /**
+     * OilLevelRepository constructor.
+     * @param OilLevelDao $dao
+     */
+    public function __construct(OilLevelDao $dao)
+    {
+        $this->dao = $dao;
+    }
+
+    /**
+     * 根据条件获取列表数据
+     *
+     * 本函数用于根据给定的条件数组 $where,从数据库中检索满足条件的数据列表。
+     * 它支持分页查询,每页的数据数量由 $limit 指定,查询的页码由 $page 指定。
+     * 函数返回一个包含两个元素的数组,第一个元素是数据总数 $count,第二个元素是当前页的数据列表 $list。
+     *
+     * @param array $where 查询条件数组
+     * @param int $page 查询的页码
+     * @param int $limit 每页的数据数量
+     * @return array 返回包含 'count' 和 'list' 两个元素的数组
+     */
+    public function getList(array $where, $page, $limit)
+    {
+        // 根据条件查询数据
+        $query = $this->dao->search($where);
+
+        // 统计满足条件的数据总数
+        $count = $query->count($this->dao->getPk());
+
+        // 获取当前页的数据列表
+        $list = $query->page($page, $limit)->select();
+
+        // 返回数据总数和当前页的数据列表
+        return compact('count', 'list');
+    }
+
+    /**
+     * 创建或编辑用户分组的表单
+     *
+     * 本函数用于生成添加新用户分组或编辑已存在用户分组的表单。根据$id$参数的值来判断是创建新分组还是编辑已有分组。
+     * 表单的动作(action)根据$id$是否有值来决定是向系统请求创建新用户分组还是更新已有用户分组的信息。
+     *
+     * @param int|null $id 用户分组的ID。如果ID为null,则表示创建新分组;如果ID有值,则表示编辑已存在的分组。
+     * @param array $formData 表单的初始数据。用于在编辑分组时填入已有的分组信息。
+     * @return \EasyWeChat\Kernel\Messages\MiniprogramForm|Form
+     */
+    public function form($id = null, array $formData = [])
+    {
+        // 判断当前操作是创建还是编辑用户分组
+        $isCreate = is_null($id);
+
+        // 根据操作类型生成表单的动作URL
+        $action = Route::buildUrl($isCreate ? 'systemOilLevelCreate' : 'systemOilLevelUpdate', $isCreate ? [] : compact('id'))->build();
+
+        // 返回生成的表单对象,设置表单的动作、标题和初始数据
+        return Elm::createForm($action, [
+            Elm::input('group_name', '分组名称:')->placeholder('请输入用户分组名称')->required()
+        ])->setTitle($isCreate ? '添加用户分组' : '编辑用户分组')->formData($formData);
+    }
+
+    /**
+     * 更新表单数据。
+     * 该方法用于根据给定的ID获取数据库中的记录,并使用这些数据来构建一个表单,以便用户可以查看或编辑这些数据。
+     *
+     * @param int $id 表单记录的唯一标识符。
+     * @return array|\EasyWeChat\Kernel\Messages\MiniprogramForm|Form
+     */
+    public function updateForm($id)
+    {
+        // 通过ID从数据库获取记录,并转换为数组格式,用于填充表单
+        return $this->form($id, $this->dao->get($id)->toArray());
+    }
+
+}

+ 12 - 2
app/controller/admin/user/Award.php

@@ -49,7 +49,17 @@ class Award extends BaseController
         $where = $this->request->params(['day']);
         return app('json')->success($this->repository->getList($where, $page, $limit));
     }
-
-
+    /**
+     * 奖池列表
+     * @return \think\response\Json
+     * @author Qinii
+     * @day 2023/9/24
+     */
+    public function lake_lst()
+    {
+        [$page, $limit] = $this->getPage();
+        $where = $this->request->params(['type']);
+        return app('json')->success($this->repository->getLakeList($where, $page, $limit));
+    }
 
 }

+ 144 - 0
app/controller/admin/user/OilLevel.php

@@ -0,0 +1,144 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+
+namespace app\controller\admin\user;
+
+
+use app\common\dao\user\OilLevelDao;
+use app\common\repositories\store\ExcelRepository;
+use app\common\repositories\user\AwardIntegralPriceRepository;
+use app\common\repositories\user\OilLevelRepository;
+use app\common\repositories\user\UserInfoRepository;
+use app\validate\admin\OilLevelValidate;
+use crmeb\basic\BaseController;
+use app\common\repositories\user\UserBillRepository;
+use crmeb\services\ExcelService;
+use think\App;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+
+/**
+ * Class Award
+ * app\controller\admin\user
+ * 用户扩展字段设置
+ */
+class OilLevel extends BaseController
+{
+    protected $repository;
+
+    public function __construct(App $app, AwardIntegralPriceRepository $repository)
+    {
+        parent::__construct($app);
+        $this->repository = $repository;
+    }
+
+    /**
+     *  列表
+     * @return \think\response\Json
+     * @author Qinii
+     * @day 2023/9/24
+     */
+    public function lst()
+    {
+        [$page, $limit] = $this->getPage();
+        $where = $this->request->params(['day']);
+        return app('json')->success($this->repository->getList($where, $page, $limit));
+    }
+    /**
+     * 添加
+     * @param OilLevelValidate $validate
+     * @return mixed
+     * @author Qinii
+     */
+    public function create(OilLevelValidate $validate,OilLevelRepository $repository)
+    {
+        $data = $this->checkParams($validate);
+        $grade = $repository->where('grade', $data['grade'])->find();
+        if ($grade){
+            return app('json')->fail('等级已存在');
+        }
+        $this->repository->create($data);
+        return app('json')->success('添加成功');
+
+    }
+
+    /**
+     * 文章详情
+     * @param $id
+     * @return \think\response\Json
+     * @author wuhaotian
+     * @email 442384644@qq.com
+     * @date 2024/7/4
+     */
+    public function detail($id)
+    {
+//        if (!$this->repository->merExists($this->request->merId(), $id))
+//            return app('json')->fail('数据不存在');
+
+        return app('json')->success($this->repository->getWith($id));
+    }
+
+    /**
+     * 更新
+     * @param $id
+     * @param OilLevelValidate $validate
+     * @return mixed
+     * @author Qinii
+     */
+    public function update($id, OilLevelValidate $validate,OilLevelRepository $repository)
+    {
+        $data = $this->checkParams($validate);
+//        if (!$this->repository->merExists($this->request->merId(), $id))
+//            return app('json')->fail('数据不存在');
+        $grade = $repository->where('grade', $data['grade'])->find();
+        if ($grade){
+            return app('json')->fail('等级已存在');
+        }
+        $this->repository->update($id, $data);
+
+        return app('json')->success('编辑成功');
+    }
+
+    /**
+     * 删除
+     * @param $id
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     * @author Qinii
+     */
+    public function delete($id)
+    {
+//        if (!$this->repository->merExists($this->request->merId(), $id))
+//            return app('json')->fail('数据不存在');
+
+        $this->repository->delete($id);
+
+        return app('json')->success('删除成功');
+    }
+    /**
+     * 验证数据
+     * @param OilLevelValidate $validate
+     * @return array
+     * @author Qinii
+     */
+    public function checkParams(OilLevelValidate $validate)
+    {
+        $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
+        $validate->check($data);
+        return $data;
+    }
+
+}

+ 28 - 0
app/validate/admin/GiftlLevelValidate.php

@@ -0,0 +1,28 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+
+namespace app\validate\admin;
+
+use think\Validate;
+
+class GiftlLevelValidate extends Validate
+{
+    protected $failException = true;
+
+    protected $rule = [
+        'name|等级名' => 'require',
+        'grade|级别' => 'require|integer',
+        'achievement|业绩要求' => 'require',
+        'award_ratio|分红比例' => 'require',
+    ];
+}

+ 28 - 0
app/validate/admin/OilLevelValidate.php

@@ -0,0 +1,28 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+
+namespace app\validate\admin;
+
+use think\Validate;
+
+class OilLevelValidate extends Validate
+{
+    protected $failException = true;
+
+    protected $rule = [
+        'name|等级名' => 'require',
+        'grade|级别' => 'require|integer',
+        'achievement|业绩要求' => 'require',
+        'award_ratio|分红比例' => 'require',
+    ];
+}

+ 40 - 4
route/admin/award.php

@@ -19,10 +19,10 @@ Route::group(function () {
 
     //积分价格
     Route::group('system/award/price', function () {
-//        Route::get('create/form', '/createForm')->name('systemArticleCategoryCreateForm')->option([
+//        Route::get('create/form', '/createForm')->name('OilLevelCreateForm')->option([
 //            '_alias' => '文章分类添加表单',
 //            '_auth' => false,
-//            '_form' => 'systemArticleCategoryCreate',
+//            '_form' => 'OilLevelCreate',
 //        ]);
         Route::get('lst', '/lst')->name('systemAwardPriceLst')->option([
             '_alias' => '积分价格列表',
@@ -32,10 +32,46 @@ Route::group(function () {
 //            '_auth'  => false,
 //        ]);
     })->prefix('admin.user.award')->option([
-        '_path' => '/cms/articleCategory',
+        '_path' => '/award/price',
+        '_auth' => true,
+    ]);
+    Route::group('system/award/oil_level', function () {
+        Route::get('create/form', '/createForm')->name('OilLevelCreateForm')->option([
+            '_alias' => '添加节能油等级',
+            '_auth' => false,
+            '_form' => 'OilLevelCreate',
+        ]);
+        Route::get('lst', '/lst')->name('OilLevelLst')->option([
+            '_alias' => '节能油等级列表',
+        ]);
+        Route::post('create', '/create')->name('OilLevelCreate')->option([
+            '_alias' => '节能油等级添加',
+        ]);
+//        Route::get('update/form/:id', '/updateForm')->name('OilLevelUpdateForm')->option([
+//            '_alias' => '文章分类编辑表单',
+//            '_auth' => false,
+//            '_form' => 'OilLevelUpdate',
+//        ]);
+        Route::post('update/:id', '/update')->name('OilLevelUpdate')->option([
+            '_alias' => '节能油等级编辑',
+        ]);
+//        Route::post('status/:id', '/switchStatus')->name('OilLevelStatus')->option([
+//            '_alias' => '文章分类修改状态',
+//        ]);
+        Route::delete('delete/:id', '/delete')->name('OilLevelDelete')->option([
+            '_alias' => '节能油等级删除',
+        ]);
+        Route::get('detail/:id', '/detail')->name('OilLevelDetail')->option([
+            '_alias' => '节能油等级详情',
+        ]);
+//        Route::get('select', '/select')->option([
+//            '_alias' => '文章分类筛选',
+//            '_auth'  => false,
+//        ]);
+    })->prefix('admin.user.oillevel')->option([
+        '_path' => '/award/oillevel',
         '_auth' => true,
     ]);
-
 
 })->middleware(AllowOriginMiddleware::class)
     ->middleware(AdminTokenMiddleware::class, true)