소스 검색

Merge branch 'master' of ssh://git.dever.cc:10022/dever-product/churen

rabin 3 년 전
부모
커밋
b28aa5f393
6개의 변경된 파일273개의 추가작업 그리고 122개의 파일을 삭제
  1. 14 0
      learn/active/database/code.php
  2. 31 1
      learn/active/database/info_refund.php
  3. 33 3
      learn/active/database/order.php
  4. 151 106
      learn/active/lib/Manage.php
  5. 18 7
      learn/active/src/Off.php
  6. 26 5
      learn/active/src/User.php

+ 14 - 0
learn/active/database/code.php

@@ -3,6 +3,7 @@ $status = array
 (
 (
     1 => '待核销',
     1 => '待核销',
     2 => '已核销',
     2 => '已核销',
+    3 => '已作废',
 );
 );
 $act_status = array
 $act_status = array
 (
 (
@@ -228,5 +229,18 @@ return array
             'order' => array('cdate' => 'desc'),
             'order' => array('cdate' => 'desc'),
             'col' => '*',
             'col' => '*',
         ),
         ),
+        'getCode' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'order_id' => 'yes',
+                'status' => array('yes','in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('cdate' => 'desc'),
+            'col' => '*',
+        ),
     ),
     ),
 );
 );

+ 31 - 1
learn/active/database/info_refund.php

@@ -1,5 +1,9 @@
 <?php
 <?php
-
+$status = array
+(
+    1 => '退款失败',
+    2 => '退款成功',
+);
 return array
 return array
 (
 (
     # 表名
     # 表名
@@ -58,6 +62,19 @@ return array
             // 'list'      => true,
             // 'list'      => true,
         ),
         ),
 
 
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '退款状态',
+            'default'   => '1',
+            'desc'      => '退款状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'search'    => 'select',
+            // 'list'      => true,
+        ),
+
+
         'audit_admin'     => array
         'audit_admin'     => array
         (
         (
             'type'      => 'int-11',
             'type'      => 'int-11',
@@ -112,5 +129,18 @@ return array
             'order' => array('cdate' => 'desc'),
             'order' => array('cdate' => 'desc'),
             'col' => '*',
             'col' => '*',
         ),
         ),
+        'getNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'order_id' => 'yes',
+                'state' => 1,
+                'status' => 2,
+            ),
+            'type' => 'one',
+            'order' => array('cdate' => 'desc'),
+            'col' => 'sum(num) as num',
+        ),
     ),
     ),
 );
 );

+ 33 - 3
learn/active/database/order.php

@@ -2,9 +2,9 @@
 $excel = false;
 $excel = false;
 $excel[] = array('数据导出','数据导出','active/lib/excel.out_active_order');
 $excel[] = array('数据导出','数据导出','active/lib/excel.out_active_order');
 $list_button = array();
 $list_button = array();
-if (Dever::load('manage/auth')->checkFunc('active.order', 'editRefund', '退款')) {
-    $list_button['fast'] = array('退款', '"info_refund&project=active&search_option_order_id={id}"');
-    // $list_button['oper'] = array('退款', '"active/lib/manage.refund?id={id}"', '{status} == 2');
+if (Dever::load('manage/auth')->checkFunc('active.order', 'editRefund', '全额退款')) {
+    // $list_button['fast'] = array('退款', '"info_refund&project=active&search_option_order_id={id}"');
+    $list_button['oper'] = array('全额退款', '"active/lib/manage.refund?id={id}"', '{status} == 2');
 }
 }
 $list_button['list'] = array('查看详情','"info_code&project=active&id={id}&page_type=1&[refer]"');
 $list_button['list'] = array('查看详情','"info_code&project=active&id={id}&page_type=1&[refer]"');
 $pay_type = array
 $pay_type = array
@@ -168,6 +168,36 @@ return array
             // 'update'    => 'textarea',
             // 'update'    => 'textarea',
         ),
         ),
 
 
