WIN-2308041133\Administrator 5 月之前
父节点
当前提交
ba4173a39d

+ 48 - 0
app/common/dao/user/GiftLevelDao.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\GiftLevel;
+
+/**
+ * Class GiftLevelDao
+ * @package app\common\dao\user
+ * @author xaboy
+ * @day 2020-05-07
+ */
+class GiftLevelDao extends BaseDao
+{
+
+    /**
+     * @return BaseModel
+     * @author xaboy
+     * @day 2020-03-30
+     */
+    protected function getModel(): string
+    {
+        return GiftLevel::class;
+    }
+
+    public function search($where)
+    {
+//        return $this->getModel()::getDB()->where($where);
+        $query = $this->getModel()::getDB();
+        return $query;
+    }
+
+}

+ 113 - 0
app/common/repositories/user/GiftLevelRepository.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\GiftLevelDao;
+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 GiftLevelRepository
+ * @package app\common\repositories\user
+ * @author xaboy
+ * @day 2020-05-07
+ * @mixin GiftLevelDao
+ */
+class GiftLevelRepository extends BaseRepository
+{
+    /**
+     * @var GiftLevelDao
+     */
+    protected $dao;
+
+    /**
+     * GiftLevelRepository constructor.
+     * @param GiftLevelDao $dao
+     */
+    public function __construct(GiftLevelDao $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 ? 'systemGiftLevelCreate' : 'systemGiftLevelUpdate', $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());
+    }
+
+}

+ 0 - 2
app/controller/admin/store/StoreProduct.php

@@ -113,10 +113,8 @@ class StoreProduct extends BaseController
      */
     public function detail($id)
     {
-        @file_put_contents('quanju.txt',$id,"-测试1\r\n",8);
         if (!$this->repository->merExists(null, $id))
             return app('json')->fail('数据不存在');
-        @file_put_contents('quanju.txt',"-测试2\r\n",8);
         return app('json')->success($this->repository->getAdminOneProduct($id, 0));
     }
 

+ 76 - 0
app/controller/admin/user/Award.php

@@ -16,8 +16,10 @@ namespace app\controller\admin\user;
 
 use app\common\repositories\store\ExcelRepository;
 use app\common\repositories\user\AwardIntegralPriceRepository;
+use app\common\repositories\user\GiftLevelRepository;
 use app\common\repositories\user\OilLevelRepository;
 use app\common\repositories\user\UserInfoRepository;
+use app\validate\admin\GiftLevelValidate;
 use app\validate\admin\OilLevelValidate;
 use crmeb\basic\BaseController;
 use app\common\repositories\user\UserBillRepository;
@@ -151,4 +153,78 @@ class Award extends BaseController
         $validate->check($data);
         return $data;
     }
+    /**
+     *  列表
+     * @return \think\response\Json
+     * @author Qinii
+     * @day 2023/9/24
+     */
+    public function gift_lst(GiftLevelValidate $validate,GiftLevelRepository $repository)
+    {
+        [$page, $limit] = $this->getPage();
+        $where = $this->request->params(['']);
+        return app('json')->success($repository->getList($where, $page, $limit));
+    }
+    /**
+     * 添加
+     * @param GiftLevelValidate $validate
+     * @return mixed
+     * @author Qinii
+     */
+    public function gift_create(GiftLevelValidate $validate,GiftLevelRepository $repository)
+    {
+        $data = $this->gift_checkParams($validate);
+        $grade = app()->make(GiftLevelRepository::class)->getSearch([])->where('grade', $data['grade'])->find();
+        if ($grade){
+            return app('json')->fail('等级已存在');
+        }
+        $data['update_time'] = time();
+        $repository->create($data);
+        return app('json')->success('添加成功');
+
+    }
+
+
+    /**
+     * 更新
+     * @param $id
+     */
+    public function gift_update($id, GiftLevelValidate $validate,GiftLevelRepository $repository)
+    {
+        $data = $this->gift_checkParams($validate);
+//        if (!$this->repository->merExists($this->request->merId(), $id))
+//            return app('json')->fail('数据不存在');
+        $grade = app()->make(GiftLevelRepository::class)->getSearch([])->whereNotIn('id',[$id])->where('grade', $data['grade'])->find();
+        if ($grade){
+            return app('json')->fail('等级已存在');
+        }
+        $repository->update($id, $data);
+
+        return app('json')->success('编辑成功');
+    }
+
+    /**
+     * 删除
+     */
+    public function gift_delete($id,GiftLevelRepository $repository)
+    {
+//        if (!$this->repository->merExists($this->request->merId(), $id))
+//            return app('json')->fail('数据不存在');
+
+        $repository->delete($id);
+
+        return app('json')->success('删除成功');
+    }
+    /**
+     * 验证数据
+     * @param GiftLevelValidate $validate
+     * @return array
+     * @author Qinii
+     */
+    public function gift_checkParams(GiftLevelValidate $validate)
+    {
+        $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
+        $validate->check($data);
+        return $data;
+    }
 }

+ 28 - 0
app/validate/admin/GiftLevelValidate.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 GiftLevelValidate extends Validate
+{
+    protected $failException = true;
+
+    protected $rule = [
+        'name|等级名' => 'require',
+        'grade|级别' => 'require|integer',
+        'achievement|业绩要求' => 'require',
+        'award_ratio|分红比例' => 'require',
+    ];
+}

+ 11 - 2
route/admin/award.php

@@ -42,8 +42,17 @@ Route::group(function () {
         Route::delete('oil/delete/:id', '/oil_delete')->name('systemAwardOilDelete')->option([
             '_alias' => '节能油等级删除',
         ]);
-        Route::get('oil/detail/:id', '/oil_detail')->name('systemAwardOilDetail')->option([
-            '_alias' => '节能油等级详情',
+        Route::get('gift/lst', '/gift_lst')->name('systemAwardgiftLst')->option([
+            '_alias' => '礼包等级列表',
+        ]);
+        Route::post('gift/create', '/gift_create')->name('systemAwardgiftCreate')->option([
+            '_alias' => '礼包等级添加',
+        ]);
+        Route::post('gift/update/:id', '/gift_update')->name('systemAwardgiftUpdate')->option([
+            '_alias' => '礼包等级编辑',
+        ]);
+        Route::delete('gift/delete/:id', '/gift_delete')->name('systemAwardgiftDelete')->option([
+            '_alias' => '礼包等级删除',
         ]);
     })->prefix('admin.user.award')->option([
         '_path' => '/award/price',