rabin 2 years ago
parent
commit
beecaa49b4

+ 39 - 28
app/cash/lib/Order.php

@@ -7,7 +7,7 @@ use Dever;
 class Order
 {
 	# 更新结算单
-    public function up($order, $jstype = 1, $audit = 1, $refund = false)
+    public function up($order, $jstype = 1, $audit = 1, $refund = false, $pay_type = 1)
     {
         Dever::config('base')->hook = true;
         if (!$order) {
@@ -35,40 +35,46 @@ class Order
         $info = Dever::db('cash/order')->find($where);
 
         $update = $where;
-        $update['type'] = $order['type'];
-        $update['type_id'] = $order['type_id'];
-        if ($order['source_type']) {
-            $update['source_type'] = $order['source_type'];
-            $update['source_id'] = $order['source_id'];
-        }
-        
+        $update['pay_type'] = $pay_type;
         $update['status'] = $status;
         $update['audit'] = $audit;
         $update['audit_type'] = $audit_type;
 
-        if ($update['status'] == 2) {
-        	$update['operdate'] = time();
-            $update['fdate'] = $update['operdate'];
-            if (isset($order['fdate']) && $order['fdate'] && ($order['status'] == 5 || $order['status'] == 6)) {
-                $update['fdate'] = $order['fdate'];
+        if ($info && $jstype == 3) {
+
+        } else {
+            
+            $update['type'] = $order['type'];
+            $update['type_id'] = $order['type_id'];
+            if ($order['source_type']) {
+                $update['source_type'] = $order['source_type'];
+                $update['source_id'] = $order['source_id'];
             }
-        }
 
-        $update['source_order_num'] = $order['order_num'];
-        $update['num'] = $order['num'];
+            if ($update['status'] == 2) {
+                $update['operdate'] = time();
+                $update['fdate'] = $update['operdate'];
+                if (isset($order['fdate']) && $order['fdate'] && ($order['status'] == 5 || $order['status'] == 6)) {
+                    $update['fdate'] = $order['fdate'];
+                }
+            }
 
-        if ($refund) {
-            $update['cash'] = $refund['cash'];
-            $update['p_cash'] = isset($refund['p_cash']) ? $refund['p_cash'] : 0;
-        } else {
-            $update['cash'] = $order['price'];
-            $update['p_cash'] = $order['p_price'];
-        }
+            $update['source_order_num'] = $order['order_num'];
+            $update['num'] = $order['num'];
 
-        if ($jstype == 2) {
-            $update['cash'] = -1*$update['cash'];
-            $update['p_cash'] = -1*$update['p_cash'];
-            $update['num'] = -1*$update['num'];
+            if ($refund) {
+                $update['cash'] = $refund['cash'];
+                $update['p_cash'] = isset($refund['p_cash']) ? $refund['p_cash'] : 0;
+            } else {
+                $update['cash'] = $order['price'];
+                $update['p_cash'] = $order['p_price'];
+            }
+
+            if ($jstype == 2) {
+                $update['cash'] = -1*$update['cash'];
+                $update['p_cash'] = -1*$update['p_cash'];
+                $update['num'] = -1*$update['num'];
+            }
         }
 
         if ($info) {
@@ -83,7 +89,12 @@ class Order
             # 如果是退款结算,同时要把主订单也结算
             $where = array();
             $where['source_order_id'] = $order['id'];
-            $where['jstype'] = 1;
+            if ($pay_type > 1) {
+                $where['jstype'] = 3;
+            } else {
+                $where['jstype'] = 1;
+            }
+            
             $where['audit'] = 1;
             $where['clear'] = true;
             $info = Dever::db('cash/order')->find($where);

+ 3 - 0
app/shop/lib/Refund.php

@@ -437,6 +437,9 @@ class Refund
                     Dever::db($this->order_table)->update(array('where_id' => $order['id'], 'card_code_cash' => $card_code_cash, 'clear' => true));
                 }
                 Dever::db('card/code')->decUseCash(array('where_id' => $order['card_code_id'], 'set_use_cash' => $order['card_code_cash']));
+
+                Dever::load('cash/lib/order')->up($order, 3, 2, $info, 2);
+
             } elseif (isset($order['wallet_cash']) && $order['wallet_cash'] && $order['wallet_cash'] > 0) {
                 # 还原钱包
                 

+ 6 - 1
app/shop/lib/Sell.php

@@ -381,6 +381,9 @@ class Sell
                 if (isset($data['card_code_id']) && $data['card_code_id'] && $data['card_code_cash'] > 0) {
                     # 还原礼品卡
                     Dever::db('card/code')->decUseCash(array('where_id' => $data['card_code_id'], 'set_use_cash' => $data['card_code_cash']));
+
+                    Dever::load('cash/lib/order')->up($data, 3, 2, false, 2);
+
                 } elseif (isset($data['wallet_cash']) && $data['wallet_cash'] && $data['wallet_cash'] > 0) {
                     # 还原钱包
                     
@@ -1093,7 +1096,7 @@ class Sell
                     $order_data['source_id'] = -1;
                     $order_data['price'] = $price;
                     $order_data['p_price'] = $card['cash'];
-                    Dever::load('cash/lib/order')->up($order_data, 3, 1);
+                    Dever::load('cash/lib/order')->up($order_data, 3, 1, false, 2);
                 }
             }
             
@@ -1328,6 +1331,8 @@ class Sell
                 $card_update['where_id'] = $info['card_code_id'];
                 $card_update['status'] = 4;
                 Dever::db('goods/card_code')->update($card_update);
+
+                Dever::load('cash/lib/order')->up($info, 3, 2, false, 2);
             }
 
             if ($info['shop_type'] == 2) {

+ 13 - 0
service/agent/database/member.php

@@ -885,5 +885,18 @@ return array
             'type' => 'all',
             'col' => '*',
         ),
+
+        'getDataByRole' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'role' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'order' => array('id' => 'desc'),
+            'type' => 'all',
+            'col' => '*',
+        ),
     ),
 );