+        'code_num'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '已使用数量',
+            'default'   => '0',
+            'desc'      => '已使用数量',
+            'match'     => 'option',
+            // 'list'      => true,
+        ),
+
+        'no_num'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '未核销数量',
+            'default'   => '0',
+            'desc'      => '未核销数量',
+            'match'     => 'option',
+            // 'list'      => true,
+        ),
+
+        'refund_num'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '退款数量',
+            'default'   => '0',
+            'desc'      => '退款数量',
+            'match'     => 'option',
+            // 'list'      => true,
+        ),
+
         'remark'      => array
         'remark'      => array
 	    (
 	    (
 	        'type'      => 'varchar-300',
 	        'type'      => 'varchar-300',

+ 151 - 106
learn/active/lib/Manage.php

@@ -17,55 +17,10 @@ Class Manage
         } else {
         } else {
             $uid = $data['uid'];
             $uid = $data['uid'];
         }
         }
-        $active = Dever::db('active/info')->find($data['active_id']);
-        if (time() > $active['act_start']) {
-            Dever::alert('活动已开始,不能退款');
-        }
-        $code = Dever::db('active/code')->state(array('order_id'=>$data['id'],'buy_uid'=>$uid));
-        $icode = Dever::db('active/code')->state(array('order_id'=>$data['id'],'buy_uid'=>$uid,'status'=>1));
-        $count = count($code);
-        $num = $data['num'] - $count;
-        if ($count == 0 ) {
-            $price = $data['price'];
-        } elseif ( $count > 0 && $num > 0) {
-            $inum = count($icode);
-            $price = ($num + $inum) * $active['price'];
-        }
-		$param = array
-        (
-            'project_id' => 6,
-            'channel_id' => 1,
-            'system_source' => 1,
-            'account_id' => 8,
-            'order_id' => $data['order_num'],
-            'refund_cash' => $price,
-            //'refund_order_id' => '',
-        );
-        if ($data['status'] != 2) {
-        	Dever::alert('此状态下不可退款');
-        }
-
-
-        if ($data['price'] > 0) {
-            $result = Dever::load('pay/api.refund', $param);
-
-            if (!$result) {
-                # 退款失败,抛出错误
-                //throw new \Exception('退款失败');
-                Dever::alert('退款失败,请联系管理员');
-            } else { 
-                $admin = Dever::load('manage/auth.data');
-                $time = time();
-                if ($price == $data['price']) {
-                    Dever::db('active/order')->update(array('where_id'=>$id,'set_status'=>6,'set_refund_admin'=>$admin['id'],'set_rdate'=>$time));
-                } else {
-                    Dever::db('active/order')->update(array('where_id'=>$id,'set_status'=>5,'set_refund_admin'=>$admin['id'],'set_rdate'=>$time));
-                }
-            	
-            }
-        }
+        $this->common($data,1);
   		return 'reload';
   		return 'reload';
 	}
 	}
