Kaynağa Gözat

工单结算

whitefang 1 yıl önce
ebeveyn
işleme
18bb848fa0

+ 0 - 15
app/adminapi/controller/finance/AccountLogController.php

@@ -1,17 +1,4 @@
 <?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\finance;
 
 use app\adminapi\controller\BaseAdminController;
@@ -30,7 +17,6 @@ class AccountLogController extends BaseAdminController
     /**
      * @notes 账户流水明细
      * @return \think\response\Json
-     * @author 段誉
      * @date 2023/2/24 15:25
      */
     public function lists()
@@ -42,7 +28,6 @@ class AccountLogController extends BaseAdminController
     /**
      * @notes 用户余额变动类型
      * @return \think\response\Json
-     * @author 段誉
      * @date 2023/2/24 15:25
      */
     public function getUmChangeType()

+ 39 - 0
app/adminapi/controller/finance/WorkerAccountLogController.php

@@ -0,0 +1,39 @@
+<?php
+namespace app\adminapi\controller\finance;
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\finance\WorkerAccountLogLists;
+use app\common\enum\worker\WorkerAccountLogEnum;
+
+/***
+ * 账户流水控制器
+ * Class AccountLogController
+ * @package app\adminapi\controller
+ */
+class WorkerAccountLogController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 账户流水明细
+     * @return \think\response\Json
+     * @date 2023/2/24 15:25
+     */
+    public function lists()
+    {
+        return $this->dataLists(new WorkerAccountLogLists());
+    }
+
+
+    /**
+     * @notes 用户余额变动类型
+     * @return \think\response\Json
+     * @date 2023/2/24 15:25
+     */
+    public function getUmChangeType()
+    {
+        return $this->data(WorkerAccountLogEnum::getUserMoneyChangeTypeDesc());
+    }
+
+
+}

+ 99 - 0
app/adminapi/lists/finance/WorkerAccountLogLists.php

