rabin 2 роки тому
батько
коміт
67c1b19924
2 змінених файлів з 63 додано та 59 видалено
  1. 62 58
      lib/Profit.php
  2. 1 1
      src/Profit.php

+ 62 - 58
lib/Profit.php

@@ -39,6 +39,9 @@ class Profit
     public function getInfo($id)
     {
         $data = Dever::db('account/profit_log')->find($id);
+        if (!$data) {
+            return false;
+        }
         $data = $this->info($data);
         return $data;
     }
@@ -93,65 +96,11 @@ class Profit
         $info = $this->get($uid, $profit['id'], $config['id'], $config['project_id']);
 
         # 开始处理入账
-        $this->handle($profit, $uid, $cash, $info['id'], $project['source'], $source, $source_id, $name, $status, $desc);
+        $this->handle($profit, $uid, $cash, $info['id'], $project['source'], $status, $source, $source_id, $name, $desc);
         
         return true;
     }
 
-    # 入账
-    private function add($uid, $cash, $profit_id, $status, $source, $source_id, $name = '', $desc = '')
-    {
-        $data['clear'] = true;
-        $data['profit_id'] = $profit_id;
-        $data['source'] = $source;
-        $data['source_id'] = $source_id;
-        
-        $log = Dever::db('account/profit_log')->one($data);
-        $data['uid'] = $uid;
-
-        if ($name) {
-            $data['name'] = $name;
-        }
-        if ($desc) {
-            $data['desc'] = $desc;
-        }
-        $data['status'] = $status;
-        if ($log) {
-            # 结算
-            if ($cash > 0 && $log['cash'] != $cash) {
-                $status = 3;
-                if ($cash > $log['cash']) {
-                    $cash = $log['cash'];
-                }
-            }
-            if ($status == 2) {
-                $data['ycash'] = $cash;
-            } elseif ($status == 3) {
-                $data['ycash'] = $log['ycash'] + $cash;
-            } elseif ($status == 4) {
-                $data['ycash'] = 0;
-            }
-            $data['where_id'] = $log['id'];
-            Dever::db('account/profit_log')->update($data);
-
-            $update['where_id'] = $profit_id;
-            $update['set_ycash'] = $data['ycash'];
-            Dever::db('account/profit')->incYcash($update);
-        } else {
-            # 入账
-            $data['cash'] = $cash;
-            if ($status == 2) {
-                $data['ycash'] = $cash;
-            }
-            $data['order_num'] = $this->createOrderNum();
-            $id = Dever::db('account/profit_log')->insert($data);
-
-            $update['where_id'] = $profit_id;
-            $update['set_cash'] = $data['cash'];
-            Dever::db('account/profit')->incCash($update);
-        }
-    }
-
     # 生成订单号
     private function createOrderNum()
     {
@@ -165,19 +114,19 @@ class Profit
     }
 
     # 计算金额
-    private function handle($profit, $uid, $cash, $profit_id, $project_source, $source, $source_id, $name, $status, $desc)
+    private function handle($profit, $uid, $cash, $profit_id, $project_source, $status, $source, $source_id, $name, $desc)
     {
         $rule = Dever::db('account/config_profit_rule')->select(array('profit_id' => $profit['id']));
         if ($rule) {
             $child = array();
             foreach ($rule as $k => $v) {
-                $child[$v['level']] = $this->rule($v, $child, $uid, $cash, $profit_id, $project_source, $source, $source_id, $name, $status, $desc);
+                $child[$v['level']] = $this->rule($v, $child, $uid, $cash, $profit_id, $project_source, $status, $source, $source_id, $name, $desc);
             }
         }
         return $cash;
     }
 
-    private function rule($rule, $child, $uid, $cash, $profit_id, $project_source, $source, $source_id, $name, $status, $desc)
+    private function rule($rule, $child, $uid, $cash, $profit_id, $project_source, $status, $source, $source_id, $name, $desc)
     {
         if ($rule['level'] > 0) {
             $parent = Dever::load('invite/api')->getParent($uid, $rule['level']);
@@ -239,4 +188,59 @@ class Profit
         eval($eval);
         return $value;
     }
+
+    # 入账
+    private function add($uid, $cash, $profit_id, $status, $source, $source_id, $name = '', $desc = '')
+    {
+        $data['clear'] = true;
+        $data['profit_id'] = $profit_id;
+        $data['source'] = $source;
+        $data['source_id'] = $source_id;
+        
+        $log = Dever::db('account/profit_log')->one($data);
+        $data['uid'] = $uid;
+
+        if ($name) {
+            $data['name'] = $name;
+        }
+        if ($desc) {
+            $data['desc'] = $desc;
+        }
+        $data['status'] = $status;
+        if ($log) {
+            # 结算
+            if ($cash > 0 && $log['cash'] != $cash) {
+                $status = 3;
+                if ($cash > $log['cash']) {
+                    $cash = $log['cash'];
+                }
+            }
+            echo $status;die;
+            if ($status == 2) {
+                $data['ycash'] = $cash;
+            } elseif ($status == 3) {
+                $data['ycash'] = $log['ycash'] + $cash;
+            } elseif ($status == 4) {
+                $data['ycash'] = 0;
+            }
+            $data['where_id'] = $log['id'];
+            Dever::db('account/profit_log')->update($data);
+
+            $update['where_id'] = $profit_id;
+            $update['set_ycash'] = $data['ycash'];
+            Dever::db('account/profit')->incYcash($update);
+        } else {
+            # 入账
+            $data['cash'] = $cash;
+            if ($status == 2) {
+                $data['ycash'] = $cash;
+            }
+            $data['order_num'] = $this->createOrderNum();
+            $id = Dever::db('account/profit_log')->insert($data);
+
+            $update['where_id'] = $profit_id;
+            $update['set_cash'] = $data['cash'];
+            Dever::db('account/profit')->incCash($update);
+        }
+    }
 }

+ 1 - 1
src/Profit.php

@@ -50,7 +50,7 @@ class Profit extends Core
     	//Dever::load('account/lib/profit.up_commit', $this->uid, 100, 'zhitui', 'type', 1, 'xxx订单记录', 1, 'test');
 
     	# 结算5块钱
-    	Dever::load('account/lib/profit.up_commit', $this->uid, 100, 'zhitui', 'type', 2, 'xxx订单记录', 2, 'test');
+    	Dever::load('account/lib/profit.up_commit', $this->uid, 100, 'zhitui', 1, 'type', 5, 'xxx订单记录', 'test');
 
     	return 'ok';
     }