Explorar o código

add - 门店结算

liugc hai 1 ano
pai
achega
991e74ce0d

+ 108 - 0
app/adminapi/controller/tenant/TenantRatingCommissionController.php

@@ -0,0 +1,108 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+
+namespace app\adminapi\controller\tenant;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\tenant\TenantRatingCommissionLists;
+use app\adminapi\logic\tenant\TenantRatingCommissionLogic;
+use app\adminapi\validate\tenant\TenantRatingCommissionValidate;
+
+
+/**
+ * TenantRatingCommission控制器
+ * Class TenantRatingCommissionController
+ * @package app\adminapi\controller
+ */
+class TenantRatingCommissionController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function lists()
+    {
+        return $this->dataLists(new TenantRatingCommissionLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function add()
+    {
+        $params = (new TenantRatingCommissionValidate())->post()->goCheck('add');
+        $result = TenantRatingCommissionLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(TenantRatingCommissionLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function edit()
+    {
+        $params = (new TenantRatingCommissionValidate())->post()->goCheck('edit');
+        $result = TenantRatingCommissionLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(TenantRatingCommissionLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function delete()
+    {
+        $params = (new TenantRatingCommissionValidate())->post()->goCheck('delete');
+        TenantRatingCommissionLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function detail()
+    {
+        $params = (new TenantRatingCommissionValidate())->goCheck('detail');
+        $result = TenantRatingCommissionLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

+ 77 - 0
app/adminapi/lists/tenant/TenantRatingCommissionLists.php

@@ -0,0 +1,77 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\tenant;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\tenant\TenantRatingCommission;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * TenantRatingCommission列表
+ * Class TenantRatingCommissionLists
+ * @package app\adminapi\lists
+ */
+class TenantRatingCommissionLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['rating_start', 'rating_end', 'commission', 'tenant_id'],
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function lists(): array
+    {
+        return TenantRatingCommission::where($this->searchWhere)
+            ->field(['id', 'rating_start', 'rating_end', 'commission', 'tenant_id'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function count(): int
+    {
+        return TenantRatingCommission::where($this->searchWhere)->count();
+    }
+
+}

+ 112 - 0
app/adminapi/logic/tenant/TenantRatingCommissionLogic.php

@@ -0,0 +1,112 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\tenant;
+
+
+use app\common\model\tenant\TenantRatingCommission;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * TenantRatingCommission逻辑
+ * Class TenantRatingCommissionLogic
+ * @package app\adminapi\logic
+ */
+class TenantRatingCommissionLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            TenantRatingCommission::create([
+                'rating_start' => $params['rating_start'],
+                'rating_end' => $params['rating_end'],
+                'commission' => $params['commission'],
+                'tenant_id' => $params['tenant_id']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            TenantRatingCommission::where('id', $params['id'])->update([
+                'rating_start' => $params['rating_start'],
+                'rating_end' => $params['rating_end'],
+                'commission' => $params['commission'],
+                'tenant_id' => $params['tenant_id']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public static function delete(array $params): bool
+    {
+        return TenantRatingCommission::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public static function detail($params): array
+    {
+        return TenantRatingCommission::findOrEmpty($params['id'])->toArray();
+    }
+}

+ 102 - 0
app/adminapi/validate/tenant/TenantRatingCommissionValidate.php

@@ -0,0 +1,102 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\tenant;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * TenantRatingCommission验证器
+ * Class TenantRatingCommissionValidate
+ * @package app\adminapi\validate
+ */
+class TenantRatingCommissionValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'rating_start' => 'require',
+        'rating_end' => 'require',
+        'commission' => 'require',
+        'tenant_id' => 'require',
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'rating_start' => '评分开始',
+        'rating_end' => '评分结束',
+        'commission' => '抽点比例%',
+        'tenant_id' => '租户ID',
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return TenantRatingCommissionValidate
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['rating_start','rating_end','commission','tenant_id']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return TenantRatingCommissionValidate
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','rating_start','rating_end','commission','tenant_id']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return TenantRatingCommissionValidate
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return TenantRatingCommissionValidate
+     * @author likeadmin
+     * @date 2025/02/26 18:03
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 23 - 2
app/api/logic/PerformanceLogic.php

@@ -109,10 +109,21 @@ class PerformanceLogic extends BaseLogic
             //系统回收金额
             $work->system_amount = $worker_price-$settlement_amount-$work->earnest_money-$work->add_work_amount;
 
+            //门店结算金额
+            if($work->tenant_id > 0){
+                $percentage = TenantRatingCommissionLogic::getCommissionByTenantId($work->tenant_id);
+                if($percentage > 0){
+                    $work->system_amount = bcmul($worker_price, bcdiv($percentage, 100, 4),2);
+                    $work->tenant_all_amount = $worker_price - $work->system_amount;
+                    $work->tenant_amount = $work->tenant_all_amount - $settlement_amount - $work->earnest_money - $work->add_work_amount;
+                }
+                Log::info('平台抽成门店的比例:'.'门店ID:'.$work->tenant_id.',平台抽成:'.$percentage);
+            }
+
             //工程师可提现金额,汇总了加单金额
             $settlement_amount += (float)$work->add_work_amount;
 
-            Log::info('工单'.$work->id.',总服务费:'.$worker_price.'可提现金额:'.$settlement_amount.',加单金额:'.$work->add_work_amount.',缴纳质保金:'.$work->earnest_money.',系统回收金额:'.$work->system_amount);
+            Log::info('工单'.$work->id.',总服务费:'.$worker_price.'可提现金额:'.$settlement_amount.',加单金额:'.$work->add_work_amount.',缴纳质保金:'.$work->earnest_money.',系统回收金额:'.$work->system_amount.',门店总金额(包含工程师):'.$work->tenant_all_amount . ',门店实际金额:'.$work->tenant_amount);
 
             WorkerAccountLogLogic::addAccountLog($work,$settlement_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);
         }
@@ -178,10 +189,20 @@ class PerformanceLogic extends BaseLogic
             //系统回收金额
             $work->system_amount = $work->worker_price-$settlement_amount-$work->earnest_money-$work->add_work_amount;
 
+            //门店结算金额
+            if($work->tenant_id > 0){
+                $percentage = TenantRatingCommissionLogic::getCommissionByTenantId($work->tenant_id);
+                if($percentage > 0){
+                    $work->system_amount = bcmul($work->worker_price, bcdiv($percentage, 100, 4),2);
+                    $work->tenant_all_amount = $work->worker_price - $work->system_amount;
+                    $work->tenant_amount = $work->tenant_all_amount - $settlement_amount - $work->earnest_money - $work->add_work_amount;
+                }
+                Log::info('calculatePerformanceCommission:平台抽成门店的比例:'.'门店ID:'.$work->tenant_id.',平台抽成:'.$percentage);
+            }
             //工程师可提现金额,汇总了加单金额
             $settlement_amount += (float)$work->add_work_amount;
 
-            Log::info('工单'.$work->id.',总服务费:'.$work->worker_price.'可提现金额:'.$settlement_amount.',加单金额:'.$work->add_work_amount.',缴纳质保金:'.$work->earnest_money.',系统回收金额:'.$work->system_amount);
+            Log::info('calculatePerformanceCommission:工单'.$work->id.',总服务费:'.$work->worker_price.'可提现金额:'.$settlement_amount.',加单金额:'.$work->add_work_amount.',缴纳质保金:'.$work->earnest_money.',系统回收金额:'.$work->system_amount.',门店总金额(包含工程师):'.$work->tenant_all_amount . ',门店实际金额:'.$work->tenant_amount);
 
             WorkerAccountLogLogic::addAccountLog($work,$settlement_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);
         }

+ 48 - 0
app/api/logic/TenantRatingCommissionLogic.php

@@ -0,0 +1,48 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\api\logic;
+
+use app\common\enum\PayEnum;
+use app\common\logic\BaseLogic;
+use app\common\model\master_worker\MasterWorkerTeam;
+use app\common\model\recharge\RechargeOrder;
+use app\common\model\tenant\TenantRatingCommission;
+use app\common\model\user\User;
+use app\common\service\ConfigService;
+
+
+/**
+ * 服务分抽成
+ * Class TenantRatingCommissionLogic
+ * @package app\shopapi\logic
+ */
+class TenantRatingCommissionLogic extends BaseLogic
+{
+
+    /**
+     * 获取抽成比例
+     *  eg:
+     *  3.5 <= 3.8 < 4.0
+     *
+     */
+    public static function getCommissionByTenantId($tenant_id)
+    {
+        $comprehensive_score = MasterWorkerTeam::where('tenant_id',$tenant_id)->value('comprehensive_score')??0;
+        return TenantRatingCommission::where('tenant_id',$tenant_id)
+            ->where('rating_start','<=',$comprehensive_score)
+            ->where('rating_end','>',$comprehensive_score)->value('commission')??0;
+    }
+
+}

+ 34 - 0
app/common/model/tenant/TenantRatingCommission.php

@@ -0,0 +1,34 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\tenant;
+
+
+use app\common\model\BaseModel;
+
+
+
+/**
+ * TenantRatingCommission模型
+ * Class TenantRatingCommission
+ * @package app\common\model
+ */
+class TenantRatingCommission extends BaseModel
+{
+    
+    protected $name = 'tenant_rating_commission';
+    
+
+    
+}