rabin 2 rokov pred
rodič
commit
3222e4a75e
4 zmenil súbory, kde vykonal 35 pridanie a 20 odobranie
  1. 1 1
      database/profit.php
  2. 8 2
      lib/Info.php
  3. 25 16
      lib/Profit.php
  4. 1 1
      src/Profit.php

+ 1 - 1
database/profit.php

@@ -70,7 +70,7 @@ return array
             'match'     => 'option',
             'update'    => 'text',
             'list_name' => '未结算',
-            'list'      => '{cash}-{y_cash}',
+            'list'      => '{cash}-{ycash}',
         ),
 
         'ycash'        => array

+ 8 - 2
lib/Info.php

@@ -55,7 +55,10 @@ class Info
             return $this->alert('金额不能为0', $state);
         }
         
-        $config = Dever::db('account/config')->find(array('key' => $config));
+        if (!is_array($config)) {
+            $config = Dever::db('account/config')->find(array('key' => $config));
+        }
+        
         if (!$config) {
             return $this->alert('账户信息不存在', $state);
         }
@@ -66,7 +69,10 @@ class Info
             return $this->alert('用户信息不存在', $state);
         }
 
-        $type = Dever::db('account/config_type')->find(array('key' => $type));
+        if (!is_array($type)) {
+            $type = Dever::db('account/config_type')->find(array('key' => $type));
+        }
+        
         if (!$type) {
             return $this->alert('交易类型不存在', $state);
         }

+ 25 - 16
lib/Profit.php

@@ -96,7 +96,7 @@ class Profit
         $info = $this->get($uid, $profit['id'], $config['id'], $config['project_id']);
 
         # 开始处理入账
-        $this->handle($profit, $uid, $cash, $info['id'], $project['source'], $status, $source, $source_id, $name, $desc);
+        $this->handle($profit, $config, $uid, $cash, $info['id'], $project['source'], $status, $source, $source_id, $name, $desc);
         
         return true;
     }
@@ -114,19 +114,19 @@ class Profit
     }
 
     # 计算金额
-    private function handle($profit, $uid, $cash, $profit_id, $project_source, $status, $source, $source_id, $name, $desc)
+    private function handle($profit, $config, $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, $status, $source, $source_id, $name, $desc);
+                $child[$v['level']] = $this->rule($v, $child, $config, $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, $status, $source, $source_id, $name, $desc)
+    private function rule($rule, $child, $config, $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']);
@@ -173,7 +173,7 @@ class Profit
             $cash = $this->run($exp, $replace);
         }
         if ($cash > 0) {
-            $this->add($uid, $cash, $profit_id, $status, $source, $source_id, $name, $desc);
+            $this->add($config, $uid, $cash, $profit_id, $status, $source, $source_id, $name, $desc);
             return $cash;
         }
         return false;
@@ -190,7 +190,7 @@ class Profit
     }
 
     # 入账
-    private function add($uid, $cash, $profit_id, $status, $source, $source_id, $name = '', $desc = '')
+    private function add($config, $uid, $cash, $profit_id, $status, $source, $source_id, $name = '', $desc = '')
     {
         $data['clear'] = true;
         $data['profit_id'] = $profit_id;
@@ -215,20 +215,17 @@ class Profit
                     $cash = $log['cash'];
                 }
             }
-            echo $status;die;
-            if ($status == 2) {
+            if ($status == 1) {
+                $data['cash'] = $cash;
+            } elseif ($status == 2) {
                 $data['ycash'] = $cash;
             } elseif ($status == 3) {
                 $data['ycash'] = $log['ycash'] + $cash;
             } elseif ($status == 4) {
                 $data['ycash'] = 0;
             }
-            $data['where_id'] = $log['id'];
+            $id = $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;
@@ -237,10 +234,22 @@ class Profit
             }
             $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);
+        if ($id && $id > 0) {
+            if (isset($data['cash']) && $data['cash']) {
+                $update['where_id'] = $profit_id;
+                $update['set_cash'] = $data['cash'];
+                Dever::db('account/profit')->incCash($update);   
+            }
+            if (isset($data['ycash']) && $data['ycash']) {
+                $update['where_id'] = $profit_id;
+                $update['set_ycash'] = $data['ycash'];
+                Dever::db('account/profit')->incYcash($update);
+
+                # 同步钱包
+                Dever::load('account/lib/info.up_commit', $uid, $data['ycash'], 'shouyi', $config, $name, $source, $source_id, 1);
+            }
         }
     }
 }

+ 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', 1, 'type', 5, 'xxx订单记录', 'test');
+    	Dever::load('account/lib/profit.up_commit', $this->uid, 100, 'zhitui', 2, 'type', 5, 'xxx订单记录', 'test');
 
     	return 'ok';
     }