+
     public function insertInfoRefund ($id,$name,$data)
     public function insertInfoRefund ($id,$name,$data)
     {
     {
         $num = Dever::param('num',$data);
         $num = Dever::param('num',$data);
@@ -85,52 +40,14 @@ Class Manage
     {
     {
         $num = Dever::param('num',$data);
         $num = Dever::param('num',$data);
         $order_id = Dever::param('order_id',$data);
         $order_id = Dever::param('order_id',$data);
+        $code_id = Dever::param('code_id',$data);
         $data = Dever::db('active/order')->find($order_id);
         $data = Dever::db('active/order')->find($order_id);
-        $info = Dever::db('active/info_refund')->state(array('order_id'=>$order_id));
-        $active = Dever::db('active/info')->find($data['active_id']);
-        // if (time() >= $active['act_start']) {
-        //     Dever::alert('活动已开始,不能退款');
-        // }
-        // if ($num > $data['num']) {
-        //     Dever::alert('退款数量大于购买数量');
-        // }
-
-        $price = $num * $active['price'];
-        $refund_num = $data['order_num'] . '_' . count($info);
-        $param = array
-        (
-            'project_id' => 6,
-            'channel_id' => 1,
-            'system_source' => 1,
-            'account_id' => 8,
-            'order_id' => $data['order_num'],
-            'refund_cash' => $price,
-            'refund_order_id' => $refund_num,
-        );
-        if ($data['status'] != 2) {
-            Dever::alert('此状态下不可退款');
-        }
-        if ($price > 0) {
-            $result = Dever::load('pay/api.refund', $param);
-
-            if (!$result) {
-                # 退款失败,抛出错误
-                //throw new \Exception('退款失败');
-                Dever::alert('退款失败,请联系管理员');
-            } else { 
-
-                $admin = Dever::load('manage/auth.data');
-                $time = time();
-                if ($price == $data['price']) {
-                    Dever::db('active/order')->update(array('where_id'=>$id,'set_status'=>6,'set_refund_admin'=>$admin['id'],'set_rdate'=>$time));
-                } else {
-                    Dever::db('active/order')->update(array('where_id'=>$id,'set_status'=>5,'set_refund_admin'=>$admin['id'],'set_rdate'=>$time));
-                }
-            }
-        }
+        // $info = Dever::db('active/info_refund')->state(array('order_id'=>$order_id));
+        // $active = Dever::db('active/info')->find($data['active_id']);
+       $this->common($data,2,$num,$id);
         return 'reload';
         return 'reload';
     }
     }
-
+    
     public function show($id)
     public function show($id)
     {
     {
         $data = Dever::db('active/order')->find($id);
         $data = Dever::db('active/order')->find($id);
@@ -250,6 +167,7 @@ Class Manage
         return 'ok';
         return 'ok';
     }
     }
 
 
+
     public function list()
     public function list()
     {
     {
         $id = Dever::input('id');
         $id = Dever::input('id');
@@ -261,6 +179,17 @@ Class Manage
             $user = Dever::db('active/user')->find($info['mid']);
             $user = Dever::db('active/user')->find($info['mid']);
             $info['uid'] = $user['id'];
             $info['uid'] = $user['id'];
         }
         }
+
+        $code = Dever::db('active/code')->getCode(array('order_id' => $id,'status'=>'1,2'));
+        $use_code = count($code);#已领取的所有数量
+        
+        if (!$info['refund_num']) {
+            $info['refund_num'] = 0;
+        }
+        $no_code = $info['num'] - $use_code - $info['refund_num'];#未使用的数量
+        if ($info['mid'] && $info['mid'] > 0) {
+            $user = Dever::db('active/user')->find($info['mid']);
+            $member = Dever::db('agent/member')->find($info['mid']);
         $code = Dever::db('active/code')->state(array('order_id' => $id));
         $code = Dever::db('active/code')->state(array('order_id' => $id));
         $use_code = count($code);
         $use_code = count($code);
         $no_code = $info['num'] - $use_code;
         $no_code = $info['num'] - $use_code;
@@ -314,6 +243,7 @@ Class Manage
                 (
                 (
                     array('已使用', $use_code),
                     array('已使用', $use_code),
                     array('未使用', $no_code),
                     array('未使用', $no_code),
+                    array('退款数量', $info['refund_num']),
                 ),
                 ),
             ),
             ),
         );
         );
@@ -330,6 +260,19 @@ Class Manage
                 ),
                 ),
             ),
             ),
         );
         );
