rabin 3 роки тому
батько
коміт
91c5c047f8

+ 25 - 0
app/shop/database/info.php

@@ -556,6 +556,16 @@ return array
             'option'    => $act,
         ),
 
+        'sign_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '签约id',
+            'default'   => '',
+            'desc'      => '签约id',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'mid'      => array
         (
             'type'      => 'varchar-50',
@@ -729,6 +739,21 @@ return array
 
     'request' => array
     (
+        'search' => array
+        (
+            'option' => array
+            (
+                'ids' => array('yes-id', 'in'),
+                'name' => array('yes', 'like'),
+                'id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'limit' => '0,20',
+            'col' => 'name as name, id, id as value, "" as selected, "" as disabled,mid|id',
+        ),
+
         'getSearch' => array
         (
             # 匹配的正则或函数 选填项

+ 64 - 7
app/shop/database/sign.php

@@ -10,8 +10,20 @@ $mer_type = array
     1 => '企业商户',
     //3 => '小微商户',
 );
+$create_shop = array
+(
+    1 => '绑定现有门店',
+    2 => '生成体验店',
+    //3 => '生成零售店',
+);
 $shop = array();
 $desc = '';
+$col = Dever::input('col');
+if (!$col) {
+    $tab = array('门店信息', '法人信息', '企业信息', '银行信息');
+} else {
+    $tab = '';
+}
 
 $step = array
 (
@@ -39,6 +51,10 @@ return array
     # 后台菜单排序
     'order' => -100,
     'step' => $step,
+    'end' => array
+    (
+        'update' => 'shop/lib/manage.sign',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -84,17 +100,38 @@ return array
             // 'update'    => 'text',
         ),
 
+        'cash'      => array
+        (
+            'type'      => 'varchar-30',
+            'name'      => '打款金额',
+            'default'   => '',
+            'desc'      => '打款金额',
+            'match'     => 'option',
+            'update'    => $col ? 'text' : false,
+        ),
+
+        'create_shop'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '绑定门店',
+            'default'   => '1',
+            'desc'      => '绑定门店',
+            'match'     => 'option',
+            'update'    => $col ? 'radio' : false,
+            'option'    => $create_shop,
+            'control'   => 'create_shop',
+        ),
+
         'shop_id'       => array
         (
             'type'      => 'int-11',
-            'name'      => '店铺id',
+            'name'      => '选择现有门店',
             'default'   => '0',
             'desc'      => '请选择用户',
             'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            // 'search'  => 'select',
-            'value'     => $shop ? $shop['id'] : false,
-            //'list'      => '{uid} > 0 ? Dever::load("passport/user-find#username", {uid}) : "匿名用户"',
+            'update'    => $col ? 'select' : false,
+            'update_search' => 'shop/lib/manage.search_shop',
+            'show'      => 'create_shop=1',
         ),
 
         'shop_name'      => array
@@ -465,6 +502,8 @@ return array
             'default'   => '1',
             'desc'      => '请选择状态',
             'match'     => 'is_numeric',
+            'list_name' => '最新进度',
+            'list'      => 'Dever::load("shop/lib/sign.getLog", {id})',
         ),
         
         'cdate'     => array
@@ -487,15 +526,33 @@ return array
         # 更新页面顶部描述
         'desc' => $desc,
         # 更新页面tab切换
-        'tab' => array('门店信息', '法人信息', '企业信息', '银行信息'),
+        'tab' => $tab,
         //'list' => 'update',
         'list_button' => array
         (
             'add' => array('编辑', '', '{step} == -1'),
             'delete' => array('删除', '', '{step} == -1'),
             'oper' => array('提交资料', 'shop/lib/sign.handle?sign_id={id}', '{step} == -1'),
-            'oper2' => array('提交资料', 'shop/lib/sign.handle?sign_id={id}', '{step} == -1'),
+            'fast' => array('打款确认', '"sign&where_id={id}&col=cash"', '{step} == 2'),
+            'copy' => array('复制链接', 'shop/lib/sign.getAgreement?sign_id={id}', '{step} == 4'),
             'list' => array('查看日志', '"sign_log&search_option_sign_id={id}&oper_table=sign"'),
+            'fast1' => array('绑定门店', '"sign&where_id={id}&col=create_shop,shop_id"', '{step} == 5'),
         )
     ),
+
+    'request' => array
+    (
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'step' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'asc'),
+            'col' => '*',
+        ),
+    )
 );

+ 4 - 3
app/shop/database/sign_log.php

@@ -17,6 +17,7 @@ if ($id) {
 }
 
 $step = Dever::db('shop/sign')->config['step'];
