未加星标

WeMall微信商城签到插件Sign的主要源码

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

WeMall微信商城源码签到插件Sign,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考

AdminController.class.php

<php
namespace Addons\Sign\Controller;
class AdminController extends InitController
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$config = M("AddonSignConfig")->find();
$this->assign("config", $config);
$record = D(’Addons://Sign/AddonSignRecord’); // 实例化User对象
$count = $record->count();// 查询满足要求的总记录数
$Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
$Page->setConfig(’theme’, "<div class=’widget-content padded text-center’><ul class=’pagination’></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><a> %HEADER% %NOW_PAGE%/%TOTAL_PAGE% 页</a></ul></div>");
$show = $Page->show();// 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
$record = $record->limit($Page->firstRow . ’,’ . $Page->listRows)->order("id desc")->relation(true)->select();
$this->assign("record", $record);// 赋值数据集
$this->assign(’page’, $show);// 赋值分页输出
$this->display();
}
public function addConfig()
{
M("AddonSignConfig")->where(array("id" => "1"))->save($_POST);
$this->success(’修改成功’, ’Admin/Admin/index/addon/Sign’);
}
}

IndexController.class.php

<?php
namespace Addons\Sign\Controller;
class IndexController extends InitController
{
public $appUrl = "";
public function __construct()
{
parent::__construct();
$this->appUrl = "http://" . I("server.HTTP_HOST");
}
public function init()
{
return R("App/Common/init");
}
public function oauthRegister($wxuser)
{
return R("App/Common/oauthRegister", array($wxuser));
}
public function index()
{
$user = R("App/Public/oauthLogin");
// $user = M("User")->where(array("uid" => session("userUid")))->find();
$contact = M("Contact")->where(array("user_id" => $user["id"]))->find();
if ($contact) {$this->assign("contact", $contact);
}
$config = M("Config")->find();
$this->assign("config", $config);
$this->assign("user", $user);
$product = M("addonScore")->select();
$this->assign("product", $product);
$this->display();
}
public function addOrder()
{
// $user = M("User")->where(array("uid" => session("userUid")))->find();
$user = M("User")->where(array("id" => session("userId")))->find();
$score = floatval($user["score"]) - floatval($_POST["score"]);
if ($score >= 0) {M("User")->where(array("id" => $user["id"]))->save(array("score" => $score));
} else {return;
}
$userHas = M("Contact")->where(array("user_id" => session("userId")))->find();
if ($userHas) {$contact ["id"] = $userHas ["id"];$contact ["user_id"] = session("userId");$contact ["name"] = $_POST ["name"];$contact ["phone"] = $_POST ["phone"];$contact ["address"] = $_POST ["address"];M("Contact")->save($contact);
} else {$contact ["user_id"] = session("userId");$contact ["name"] = $_POST ["name"];$contact ["city"] = "";$contact ["area"] = "";$contact ["phone"] = $_POST ["phone"];$contact ["address"] = $_POST ["address"];M("Contact")->add($contact);
}
$userHas = M("Contact")->where(array("user_id" => session("userId")))->find();
$contact_id = $userHas["id"];
$data ["user_id"] = session("userId");
$data ["contact_id"] = $contact_id;
$data ["orderid"] = date("ymdhis") . mt_rand(1, 9);
$data ["totalscore"] = $_POST["score"];
$data ["status"] = 0;
$data ["note"] = $_POST ["note"];
$data ["time"] = date("Y-m-d H:i:s");
$data ["score_id"] = $_POST ["id"];
$result = M("AddonScoreOrder")->add($data);
if ($result) {$this->ajaxReturn($result);
}
}
public function sign(){
$today = date("Y-m-d");
$where["time"] = array("like", $today . "%");
$where["user_id"] = session("userId");
$record = D("Addons://Sign/AddonSignRecord")->where($where)->find();
if ($record) {$this->ajaxReturn(array("status" => 0));return;
}
$user = M("User")->where(array("id" => session("userId")))->find();
$count = 0;
do{$count++;$yesterday = date("Y-m-d", strtotime("-$count day"));$where["time"] = array("like", $yesterday . "%");$record = D("AddonSignRecord")->where($where)->find();
} while ($record);
$continue_sign = $count-1;
$config = M("AddonSignConfig")->find();
if ($config) {$addScore = floatval($continue_sign) * floatval($config["continue_sign"]) + floatval($config["first_sign"]);M("AddonSignRecord")->add(array("user_id" => session("userId"), "score" => $addScore));$score = floatval($user["score"]) + $addScore;M("User")->where(array("id" => $user["id"]))->save(array("score" => $score));$this->ajaxReturn(array("status" => 1, "score" => $addScore));
}
}
}