+        $button = array();
+        if ($info['status'] > 1 && $no_code > 0) {
+            if (Dever::load('manage/auth')->checkFunc('active.order', 'editrefund', '未使用退款')) {
+                $purl = Dever::url('project/database/update?project=active&table=info_refund&search_option_order_id='.$info['id'].'&col=num,order_id', 'manage');
+                $button[] = array
+                (
+                    'type' => 'edit',
+                    'link' => $purl,
+                    'name' => '未使用退款',
+                );
+            }
+        }
+        
         if ($use_code > 0) {
         if ($use_code > 0) {
            $result +=  $this->table($id);
            $result +=  $this->table($id);
             
             
@@ -337,7 +280,7 @@ Class Manage
         $head = array
         $head = array
         (
         (
             'name' => '基本资料',
             'name' => '基本资料',
-            'btn' => '',
+            'btn' => $button,
         );
         );
         $html = Dever::show($head, $result);
         $html = Dever::show($head, $result);
         return $html;
         return $html;
@@ -347,7 +290,7 @@ Class Manage
     {
     {
         $data = Dever::db('active/code')->state(array('order_id' => $id));
         $data = Dever::db('active/code')->state(array('order_id' => $id));
         if ($data) {
         if ($data) {
-            $head = array('参加人信息', '核销码', '核销状态', '领取时间', '核销时间','核销人');
+            $head = array('参加人信息', '核销码', '核销状态', '领取时间', '核销时间', '核销人', '管理');
             $body = array();
             $body = array();
             foreach ($data as $k => $v) {
             foreach ($data as $k => $v) {
                 $user = Dever::db('active/user')->find($v['join_uid']);
                 $user = Dever::db('active/user')->find($v['join_uid']);
@@ -358,7 +301,7 @@ Class Manage
                 $admin_name = '';
                 $admin_name = '';
                 if ($v['status'] == 1) {
                 if ($v['status'] == 1) {
                     $status = '待核销';
                     $status = '待核销';
-                } else {
+                } elseif($v['status'] == 2) {
                     $status = '已核销';
                     $status = '已核销';
                    if ($v['audit_admin'] && $v['audit_admin'] >0) {
                    if ($v['audit_admin'] && $v['audit_admin'] >0) {
                        $admin = Dever::load('manage/admin-find',$v['audit_admin']);
                        $admin = Dever::load('manage/admin-find',$v['audit_admin']);
@@ -373,6 +316,8 @@ Class Manage
                             }
                             }
                         }
                         }
                    }
                    }
+                } else {
+                    $status = '已作废';
                 }
                 }
                 $cdate = '';
                 $cdate = '';
                 if ($v['cdate']) {
                 if ($v['cdate']) {
@@ -382,6 +327,11 @@ Class Manage
                 if ($v['offdate']) {
                 if ($v['offdate']) {
                     $offdate = date('Y-m-d H:i',$v['offdate']);
                     $offdate = date('Y-m-d H:i',$v['offdate']);
                 }
                 }
+                $m = '';
+                if ($v['status'] == 1) {
+                    $url = Dever::url('lib/manage.setOrder&order_id=' . $v['order_id'].'&code_id='.$v['id'], 'active');
+                    $m = '<a href="javascript:;" onclick="load( \''.$url.'\')" class="layui-btn">退款</a>';
+                }
                 $d = array
                 $d = array
                 (
                 (
                     $join_name,
                     $join_name,
@@ -390,6 +340,7 @@ Class Manage
                     $cdate,
                     $cdate,
                     $offdate,
                     $offdate,
                     $admin_name,
                     $admin_name,
+                    $m,
                 );
                 );
                 $body[] = $d;
                 $body[] = $d;
             }
             }
@@ -405,17 +356,111 @@ Class Manage
            return $result;
            return $result;
         }
         }
     }
     }