+$step[100] = '绑定门店';
 
 return array
 (
@@ -55,9 +56,9 @@ return array
         'step'      => array
         (
             'type'      => 'int-11',
-            'name'      => '当前步骤',
+            'name'      => '当前进度',
             'default'   => '',
-            'desc'      => '当前步骤',
+            'desc'      => '当前进度',
             'match'     => 'option',
             'update'    => 'text',
             'option'    => $step,
@@ -134,7 +135,7 @@ return array
             'match'     => array('is_numeric', time()),
             'desc'      => '',
             # 只有insert时才生效
-            'insert'    => true,
+            //'insert'    => true,
             'list'      => 'date("Y-m-d H:i:s", {cdate})',
         ),
     ),

+ 53 - 7
app/shop/lib/Manage.php

@@ -6,6 +6,32 @@ use Dever;
 
 class Manage
 {
+    # 金额确认
+    public function sign($id, $name, $data)
+    {
+        $cash = Dever::param('cash', $data);
+        if ($cash && $cash > 0) {
+            $sign = Dever::db('shop/sign')->find($id);
+            Dever::load('shop/lib/sign')->account_check($sign, $cash);
+        }
+
+        $create_shop = Dever::param('create_shop', $data);
+        $shop_id = Dever::param('shop_id', $data);
+        if ($create_shop) {
+            if ($create_shop == 1) {
+                # 绑定门店
+                if (!$shop_id) {
+                    Dever::alert('请选择门店');
+                }
+
+                Dever::load('shop/lib/sign')->bind($id, $shop_id);
+            } else {
+                # 生成门店
+                Dever::alert('暂时无法生成门店');
+            }
+        }
+    }
+
     public function sellOrderPs($id, $name, $data)
     {
         Dever::config('base')->hook = true;
@@ -545,6 +571,21 @@ class Manage
         return Dever::search('shop/info');
     }
 
+    # 获取门店
+    public function search_shop_api()
+    {
+        $data = Dever::search('shop/info');
+        $result = array();
+        if ($data) {
+            foreach ($data as $k => $v) {
+                if (!$v['mid']) {
+                    $result[] = $data[$k];
+                }
+            }
+        }
+        return $result;
+    }
+
     # 获取环比增长
     public function getGoodsHb($num, $day, $goods_id)
     {
@@ -678,17 +719,22 @@ class Manage
         $info = Dever::db('shop/sell_order')->find($id);
         $res = array();
         $goods = Dever::db('shop/sell_order_goods')->getGoods(array('order_id'=>$id));
+        $data = array();
         foreach($goods as $k => $v){
             $data[] = Dever::db('goods/info')->fetch('select `name` from churen_goods_info where id = '.$v['goods_id'].' and state =1');
         }
-        foreach($data as $k => $v){
-            $res[] = $v['name'];
-        }
-        if (count($res) > 3){
-            $html = $res[0].'<br/>'.$res[1].'<br/>'.$res['2'].'……';
-        } else {
-             $html = implode('<br/>',$res);
+        $html = '';
+        if ($data) {
+            foreach($data as $k => $v){
+                $res[] = $v['name'];
+            }
+            if (count($res) > 3){
+                $html = $res[0].'<br/>'.$res[1].'<br/>'.$res['2'].'……';
+            } else {
+                 $html = implode('<br/>',$res);
+            }
         }
+        
        
         return $html;
     }

+ 75 - 21
app/shop/lib/Sign.php

@@ -25,13 +25,62 @@ Class Sign {
 	);
 
 	# 计划任务
-	public function cron()
+	public function cron_api()
 	{
-		# 对已签约的
+		$where['step'] = '4,5';
+		$data = Dever::db('shop/sign')->getData($where);
+		if ($data) {
+			foreach ($data as $k => $v) {
+				$this->check($v);
+			}
+		}
+		return 'ok';
+	}
+
+	# 绑定门店
+	public function bind($sign_id, $shop_id)
+	{
+		$sign = Dever::db('shop/sign')->find($sign_id);
+		if (!$sign) {
+			Dever::alert('签约信息不存在');
+		}
+		$shop = Dever::db('shop/info')->find($shop_id);
+		if (!$shop) {
+			Dever::alert('门店不存在');
+		}
+		if ($shop['mid']) {
+			Dever::alert('门店已绑定银联商户号');
+		}
+		$state = Dever::db('shop/info')->update(array('where_id' => $shop_id, 'mid' => $sign['mid'], 'sign_id' => $sign['id']));
+		if ($state) {
+			$this->log(100, $sign, '门店['.$shop['name'].']绑定成功');
+		} else {
+			Dever::db('shop/sign')->update(array('where_id' => $sign_id, 'shop_id' => '-1'));
+			Dever::alert('门店绑定失败');
+		}
+	}
+
+	# 获取合同链接
+	public function getAgreement($sign_id)
+	{
+		$sign = Dever::db('shop/sign')->find($sign_id);
+		return $this->agreement($sign, false);
 	}
 
-	# 获取日志
+	# 获取最新一条日志
 	public function getLog($sign_id)
+	{
+		$sign = Dever::db('shop/sign')->find($sign_id);
+		$log = Dever::db('shop/sign_log')->find(array('sign_id' => $sign['id']));
+		if ($log) {
+			$date = date('Y-m-d H:i', $log['cdate']);
+			$step = Dever::db('shop/sign')->config['step'][$log['step']];
+			return $date . '<br />' . $step . '<br />' . $log['desc'];
+		}
+	}
+
+	# 获取日志列表
+	public function getLogList($sign_id)
 	{
 		$sign = Dever::db('shop/sign')->find($sign_id);
 		if (!$sign) {
@@ -77,12 +126,12 @@ Class Sign {
 		}
 		$sign['bank_acct_no'] = str_replace(' ', '', $sign['bank_acct_no']);
 		switch($sign['step']) {
-			case -1;
+			case -1:
 				# 提交资料
 				return $this->up($sign);
 				break;
-			case 1;
-			case 6;
+			case 1:
+			case 6:
 				if ($sign['bank_acct_type'] == 1) {
 					# 对公打款
 					return $this->account($sign);
@@ -91,15 +140,16 @@ Class Sign {
 					return $this->agreement($sign);
 				}
 				break;
-			case 2;
+			case 2:
 				# 打款验证
 				return $this->account_check($sign);
 				break;
-			case 4;
+			case 4:
+			case 5:
 				# 验证签约
 				return $this->check($sign);
 				break;
-			case 5;
+			case 6:
 				# 签约成功,变更签约?
 				return '签约已成功,后续可以变更签约';
 				return $this->up($sign);
@@ -257,10 +307,10 @@ Class Sign {
 	}
 
 	# 3.6  对公账户认证接口
-	public function account_check($sign)
+	public function account_check($sign, $num)
 	{
 		$step = 3;
-		$trans_amt = Dever::input('num');
+		$trans_amt = $num;
 		$service = 'company_account_verify';
 		$data['ums_reg_id'] = $sign['ums_reg_id'];
 		$data['company_account'] = $sign['bank_acct_no'];
@@ -297,7 +347,7 @@ Class Sign {
 			$update['clear'] = true;
 			Dever::db('shop/sign')->update($update);
 			if ($log) {
-				$this->log($update['step'], $sign, '获取前台签约合同链接', $data, $result['data'], $result['request_seq']);
+				$this->log($update['step'], $sign, '请复制链接进行合同签署', $data, $result['data'], $result['request_seq']);
 			} else {
 				return $update['url'];
 			}
@@ -314,11 +364,8 @@ Class Sign {
 		$service = 'apply_qry';
 		$data['ums_reg_id'] = $sign['ums_reg_id'];
 		$result = $this->get($service, $data, $sign['ums_reg_id']);
-		print_r($result);die;
 		if ($result && $result['code'] == 1 && isset($result['data']['apply_status'])) {
-			if ($result['data']['apply_status'] == '01') {
-				$step = 5;
-			} elseif ($result['data']['apply_status'] == '03') {
+			if ($result['data']['apply_status'] == '03') {
 				$step = 6;
 			}
 			$update = array();
@@ -327,9 +374,6 @@ Class Sign {
 			$update['clear'] = true;
 			if ($result['data']['apply_status'] == '03' && isset($result['data']['mer_no']) && $result['data']['mer_no']) {
 				$update['mid'] = $result['data']['mer_no'];
-				if (isset($sign['shop_id']) && $sign['shop_id']) {
-					Dever::db('shop/info')->update(array('where_id' => $sign['shop_id'], 'mid' => $update['mid']));
-				}
 			}
 			Dever::db('shop/sign')->update($update);
 			$this->log($update['step'], $sign, $result['data']['apply_status_msg'], $data, $result['data'], $result['request_seq']);
@@ -390,7 +434,7 @@ Class Sign {
 
 		if ($response) {
 			$response = Dever::json_decode($response);
-			if (isset($response['res_code']) && $response['res_code'] == '0000') {
+			if (isset($response['res_code']) && ($response['res_code'] == '0000' || $response['res_code'] == '1446')) {
 				$result['code'] = 1;
 				$result['msg'] = '请求成功';
 				$result['data'] = $response;
@@ -473,6 +517,11 @@ Class Sign {
 		$data['step'] = $step;
 		$data['sign_id'] = $sign['id'];
 		$data['desc'] = $msg;
+		$info = false;
+		if ($step == 4 || $step == 5) {
+			$info = Dever::db('shop/sign_log')->find($data);
+		}
+		
 		$admin = Dever::load('manage/auth.info');
 		if ($admin) {
 			$data['admin_id'] = $admin['id'];
@@ -489,8 +538,13 @@ Class Sign {
 			}
 			$data['response'] = $response;
 		}
+		if ($info) {
+			$data['where_id'] = $info['id'];
+			Dever::db('shop/sign_log')->update($data);
+		} else {
+			Dever::db('shop/sign_log')->insert($data);
+		}
 		
-		Dever::db('shop/sign_log')->insert($data);
 		return $msg;
 	}
 }