+ 37 - 53
service/agent/lib/Import.php

@@ -77,74 +77,58 @@ class Import
 
     public function get_area_api()
     {
-        $this->date = Dever::maketime('2021-09-01 00:00:00');
         Dever::config('base')->hook = true;
-        $host = 'https://cryl.yijiuguanfang.com/attachment/';
-        
-        $state = 1;
-        while($state) {
-            $state = $this->get_area_act($host, $state);
-        }
-        return 'ok';
-    }
-
-    public function get_area_act($host, $index = 0)
-    {
-        # 获取已审核通过、权益已发放的用户
-        $index = $index - 1;
-        $limit = 1000;
-        
-        $data = $this->db->fetchAll('select * from ims_ewei_shop_member where status = 1 and  prestatus = 1 and isagent = 1 order by id asc limit ' . $index . ', ' . $limit);
+        $data = Dever::db('agent/member')->getDataByRole(array('role' => '2,3,4'));
 
         if (!$data) {
             return false;
         }
 
         foreach ($data as $k => $v) {
-            $data['address'] = $v['province'] . $v['city'] . $v['area'] . $v['street'];
-            if ($v['datavalue']) {
-                $v['datavalue'] = trim(str_replace(" ", ',', $v['datavalue']));
-                $temp = explode(',', $v['datavalue']);
-                if (isset($temp[0]) && $temp[0]) {
-                    $a['id'] = $temp[0];
-                    $a['clear'] = true;
-                    $info = Dever::db('area/province')->one($a);
-                    if (!$info) {
-                        $this->log($v['id'], 9, $data['address'], '省份编码错误:' . $temp[0]);
-                        continue;
-                    }
+            $area = explode(',', $v['area']);
+
+            $num = count($area);
+
+            $area_name = Dever::load("area/api.string", $v['area']);
+            if ($v['role'] == 2 && $num != 2) {
+                $this->log($v['id'], 9, $area_name, '城市错误');
+            }
+            if ($v['role'] == 3 && $num != 3) {
+                $this->log($v['id'], 9, $area_name, '区县错误');
+            }
+            if ($v['role'] == 4 && $num != 4) {
+                $this->log($v['id'], 9, $area_name, '街道错误');
+            }
+            if ($v['area']) {
+                $check = Dever::db('agent/member')->find(array('area' => $v['area'], 'role' => $v['role']));
+                if (!$check) {
+                    $this->log($v['id'], 9, $area_name, '区域匹配错误');
                 }
-                if (isset($temp[1]) && $temp[1]) {
-                    $a['id'] = $temp[1];
-                    $a['clear'] = true;
-                    $info = Dever::db('area/city')->one($a);
-                    if (!$info) {
-                        $this->log($v['id'], 9, $data['address'], '城市编码错误:' . $temp[1]);
+                if ($v['role'] == 2 && isset($area[1]) && $area[1]) {
+                    $city = Dever::db('area/city')->find($area[1]);
+                    if ($city['status'] == 1) {
+                        //$this->log($v['id'], 9, $area_name, '城市占用错误');
+                        Dever::load('area/api')->upStatus($v['area'], 2);
                     }
                 }
-
-                if (isset($temp[2]) && $temp[2]) {
-                    $a['id'] = $temp[2];
-                    $a['clear'] = true;
-                    $info = Dever::db('area/county')->one($a);
-                    if (!$info) {
-                        $this->log($v['id'], 9, $data['address'], '区县编码错误:' . $temp[2]);
+                if ($v['role'] == 3 && isset($area[2]) && $area[2]) {
+                    $city = Dever::db('area/county')->find($area[2]);
+                    if ($city['status'] == 1) {
+                        //$this->log($v['id'], 9, $area_name, '区县占用错误');
+                        Dever::load('area/api')->upStatus($v['area'], 2);
                     }
                 }
-
-                if (isset($v['streetvalue']) && $v['streetvalue']) {
-                    $a['id'] = $v['streetvalue'];
-                    $a['clear'] = true;
-                    $info = Dever::db('area/town')->one($a);
-                    if (!$info) {
-                        $this->log($v['id'], 9, $data['address'], '街道编码错误:' . $v['streetvalue']);
+                if ($v['role'] == 4 && isset($area[3]) && $area[3]) {
+                    $city = Dever::db('area/town')->find($area[3]);
+                    if ($city['status'] == 1) {
+                        //$this->log($v['id'], 9, $area_name, '街道占用错误');
+                        Dever::load('area/api')->upStatus($v['area'], 2);
                     }
                 }
-                
-            } else {
-                $this->log($v['id'], 9, $data['address'], '无区域编码');
             }
+            
         }
+        return 'ok';
     }
 
     public function get_data($host, $index = 0)
@@ -711,7 +695,7 @@ class Import
     }
 
     # 导入日志记录
-    public function log($mid, $type, $before, $after, $update = false)
+    public function log($mid, $type, $before, $after, $update = true)
     {
         # 地区、直推代理人数、团队业绩
         $data['mid'] = $mid;

+ 1 - 1
service/agent/lib/Order.php

@@ -469,7 +469,7 @@ class Order
 
         $result = implode(',', $result);
         $result = str_replace(',-1', '', $result);
-        $area_info = Dever::db('agent/member_area')->getOne(array('area' => $result));
+        $area_info = Dever::db('agent/member_area')->getOne(array('area' => $result, 'role' => $role['id']));
         if ($area_info) {
             if ($mid) {
                 if ($mid != $area_info['mid']) {