Przeglądaj źródła

增加质保金明细流水及统计

林海涛 1 rok temu
rodzic
commit
fa027c21b7

+ 24 - 0
app/common/model/master_worker/MasterWorker.php

@@ -7,7 +7,9 @@
 namespace app\common\model\master_worker;
 
 use app\common\model\BaseModel;
+use app\common\model\dict\DictData;
 use app\common\model\MasterWorkerRegister;
+use think\facade\Cache;
 
 /**
  * 师傅表
@@ -35,4 +37,26 @@ class MasterWorker extends BaseModel
         return $this->hasOne(MasterWorkerRegister::class, 'worker_id', 'id');
     }
 
+    public function getRetentionMoneyStatusTextAttr($value,$data):string{
+        $default = Cache::get('RETENTION_MONEY_STATUS');
+        if (!$default) {
+            $status = DictData::whereIn('type_value', 'retention_money_status')->column('name','value');
+            Cache::set('RETENTION_MONEY_STATUS', json_encode($status,true),5);
+        } else {
+            $status = json_decode($default);
+        }
+        return $status[$data['retention_money_status']] ?? '';
+    }
+
+    public function getRetentionPayStatusTextAttr($value,$data):string{
+        $default = Cache::get('RETENTION_PAY_STATUS');
+        if (!$default) {
+            $status = DictData::whereIn('type_value', 'retention_pay_status')->column('name','value');
+            Cache::set('RETENTION_PAY_STATUS', json_encode($status,true),5);
+        } else {
+            $status = json_decode($default);
+        }
+        return $status[$data['retention_pay_status']] ?? '';
+    }
+
 }

+ 18 - 0
app/common/model/master_worker/MasterWorkerRetentionMoneyLog.php

@@ -0,0 +1,18 @@
+<?php
+/**
+ * @author 林海涛
+ * @date 2024/7/28 上午10:36
+ */
+namespace app\common\model\master_worker;
+
+use app\common\model\BaseModel;
+
+class MasterWorkerRetentionMoneyLog extends BaseModel
+{
+    protected $name = 'master_worker_retention_money_log';
+    public function getActionTextAttr($value,$data)
+    {
+        $status = [1=>'+',2=>'-'];
+        return $status[$data['action']];
+    }
+}

+ 23 - 0
app/workerapi/controller/RetentionMoneyController.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace app\workerapi\controller;
+
+use app\workerapi\lists\MasterWorkerRetentionMoneyLogLists;
+use app\workerapi\logic\RetentionMoneyLogic;
+
+class RetentionMoneyController extends BaseApiController
+{
+    public function totalAmount()
+    {
+        $result = RetentionMoneyLogic::totalAmount(['worker_id' => $this->userId]);
+        if (false === $result) {
+            return $this->fail(RetentionMoneyLogic::getError());
+        }
+        return $this->success('操作成功',$result, 1, 0);
+    }
+
+    public function lists()
+    {
+        return $this->dataLists(new MasterWorkerRetentionMoneyLogLists());
+    }
+}

+ 34 - 0
app/workerapi/lists/MasterWorkerRetentionMoneyLogLists.php

@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author 林海涛
+ * @date 2024/7/28 上午11:30
+ */
+namespace app\workerapi\lists;
+use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
+
+class MasterWorkerRetentionMoneyLogLists extends BaseWorkerDataLists
+{
+
+    public function queryWhere()
+    {
+        $where = [];
+        $where[] = ['worker_id', '=', $this->userId];
+        return $where;
+    }
+
+    public function lists(): array
+    {
+        return MasterWorkerRetentionMoneyLog::where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->append(['action_text'])
+            ->field(['id', 'action','amount','remark','create_time','update_time'])
+            ->order(['id' => 'dsc'])
+            ->select()
+            ->toArray();
+    }
+
+    public function count(): int
+    {
+        return MasterWorkerRetentionMoneyLog::where($this->queryWhere())->count();
+    }
+}

+ 43 - 0
app/workerapi/logic/RetentionMoneyLogic.php

@@ -0,0 +1,43 @@
+<?php
+namespace app\workerapi\logic;
+use app\common\enum\worker\WorkerAccountLogEnum;
+use app\common\logic\BaseLogic;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
+
+/**
+ * @author 林海涛
+ * @date 2024/7/28 上午10:32
+ */
+class RetentionMoneyLogic extends BaseLogic
+{
+    public static function totalAmount($params)
+    {
+        try{
+            $model = MasterWorker::findOrEmpty($params['worker_id']);
+            if($model->isEmpty()){
+                throw new \Exception('用户不存在');
+            }
+            $where = [];
+            $where[] = ['worker_id','=',$params['worker_id']] ;
+            $incWhere =$where;
+            $incWhere[] = ['action', '=',WorkerAccountLogEnum::INC];
+            $data['amount_inc_total'] = MasterWorkerRetentionMoneyLog::where($incWhere)
+                ->sum('amount');
+            $outWhere = $where;
+            $outWhere[] =['action', '=',WorkerAccountLogEnum::DEC];
+            $data['amount_dec_total'] = MasterWorkerRetentionMoneyLog::where($outWhere)
+                ->sum('amount');
+            $data['amount_available_total'] = $data['amount_inc_total'] - $data['amount_dec_total'];
+            $data['retention_money_status'] = $model->retention_money_status;
+            $data['retention_money_status_text'] = $model->retention_money_status_text;
+            $data['retention_pay_status'] = $model->retention_pay_status;
+            $data['retention_pay_status_text'] = $model->retention_pay_status_text;
+            return $data;
+        } catch(\Exception $e){
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+}