Your Name %!s(int64=2) %!d(string=hai) anos
pai
achega
6ae4547b0e

+ 155 - 0
learn/active/database/info.php

@@ -0,0 +1,155 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'info',
+    # 显示给用户看的名称
+    'lang' => '活动列表',
+    # 后台菜单排序
+    'order' => 2,
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '活动名称',
+            'default'   => '',
+            'desc'      => '活动名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '限购数量-单位:张',
+            'default'   => '',
+            'desc'      => '限购数量',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'price'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '票价-单位:元',
+            'default'   => '0',
+            'desc'      => '票价-单位:元',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'banner'       => array
+        (
+            'type'      => 'text-255',
+            'name'      => '顶部banner',
+            'default'   => '',
+            'desc'      => '顶部banner',
+            'match'     => 'is_string',
+            'update'    => 'images',
+            'key'       => '1',
+            // 'place'     => '759*562',
+        ),
+
+        'pic'       => array
+        (
+            'type'      => 'text-255',
+            'name'      => '购买成功后的背景图',
+            'default'   => '',
+            'desc'      => '购买成功后的背景图',
+            'match'     => 'is_string',
+            'update'    => 'image',
+            'key'       => '1',
+            // 'place'     => '759*562',
+        ),
+
+        'desc'      => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '活动说明',
+            'default'   => '',
+            'desc'      => '活动说明',
+            'match'     => 'is_string',
+            'update'    => 'editor',
+            //'search'    => 'fulltext',
+            //'list'      => true,
+        ),
+
+        'reorder'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '排序-数值越大越靠前',
+            'default'   => '1',
+            'desc'      => '请输入排序',
+            'match'     => 'option',
+            'update'  => 'text',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+            'edit'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '创建时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+    	//'insert' => false,
+        'delete' => false,
+        // 'edit' => false,
+        
+    ),
+
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                // 'id' => array('yes','>'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'asc'),
+            'col' => '*',
+        ),
+    ),
+);

+ 203 - 0
learn/active/database/order.php

@@ -0,0 +1,203 @@
+<?php
+
+$pay_type = array
+(
+    1 => '在线支付',
+);
+
+$status = array
+(
+    1 => '待支付',
+    2 => '已完成',
+    3 => '已关闭',
+);
+$active = function()
+{
+    $array = array();
+    $info = Dever::load('active/info-state');
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+return array
+(
+    # 表名
+    'name' => 'order',
+    # 显示给用户看的名称
+    'lang' => '活动订单',
+    'order' => 100,
+    
+    // 'end' => array
+    // (
+    //     'insert' => 'cash/lib/set.orderUpdate_commit',
+    //     'update' => 'cash/lib/set.orderUpdate_commit',
+    // ),
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            // 'list'      => true,
+        ), 
+
+        'order_num'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '订单单号',
+            'default'   => '',
+            'desc'      => '订单单号',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'mid'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '代理商姓名/手机号',
+            'default'   => '-1',
+            'desc'      => '代理商',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => array
+            (
+                'api' => 'agent/member-getSearch',
+                'col' => 'col',
+                'result' => 'id',
+                'search' => 'mid',
+            ),
+            'list_name' => '代理商信息',
+            'list'      => 'Dever::load("agent/lib/member.getOne", {mid}, "agent/member", true)',
+        ),
+
+        'active_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '活动名称',
+            'default'   => '-1',
+            'desc'      => '活动名称',
+            'match'     => 'is_string',
+            'option'    => $active,
+            'update'    => 'text',
+            // 'search'    => 'text',
+            'list'      => true,
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '数量',
+            'default'   => '',
+            'desc'      => '数量',
+            'match'     => 'option',
+            'list'      => true,
+        ),
+
+        'price'        => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '金额',
+            'default'   => '0',
+            'desc'      => '金额',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '支付状态',
+            'default'   => '1',
+            'desc'      => '支付状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'pay_type'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '支付类型',
+            'default'   => '1',
+            'desc'      => '支付类型',
+            'match'     => 'is_numeric',
+            'option'    => $pay_type,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '生成时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'    => 'date',
+            'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        // 'edit' => false,
+        'insert' => false,
+        // 'excel'	=> true,
+    ),
+
+    'request' => array
+    (
+        // # 获取数量
+        'getNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'mid' => 'yes',
+                'active_id' => 'yes',
+                'status' =>2,
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(num) as total',
+        ),
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'mid' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('cdate'=>'desc'),
+            'page' => array(20,'list'),
+            'col' => '*',
+        ),
+    ),
+);

+ 10 - 0
learn/active/index.php

@@ -0,0 +1,10 @@
+<?php
+
+define('DEVER_APP_NAME', 'active');
+define('DEVER_APP_LANG', '活动管理');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 20);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-website');
+define('DEVER_GROUP_ORDER', 1);
+define('DEVER_GROUP_NAME', '商学院');
+include(DEVER_APP_PATH . '../boot.php');

