dever 6 år sedan
förälder
incheckning
9ea962ea59
7 ändrade filer med 438 tillägg och 0 borttagningar
  1. 16 0
      youzan/config/base.php
  2. 65 0
      youzan/config/wechat.php
  3. 96 0
      youzan/database/card.php
  4. 125 0
      youzan/database/card_log.php
  5. 7 0
      youzan/index.php
  6. 54 0
      youzan/src/Auth.php
  7. 75 0
      youzan/src/Card.php

+ 16 - 0
youzan/config/base.php

@@ -0,0 +1,16 @@
+<?php
+
+# 一些基本配置
+$config['base'] = array
+(
+	# 后台头部菜单
+	'top' => 'main/project_id-7',
+);
+
+# 模板配置
+$config['template'] = array
+(
+	
+);
+
+return $config;

+ 65 - 0
youzan/config/wechat.php

@@ -0,0 +1,65 @@
+<?php
+# 小程序基本配置
+$config['type'] = 7;
+
+$config['token'] = array
+(
+	'name' => '获取有赞的token',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://open.youzan.com/oauth/token?',
+	'param' => array
+	(
+		'client_id' => 'appid',
+		'client_secret' => 'secret',
+		'grant_type' => 'silent',
+		'kdt_id' => 'key',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		'access_token' => 'token',
+		'expires_in' => 'expires_in',
+	),
+);
+
+$config['card'] = array
+(
+	'name' => '发放优惠券',
+	'method' => 'post',
+	'json' => false,
+	'url' => 'https://open.youzan.com/api/oauthentry/youzan.ump.coupon/3.0.0/take?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'coupon_group_id' => 'coupon_group_id',
+		'mobile' => 'mobile',
+		'weixin_openid' => 'weixin_openid',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
+$config['get_msg'] = array
+(
+	'name' => '获取帐号下已存在的模板列表',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/cgi-bin/wxopen/template/list?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'offset' => '0',
+		'count' => '20',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
+return $config;

+ 96 - 0
youzan/database/card.php

@@ -0,0 +1,96 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'card',
+	# 显示给用户看的名称
+	'lang' => '优惠券码',
+	'order' => 100,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			//'list'		=> true,
+		),
+
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '项目ID',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-20',
+			'name' 		=> '活动key-通过key值搜索数据',
+			'default' 	=> '',
+			'desc' 		=> '活动key-通过key值搜索数据',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-120',
+			'name' 		=> '标题',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'card_id'		=> array
+		(
+			'type' 		=> 'varchar-120',
+			'name' 		=> '活动id',
+			'default' 	=> '',
+			'desc' 		=> '活动id',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'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' 		=> '',
+			'default' 	=> '',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'top' => Dever::config('base', 'youzan')->top,
+
+	'manage' => array
+	(
+		//'delete' => false,
+		//'insert' => false,
+		//'edit' => false,
+	),
+);

+ 125 - 0
youzan/database/card_log.php

@@ -0,0 +1,125 @@
+<?php
+
+$status = array
+(
+	1 => '发送中',
+	2 => '发送成功',
+	3 => '发送失败',
+);
+
+return array
+(
+	# 表名
+	'name' => 'card_log',
+	# 显示给用户看的名称
+	'lang' => '优惠券发送日志',
+	'order' => 90,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '项目',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'card_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '优惠券id',
+			'default' 	=> '',
+			'desc' 		=> '优惠券id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> 'Dever::load("youzan/card-one#name", {card_id})',
+		),
+
+		'touser'		=> array
+		(
+			'type' 		=> 'varchar-120',
+			'name' 		=> '接收者',
+			'default' 	=> '',
+			'desc' 		=> '接收者',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'num'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '发送次数',
+			'default' 	=> '0',
+			'desc' 		=> '发送次数',
+			'match' 	=> 'option',
+			//'search'	=> 'order',
+			'list'		=> true,
+		),
+
+		'result'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '微信返回信息',
+			'default' 	=> '',
+			'desc' 		=> '微信返回信息',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'list'		=> true,
+			'modal'		=> '查看详情',
+		),
+
+		'status'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '状态',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $status,
+			'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' 		=> '',
+			'default' 	=> '',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'top' => Dever::config('base', 'youzan')->top,
+
+	'manage' => array
+	(
+		'delete' => false,
+		'insert' => false,
+		'edit' => false,
+	),
+);