@@ -0,0 +1,99 @@
+<?php
+namespace app\adminapi\lists\finance;
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\enum\worker\WorkerAccountLogEnum;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\master_worker\MasterWorkerAccountLog;
+use app\common\model\user\UserAccountLog;
+use app\common\service\FileService;
+
+
+/**
+ * 账记流水列表
+ * Class WorkerAccountLogLists
+ * @package app\adminapi\lists\finance
+ */
+class WorkerAccountLogLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+    /**
+     * @notes 搜索条件
+     * @return array
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['al.change_type'],
+        ];
+    }
+
+
+    /**
+     * @notes 搜索条件
+     */
+    public function queryWhere()
+    {
+        $where = [];
+        // 用户余额
+        if (isset($this->params['type']) && $this->params['type'] == 'um') {
+            $where[] = ['change_type', 'in', WorkerAccountLogEnum::getUserMoneyChangeType()];
+        }
+
+        if (!empty($this->params['user_info'])) {
+            $where[] = ['u.sn|u.nickname|u.mobile|u.account', 'like', '%' . $this->params['user_info'] . '%'];
+        }
+
+        if (!empty($this->params['start_time'])) {
+            $where[] = ['al.create_time', '>=', strtotime($this->params['start_time'])];
+        }
+
+        if (!empty($this->params['end_time'])) {
+            $where[] = ['al.create_time', '<=', strtotime($this->params['end_time'])];
+        }
+
+        return $where;
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     */
+    public function lists(): array
+    {
+        $field = 'u.nickname,u.account,u.sn,u.avatar,u.mobile,al.action,al.change_amount,al.left_amount,al.change_type,al.work_sn,al.create_time';
+        $lists = MasterWorkerAccountLog::alias('al')
+            ->join('master_worker u', 'u.id = al.worker_id')
+            ->field($field)
+            ->where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->order('al.id', 'desc')
+            ->limit($this->limitOffset, $this->limitLength)
+            ->select()
+            ->toArray();
+
+        foreach ($lists as &$item) {
+            $item['avatar'] = FileService::getFileUrl($item['avatar']);
+            $item['change_type_desc'] = WorkerAccountLogEnum::getChangeTypeDesc($item['change_type']);
+            $symbol = $item['action'] == WorkerAccountLogEnum::INC ? '+' : '-';
+            $item['change_amount'] = $symbol . $item['change_amount'];
+        }
+
+        return $lists;
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     */
+    public function count(): int
+    {
+        return MasterWorkerAccountLog::alias('al')
+            ->join('master_worker u', 'u.id = al.worker_id')
+            ->where($this->queryWhere())
+            ->where($this->searchWhere)
+            ->count();
+    }
+}

+ 26 - 1
app/api/logic/PerformanceLogic.php

@@ -2,7 +2,11 @@
 
 namespace app\api\logic;
 
+use app\common\enum\worker\WorkerAccountLogEnum;
 use app\common\logic\BaseLogic;
+use app\common\logic\WorkerAccountLogLogic;
+use app\common\model\performance\PerformanceRules;
+use think\facade\Db;
 
 
 /**
@@ -12,9 +16,30 @@ use app\common\logic\BaseLogic;
  */
 class PerformanceLogic extends BaseLogic
 {
-    public static function calculatePerformance($param)
+    /**
+     * @param $work
+     * @return false|void
+     */
+    public static function calculatePerformance($work)
     {
         //工单已完结,进行结算,结算完成后设置work_pay_status为2,已结算
+            $rule = PerformanceRules::whereFindInSet('goods_category_ids',$work->goods_category_id)->findOrEmpty();
+            if($rule->isEmpty()){
+                $work->work_pay_status = 3;
+            }else{
+                $work->work_pay_status = 2;
+            }
+            $work->save();
 
+            //师傅金额结算
+            if(!$rule->isEmpty()){
+                if($rule['type']==0){
+                    $work_price = $work->work_total;
+                }else{
+                    $work_price = $work->work_amount;
+                }
+                $settlement_amount = bcmul($work_price, $rule['rate']);
+                WorkerAccountLogLogic::addAccountLog($work,$settlement_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);
+            }
     }
 }

+ 2 - 2
app/api/logic/ServiceOrderLogic.php

@@ -10,6 +10,7 @@ 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\performance\PerformanceRules;
 use app\common\model\recharge\OrderGoods;
 use app\common\model\works\ServiceWork;
 use app\workerapi\logic\ServiceWorkLogLogic;
@@ -284,7 +285,7 @@ class ServiceOrderLogic extends BaseLogic
 
             //确认所有订单总金额和结算金额
             //若订单是全款已支付订单
-            if(count($orders)==1 and $orders[0]['payment_type']=0 and $orders[0]['pay_status']==1){
+            if(count($orders)==1 and $orders[0]['payment_type']==0 and $orders[0]['pay_status']==1){
                 $service_work->work_status = 7;
                 $service_work->user_confirm_status = 5;
                 $service_work->work_total = $orders[0]['order_total'];
@@ -298,7 +299,6 @@ class ServiceOrderLogic extends BaseLogic
                 }
                 $service_work->work_total = $order_total;
             }
-
             $service_work->save();
 
             $work_log = [

+ 0 - 13
app/common/enum/user/AccountLogEnum.php

@@ -1,17 +1,4 @@
 <?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\enum\user;
 
 /**

+ 136 - 0
app/common/enum/worker/WorkerAccountLogEnum.php

@@ -0,0 +1,136 @@
+<?php
+namespace app\common\enum\worker;
+
+/**
+ * 师傅账户流水变动表枚举
+ * Class AccountLogEnum
+ * @package app\common\enum
+ */
+class WorkerAccountLogEnum
+{
+    /**
+     * 变动类型命名规则:对象_动作_简洁描述
+     * 动作 DEC-减少 INC-增加
+     * 对象 UM-师傅余额
+     */
+
+    /**
+     * 变动对象
+     * UM 师傅余额(user_money)
+     */
+    const UM = 1;
+
+    /**
+     * 动作
+     * INC 增加
+     * DEC 减少
+     */
+    const INC = 1;
+    const DEC = 2;
+
+
+    /**
+     * 师傅余额减少类型
+     */
+    const UM_DEC_ADMIN = 100;
+    /**
+     * 师傅余额增加类型
+     */
+    const UM_INC_ADMIN = 200;
+
+    /**
+     * 师傅余额(减少类型汇总)
+     */
+    const UM_DEC = [
+        self::UM_DEC_ADMIN,
+    ];
+
+
+    /**
+     * 师傅余额(增加类型汇总)
+     */
+    const UM_INC = [
+        self::UM_INC_ADMIN,
+    ];
+
+
+    /**
+     * @notes 动作描述
+     * @param $action
+     * @param false $flag
+     * @return string|string[]
+     */
+    public static function getActionDesc($action, $flag = false)
+    {
+        $desc = [
+            self::DEC => '减少',
+            self::INC => '增加',
+        ];
+        if ($flag) {
+            return $desc;
+        }
+        return $desc[$action] ?? '';
+    }
+
+
+    /**
+     * @notes 变动类型描述
+     * @param $changeType
+     * @param false $flag
+     * @return string|string[]
+     */
+    public static function getChangeTypeDesc($changeType, $flag = false)
+    {
+        $desc = [
+            self::UM_DEC_ADMIN => '平台减少余额',
+            self::UM_INC_ADMIN => '平台增加余额',
+        ];
+        if ($flag) {
+            return $desc;
+        }
+        return $desc[$changeType] ?? '';
+    }
+
+
+    /**
+     * @notes 获取师傅余额类型描述
+     * @return string|string[]
+     */
+    public static function getUserMoneyChangeTypeDesc()
+    {
+        $UMChangeType = self::getUserMoneyChangeType();
+        $changeTypeDesc = self::getChangeTypeDesc('', true);
+        return array_filter($changeTypeDesc, function ($key) use ($UMChangeType) {
+            return in_array($key, $UMChangeType);
+        }, ARRAY_FILTER_USE_KEY);
+    }
+
+
+    /**
+     * @notes 获取师傅余额变动类型
+     * @return int[]
+     */
+    public static function getUserMoneyChangeType() : array
+    {
+        return array_merge(self::UM_DEC, self::UM_INC);
+    }
+
+
+    /**
+     * @notes 获取变动对象
+     * @param $changeType
+     * @return false
+     */
+    public static function getChangeObject($changeType)
+    {
+        // 师傅余额
+        $um = self::getUserMoneyChangeType();
+        if (in_array($changeType, $um)) {
+            return self::UM;
+        }
+
+        // 其他...
+
+        return false;
+    }
+}

+ 60 - 0
app/common/logic/WorkerAccountLogLogic.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace app\common\logic;
+
+use app\common\enum\worker\WorkerAccountLogEnum;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker\MasterWorkerAccountLog;
+use think\Exception;
+
+class WorkerAccountLogLogic extends BaseLogic
+{
+    /**
+     * @param $work //工单对象
+     * @param $change_amount //变动数量
+     * @param $change_type //变动类型
+     * @param $action //动作 1-增加 2-减少
+     * @return bool|void
+     * @throws Exception
+     */
+    public static function addAccountLog($work,$changeAmount,$changeType,$action, string $remark = '',  array $extra = [])
+    {
+        $worker = MasterWorker::findOrFail($work->master_worker_id);
+        if($worker->isEmpty()) {
+            throw new Exception('师傅不存在');
+        }
+
+        $changeObject = WorkerAccountLogEnum::getChangeObject($changeType);
+        if(!$changeObject) {
+            throw new Exception('结算错误');
+        }
+
+        switch ($changeObject) {
+            // 用户余额
+            case WorkerAccountLogEnum::UM:
+                $left_amount = $worker->user_money;
+                break;
+            // 其他
+        }
+
+        $data = [
+            'sn' => generate_sn(MasterWorkerAccountLog::class, 'sn', 20),
+            'worker_id' => $work->master_worker_id,
+            'change_object' => $changeObject,
+            'change_type' => $changeType,
+            'action' => $action,
+            'left_amount' => $left_amount,
+            'change_amount' => $changeAmount,
+            'work_sn' => $work->work_sn,
+            'remark' => $remark,
+            'extra' => $extra ? json_encode($extra, JSON_UNESCAPED_UNICODE) : '',
+        ];
+
+        MasterWorkerAccountLog::create($data);
+
+        $worker->user_money = $left_amount + ($action==1?$changeAmount:-$changeAmount);
+        $worker->save();
+
+        return true;
+    }
+}

+ 19 - 0
app/common/model/master_worker/MasterWorkerAccountLog.php

@@ -0,0 +1,19 @@
+<?php
+namespace app\common\model\master_worker;
+
+use app\common\model\BaseModel;
+use app\common\model\MasterWorkerRegister;
+use think\model\concern\SoftDelete;
+
+/**
+ * 师傅账户流水记录模型
+ * Class MasterWorker
+ * @package app\common\model
+ */
+class MasterWorkerAccountLog extends BaseModel
+{
+    protected $name = 'master_worker_account_log';
+    use SoftDelete;
+
+    protected $deleteTime = 'delete_time';
+}