最新代码

上级 2ec9bc74
...@@ -16,3 +16,5 @@ composer.lock ...@@ -16,3 +16,5 @@ composer.lock
.svn .svn
.vscode .vscode
node_modules node_modules
application/database.php
public/nginx.htaccess
...@@ -18,6 +18,8 @@ class TtCode extends Backend ...@@ -18,6 +18,8 @@ class TtCode extends Backend
*/ */
protected $model = null; protected $model = null;
protected $noNeedRight = ['admin_user'];
public function _initialize() public function _initialize()
{ {
parent::_initialize(); parent::_initialize();
...@@ -36,5 +38,46 @@ class TtCode extends Backend ...@@ -36,5 +38,46 @@ class TtCode extends Backend
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/ */
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $key => $value) {
$list[$key]['user_id'] = \app\admin\model\User::where('id',$value['user_id'])->value('nickname');
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 搜索下拉框
*/
public function admin_user()
{
$user = \app\admin\model\User::select();
$user = collection($user)->toArray();
foreach ($user as $key => $value) {
$user[$key]['name'] = $value['nickname'];
}
return $user;
}
} }
...@@ -3,7 +3,15 @@ ...@@ -3,7 +3,15 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Backend; use app\common\controller\Backend;
use app\admin\library\Auth;
use Exception;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
/** /**
* 平级奖励 * 平级奖励
* *
...@@ -36,5 +44,86 @@ class TtLevelReward extends Backend ...@@ -36,5 +44,86 @@ class TtLevelReward extends Backend
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/ */
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $key => $value) {
$list[$key]['group_id'] = \app\admin\model\UserGroup::where('id',$value['group_id'])->value('name');
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
$this->view->assign('group_id', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker','disabled']));
return $this->view->fetch();
}
} }
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<div class="widget-body no-padding"> <div class="widget-body no-padding">
<div id="toolbar" class="toolbar"> <div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('tt_code/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> <!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('tt_code/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('tt_code/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('tt_code/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('tt_code/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('tt_code/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('tt_code/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a> <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('tt_code/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul> </ul>
</div> </div> -->
</div> </div>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div class="widget-body no-padding"> <div class="widget-body no-padding">
<div id="toolbar" class="toolbar"> <div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('tt_distribution/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> <!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('tt_distribution/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('tt_distribution/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('tt_distribution/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('tt_distribution/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('tt_distribution/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('tt_distribution/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a> <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('tt_distribution/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul> </ul>
</div> </div> -->
</div> </div>
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Group_id')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Group_id')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-group_id" data-rule="required" data-source="group/index" class="form-control selectpage" name="row[group_id]" type="text" value="{$row.group_id|htmlentities}"> {$group_id}
<!-- <input id="c-group_id" data-rule="required" data-source="group/index" class="form-control selectpage" name="row[group_id]" type="text" value="{$row.group_id|htmlentities}"> -->
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div class="widget-body no-padding"> <div class="widget-body no-padding">
<div id="toolbar" class="toolbar"> <div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('tt_level_reward/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> <!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('tt_level_reward/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('tt_level_reward/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('tt_level_reward/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('tt_level_reward/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('tt_level_reward/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('tt_level_reward/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a> <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('tt_level_reward/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul> </ul>
</div> </div> -->
</div> </div>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Api; use app\common\controller\Api;
use app\common\model\User;
/** /**
* 首页接口 * 首页接口
...@@ -20,4 +21,6 @@ class Index extends Api ...@@ -20,4 +21,6 @@ class Index extends Api
{ {
$this->success('请求成功'); $this->success('请求成功');
} }
} }
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
namespace app\api\controller; namespace app\api\controller;
use app\admin\model\TtCode;
use app\common\controller\Api; use app\common\controller\Api;
use app\common\library\Ems; use app\common\library\Ems;
use app\common\library\Sms; use app\common\library\Sms;
use fast\Random; use fast\Random;
use think\Validate; use think\Validate;
/** /**
* 会员接口 * 会员接口
*/ */
...@@ -37,15 +37,27 @@ class User extends Api ...@@ -37,15 +37,27 @@ class User extends Api
*/ */
public function login() public function login()
{ {
$account = $this->request->request('account'); $account = $this->request->request('username');
$password = $this->request->request('password'); $password = $this->request->request('password');
if (!$account || !$password) { if (!$account || !$password) {
$this->error(__('Invalid parameters')); $this->error(__('Invalid parameters'));
} }
$ret = $this->auth->login($account, $password); $ret = $this->auth->login($account, $password,\app\common\model\User::TYPE_TT);
if ($ret) { if ($ret) {
$data = ['userinfo' => $this->auth->getUserinfo()]; $data = ['userinfo' => $this->auth->getUserinfo()];
$this->success(__('Logged in successful'), $data); //检查并处理押金
$res = \app\common\model\User::depositChange($data['userinfo']['id']);
switch ($res['code']){
case 1:
$this->success(__('Logged in successful'), $data);
break;
case 2:
$this->error('登录失败,账户异常');
break;
default:
$this->error('系统异常');
break;
}
} else { } else {
$this->error($this->auth->getError()); $this->error($this->auth->getError());
} }
...@@ -105,6 +117,7 @@ class User extends Api ...@@ -105,6 +117,7 @@ class User extends Api
$email = $this->request->request('email'); $email = $this->request->request('email');
$mobile = $this->request->request('mobile'); $mobile = $this->request->request('mobile');
$code = $this->request->request('code'); $code = $this->request->request('code');
$code_tt = $this->request->request('code_tt');
if (!$username || !$password) { if (!$username || !$password) {
$this->error(__('Invalid parameters')); $this->error(__('Invalid parameters'));
} }
...@@ -118,8 +131,13 @@ class User extends Api ...@@ -118,8 +131,13 @@ class User extends Api
if (!$ret) { if (!$ret) {
$this->error(__('Captcha is incorrect')); $this->error(__('Captcha is incorrect'));
} }
$ret = $this->auth->register($username, $password, $email, $mobile, []); $ttCodeInfo = TtCode::where('code',$code_tt)->where('parent_id','>',0)->where('status',0)->find();
if ($ret) { if(empty($ttCodeInfo)){
$this->error('无效的站长码');
}
$ret = $this->auth->register($username, $password, $email, $mobile, [],[],$ttCodeInfo['parent_id'],\app\common\model\User::TYPE_TT);
$resMoney = \app\common\model\User::money(10,$ttCodeInfo['parent_id'],'拉新注册');
if ($ret && $resMoney){
$data = ['userinfo' => $this->auth->getUserinfo()]; $data = ['userinfo' => $this->auth->getUserinfo()];
$this->success(__('Sign up successful'), $data); $this->success(__('Sign up successful'), $data);
} else { } else {
...@@ -323,4 +341,6 @@ class User extends Api ...@@ -323,4 +341,6 @@ class User extends Api
$this->error($this->auth->getError()); $this->error($this->auth->getError());
} }
} }
} }
...@@ -131,23 +131,23 @@ class Auth ...@@ -131,23 +131,23 @@ class Auth
* @param array $extend 扩展参数 * @param array $extend 扩展参数
* @return boolean * @return boolean
*/ */
public function register($username, $password, $email = '', $mobile = '',$popularizeId = '', $extend = []) public function register($username, $password, $email = '', $mobile = '',$popularizeId = '', $extend = [],$parent_id='',$type=User::TYPE_YNS)
{ {
// 检测用户名、昵称、邮箱、手机号是否存在 // 检测用户名、昵称、邮箱、手机号是否存在
if (User::getByUsername($username)) { if (User::getByUsername($username)) {
$this->setError('Username already exist'); $this->setError(__('Username already exist'));
return false; return false;
} }
if (User::getByNickname($username)) { if (User::getByNickname($username)) {
$this->setError('Nickname already exist'); $this->setError(__('Nickname already exist'));
return false; return false;
} }
if ($email && User::getByEmail($email)) { if ($email && User::getByEmail($email)) {
$this->setError('Email already exist'); $this->setError(__('Email already exist'));
return false; return false;
} }
if ($mobile && User::getByMobile($mobile)) { if ($mobile && User::getByMobile($mobile)) {
$this->setError('Mobile already exist'); $this->setError(__('Moile already existb'));
return false; return false;
} }
...@@ -163,6 +163,8 @@ class Auth ...@@ -163,6 +163,8 @@ class Auth
'level' => 1, 'level' => 1,
'score' => 0, 'score' => 0,
'avatar' => '', 'avatar' => '',
'parent_id'=>$parent_id,
'type' =>$type
]; ];
$params = array_merge($data, [ $params = array_merge($data, [
'nickname' => preg_match("/^1[3-9]{1}\d{9}$/",$username) ? substr_replace($username,'****',3,4) : $username, 'nickname' => preg_match("/^1[3-9]{1}\d{9}$/",$username) ? substr_replace($username,'****',3,4) : $username,
...@@ -172,7 +174,9 @@ class Auth ...@@ -172,7 +174,9 @@ class Auth
'logintime' => $time, 'logintime' => $time,
'loginip' => $ip, 'loginip' => $ip,
'prevtime' => $time, 'prevtime' => $time,
'status' => 'normal' 'status' => 'normal',
'parent_id' => $parent_id,
'type' => $type
]); ]);
$params['password'] = $this->getEncryptPassword($password, $params['salt']); $params['password'] = $this->getEncryptPassword($password, $params['salt']);
$params = array_merge($params, $extend); $params = array_merge($params, $extend);
...@@ -209,10 +213,10 @@ class Auth ...@@ -209,10 +213,10 @@ class Auth
* @param string $password 密码 * @param string $password 密码
* @return boolean * @return boolean
*/ */
public function login($account, $password) public function login($account, $password,$type=1)
{ {
$field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username'); $field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username');
$user = User::get([$field => $account]); $user = User::get([$field => $account,'type'=>$type]);
if (!$user) { if (!$user) {
$this->setError('Account is incorrect'); $this->setError('Account is incorrect');
return false; return false;
......
<?php
namespace app\common\model;
use think\Model;
/**
* 平级分销
*/
class TtCode Extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 修改邀请码状态
* @param $user_id
* @param $parent_id
* @param $code
* @return TtCode
*/
public static function updateCode($user_id,$parent_id,$code)
{
return self::where('code',$code)->update(['status'=>1,'user_id'=>$user_id,'parent_id'=>$parent_id]);
}
}
<?php
namespace app\common\model;
use think\Model;
/**
* 三级分销
*/
class TtDistribution Extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $updateTime = false;
// 追加属性
protected $append = [
];
}
<?php
namespace app\common\model;
use think\Model;
/**
* 订单
*/
class TtEx Extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $updateTime = false;
// 追加属性
protected $append = [
];
const HEAD_SALES = 10%; // 团长销售比例
const MINISTER_SALES = 15%; // 部长销售比例
const PARTNERSHIP_SALES = 18%; // 合伙人销售比例
public static function sale($code_id)
{
$info = self::where('code_id',$code_id)->field('real_money')->select();
var_dump(expression)
// if($info){
// }
}
}
<?php
namespace app\common\model;
use think\Model;
/**
* 平级分销
*/
class TtLevelReward Extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 获取平级奖励价格
* @param $group_id 角色ID
* @return bool|float|mixed|string|null
*/
public static function getPrice($group_id)
{
return self::where('group_id',$group_id)->value('price');
}
}
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
namespace app\common\model; namespace app\common\model;
use app\admin\controller\general\Profile;
use app\admin\model\TtCode;
use think\Db;
use think\Model; use think\Model;
/** /**
* 会员模型 * 会员模型
*/ */
...@@ -20,6 +22,14 @@ class User extends Model ...@@ -20,6 +22,14 @@ class User extends Model
'url', 'url',
]; ];
const NEW_REWARD = 500; //拉新奖励
const STATUS_TRUE = 'normal';//用户状态正常
const STATUS_FALSE = 'hidden'; //用户状态禁用
const TYPE_TT = 2;//陶特分销
const TYPE_YNS = 1;//陶特易农社
/** /**
* 获取个人URL * 获取个人URL
* @param string $value * @param string $value
...@@ -135,4 +145,234 @@ class User extends Model ...@@ -135,4 +145,234 @@ class User extends Model
} }
return $level; return $level;
} }
/**
* 减少余额
* @param $money 金额
* @param $user_id 用户ID
* @param $memo 注释
* @throws \think\exception\DbException
*/
public static function subMoney($money,$user_id,$memo)
{
$user = self::get($user_id);
if ($user && $money != 0) {
$before = $user->money;
$after = function_exists('bcsub') ? bcsub($user->money, $money, 2) : $user->user - $money;
if($after < 0) return false;
//更新会员信息
$user->save(['money' => $after]);
//写入日志
MoneyLog::create(['user_id' => $user_id, 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => $memo]);
return true;
}
}
/**
* 变更冻结金额
* @param int $money 余额
* @param int $user_id 会员ID
* @param string $memo 备注
*/
public static function frozen($money, $user_id,$type)
{
$user = self::get($user_id);
if ($user && $money != 0) {
if($type == 1){
//增加冻结金额
$after = function_exists('bcadd') ? bcadd($user->frozen, $money, 2) : $user->frozen + $money;
$user->save(['frozen' => $after]);
return True;
}else{
//减少冻结金额
$after = function_exists('bcsub') ? bcsub($user->frozen, $money, 2) : $user->frozen - $money;
if($after < 0)return false;
$user->save(['frozen' => $after]);
return true;
}
}
}
/**
* 检测用户名是否存在
* @param $username
*/
public static function getByUsername($username)
{
return self::where('username',$username)->where('status',self::STATUS_TRUE)->find();
}
/**
* 检测昵称是否存在
* @param $nickname
*/
public static function getByNickname($nickname)
{
return self::where('nickname',$nickname)->where('status',self::STATUS_TRUE)->find();
}
/**
* 检测邮箱是否存在
* @param $nickname
*/
public static function getByEmail($email)
{
return self::where('email',$email)->where('status',self::STATUS_TRUE)->find();
}
/**
* 检测手机号是否存在
* @param $mobile
*/
public static function getByMobile($mobile)
{
return self::where('mobile',$mobile)->where('status',self::STATUS_TRUE)->find();
}
/**
* 扣除金额,解除上级冻结金额
* @throws \think\exception\DbException
*/
public static function depositChange($user_id)
{
$info = self::get($user_id);
Db::startTrans();
//获取创建30天后的时间戳
try{
$nextMonth = $info->createtime + 86400 * 30;
//判断是否交了押金
if($info->is_deposit == 1) ['code'=>1];
if($info->money >= self::NEW_REWARD){
//扣除用户余额
self::subMoney(self::NEW_REWARD,$user_id,'扣除服务费');
//解除上级冻结金额
self::frozen(self::NEW_REWARD,$info->parent_id,2);
//返还上级冻结金额
self::money(self::NEW_REWARD,$info->parent_id,'返回冻结金额');
//记录已交押金
self::where('id',$user_id)->update(['is_deposit'=>1]);
Db::commit();
return ['code'=>1];
}else if($nextMonth < time()){
//禁用账户
self::where('id',$user_id)->update(['status'=>self::STATUS_FALSE]);
//恢复站长码
TtCode::where('user_id',$user_id)->update(['status'=>0,'user_id'=>self::STATUS_FALSE]);
//将最后余额返还上级
self::money($info->money,$info->parent_id,'返回冻结金额');
//根据用户余额 解除上级冻结金额
self::frozen($info->money,$info->parent_id,2);
//清空用户余额
self::where('id',$user_id)->update(['money'=>0]);
Db::commit();
return ['code'=>2];
}else{
return ['code'=>1];
}
}catch (\Exception $e){
dump($e->getMessage());
Db::rollback();
return false;
}
}
/**
* 检测账户是否可以晋升 (缺少条件 :订单判断)
* @param $user_id
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public static function testGroup($user_id)
{
$info = self::get($user_id);
switch ($info['group_id']){
case 3:
$count = self::where('parent_id',$user_id)->where('status',self::STATUS_TRUE)->where('group_id',3)->count();
if($count >= 5){
$group_id = 2;
}
break;
case 2:
$count = self::where('parent_id',$user_id)->where('status',self::STATUS_TRUE)->where('group_id',2)->count();
if($count >= 5){
$group_id = 1;
}
break;
}
}
/*
* 三级分销
* @param int $money 金额
* @param int $user_id 用户
*/
public static function distribution($money, $user_id)
{
// 查询用户信息
$user = self::get($user_id);
if(!$user){
return ['code'=>0];
}
// 查询三级分销比例
$distribution = TtDistribution::where('id',1)->find();
// 计算分销金额
$distribution_money = $money * ($distribution['primary_distribution']/100 + $distribution['secondary_distribution']/100 +$distribution['third_distribution']/100);
// 计算现有余额扣除分销金额
$now_money = $user->money + ($money - $distribution_money);
// 更新用户的余额
$user_money = self::where('id',$user_id)->update(['money' => $now_money]);
// 一级分销开始
if($user->parent_id != 0){
// 查询我的直属上级
$first_level = self::where('id',$user->parent_id)->find();
// 计算直属上级的余额加上分销的金额
$first_distribution = $money * ($distribution['primary_distribution']/100) + $first_level['money'];
// 更新直属上级的余额
$first_user_money = self::where('id',$first_level['id'])->update(['money' => $first_distribution]);
// 写入余额变动日志
if($first_user_money){
MoneyLog::create(['user_id' => $first_level['id'], 'money' => $money * ($distribution['primary_distribution']/100), 'before' => $first_level['money'], 'after' => $first_user_money, 'memo' => '直属上级获得佣金']);
}
//二级分销开始
if($first_level['parent_id'] != 0){
// 查询我上级的上级
$second_level = self::where('id',$first_level['parent_id'])->find();
// 计算二级上级的余额加上分销的金额
$second_distribution = $money * ($distribution['secondary_distribution']/100) + $second_level['money'];
// 更新二级上级的余额
$second_user_money = self::where('id',$second_level['id'])->update(['money' => $second_distribution]);
// 写入余额变动日志
if($second_user_money){
MoneyLog::create(['user_id' => $second_level['id'], 'money' => $money * ($distribution['secondary_distribution']/100), 'before' => $second_level['money'], 'after' => $second_user_money, 'memo' => '二级上级获得佣金']);
}
//三级分销开始
if($second_level['parent_id'] != 0){
// 查询我上级的上级的上级
$third_level = self::where('id',$second_level['parent_id'])->find();
// 计算三级上级的余额加上分销的金额
$third_distribution = $money * ($distribution['third_distribution']/100) + $third_level['money'];
// 更新三级上级的余额
$third_user_money = self::where('id',$third_level['id'])->update(['money' => $third_distribution]);
// 写入余额变动日志
if($third_user_money){
MoneyLog::create(['user_id' => $third_level['id'], 'money' => $money * ($distribution['third_distribution']/100), 'before' => $third_level['money'], 'after' => $third_user_money, 'memo' => '三级上级获得佣金']);
}
}
//三级分销技术
}
//二级分销结束
}
//一级分销结束
if($user_money){
// 写入余额变动日志
MoneyLog::create(['user_id' => $user_id, 'money' => $money - $distribution_money, 'before' => $user->money, 'after' => $now_money, 'memo' => '分销获得佣金']);
return true;
} else {
return false;
}
}
} }
...@@ -20,9 +20,9 @@ return [ ...@@ -20,9 +20,9 @@ return [
// 数据库名 // 数据库名
'database' => Env::get('database.database', 'taote'), 'database' => Env::get('database.database', 'taote'),
// 用户名 // 用户名
'username' => Env::get('database.username', 'taote'), 'username' => Env::get('database.username', 'root'),
// 密码 // 密码
'password' => Env::get('database.password', 'R6azbxHLxhyFDBMA'), 'password' => Env::get('database.password', 'root'),
// 端口 // 端口
'hostport' => Env::get('database.hostport', ''), 'hostport' => Env::get('database.hostport', ''),
// 连接dsn // 连接dsn
......
...@@ -183,7 +183,7 @@ class User extends Frontend ...@@ -183,7 +183,7 @@ class User extends Frontend
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]); $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
return false; return false;
} }
if ($this->auth->login($account, $password)) { if ($this->auth->login($account, $password,\app\common\model\User::TYPE_YNS)) {
$this->success(__('Logged in successful'), $url ? $url : url('index/order')); $this->success(__('Logged in successful'), $url ? $url : url('index/order'));
} else { } else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]); $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
......
...@@ -22,15 +22,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -22,15 +22,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url, url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id', pk: 'id',
sortName: 'id', sortName: 'id',
// 搜索按钮框展开
searchFormVisible: true,
// 隐藏搜索按钮
showSearch: false,
//隐藏搜索框
search:false,
//隐藏切换按钮
showToggle: false,
//隐藏列按钮
showColumns: false,
//隐藏导出按钮
showExport: false,
columns: [ columns: [
[ [
{checkbox: true}, // {checkbox: true},
{field: 'id', title: __('Id')}, {field: 'id', title: __('Id'), operate:false},
{field: 'code', title: __('Code')}, {field: 'code', title: __('Code'), operate:'LIKE'},
{field: 'user_id', title: __('User_id')}, {field: 'user_id', title: __('User_id'), searchList: $.getJSON('tt_code/admin_user')},
{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status}, {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
] ]
] ]
}); });
......
...@@ -6,9 +6,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -6,9 +6,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
Table.api.init({ Table.api.init({
extend: { extend: {
index_url: 'tt_distribution/index' + location.search, index_url: 'tt_distribution/index' + location.search,
add_url: 'tt_distribution/add', // add_url: 'tt_distribution/add',
edit_url: 'tt_distribution/edit', edit_url: 'tt_distribution/edit',
del_url: 'tt_distribution/del', // del_url: 'tt_distribution/del',
multi_url: 'tt_distribution/multi', multi_url: 'tt_distribution/multi',
import_url: 'tt_distribution/import', import_url: 'tt_distribution/import',
table: 'tt_distribution', table: 'tt_distribution',
...@@ -22,13 +22,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -22,13 +22,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url, url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id', pk: 'id',
sortName: 'id', sortName: 'id',
// 隐藏搜索按钮
showSearch: false,
//隐藏搜索框
search:false,
//隐藏切换按钮
showToggle: false,
//隐藏列按钮
showColumns: false,
//隐藏导出按钮
showExport: false,
columns: [ columns: [
[ [
{checkbox: true}, // {checkbox: true},
{field: 'id', title: __('Id')}, // {field: 'id', title: __('Id')},
{field: 'primary_distribution', title: __('Primary_distribution')}, {field: 'primary_distribution', title: __('Primary_distribution'), formatter: Controller.api.formatter.percent},
{field: 'secondary_distribution', title: __('Secondary_distribution')}, {field: 'secondary_distribution', title: __('Secondary_distribution'), formatter: Controller.api.formatter.percent},
{field: 'third_distribution', title: __('Third_distribution')}, {field: 'third_distribution', title: __('Third_distribution'), formatter: Controller.api.formatter.percent},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
] ]
] ]
...@@ -46,6 +56,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -46,6 +56,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
api: { api: {
bindevent: function () { bindevent: function () {
Form.api.bindevent($("form[role=form]")); Form.api.bindevent($("form[role=form]"));
},
formatter: {
percent:function(value, row) {
return '<span>'+value+'%</span>';
}
} }
} }
}; };
......
...@@ -8,7 +8,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -8,7 +8,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
index_url: 'tt_level_reward/index' + location.search, index_url: 'tt_level_reward/index' + location.search,
add_url: 'tt_level_reward/add', add_url: 'tt_level_reward/add',
edit_url: 'tt_level_reward/edit', edit_url: 'tt_level_reward/edit',
del_url: 'tt_level_reward/del', // del_url: 'tt_level_reward/del',
multi_url: 'tt_level_reward/multi', multi_url: 'tt_level_reward/multi',
import_url: 'tt_level_reward/import', import_url: 'tt_level_reward/import',
table: 'tt_level_reward', table: 'tt_level_reward',
...@@ -22,12 +22,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -22,12 +22,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url, url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id', pk: 'id',
sortName: 'id', sortName: 'id',
// 隐藏搜索按钮
showSearch: false,
//隐藏搜索框
search:false,
//隐藏切换按钮
showToggle: false,
//隐藏列按钮
showColumns: false,
//隐藏导出按钮
showExport: false,
columns: [ columns: [
[ [
{checkbox: true}, // {checkbox: true},
{field: 'id', title: __('Id')}, // {field: 'id', title: __('Id')},
{field: 'group_id', title: __('Group_id')}, {field: 'group_id', title: __('Group_id')},
{field: 'price', title: __('Price'), operate:'BETWEEN'}, {field: 'price', title: __('Price'), operate:'BETWEEN',formatter: Controller.api.formatter.company},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
] ]
] ]
...@@ -45,6 +55,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -45,6 +55,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
api: { api: {
bindevent: function () { bindevent: function () {
Form.api.bindevent($("form[role=form]")); Form.api.bindevent($("form[role=form]"));
},
formatter: {
company:function(value, row) {
return '<span>'+value+'元/单</span>';
}
} }
} }
}; };
......
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论