-    // #将已经注册活动的用户放到用户表中
-    // public function user_cron()
-    // {
-    //     $data = Dever::db('active/order')->state();
-    //     foreach ($data as $k => $v) {
-    //         $user = Dever::db('active/user')->find(array('mid'=>$v['mid']));
-    //         if (!$user) {
-    //             $member = Dever::db('agent/member')->find($v['mid']);
-    //             $where['mobile'] = $member['mobile'];
-    //             $where['idcard'] = $member['idcard'];
-    //         }
-    //     }
-    // }
+    public function setOrder_api($order_id,$code_id){
+        $data = Dever::db('active/order')->find($order_id);
+        $ids = $this->common($data,3,'',$code_id);
+        if ($ids) {
+            $w['where_id'] = $code_id;
+            $w['status'] = 3;
+            Dever::db('active/code')->update($w);
+        }
+        return 'reload';
+    }
+
+    public function common($data,$type,$num=false,$refund_id=false){
+        $active = Dever::db('active/info')->find($data['active_id']);
+        $info = Dever::db('active/info_refund')->state(array('order_id'=>$data['id']));
+        if (time() > $active['act_start']) {
+            Dever::alert('活动已开始,不能退款');
+        }
+        if ($type == 1) {
+            if ($data['status'] != 2) {
+                Dever::alert('此状态下不可退款');
+            }
+            $refund_num = $data['num'];
+            $price = $data['price'];
+        }
+        if ($type == 2) {
+            $price = $num * $active['price'];
+            $refund_num = $num;
+        }
+        if ($type == 3) {
+            $refund_num = 1;
+            $price = $active['price'];
+        }
+        
+        $param = array
+        (
+            'project_id' => 6,
+            'channel_id' => 1,
+            'system_source' => 1,
+            'account_id' => 8,
+            'order_id' => $data['order_num'],
+            'refund_cash' => $price,
+            //'refund_order_id' => '',
+        );
+        if ($type != 1) {
+            $param['refund_order_id'] = $data['order_num'] . '_' . count($info);
+        }
+        
+        if ($data['price'] > 0) {
+            $result = Dever::load('pay/api.refund', $param);
+
+            if (!$result) {
+                # 退款失败,抛出错误
+                //throw new \Exception('退款失败');
+                Dever::alert('退款失败,请联系管理员');
+            } else { 
+                $admin = Dever::load('manage/auth.data');
+                $time = time();
+                $where['where_id'] = $data['id'];
+                $where['status'] = 6;
+                $where['refund_admin'] = $admin['id'];
+                $where['rdate'] = $time;
+                if (!$data['refund_num']) {
+                    $data['refund_num'] = 0;
+                }
+                $where['refund_num'] = $refund_num + $data['refund_num'];
+
+                if ($type == 1 || ($type == 2 && $price = $data['price'])) {
+                    Dever::db('active/order')->update($where);
+                } elseif (($type == 2 && $price != $data['price']) || $type == 3) {
+                    $where['status'] = 5;
+                    $ids = Dever::db('active/order')->update($where);
+                    return $ids;
+                }
+                if ($type == 2) {
+                    $insert['status'] = 2;
+                    $insert['where_id'] = $refund_id;
+                    $insert['audit_admin'] = $admin['id'];
+                    Dever::db('active/info_refund')->update($insert);
+                }
+            }
+        }
+    }
+
+    #更新数量
+    public function upNum_api($order_id)
+    {
+        $data = Dever::db('active/order')->find($order_id);
+        if (!$data['refund_num']) {
+            $w['refund_num'] = 0;
+        } else {
+            $w['refund_num'] =$data['refund_num'];
+        }
+        if (!$data['code_num']) {
+            $w['code_num'] = 0;
+        }
+        if (!$data['no_num']) {
+            $w['no_num'] = 0;
+        }
+        #已使用的数量
+        $code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>'1,2'));
+        $w['code_num'] = count($code);
+        #待核销的数量
+        $no_code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>1));
+        $w['no_num'] = count($no_code);
+        $w['where_id'] = $data['id'];
+        Dever::db('active_order')->update($w);
+    }
 }
 }

+ 18 - 7
learn/active/src/Off.php

@@ -30,13 +30,24 @@ Class Off extends Coreoff
 		}
 		}
 		$count = strlen($code);
 		$count = strlen($code);
 		$res = array();
 		$res = array();
-		$where['status'] = 1;
-		if ($count > 6) {
-			$where['mobile'] = $code;
-			$data = Dever::db('active/code')->find($where);
-		} else {
-			$where['write_code'] = $code;
-			$data = Dever::db('active/code')->find($where);
+		if ($code) {
+			$data = Dever::db('active/code')->find(array('write_code'=>$code));
+			if (!$data) {
+				if (strlen($code) != 11){
+					Dever::alert('手机号或核销码不正确');
+				} else {
+					$tell = preg_match("^1[3456789]\d{9}$/",$code);
+					if ($tell) {
+						$user = Dever::db('active/user')->find(array('mobile'=>$code));
+						if ($user) {
+							$data = Dever::db('active/code')->find(array('join_id'=>$user['id']));
+						} else {
+							Dever::alert('手机号或核销码不正确');
+						}
+					}
+				}
+				
+			}
 		}
 		}
 		$active = Dever::db('active/info')->find($where['active_id']);
 		$active = Dever::db('active/info')->find($where['active_id']);
 		if ($data) {
 		if ($data) {

+ 26 - 5
learn/active/src/User.php

@@ -15,15 +15,29 @@ Class User extends Core
     	if ($info['status'] == 2) {
     	if ($info['status'] == 2) {
     		$member = Dever::load('active/lib/user')->agent($user);
     		$member = Dever::load('active/lib/user')->agent($user);
     		if (!$member) {
     		if (!$member) {
+
+    			Dever::alert('仅限代理商购买');
+    		}
+    	} elseif ($info['status'] == 3) {
+    		if ($member) {
+    			Dever::alert('代理商不可购买');
+    		}
+    	} 
+    	$code = Dever::db('active/code')->getCode(array('order_id'=>$order_id,'status'=>'1,2'));
+
 				Dever::alert('仅限代理商领取');
 				Dever::alert('仅限代理商领取');
 			}
 			}
     	}
     	}
     	$code = Dever::db('active/code')->state(array('order_id'=>$order_id));
     	$code = Dever::db('active/code')->state(array('order_id'=>$order_id));