Index_index.html

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>签到系统</title>
<meta name="format-detection" content="telephone=no, address=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- apple devices fullscreen -->
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link href="__CSS__/bootstrap.min.css" rel="stylesheet">
<link href="__CSS__/font-awesome.min.css" rel="stylesheet">
<link href="__CSS__/animate.css" rel="stylesheet">
<link href="__CSS__/common.css" rel="stylesheet">
<link href="__CSS__/sign.css" rel="stylesheet">
</head>
<body>
<div class="container container-fill">
<div class="pcenter-main">
<div class="head"><div class="pdetail"> <div class="img-circle"><img src="{$user.avater}"></div> <div class="pull-left"> <span class="name">{$user.username}</span> <span class="type">会员ID: {$user.id}</span> </div></div><div class="head-nav"> <a class="head-nav-list">积分<span id="myscore">{$user.score}</span></a> <a class="head-nav-list"><span class="pull-center"><span class="btn btn-default" onclick="signIn(this)" style="color: #fff;background-color: transparent;border-color: #fff;">今日签到</span></span></a></div>
</div>
</div>
<div class="scroll-container">
<div class="wrapper"><ul class="list-group"> <volist name="product" id="product"> <li class="list-group-item"> <div class="con"> <div class="list-hd"> <h5>{$product.name}</h5> </div> <div class="list-con"> <img src="__PUBLIC__/Uploads/{$product.image}"> </div> <div class="list-ft"> <div class="pull-left" style="margin-left: 12px;">积分:<b>{$product.score}</b></div> <div class="pull-right btn btn-default" style="margin-right: 12px;"><a onclick="doCart(this , ’{$product.score}’ , ’{$product.id}’)" style="color: black;">立即兑换</a> </div> </div> </div> </li> </volist></ul>
</div>
</div>
<div id="cover2" style="display: none; position: fixed; width: 100%; height: 100%;"></div>
<div class="tc_c2" id="join_box"
style="left: 0px; bottom: 0px; z-index: 3000; position: fixed; display: none;width: 100%;">
<div class="join_box_Xq_out" style="max-height: 641px;"><div class="tc_c_close"> <div><img title="关闭" onclick="hidePop(this);" ontouchstart="" src="__IMG__/share_qr_close3.png"></div></div><div class="join_box_Xq"> <ul id="ul_join_property" class="pop_massage"> <li> <div class="optionsName">姓名</div> <div class="inpoutK"> <input value="{$contact.name}" type="text" class="font0" name="name" id="name"> </div> </li> <li> <div class="optionsName">手机</div> <div class="inpoutK"> <input value="{$contact.phone}" type="text" class="font0" name="phone" id="phone"> </div> </li> <li> <div class="optionsName">地址</div> <div class="inpoutK"> <input value="{$contact.address}" type="text" class="font0" name="address" id="address"> </div> </li> <li> <div class="optionsName">备注</div> <div class="inpoutK"> <input value="" type="text" class="font0" name="note" id="note"> </div> </li> </ul></div><div class="tc_c_btn2" ontouchstart="" id="xdBtn"> <a title="返回" class="fanHui" href="javascript:void(0);" ontouchstart="" onclick="_joinBox._prev()" style="display: none;"></a> <div class="join_Btn"> <input id="input_submit" class="blueBtn" type="submit" value="我要报名" style="display: none; width: 100%;"> <a style="width: 100%;" id="a_submit" class="blueBtn font02" href="javascript:void(0);" onclick="submitOrder()">提交</a> </div></div>
</div>
</div>
<div id="alert" class="alert" style="display: none; top: 165px; left: 42.5px;text-align: center;">
<div id="alert_title">温馨提示</div>
<div id="alert_text"></div>
<div id="alert_button"><button id="alert_button_ok" class="button_3" ontouchstart="" onclick="hideAlert()">知道了</button></div>
<div id="alert_cancel" class="alert_cancel" ontouchstart="" onclick=""></div>
</div>
</div>
<script type="text/javascript" src="__JS__/jquery.min.js"></script>
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script>
var id = 0;
var score = 0;
function hidePop(){
$("#join_box").hide();
$("#cover2").hide();
}
function showPop(){
$("#join_box").show();
$("#cover2").show();
}
function doCart(obj , scoreIn ,idIn){
if(parseFloat(scoreIn) > parseFloat($(’#myscore’).html())){alert("积分不足!");return;
}
id = idIn;
score = scoreIn;
showPop();
}
var signFlag = true;
function signIn(obj){
$.ajax({type: "post",url: "{:u_addons(’Sign://Index/sign’)}",data: {},success: function (data) { if(data){ var json = eval(data) $("#alert").show(); if (typeof json.score != "undefined") { $("#alert_text").html("恭喜您获得"+json.score+"积分"); }else{ $("#alert_text").html("对不起,您已签到!"); } }},beforeSend: function () {},complete: function () {}
});
// $("#alert").show();
}
function hideAlert(){
$("#alert").hide();
location.reload();
}
var submitFlag = true;
function submitOrder(){
if (submitFlag == false) {alert("请不要重复操作!");return;
};
var name = $(’#name’).val();
var phone = $(’#phone’).val();
var address = $(’#address’).val();
var note = $(’#note’).val();
if (name.length == 0 || phone.length == 0 || address.length == 0) {alert("请核对输入的信息!");return;
};
submitFlag = false;
$.ajax({type: "post",url: "{:u_addons(’Sign://Index/addOrder’)}",data: { name: name, phone: phone, id: id, score: score, address: address, note: note},success: function (data) { if(data){ hidePop(); alert("商品兑换成功!"); location.reload(); }},beforeSend: function () {},complete: function () {}
});
}
</script>
</body>
</html>

Admin_index.html

<section class="content-header">
<h1>
签到管理
<small></small>
</h1>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<!-- /.col -->
<div class="col-md-12"><div class="box box-danger"> <div class="box-header with-border"> <h3 class="box-title">签到管理</h3> <!-- /.box-tools --> </div> <!-- /.box-header --> <div class="box-body no-padding"> <div class="heading tabs" style="background: transparent;"> <ul class="nav nav-tabs pull-left" data-tabs="tabs" id="tabs"> <li class="active"> <a data-toggle="tab" href="#tab1"><i class="icon-comments"></i><span>签到设置</span></a> </li> <li class=""> <a data-toggle="tab" href="#tab2"><i class="icon-user"></i><span>签到记录</span></a> </li> </ul> </div> <div class="tab-content padded" id="my-tab-content"style="margin-top: 60px;"> <div class="tab-pane active" id="tab1"> <!-- <h3>签到设置</h3> --> <p> <form action="{:u_addons(’Sign://Admin/Admin/addConfig’)}" id="myForm" method="post" onsubmit="return false;" class="form-horizontal"> <div class="form-group"> <label class="control-label col-md-2">签到名称</label> <div class="col-md-7"> <input class="form-control" placeholder="" value="{$config.name}" name="name" type="text"> </div> </div> <div class="form-group"> <label class="control-label col-md-2">首次签到赠送积分</label> <div class="col-md-7"> <input class="form-control" placeholder="" value="{$config.first_sign}" name="first_sign" type="text"> </div> </div> <div class="form-group"> <label class="control-label col-md-2">连续签到增长积分</label> <div class="col-md-7"> <input class="form-control" placeholder="" value="{$config.continue_sign}" name="continue_sign" type="text"> </div> </div> <!-- <div class="form-group"> <label class="control-label col-md-2">最大连续签到天数</label> <div class="col-md-7"> <input class="form-control" placeholder="" value="{$config.max_sign}" name="max_sign" type="text"> </div> </div> --> <div class="form-group"> <label class="control-label col-md-2"></label> <div class="col-md-7"> <button class="btn btn-primary" onclick="myFormSubmit(’{:u_addons(\’Sign://Admin/Admin/index\’)}’)" type="submit">提交 </button> <button class="btn btn-default-outline">取消</button> </div> </div> </form> </p> </div> <div class="tab-pane" id="tab2"> <!-- <h3>签到记录</h3> --> <p> <div class="widget-content padded clearfix"> <table class="table table-hover"> <thead> <th class="check-header hidden-xs"> <label><input id="checkAll" name="checkAll" type="checkbox"><span></span></label> </th> <th> ID </th> <th> 用户名 </th> <th class="hidden-xs"> 积分 </th> <th class="hidden-xs"> 时间 </th> </thead> <tbody> <volist name="record" id="record"> <tr> <td class="check hidden-xs"> <label><input name="optionsRadios1" type="checkbox" value="option1"><span></span></label> </td> <td> {$record.id} </td> <td> {$record.username} </td> <td class="hidden-xs"> {$record.score} </td> <td class="hidden-xs"> {$record.time} </td> </tr> </volist> </tbody> </table> {$page} </div> </p> </div> </div> </div></div><!-- /. box -->
</div>
<!-- /.col -->
</div>
</section>

wemall官网网址:www.wemallshop.com


WeMall微信商城签到插件Sign的主要源码

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: 微信CSS数据UBUT大连
分页:12
转载请注明
本文标题:WeMall微信商城签到插件Sign的主要源码
本站链接:http://www.codesec.net/view/481186.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(34)