Преглед изворни кода

add - 服务完结后的分成 / 物业用户提现

liugc пре 1 година
родитељ
комит
e449332635

+ 108 - 0
app/adminapi/controller/property/PropertyCommissionController.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\property;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\property\PropertyCommissionLists;
+use app\adminapi\logic\property\PropertyCommissionLogic;
+use app\adminapi\validate\property\PropertyCommissionValidate;
+
+
+/**
+ * PropertyCommission控制器
+ * Class PropertyCommissionController
+ * @package app\adminapi\controller
+ */
+class PropertyCommissionController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function lists()
+    {
+        return $this->dataLists(new PropertyCommissionLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function add()
+    {
+        $params = (new PropertyCommissionValidate())->post()->goCheck('add');
+        $result = PropertyCommissionLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(PropertyCommissionLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function edit()
+    {
+        $params = (new PropertyCommissionValidate())->post()->goCheck('edit');
+        $result = PropertyCommissionLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(PropertyCommissionLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function delete()
+    {
+        $params = (new PropertyCommissionValidate())->post()->goCheck('delete');
+        PropertyCommissionLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function detail()
+    {
+        $params = (new PropertyCommissionValidate())->goCheck('detail');
+        $result = PropertyCommissionLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

+ 2 - 2
app/adminapi/controller/property/PropertyHeadController.php

@@ -89,8 +89,8 @@ class PropertyHeadController extends BaseAdminController
      */
     public function delete()
     {
-        $params = (new PropertyHeadValidate())->post()->goCheck('delete');
-        PropertyHeadLogic::delete($params);
+        //$params = (new PropertyHeadValidate())->post()->goCheck('delete');
+        //PropertyHeadLogic::delete($params);
         return $this->success('删除成功', [], 1, 1);
     }
 

+ 3 - 2
app/adminapi/controller/property/PropertyOrderController.php

@@ -53,12 +53,13 @@ class PropertyOrderController extends BaseAdminController
      */
     public function add()
     {
-        $params = (new PropertyOrderValidate())->post()->goCheck('add');
+        /*$params = (new PropertyOrderValidate())->post()->goCheck('add');
         $result = PropertyOrderLogic::add($params);
         if (true === $result) {
             return $this->success('添加成功', [], 1, 1);
         }
-        return $this->fail(PropertyOrderLogic::getError());
+        return $this->fail(PropertyOrderLogic::getError());*/
+        return $this->fail('无后台添加');
     }
 
 

+ 108 - 0
app/adminapi/controller/property/PropertySurplusLogController.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\property;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\property\PropertySurplusLogLists;
+use app\adminapi\logic\property\PropertySurplusLogLogic;
+use app\adminapi\validate\property\PropertySurplusLogValidate;
+
+
+/**
+ * PropertySurplusLog控制器
+ * Class PropertySurplusLogController
+ * @package app\adminapi\controller
+ */
+class PropertySurplusLogController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function lists()
+    {
+        return $this->dataLists(new PropertySurplusLogLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function add()
+    {
+        $params = (new PropertySurplusLogValidate())->post()->goCheck('add');
+        $result = PropertySurplusLogLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(PropertySurplusLogLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑 -- 审核提现:入账/取消
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function edit()
+    {
+        $params = (new PropertySurplusLogValidate())->post()->goCheck('edit');
+        $result = PropertySurplusLogLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(PropertySurplusLogLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function delete()
+    {
+        $params = (new PropertySurplusLogValidate())->post()->goCheck('delete');
+        PropertySurplusLogLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function detail()
+    {
+        $params = (new PropertySurplusLogValidate())->goCheck('detail');
+        $result = PropertySurplusLogLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

+ 78 - 0
app/adminapi/lists/property/PropertyCommissionLists.php

@@ -0,0 +1,78 @@
+<?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\property;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\property\PropertyCommission;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * PropertyCommission列表
+ * Class PropertyCommissionLists
+ * @package app\adminapi\lists
+ */
+class PropertyCommissionLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['property_head_id', 'property_user_id', 'property_order_id', 'work_id', 'order_amount', 'ratio', 'commission_amount'],
+
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function lists(): array
+    {
+        return PropertyCommission::where($this->searchWhere)
+            ->field(['id', 'property_head_id', 'property_user_id', 'property_order_id', 'work_id', 'order_amount', 'ratio', 'commission_amount'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function count(): int
+    {
+        return PropertyCommission::where($this->searchWhere)->count();
+    }
+
+}

+ 2 - 2
app/adminapi/lists/property/PropertyHeadLists.php

@@ -38,7 +38,7 @@ class PropertyHeadLists extends BaseAdminDataLists implements ListsSearchInterfa
     public function setSearch(): array
     {
         return [
-            '=' => ['property_name', 'village_name', 'address', 'head_name', 'head_mobile', 'commission_rules', 'head_bank_card', 'remark', 'user_id', 'all_profit_amount', 'surplus_profit_amount', 'extract_profit_amount'],
+            '=' => ['property_name', 'village_name', 'address', 'head_name', 'head_mobile', 'ratio', 'head_bank_card', 'remark', 'user_id', 'all_profit_amount', 'surplus_profit_amount', 'extract_profit_amount'],
 
         ];
     }
@@ -56,7 +56,7 @@ class PropertyHeadLists extends BaseAdminDataLists implements ListsSearchInterfa
     public function lists(): array
     {
         return PropertyHead::where($this->searchWhere)
-            ->field(['id', 'property_name', 'village_name', 'address', 'head_name', 'head_mobile', 'commission_rules', 'head_bank_card', 'remark', 'user_id', 'all_profit_amount', 'surplus_profit_amount', 'extract_profit_amount'])
+            ->field(['id', 'property_name', 'village_name', 'address', 'head_name', 'head_mobile', 'ratio', 'head_bank_card', 'remark', 'user_id', 'all_profit_amount', 'surplus_profit_amount', 'extract_profit_amount'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()

+ 78 - 0
app/adminapi/lists/property/PropertySurplusLogLists.php

@@ -0,0 +1,78 @@
+<?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\property;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\property\PropertySurplusLog;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * PropertySurplusLog列表
+ * Class PropertySurplusLogLists
+ * @package app\adminapi\lists
+ */
+class PropertySurplusLogLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['in_out', 'property_commission_id', 'amount', 'status', 'remark', 'property_head_id'],
+
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function lists(): array
+    {
+        return PropertySurplusLog::where($this->searchWhere)
+            ->field(['id', 'in_out', 'property_commission_id', 'amount', 'status', 'remark', 'property_head_id'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function count(): int
+    {
+        return PropertySurplusLog::where($this->searchWhere)->count();
+    }
+
+}

+ 113 - 0
app/adminapi/logic/property/PropertyCommissionLogic.php

@@ -0,0 +1,113 @@
+<?php
+namespace app\adminapi\logic\property;
+
+use app\common\enum\GoodsEnum;
+use app\common\enum\PayEnum;
+use app\common\enum\WorkEnum;
+use app\common\logic\BaseLogic;
+use app\common\model\coupon\UserCoupon;
+use app\common\model\dict\DictData;
+use app\common\model\goods\Goods;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\orders\RechargeOrder;
+use app\common\model\property\PropertyCommission;
+use app\common\model\property\PropertyHead;
+use app\common\model\property\PropertyOrder;
+use app\common\model\property\PropertySurplusLog;
+use app\common\model\property\PropertyUser;
+use app\common\model\recharge\OrderGoods;
+use app\common\model\works\ServiceWork;
+use app\workerapi\logic\ServiceWorkLogLogic;
+use think\Exception;
+use think\facade\Db;
+
+
+/**
+ *  物业分成收益逻辑
+ * Class PropertyCommissionLogic
+ * @package app\api\logic
+ */
+class PropertyCommissionLogic extends BaseLogic
+{
+    /**
+     * 提现入账申请通过
+     * @param $params
+     * @return false|true
+     */
+    public static function EntryCash($params)
+    {
+        Db::startTrans();
+        try {
+
+            $propertySurplusLogInfo = PropertySurplusLog::where([
+                "id" => $params['id'],
+                'in_out' => 2,
+                'status' => 0
+            ])->findOrEmpty();
+            if($propertySurplusLogInfo->isEmpty()){
+                throw new Exception('申请中记录不存在');
+            }
+            $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
+            $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
+            $amount = $propertySurplusLogInfo['amount'];
+            // 更新 出账记录-已入账
+            PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 1]);
+            // 更新 物业负责人已提收益
+            PropertyHead::where(['id' => $propertyHeadId])->update(['extract_profit_amount' => Db::raw('extract_profit_amount+'.$amount)]);
+
+            Db::commit();
+            return true;
+        }catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * 提现取消
+     * @param $params
+     * @return false|true
+     */
+    public static function CancelCash($params)
+    {
+        Db::startTrans();
+        try {
+            $propertySurplusLogInfo = PropertySurplusLog::where([
+                "id" => $params['id'],
+                'in_out' => 2,
+                'status' => 0
+            ])->findOrEmpty();
+            if($propertySurplusLogInfo->isEmpty()){
+                throw new Exception('申请中记录不存在');
+            }
+            $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
+            $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
+            $amount = $propertySurplusLogInfo['amount'];
+
+            // 更新 出账记录-取消
+            PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 2]);
+            // 更新 物业负责人剩余收益 金额恢复
+            PropertyHead::where(['id' => $propertyHeadId])->update(['surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$amount)]);
+
+            Db::commit();
+            return true;
+        }catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public static function detail($params): array
+    {
+        return PropertyCommission::findOrEmpty($params['id'])->toArray();
+    }
+}

+ 5 - 2
app/adminapi/logic/property/PropertyOrderLogic.php

@@ -77,7 +77,10 @@ class PropertyOrderLogic extends BaseLogic
             if($params['order_status'] == 2){
                 $upData['order_status'] = $params['order_status'];
             }
-            PropertyOrder::where('id', $params['id'])->update($upData);
+            $orderStatus = PropertyOrder::where('id', $params['id'])->value('order_status');
+            if($orderStatus == 0){
+                PropertyOrder::where('id', $params['id'])->update($upData);
+            }
             Db::commit();
             return true;
         } catch (\Exception $e) {
@@ -115,7 +118,7 @@ class PropertyOrderLogic extends BaseLogic
 
 
     /**
-     * @notes 客服
+     * @notes 客服接单即由后台提交工
      * @param array $params
      * @return bool
      * @author likeadmin

+ 199 - 0
app/adminapi/logic/property/PropertySurplusLogLogic.php

@@ -0,0 +1,199 @@
+<?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\property;
+
+
+use app\common\model\property\PropertyHead;
+use app\common\model\property\PropertySurplusLog;
+use app\common\logic\BaseLogic;
+use think\Exception;
+use think\facade\Db;
+
+
+/**
+ * PropertySurplusLog逻辑
+ * Class PropertySurplusLogLogic
+ * @package app\adminapi\logic
+ */
+class PropertySurplusLogLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            PropertySurplusLog::create([
+                'in_out' => $params['in_out'],
+                'property_commission_id' => $params['property_commission_id'],
+                'amount' => $params['amount'],
+                'status' => $params['status'],
+                'remark' => $params['remark'],
+                'property_head_id' => $params['property_head_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 2024/09/20 16:31
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            $status = PropertySurplusLog::where('id', $params['id'])->value('status');
+            if($status != 0){
+                throw new Exception('状态不允许操作');
+            }
+
+            if($params['status'] == 1){
+                self::EntryCash($params);
+            }
+            if($params['status'] == 1){
+                self::CancelCash($params);
+            }
+            /*PropertySurplusLog::where('id', $params['id'])->update([
+                'in_out' => $params['in_out'],
+                'property_commission_id' => $params['property_commission_id'],
+                'amount' => $params['amount'],
+                'status' => $params['status'],
+                'remark' => $params['remark'],
+                'property_head_id' => $params['property_head_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 2024/09/20 16:31
+     */
+    public static function delete(array $params): bool
+    {
+        return PropertySurplusLog::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public static function detail($params): array
+    {
+        return PropertySurplusLog::findOrEmpty($params['id'])->toArray();
+    }
+
+    /**
+     * 提现入账
+     * @param $params
+     * @return false|true
+     */
+    public static function EntryCash($params)
+    {
+        Db::startTrans();
+        try {
+
+            $propertySurplusLogInfo = PropertySurplusLog::where([
+                "id" => $params['id'],
+                'in_out' => 2,
+                'status' => 0
+            ])->findOrEmpty();
+            if($propertySurplusLogInfo->isEmpty()){
+                throw new Exception('申请中记录不存在');
+            }
+            $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
+            $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
+            $amount = $propertySurplusLogInfo['amount'];
+            // 更新 出账记录-已入账
+            PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 1]);
+            // 更新 物业负责人已提收益
+            PropertyHead::where(['id' => $propertyHeadId])->update(['extract_profit_amount' => Db::raw('extract_profit_amount+'.$amount)]);
+
+            Db::commit();
+            return true;
+        }catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+    /**
+     * 提现取消
+     * @param $params
+     * @return false|true
+     */
+    public static function CancelCash($params)
+    {
+        Db::startTrans();
+        try {
+            $propertySurplusLogInfo = PropertySurplusLog::where([
+                "id" => $params['id'],
+                'in_out' => 2,
+                'status' => 0
+            ])->findOrEmpty();
+            if($propertySurplusLogInfo->isEmpty()){
+                throw new Exception('申请中记录不存在');
+            }
+            $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
+            $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
+            $amount = $propertySurplusLogInfo['amount'];
+
+            // 更新 出账记录-取消
+            PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 2]);
+            // 更新 物业负责人剩余收益 金额恢复
+            PropertyHead::where(['id' => $propertyHeadId])->update(['surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$amount)]);
+
+            Db::commit();
+            return true;
+        }catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+}

+ 104 - 0
app/adminapi/validate/property/PropertyCommissionValidate.php

@@ -0,0 +1,104 @@
+<?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\property;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * PropertyCommission验证器
+ * Class PropertyCommissionValidate
+ * @package app\adminapi\validate
+ */
+class PropertyCommissionValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'property_head_id' => 'require',
+        'property_user_id' => 'require',
+        'property_order_id' => 'require',
+        'work_id' => 'require',
+
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'property_head_id' => '物业负责人ID',
+        'property_user_id' => '户主ID',
+        'property_order_id' => '物业下单ID',
+        'work_id' => '工单ID',
+
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return PropertyCommissionValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['property_head_id','property_user_id','property_order_id','work_id']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return PropertyCommissionValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','property_head_id','property_user_id','property_order_id','work_id']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return PropertyCommissionValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return PropertyCommissionValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:17
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 4 - 4
app/adminapi/validate/property/PropertyHeadValidate.php

@@ -37,7 +37,7 @@ class PropertyHeadValidate extends BaseValidate
         'address' => 'require',
         'head_name' => 'require',
         'head_mobile' => 'require',
-        'commission_rules' => 'require',
+        'ratio' => 'require',
         'head_bank_card' => 'require',
     ];
 
@@ -53,7 +53,7 @@ class PropertyHeadValidate extends BaseValidate
         'address' => '小区地址',
         'head_name' => '负责人名称',
         'head_mobile' => '负责人手机号/电话',
-        'commission_rules' => '提成规则json',
+        'ratio' => '提成比例',
         'head_bank_card' => '负责人银行卡号',
     ];
 
@@ -66,7 +66,7 @@ class PropertyHeadValidate extends BaseValidate
      */
     public function sceneAdd()
     {
-        return $this->only(['property_name','village_name','address','head_name','head_mobile','commission_rules','head_bank_card']);
+        return $this->only(['property_name','village_name','address','head_name','head_mobile','ratio','head_bank_card']);
     }
 
 
@@ -78,7 +78,7 @@ class PropertyHeadValidate extends BaseValidate
      */
     public function sceneEdit()
     {
-        return $this->only(['id','property_name','village_name','address','head_name','head_mobile','commission_rules','head_bank_card']);
+        return $this->only(['id','property_name','village_name','address','head_name','head_mobile','ratio','head_bank_card']);
     }
 
 

+ 2 - 2
app/adminapi/validate/property/PropertyOrderValidate.php

@@ -59,7 +59,7 @@ class PropertyOrderValidate extends BaseValidate
      */
     public function sceneAdd()
     {
-        return $this->only(['property_head_id','user_name','user_mobile']);
+        return $this->only(['property_head_id','householder_name','householder_mobile']);
     }
 
 
@@ -71,7 +71,7 @@ class PropertyOrderValidate extends BaseValidate
      */
     public function sceneEdit()
     {
-        return $this->only(['id','property_head_id','user_name','user_mobile']);
+        return $this->only(['id','property_head_id','householder_name','householder_mobile']);
     }
 
 

+ 102 - 0
app/adminapi/validate/property/PropertySurplusLogValidate.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\property;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * PropertySurplusLog验证器
+ * Class PropertySurplusLogValidate
+ * @package app\adminapi\validate
+ */
+class PropertySurplusLogValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'in_out' => 'require',
+        'status' => 'require',
+        'property_head_id' => 'require',
+
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'in_out' => '进出类型:1=进,2=出',
+        'status' => '状态:0=申请中,1=已入账,2=已取消(取消时金额恢复)',
+        'property_head_id' => '物业负责人id',
+
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return PropertySurplusLogValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['in_out','status','property_head_id']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return PropertySurplusLogValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','in_out','status','property_head_id']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return PropertySurplusLogValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return PropertySurplusLogValidate
+     * @author likeadmin
+     * @date 2024/09/20 16:31
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 78 - 0
app/api/controller/PropertyController.php

@@ -0,0 +1,78 @@
+<?php
+namespace app\api\controller;
+
+use app\adminapi\validate\property\PropertyOrderValidate;
+use app\api\lists\property\PropertyCommissionLists;
+use app\api\lists\property\PropertyOrderLists;
+use app\api\lists\property\PropertySurplusLogLists;
+use app\api\logic\PropertyCommissionLogic;
+use app\api\logic\PropertyOrderLogic;
+use app\api\validate\PropertyValidate;
+use think\facade\Log;
+
+/**
+ * 物业模块类
+ */
+class PropertyController extends BaseApiController
+{
+    public array $notNeedLogin = ['orderByQrcode', 'withdrawCash','orderLists'];
+    /**
+     * @notes 二维码扫码下物业单
+     * @return \think\response\Json
+     */
+    public function orderByQrcode()
+    {
+        $params = (new PropertyOrderValidate())->post()->goCheck('add');
+        $result = PropertyOrderLogic::add($params);
+        if (true === $result) {
+            return $this->success('下单成功', [], 1, 1);
+        }
+        return $this->fail(PropertyOrderLogic::getError());
+    }
+
+    /**
+     * 提现申请
+     * @return \think\response\Json
+     */
+    public function withdrawCash()
+    {
+        $params = (new PropertyValidate())->post()->goCheck('withdrawCash', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = PropertyCommissionLogic::withdrawCash($params);
+        if (false === $result) {
+            return $this->fail(PropertyCommissionLogic::getError());
+        }
+        return $this->success('申请成功,等待审核', [], 1, 1);
+    }
+
+    /**
+     * 下单列表
+     * @return \think\response\Json
+     */
+    public function orderLists()
+    {
+        return $this->dataLists(new PropertyOrderLists());
+    }
+
+    /**
+     * 进出记录列表
+     * @return \think\response\Json
+     */
+    public function surplusLists()
+    {
+        return $this->dataLists(new PropertySurplusLogLists());
+    }
+
+    /**
+     * 分成列表
+     * @return \think\response\Json
+     */
+    public function commissionLists()
+    {
+        return $this->dataLists(new PropertyCommissionLists());
+    }
+
+
+}

+ 49 - 0
app/api/lists/property/PropertyCommissionLists.php

@@ -0,0 +1,49 @@
+<?php
+namespace app\api\lists\property;
+
+use app\api\lists\BaseApiDataLists;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\property\PropertyCommission;
+use app\common\model\property\PropertyHead;
+use app\common\model\property\PropertySurplusLog;
+
+/**
+ * 订单列表
+ */
+class PropertyCommissionLists extends BaseApiDataLists implements ListsSearchInterface
+{
+
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['id'],
+        ];
+    }
+    public function queryWhere()
+    {
+        // 指定用户
+        $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
+        $where[] = ['property_head_id', '=', $propertyHeadId];
+        return $where;
+    }
+    public function lists(): array
+    {
+        $lists = PropertyCommission::where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->limit($this->limitOffset, $this->limitLength)
+            ->field(['id','property_head_id','property_user_id','property_order_id','work_id','create_time','update_time','order_amount','commission_amount'])
+            ->order('create_time desc')
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     */
+    public function count(): int
+    {
+        return PropertyCommission::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+}

+ 50 - 0
app/api/lists/property/PropertyOrderLists.php

@@ -0,0 +1,50 @@
+<?php
+namespace app\api\lists\property;
+
+use app\api\lists\BaseApiDataLists;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\property\PropertyCommission;
+use app\common\model\property\PropertyHead;
+use app\common\model\property\PropertyOrder;
+use app\common\model\property\PropertySurplusLog;
+
+/**
+ * 订单列表
+ */
+class PropertyOrderLists extends BaseApiDataLists implements ListsSearchInterface
+{
+
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['id','order_status'],
+        ];
+    }
+    public function queryWhere()
+    {
+        // 指定用户
+        $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
+        $where[] = ['property_head_id', '=', $propertyHeadId];
+        return $where;
+    }
+    public function lists(): array
+    {
+        $lists = PropertyOrder::where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->limit($this->limitOffset, $this->limitLength)
+            ->field(['id','property_head_id','property_user_id','remark','order_status','work_id','create_time','update_time'])
+            ->order('create_time desc')
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     */
+    public function count(): int
+    {
+        return PropertyOrder::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+}

+ 48 - 0
app/api/lists/property/PropertySurplusLogLists.php

@@ -0,0 +1,48 @@
+<?php
+namespace app\api\lists\property;
+
+use app\api\lists\BaseApiDataLists;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\property\PropertyHead;
+use app\common\model\property\PropertySurplusLog;
+
+/**
+ * 订单列表
+ */
+class PropertySurplusLogLists extends BaseApiDataLists implements ListsSearchInterface
+{
+
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['status','property_head_id'],
+        ];
+    }
+    public function queryWhere()
+    {
+        // 指定用户
+        $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
+        $where[] = ['property_head_id', '=', $propertyHeadId];
+        return $where;
+    }
+    public function lists(): array
+    {
+        $lists = PropertySurplusLog::where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->limit($this->limitOffset, $this->limitLength)
+            ->field(['id','in_out','amount','status','remark','create_time','update_time','property_head_id'])
+            ->order('create_time desc')
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     */
+    public function count(): int
+    {
+        return PropertySurplusLog::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+}

+ 45 - 2
app/api/logic/PropertyCommissionLogic.php

@@ -24,7 +24,7 @@ use think\facade\Db;
 
 
 /**
- *  物业分成
+ *  物业分成收益逻辑
  * Class PropertyCommissionLogic
  * @package app\api\logic
  */
@@ -72,7 +72,7 @@ class PropertyCommissionLogic extends BaseLogic
                     'commission_amount' => $commission_amount,
             ]);
             // 更新物业收益/订单状态已完结
-            PropertyHead::where(['id' => $propertyOrderInfo['property_head_id']])->update([
+            PropertyHead::where(['id' => $propertyOrderInfo['property_head_id']])->lock(true)->update([
                 'all_profit_amount' => Db::raw('all_profit_amount+'.$commission_amount),
                 'surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$commission_amount)
             ]);
@@ -80,6 +80,7 @@ class PropertyCommissionLogic extends BaseLogic
             // 进出账记录
             PropertySurplusLog::create([
                 'in_out' => 1,
+                'property_head_id' => $propertyOrderInfo['property_head_id'],
                 'property_commission_id' => $propertyCommissionInfo['id'],
                 'amount' => $commission_amount,
                 'status' => 1,
@@ -89,8 +90,50 @@ class PropertyCommissionLogic extends BaseLogic
             Db::commit();
             return true;
         }catch (\Exception $e) {
+            Db::rollback();
             self::setError($e->getMessage());
             return false;
         }
     }
+
+    /**
+     * 物业负责人用户申请提现
+     * @param $params
+     * @return false|true
+     */
+    public static function withdrawCash($params)
+    {
+        Db::startTrans();
+        try {
+            $propertyHeadInfo = PropertyHead::where('user_id',$params['user_id'])->lock(true)->findOrEmpty();
+            if($propertyHeadInfo->isEmpty()){
+                throw new Exception('物业负责人不存在');
+            }
+            $propertyHeadInfo = $propertyHeadInfo->toArray();
+            $propertyHeadId = $propertyHeadInfo['id'];
+            $surplusProfitAmount = $propertyHeadInfo['surplus_profit_amount'];
+            if(($surplusProfitAmount - $params['amount']) < 0){
+                throw new Exception('余额不足');
+            }
+            // 出账记录 - 提现
+            PropertySurplusLog::create([
+                'in_out' => 2,
+                'property_head_id' => $propertyHeadId,
+                'amount' => $params['amount'],
+                'status' => 0
+            ]);
+            // 更新 物业负责人余额收益
+            PropertyHead::where(['id' => $propertyHeadId])->update([
+                'surplus_profit_amount' => Db::raw('surplus_profit_amount-'.$params['amount'])
+            ]);
+
+            Db::commit();
+            return true;
+        }catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
 }

+ 59 - 0
app/api/logic/PropertyOrderLogic.php

@@ -0,0 +1,59 @@
+<?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\adminapi\logic\property\PropertyUserLogic;
+use app\common\model\property\PropertyOrder;
+use app\common\logic\BaseLogic;
+use think\Exception;
+use think\facade\Db;
+use think\facade\Log;
+
+
+/**
+ * PropertyOrder逻辑
+ * Class PropertyOrderLogic
+ * @package app\api\logic
+ */
+class PropertyOrderLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加 - 下物业单
+     * @param array $params
+     * @return bool
+     */
+    public static function add(array $params): bool
+    {
+        // 判断户主是否存在 返回户主id
+        $propertyUserId = PropertyUserLogic::getPropertyUserIdByMobile($params);
+        Db::startTrans();
+        try {
+            PropertyOrder::create([
+                'property_head_id' => $params['property_head_id'],
+                'property_user_id' => $propertyUserId,
+                'remark' => $params['remark']
+            ]);
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+}

+ 27 - 0
app/api/validate/PropertyValidate.php

@@ -0,0 +1,27 @@
+<?php
+namespace app\api\validate;
+
+use app\common\validate\BaseValidate;
+
+/**
+ * 物业模块验证器
+ * Class PropertyValidate
+ * @package app\api\validate
+ */
+class PropertyValidate extends BaseValidate
+{
+
+    protected $rule = [
+        'amount' => 'require'
+    ];
+
+
+    protected $message = [
+        'amount.require' => '提现金额不能为空',
+    ];
+
+    public function sceneWithdrawCash()
+    {
+        return $this->only(['amount']);
+    }
+}