+
     	$data = Dever::db('active/order')->find($order_id);
     	$data = Dever::db('active/order')->find($order_id);
     	if ($data['status'] < 2) {
     	if ($data['status'] < 2) {
     		Dever::alert('订单还没有支付');
     		Dever::alert('订单还没有支付');
     	}
     	}
-    	if ($data['num'] <= count($code)) {
+        if (!$data['refund_num']) {
+            $data['refund_num'] = 0;
+        }
+    	if ( $data['num']-$data['refund_num'] <= count($code)) {
     		Dever::alert('已领完');
     		Dever::alert('已领完');
     	} else {
     	} else {
     		$where['active_id'] = $data['active_id'];
     		$where['active_id'] = $data['active_id'];
@@ -42,6 +56,8 @@ Class User extends Core
         	}
         	}
         	$ids = Dever::db('active/code')->insert($where);
         	$ids = Dever::db('active/code')->insert($where);
         	if ($ids) {
         	if ($ids) {
+                #更新数量
+                Dever::load('active/lib/manage')->upNum();
         		$data = Dever::db('active/code')->find($ids);
         		$data = Dever::db('active/code')->find($ids);
         		return $data;
         		return $data;
         	}
         	}
@@ -133,8 +149,11 @@ Class User extends Core
 			}
 			}
 			$data['info']['mobile'] = $active['mobile'];
 			$data['info']['mobile'] = $active['mobile'];
 			#使用核销码
 			#使用核销码
-			$code = Dever::db('active/code')->state(array('order_id'=>$id));
-			$no_code = $data['info']['num']-count($code);
+			$code = Dever::db('active/code')->getCode(array('order_id'=>$id,'status'=>'1,2'));
+            if (!$$data['refund_num']){
+                $data['refund_num'] = 0;
+            }
+			$no_code = $data['info']['num']-count($code)-$data['refund_num'];
 			if ($data['info']['status'] == 4) {
 			if ($data['info']['status'] == 4) {
 				$data['info']['use_code'] = '已使用'.count($code).'个';
 				$data['info']['use_code'] = '已使用'.count($code).'个';
 				$data['info']['no_code'] = '未使用'.$no_code.'个';
 				$data['info']['no_code'] = '未使用'.$no_code.'个';
@@ -142,9 +161,11 @@ Class User extends Core
 					foreach ($code as $k => $v) {
 					foreach ($code as $k => $v) {
 						if ($v['status'] == 1) {
 						if ($v['status'] == 1) {
 							$status = '待核销';
 							$status = '待核销';
-						} else {
+						} elseif ($v['status'] == 2) {
 							$status = '已核销';
 							$status = '已核销';
-						}
+						} else {
+                            $status = '已作废';
+                        }
 						$user = Dever::db('active/user')->find($v['join_uid']);
 						$user = Dever::db('active/user')->find($v['join_uid']);
 						$data['info']['code'][$k]['name'] = $user['name'];
 						$data['info']['code'][$k]['name'] = $user['name'];
 						$data['info']['code'][$k]['mobile'] = '手机尾号'.substr($user['mobile'],-4).','.$status;
 						$data['info']['code'][$k]['mobile'] = '手机尾号'.substr($user['mobile'],-4).','.$status;