add-liche-credit

This commit is contained in:
lccsw
2022-07-20 10:46:53 +08:00
parent 64419e1d6a
commit 94b5647b6b
12 changed files with 583 additions and 11 deletions
+123
View File
@@ -7,6 +7,8 @@ class Member extends HD_Controller{
{
parent::__construct();
$this->load->model('app/liche/App_liche_users_model', 'userM');
$this->load->model('app/liche/app_liche_credits_log_model');
$this->load->library('entity/credits_entity');
}
//首页信息
@@ -149,4 +151,125 @@ class Member extends HD_Controller{
{
}
//冻结资金
public function get_freeze(){
$uid = $this->input->get_post('uid');
$user = $this->userM->get(['id'=>$uid]);
if(!$user){
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
if($this->input->method() == 'post'){
$credit = abs(intval($this->input->post('credits')));
$result = $this->credits_entity->freeze($uid,$credit,1);
if($result['code']){
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL, $result['msg']);
}
}
$this->data['uid'] = $uid;
$this->data['user'] = $user;
return $this->show_view('app/liche/member/get_freeze');
}
//增加积分
public function add_credit(){
$uid = $this->input->get_post('uid');
$user = $this->userM->get(['id'=>$uid]);
if(!$user){
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
if($this->input->method() == 'post'){
$credits = abs(intval($this->input->post('credits')));
$remark = $this->input->post('remark');
$type = $this->input->post('type');
$jsondata['admin_id'] = $this->uid;
$result = $this->credits_entity->change($uid,$credits,4,0,$remark,$jsondata);
if($result['code']){
if($type==2){
$this->credits_entity->freeze($uid,$credits);
}
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
}else{
return $this->show_json(SYS_CODE_FAIL, $result['msg']);
}
}
$this->data['uid'] = $uid;
$this->data['user'] = $user;
return $this->show_view('app/liche/member/add_credit');
}
public function get_credit_log(){
$params = $this->input->get();
$page = $params['page'];
$size = $params['size'];
!$page && $page = 1;
!$size && $size = 40;
$where = [];
if(strlen($params['type'])){
$where['type'] = $params['type'];
}else{
$params['type'] = '';
}
$params['uid'] && $where['uid'] = $params['uid'];
$type_arr = $this->app_liche_credits_log_model->get_type();
$count = $this->app_liche_credits_log_model->count($where);
$lists = [];
if($count){
$rows = $this->app_liche_credits_log_model->select($where,'id desc',$page,$size);
$uids_arr = array_unique(array_column($rows,'uid'));
$users = [];
if($uids_arr){
$uids_str = implode(',',$uids_arr);
$u_where = [
"id in ({$uids_str})" => null
];
$users = $this->userM->map('id','nickname',$u_where,'id desc',0,0,'id,nickname');
}
foreach($rows as $item){
$item['type_cn'] = $type_arr[$item['type']];
$item['nickname'] = $users[$item['uid']];
$lists[] = $item;
}
}
$this->data['params'] = $params;
$this->data['type_arr'] = $type_arr;
$this->data['lists'] = $lists;
$this->data['_title'] = '积分日志';
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
return $this->show_view('app/liche/member/credit_log_lists',true);
}
//兑换积分
public function add_items(){
$uid = $this->input->get_post('uid');
$user = $this->userM->get(['id'=>$uid]);
if(!$user){
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
if($this->input->method() == 'post'){
$credits = -1 * abs(intval($this->input->post('credits')));
$remark = $this->input->post('remark');
$item_title = $this->input->post('item_title');
$item_code = $this->input->post('item_code');
$jsondata['admin_id'] = $this->uid;
$jsondata['item_title'] = $item_title;
$jsondata['item_code'] = $item_code;
$result = $this->credits_entity->change($uid,$credits,5,0,$remark,$jsondata);
if($result['code']){
return $this->show_json(SYS_CODE_SUCCESS, '兑换成功');
}else{
return $this->show_json(SYS_CODE_FAIL, $result['msg']);
}
}
$this->data['uid'] = $uid;
$this->data['user'] = $user;
return $this->show_view('app/liche/member/add_items');
}
}
@@ -0,0 +1,39 @@
<form class="am-form am-form-horizontal" action="/app/liche/member/add_credit" data-auto="true" method="post" style="width: 90%;padding-top: 10px">
<div class="am-form-group">
<label class="am-para-label">总积分:</label>
<div class="am-para-input">
<span class="f12 lh-default ml5 text-danger"><?=$user['credits']+$user['freeze_credits']?></span>
(<span class="f12 clr999 lh-default ml5 text-danger">可用积分:<?=$user['credits']?>,冻结:<?=$user['freeze_credits']?></span>)
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">积分:</label>
<div class="am-para-input">
<input type="number" placeholder="输入积分" name="credits" style="width: 150px; display: inline;">
<!-- <span class="f12 clr999 lh-default ml5">小于0扣除积分,大于0增加积分</span>-->
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">积分类型:</label>
<div class="am-para-input w140">
<select name="type">
<option value="1">可用</option>
<option value="2">冻结</option>
</select>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">备注:</label>
<div class="am-para-input">
<textarea name="remark"></textarea>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<input name="uid" value="<?=$uid?>" type="hidden">
<div class="am-para-input">
<button class="am-btn am-btn-secondary" type="submit">保存</button>
</div>
</div>
</form>
@@ -0,0 +1,41 @@
<form class="am-form am-form-horizontal" action="/app/liche/member/add_items" data-auto="true" method="post" style="width: 90%;padding-top: 10px">
<div class="am-form-group">
<label class="am-para-label">总积分:</label>
<div class="am-para-input">
<span class="f12 lh-default ml5 text-danger"><?=$user['credits']+$user['freeze_credits']?></span>
(<span class="f12 clr999 lh-default ml5 text-danger">可用积分:<?=$user['credits']?>,冻结:<?=$user['freeze_credits']?></span>)
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">消耗积分:</label>
<div class="am-para-input">
<input type="number" placeholder="输入积分" name="credits" style="width: 150px; display: inline;">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">商品名称:</label>
<div class="am-para-input">
<input type="text" placeholder="输入商品名称" name="item_title">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">兑换码:</label>
<div class="am-para-input">
<input type="text" placeholder="输入兑换码" name="item_code">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">备注:</label>
<div class="am-para-input">
<textarea name="remark"></textarea>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<input name="uid" value="<?=$uid?>" type="hidden">
<div class="am-para-input">
<button class="am-btn am-btn-secondary" type="submit">保存</button>
</div>
</div>
</form>
+79
View File
@@ -0,0 +1,79 @@
<div class="coms-table-wrap mt10">
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/app/liche/member/get_credit_log">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">用户id</label>
<div class="am-para-inline w150">
<input type="text" name="uid" value="" v-model="params.uid"/>
</div>
</div>
<div class="am-form-group fl">
<label class="am-para-label w100">积分类型:</label>
<div class="am-para-inline w150">
<select name="type" v-model="params.type">
<option value="">全部</option>
<option v-for="(value,key) in type_arr" :value="key">{{value}}</option>
</select>
</div>
</div>
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
</div>
</form>
<div class="coms-table-bd">
<div class="fr">共有<?= $pager['totle'] ?>条数据</div>
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="10%"><span>ID</span></th>
<th width="15%"><span>用户</span></th>
<th width="10%"><span>收入积分</span></th>
<th width="10%"><span>支出积分</span></th>
<th width="10%"><span>剩余积分</span></th>
<th width="10%"><span>类型</span></th>
<th width=""><span>备注</span></th>
<th width="12%"><span>创建时间</span></th>
</tr>
</thead>
<tbody>
<?php foreach ($lists as $v) { ?>
<tr>
<td><?= $v['id'] ?></td>
<td><?= $v['nickname'] ?></td>
<td><?= $v['credit_in'] ?></td>
<td><?= $v['credit_out'] ?></td>
<td><?= $v['credit_left'] ?></td>
<td><?= $v['type_cn'] ?></td>
<td><?= $v['remark'] ?></td>
<td><?= date('Y-m-d H:i',$v['c_time']) ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
var vm = new Vue({
el: '#vue-app',
data: {
lists: [],
params: <?=json_encode($params,JSON_UNESCAPED_UNICODE)?>,
type_arr : <?=json_encode($type_arr,JSON_UNESCAPED_UNICODE)?>,
},
mounted() {
var that = this;
that.lists = <?=json_encode($lists,JSON_UNESCAPED_UNICODE)?>;
},
created: function () {
},
methods: {}
})
</script>
@@ -0,0 +1,22 @@
<form class="am-form am-form-horizontal" action="/app/liche/member/get_freeze" data-auto="true" method="post" style="width: 90%;padding-top: 10px">
<div class="am-form-group">
<label class="am-para-label">总积分:</label>
<div class="am-para-input">
<span class="f12 lh-default ml5 text-danger"><?=$user['credits']+$user['freeze_credits']?></span>
(<span class="f12 clr999 lh-default ml5 text-danger">可用积分:<?=$user['credits']?>,冻结:<?=$user['freeze_credits']?></span>)
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">积分:</label>
<div class="am-para-input">
<input type="number" placeholder="输入积分" name="credits" style="width: 150px; display: inline;">
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<input name="uid" value="<?=$uid?>" type="hidden">
<div class="am-para-input">
<button class="am-btn am-btn-secondary" type="submit">保存</button>
</div>
</div>
</form>
+22 -11
View File
@@ -27,10 +27,11 @@
<th width="10%"><span>ID</span></th>
<th width="20%"><span>用户名称</span></th>
<th width="20%"><span>手机号码</span></th>
<th width="5%"><span>是否分销</span></th>
<th width="5%"><span>分销管理</span></th>
<th width="20%"><span>创建时间</span></th>
<th>操作</th>
<th width="10%"><span>剩余积分</span></th>
<th width="10%"><span>冻结积分</span></th>
<th width="8%"><span>是否分销</span></th>
<th width="8%"><span>分销管理</span></th>
<th width=""><span>创建时间</span></th>
</tr>
</thead>
<tbody>
@@ -39,6 +40,8 @@
<td><?= $v['id'] ?></td>
<td><?= $v['nickname'] ?></td>
<td><?= $v['mobile'] ?></td>
<td><?= $v['credits'] ?></td>
<td><?= $v['freeze_credits'] ?></td>
<td>
<input type="checkbox" class="mui-switch mui-switch-anim va-mid" true-value="1" false-value="0" <?=$v['dealer']&&!$v['up_uid']?'checked':''?> onchange="set_publish(this,<?=$v['id']?>)"/>
</td>
@@ -46,7 +49,21 @@
<input type="checkbox" class="mui-switch mui-switch-anim va-mid" true-value="1" false-value="0" <?=$v['manage']?'checked':''?> onchange="set_publish(this,<?=$v['id']?>,'manage')"/>
</td>
<td><?= date('Y-m-d H:i:s',$v['c_time']) ?></td>
<td>
</tr>
<tr>
<td colspan="8" class="align-r">
<a class="am-btn am-btn-primary am-btn-xs" data-modal="/app/liche/member/add_items?uid=<?=$v['id']?>" data-title="兑换商品">
兑换商品
</a>
<a class="am-btn am-btn-primary am-btn-xs" data-modal="/app/liche/member/add_credit?uid=<?=$v['id']?>" data-title="增加减少积分">
增加积分
</a>
<a class="am-btn am-btn-primary am-btn-xs" data-modal="/app/liche/member/get_freeze?uid=<?=$v['id']?>" data-title="解冻积分">
解冻积分
</a>
<a class="am-btn am-btn-primary am-btn-xs" data-open="/app/liche/member/get_credit_log?uid=<?=$v['id']?>">
积分日志
</a>
<?if($v['umajia']){?>
<a class="am-btn am-btn-primary am-btn-xs" data-open="/app/appusual/umajia/get?uid=<?=$v['id']?>&app_id=<?=$app_id?>" data-title="编辑马甲">编辑马甲</a>
<a href="javascript:void(0)" data-ajax="post" data-action="/app/appusual/umajia/del?app_id=<?=$app_id?>"
@@ -56,12 +73,6 @@
<?}?>
</td>
</tr>
<!--
<tr>
<td colspan="3" class="align-r">
</td>
</tr>
-->
<?php } ?>
</tbody>
</table>
+4
View File
@@ -11,5 +11,9 @@ class Welcome extends CI_Controller {
}
public function test(){
$this->load->library('entity/credits_entity');
// $res = $this->credits_entity->change(4,10);
$res = $this->credits_entity->freeze(4,10,1);
print_r($res);
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by Vim
* User: lcc
* Desc: 用户积分
* Date: 2022.07.20
* Time: 14:14
*/
require_once APPPATH.'controllers/wxapp/Wxapp.php';
class Credit extends Wxapp{
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
$this->load->model('app/liche/app_liche_credits_log_model');
}
protected function get(){
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 20;
$where = [
'uid' => $this->session['uid']
];
$count = $this->app_liche_credits_log_model->count($where);
$list = [];
if($count){
$fileds = 'id,credit_in,credit_out,remark,type,c_time';
$rows = $this->app_liche_credits_log_model->select($where,'id desc',$page,$size,$fileds);
$type_arr = $this->app_liche_credits_log_model->get_type();
foreach ($rows as $item) {
$title = $type_arr[$item['type']];
$money = $item['credit_in'] ? "+{$item['credit_in']}" : "-{$item['credit_out']}";
$temp = [
'id' => $item['id'],
'title' => $title,
'desc' => $item['remark'] ? $item['remark'] : '',
'money' => $money
];
$list[] = $temp;
}
}
$data = [
'list' => $list,
'total' => $count,
'bg_list' => [
'https://qs.haodian.cn/wechat_app/liche/topicActivity/lantushijia/ex-1.jpg'
]
];
return $data;
}
protected function get_rule(){
$data = [
'title' => '规则标题',
'content' => '活动规则',
];
return $data;
}
}
+3
View File
@@ -100,6 +100,8 @@ class User extends Wxapp{
],
'isdealer' => $this->session['dealer'],
'istop' => $istop,
'credits' => $user['credits'],
'freeze_credits' => $user['freeze_credits']
);
return $data;
@@ -237,6 +239,7 @@ class User extends Wxapp{
'have_new' => $un_pay ? true : false
],
['title'=>'我的爱车','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-1.png','url'=>'/pages/mine/myCar/index'],
['title'=>'我的积分','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-6.png','url'=>'/pages/topicActivity/integral/index'],
['title'=>'联系小狸','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-3.png'],
];
if($this->session['dealer'] || $this->session['manage']){
+125
View File
@@ -0,0 +1,125 @@
<?php
/**
* Created by PhpStorm.
* User: lcc
* Date: 2022/07/14
* Time: 09:40
*/
class Credits_entity{
private $ci;
public function __construct(){
$this->ci = get_instance();
$this->ci->load->model('app/liche/app_liche_users_model');
$this->ci->load->model('app/liche/app_liche_credits_log_model');
}
/**
* 积分变动
* @param $uid 用户id
* @param $credit 积分
* @param $type 类型 0活动 1派单成功 2完成试驾 3开票 4后台录入 5兑换商品
* @param $target_id 来源id
* @param $remark 备注
* @param $jsondata 其它json数据
* @return array
*/
public function change($uid,$credit,$type=0,$target_id=0,$remark='',$jsondata=[]){
if(!$uid || !$credit){
return ['code'=>0 ,'msg'=>'参数错误'];
}
$row = $this->ci->app_liche_users_model->get(['id'=>$uid]);
if(!$row){
return ['code'=>0 ,'msg'=>'用户不存在'];
}
try {
$this->ci->db->trans_begin();
$up_where = [
'id' => $uid
];
$credit_left = $row['credits']+$row['freeze_credits'];
if($credit>0){
$up_credit = [
"credits = credits+{$credit}" => null
];
$credit_left += $credit;
}else{
$credit_out = abs($credit);
$up_credit = [
"credits = credits-{$credit_out}" => null
];
$up_where["credits >="] = abs($credit_out);
$credit_left -= $credit_out;
}
$this->ci->app_liche_users_model->update($up_credit,$up_where);
$user_aff_rows = $this->ci->app_liche_users_model->db->affected_rows();
if(!$user_aff_rows){
throw new Exception('积分不足');
}
$add_log = [
'uid' => $uid,
'type' => $type,
'credit_left' => $credit_left,
'c_time' => time()
];
if($credit>0){
$add_log['credit_in'] = $credit;
}else{
$add_log['credit_out'] = abs($credit);
}
$target_id && $add_log['target_id'] = $target_id;
$remark && $add_log['remark'] = $remark;
$jsondata && $add_log['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
$this->ci->app_liche_credits_log_model->add($add_log);
$log_aff_rows = $this->ci->app_liche_users_model->db->affected_rows();
if(!$log_aff_rows){
throw new Exception('积分不足');
}
$this->ci->db->trans_commit();
return ['code'=>1,'msg'=>'操作成功'];
}catch (Exception $e){
$this->ci->db->trans_rollback();
return ['code'=>0,'msg'=>$e->getMessage()];
}
}
/**
* 冻结积分
* @param $uid
* @param $credit
* @param $type (0冻结资金 1解冻资金)
* @return array
*/
public function freeze($uid,$credit,$type=0){
$row = $this->ci->app_liche_users_model->get(['id'=>$uid]);
$where = [
'id' => $uid
];
if($type){
if($row['freeze_credits']<$credit){
return ['code'=>0,'msg'=>'积分不足'];
}
$update = [
"credits = credits+{$credit}" => null,
"freeze_credits = freeze_credits-{$credit}" => null
];
$where['freeze_credits>='] = $credit;
}else{
if($row['credits']<$credit){
return ['code'=>0,'msg'=>'冻结积分不足'];
}
$update = [
"credits = credits-{$credit}" => null,
"freeze_credits = freeze_credits+{$credit}" => null
];
$where['credits>='] = $credit;
}
$this->ci->app_liche_users_model->update($update,$where);
$aff_rows = $this->ci->app_liche_users_model->db->affected_rows();
if($aff_rows){
return ['code'=>1,'msg'=>'操作成功'];
}else{
return ['code'=>0,'msg'=>'操作失败'];
}
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Created by Vim.
* User: lcc
* Date: 2022/07/14
* Time: 15:18
*/
class App_liche_credits_log_model extends HD_Model{
private $table_name = 'lc_app_liche_credits_log';
private $type_arr = [
0=>'活动积分',1=>'派单成功',2=>'完成试驾',
3=>'开票',4=>'后台录入',5=>'兑换商品'
];
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* @param $type
* @return string|string[]
*/
public function get_type($type){
if($this->type_arr[$type]){
$result = $this->type_arr[$type];
}else{
$result = $this->type_arr;
}
return $result;
}
}
+23
View File
@@ -22,6 +22,8 @@ alter table lc_app_liche_users add dealer tinyint(1) not null default '0'
alter table lc_app_liche_users add up_uid int(10) not null default '0' comment '上级uid' after dealer;
alter table lc_app_liche_users add manage tinyint(1) not null default 0 comment '是否分销管理' after dealer;
alter table lc_app_liche_users add deal_uid int(10) not null default 0 comment '审核分销uid' after dealer;
alter table lc_app_liche_users add credits int(10) unsigned not null default '0' COMMENT '当前可用积分' after nickname;
alter table lc_app_liche_users add freeze_credits int(10) unsigned not null default '0' COMMENT '冻结积分' after credits;
-- ----------------------------
-- Title:狸车小程序cms
@@ -101,3 +103,24 @@ create table lc_app_liche_orders (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户购车订单'
alter table lc_app_liche_orders add img varchar(100) not null default '' comment '支付截图' after descrip;
alter table lc_app_liche_orders add admin_id int(10) not null default 0 comment '管理员id' after uid;
-- ----------------------------
-- Title:狸车小程序用户积分日志表
-- Author:lcc
-- Table:lc_app_liche_credits_log
-- ---------------------------
drop table if exists lc_app_liche_credits_log;
create table lc_app_liche_credits_log (
id int(10) unsigned not null auto_increment comment '自增id',
uid int(10) unsigned not null comment '用户id',
credit_in int(11) not null comment '积分入账',
credit_out int(11) not null comment '积分出账',
credit_left int(11) not null comment '剩余积分',
type tinyint(1) not null default '1' comment '类型 0活动 1派单成功 2完成试驾 3开票 4后台录入 5兑换商品',
target_id int(10) not null default '0' comment '来源id',
remark text comment '备注更多信息',
jsondata json default null comment '其他信息',
c_time int(10) unsigned not null default '0' comment '创建时间',
u_time timestamp not null default current_timestamp on update current_timestamp,
primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='狸车小程序用户积分日志表'