+ 7 - 0
youzan/index.php

@@ -0,0 +1,7 @@
+<?php
+define('DEVER_APP_NAME', 'youzan');
+define('DEVER_APP_LANG', '有赞');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 80);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-shopping-cart');
+include(DEVER_APP_PATH . '../boot.php');

+ 54 - 0
youzan/src/Auth.php

@@ -0,0 +1,54 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| auth.php 用于做权限验证
+|--------------------------------------------------------------------------
+*/
+namespace youzan\Src;
+
+use Dever;
+use Main\Lib\Wechat;
+
+class Auth
+{
+	/**
+	 * wechat
+	 *
+	 * @var Wechat
+	 */
+	private $wechat;
+	
+	/**
+	 * result
+	 *
+	 * @var array
+	 */
+	private $result;
+	
+	/**
+	 * output
+	 *
+	 * @var string
+	 */
+	private $output;
+	
+	/**
+     * 构造函数 初始化
+     * 
+     * @return mixed
+     */
+	public function __construct()
+	{
+		$this->wechat = new Wechat();
+	}
+
+	/**
+     * 获取token 一般为系统token
+     * 
+     * @return mixed
+     */
+	public function token_api()
+	{
+		return $this->wechat->token(false, false, 2000, true);
+	}
+}

+ 75 - 0
youzan/src/Card.php

@@ -0,0 +1,75 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| 获取优惠券
+|--------------------------------------------------------------------------
+*/
+namespace Youzan\Src;
+
+use Dever;
+use Main\Lib\Wechat;
+use Main\Lib\Core;
+
+class Card
+{
+	# 发送单条模板消息
+	public function send()
+	{
+		$key = Dever::input('key');
+		$project_id = Dever::input('project_id');
+		$touser = Dever::input('touser');
+		return $this->sendOne($key, $project_id, $touser);
+	}
+
+	# 发送单条模板消息
+	public function sendOne($key, $project_id, $touser, $state = true)
+	{
+		if ($project_id > 0 && $key && $touser) {
+			$info = Dever::db('youzan/card')->one(array('option_key' => $key, 'option_project_id' => $project_id));
+			if ($info) {
+				$update = array();
+				$update['project_id'] = $info['project_id'];
+				$update['card_id'] = $info['id'];
+				$update['touser'] = $touser;
+
+				$where = array();
+				$where['option_card_id'] = $info['id'];
+				$where['option_touser'] = $update['touser'];
+				$id = Dever::upinto('youzan/card_log', $where, $update);
+
+				return Core::run($info['project_id'], 'card', 'card.sendAction', 'card.sendLog', 'youzan', $id, $state);
+			}
+		}
+
+		return false;
+	}
+
+	public function sendAction($id)
+	{
+		$info = Dever::db('youzan/card_log')->one($id);
+		if ($info) {
+			$msg = Dever::db('youzan/card')->one($info['card_id']);
+			$info['mobile'] = $info['touser'];
+			$info['coupon_group_id'] = $msg['card_id'];
+			return $info;
+		} else {
+			die;
+		}
+	}
+
+	public function sendLog($project_id, $data, $id = false)
+	{
+		$info = Dever::db('youzan/card_log')->one($id);
+		if ($info) {
+			$update['where_id'] = $info['id'];
+			$update['result'] = json_encode($data);
+			if (!isset($data['error_response'])) {
+				$update['status'] = 2;
+			} else {
+				$update['status'] = 3;
+			}
+			$update['num'] = $info['num'] + 1;
+			Dever::db('youzan/card_log')->update($update);
+		}
+	}
+}