+ 143 - 0
learn/active/src/Api.php

@@ -0,0 +1,143 @@
+<?php
+namespace Active\Src;
+
+use Dever;
+use Agent\Lib\Core;
+
+Class Api extends Core {
+	#活动详情
+	public function index(){
+		$id = Dever::input('id');
+		$data = Dever::db('active/info')->find($id);
+		$member = Dever::db('agent/member')->find($this->uid);
+		$data['member_name'] = $member['name'];
+		$data['member_mobile'] = $member['mobile'];
+		return $data;
+	}
+	#确认信息
+	public function confirm(){
+		$id = Dever::input('id');
+		if(!$id){
+			Dever::alert('活动id不能为空');
+		}
+		$num = Dever::input('num');
+		if(!$num){
+			Dever::alert('购买数量不能为空');
+		}
+		$data = Dever::db('active/info')->find($id);
+		$insert['active_id'] = $id;
+		$insert['mid'] = $this->uid;
+		$insert['num'] = $num;
+		$insert['price'] = $num * $data['price'];
+		$data = Dever::db('active/order')->getNum(array('mid'=>$this->uid,'active_id'=>$id));
+		if($data && $data['total'] && $data['tatal'] > 10){
+			Dever::alert('您已超过限购数量');
+		}
+		$insert['order_num'] = $this->getOrderId();
+		$ids = Dever::db('active/order')->insert($insert);
+
+		if($ids){
+			$info = Dever::db('active/order')->find($ids);
+			$active = Dever::db('active/info')->find($info['active_id']);
+			$param = array
+	        (
+	            'project_id' => 6,
+	            'channel_id' => 1,
+	            'system_source' => 1,
+	            'account_id' => 8,
+	            'uid' => $this->uid,
+	            'name' => $active['name'],
+	            //'openid' => $data['openid'],
+	            'cash' => $info['price'],
+	            'product_id' => $ids,
+	            'order_id' => $info['order_num'],
+	            'h5' => 1,
+	            'refer' => Dever::input('refer', 'test'),
+	        );
+
+	        $result = Dever::load('pay/api.pay', $param);
+	        $result['order_num'] = $info['order_num'];
+	        $result['order_id'] = $info['id'];
+
+	        return $result;
+		}else{
+			Dever::alert('提交失败');
+		}
+	}
+
+	 # 支付成功回调 安全加密 设置token
+    public function success_secure_api_token()
+    {
+        $project_id = Dever::input('pay_project_id');
+        $info = Dever::db('pay/project')->one($project_id);
+        if ($info) {
+            return $info['key'];
+        }
+        return 'agent_buy_dever_2020';
+    }
+
+    # 支付成功回调 安全加密
+    public function success_secure_api($param = array())
+    {
+        $this->success($param);
+    }
+
+    # 支付成功回调
+    public function success($param = array())
+    {
+        $send = $param ? $param : Dever::preInput('pay_');
+        $product_id = $send['pay_product_id'];
+        $order_id = $send['pay_order_id'];
+        $status = $send['pay_status'];
+        $cash = $send['pay_cash'];
+        $msg = $send['pay_msg'];
+
+        $order = Dever::db('active/order')->one(array('id' => $product_id, 'clear' => true));
+        if ($order && $status == 2) {
+            $update['pay_status'] = 2;
+            $update['where_id'] = $order['id'];
+            Dever::db('active/order')->update($update);
+        }
+
+        return 'ok';
+    }
+    #定时
+    public function job(){
+    	$data = Dever::db('active/order')->state(array('status'=>1));
+    	$time = time();
+    	if($data){
+    		foreach($data as $k => $v){
+    			if ($v['cdate'] && $time-$v['cdate']>300){
+    				Dever::db('active/order')->update(array('where_id'=>$v['id'],'set_status'=>3));
+    			}
+    		}
+    	}
+    	return 'ok';
+    }
+	#门票列表
+	public function GetList(){
+		$data['list'] = Dever::db('active/order')->getAll(array('mid'=>$this->uid));
+		foreach($data['list'] as $k => $v){
+			$data['list'][$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
+			if($v['status'] == 1){
+				$data['list']['status_name'] = '待支付';
+			}else{
+				$data['list']['status_name'] = '已完成';
+			}
+		}
+		return $data;
+	}
+
+	#生成订单号
+    public function getOrderId()
+    {
+        $where['order_num'] = Dever::order('D');
+        $where['clear'] = true;
+        $state = Dever::db('active/order')->one($where);
+        if (!$state) {
+            return $where['order_num'];
+        } else {
+            return $this->getOrderId();
+        }
+    }
+}

+ 2 - 0
learn/boot.php

@@ -0,0 +1,2 @@
+<?php
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../boot.php');