You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/wap/model/user/UserSign.php

88 lines
2.9 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\wap\model\user;
use service\SystemConfigService;
use basic\ModelBasic;
use traits\ModelTrait;
/**用户签到表
* Class UserSign
* @package app\wap\model\user
*/
class UserSign extends ModelBasic
{
use ModelTrait;
public static function checkUserSigned($uid)
{
return UserBill::be(['uid' => $uid, 'add_time' => ['>', strtotime('today')], 'category' => 'gold_num', 'type' => 'sign']);
}
public static function userSignedCount($uid)
{
return self::userSignBillWhere($uid)->count();
}
/**
* @param $uid
* @return Model
*/
public static function userSignBillWhere($uid)
{
return UserBill::where(['uid' => $uid, 'category' => 'gold_num', 'type' => 'sign']);
}
/**近期用户签到记录
* @param $uid
*/
public static function userSignInlist($uid, $page, $limit)
{
$list = self::userSignBillWhere($uid)->field('number,add_time')->order('add_time DESC')
->page((int)$page, (int)$limit)->select();
$list = count($list) > 0 ? $list->toArray() : [];
foreach ($list as &$value) {
$value['add_time'] = date('Y-m-d H:i:s', $value['add_time']);
}
return $list;
}
public static function sign($userInfo, $gold_name)
{
$uid = $userInfo['uid'];
$gold_coin = SystemConfigService::get('single_gold_coin') ?: 0;
$balance = bcadd($gold_coin, $userInfo['gold_num'], 0);
self::beginTrans();
$res1 = UserBill::income('用户签到', $uid, 'gold_num', 'sign', $gold_coin, 0, $balance, '签到获得' . floatval($gold_coin) . $gold_name);
$res2 = User::bcInc($uid, 'gold_num', $gold_coin, 'uid');
$res3 = self::userSign($gold_coin, $uid, $balance);
$res = $res1 && $res2 && $res3;
self::checkTrans($res);
if ($res)
return $gold_coin;
else
return false;
}
public static function userSign($gold_coin, $uid, $balance)
{
$data = [
'uid' => $uid,
'title' => '签到奖励',
'number' => $gold_coin,
'balance' => $balance,
'add_time' => time()
];
return self::set($data);
}
}