WeMall微信商城源码签到插件Sign,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考
WeMall微信商城源码签到插件Sign,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考
AdminController.class.php IndexController.class.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’, "
$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’);
}
}
namespace Addons\Sign\Controller;Index_index.html
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));
}
}
}nbsp;html>
{$user.username}
会员ID: {$user.id}
{$product.name}
style="left: 0px; bottom: 0px; z-index: 3000; position: fixed; display: none;width: 100%;">
<script></script>
<script></script>
<script><br />
var id = 0;<br />
var score = 0;<br />
function hidePop(){<br />
$("#join_box").hide();<br />
$("#cover2").hide();<br />
}<br />
function showPop(){<br />
$("#join_box").show();<br />
$("#cover2").show();<br />
}<br />
function doCart(obj , scoreIn ,idIn){<br />
if(parseFloat(scoreIn) > parseFloat($(’#myscore’).html())){<br />
alert("积分不足!");<br />
return;<br />
}<br />
id = idIn;<br />
score = scoreIn;<br />
showPop();<br />
}<br />
<br />
var signFlag = true;<br />
function signIn(obj){<br />
$.ajax({<br />
type: "post",<br />
url: "{:u_addons(’Sign://Index/sign’)}",<br />
data: {<br />
<br />
},<br />
success: function (data) {<br />
if(data){<br />
var json = eval(data)<br />
$("#alert").show();<br />
if (typeof json.score != "undefined") {<br />
$("#alert_text").html("恭喜您获得"+json.score+"积分");<br />
}else{<br />
$("#alert_text").html("对不起,您已签到!");<br />
}<br />
<br />
}<br />
},<br />
beforeSend: function () {<br />
<br />
},<br />
complete: function () {<br />
}<br />
<br />
});<br />
<br />
// $("#alert").show();<br />
}<br />
function hideAlert(){<br />
$("#alert").hide();<br />
location.reload();<br />
}<br />
var submitFlag = true;<br />
function submitOrder(){<br />
if (submitFlag == false) {<br />
alert("请不要重复操作!");<br />
return;<br />
};<br />
var name = $(’#name’).val();<br />
var phone = $(’#phone’).val();<br />
var address = $(’#address’).val();<br />
var note = $(’#note’).val();<br />
<br />
if (name.length == 0 || phone.length == 0 || address.length == 0) {<br />
alert("请核对输入的信息!");<br />
return;<br />
};<br />
submitFlag = false;<br />
<br />
$.ajax({<br />
type: "post",<br />
url: "{:u_addons(’Sign://Index/addOrder’)}",<br />
data: {<br />
name: name,<br />
phone: phone,<br />
id: id,<br />
score: score,<br />
address: address,<br />
note: note<br />
},<br />
success: function (data) {<br />
if(data){<br />
hidePop();<br />
alert("商品兑换成功!");<br />
location.reload();<br />
}<br />
},<br />
beforeSend: function () {<br />
<br />
},<br />
complete: function () {<br />
}<br />
<br />
});<br />
}<br />
</script>
Admin_index.html
签到管理










