作者 景龙
1 个管道 的构建 通过 耗费 2 秒

增加本人购买获取积分

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* 设置本人获得积分管理
*
* @icon fa fa-circle-o
*/
class Score extends Backend
{
/**
* Score模型对象
* @var \app\admin\model\Score
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Score;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = false;
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','set_rule','set_score','createtime','updatetime']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'ID',
'Set_rule' => '积分规则',
'Set_score' => '所获积分',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class Score extends Model
{
// 表名
protected $name = 'score';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'deletetime_text'
];
public function getDeletetimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['deletetime']) ? $data['deletetime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setDeletetimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
}
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Score extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Set_rule')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-set_rule" data-rule="required" class="form-control" name="row[set_rule]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Set_score')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-set_score" data-rule="required" class="form-control" name="row[set_score]" type="number" value="0">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Set_rule')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-set_rule" data-rule="required" class="form-control" name="row[set_rule]" type="text" value="{$row.set_rule}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Set_score')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-set_score" data-rule="required" class="form-control" name="row[set_score]" type="number" value="{$row.set_score}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<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-success btn-add {:$auth->check('score/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('score/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('score/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('score/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>-->
<div class="dropdown btn-group {:$auth->check('score/multi')?'':'hide'}">
<!--<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
<ul class="dropdown-menu text-left" role="menu">
<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>
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('score/edit')}"
data-operate-del="{:$auth->check('score/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -29,6 +29,7 @@ class Comments extends Api
* @ApiRoute (/api/comments/comment)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="商品id")
* @ApiParams (name="order_id", type="integer", required=true, description="订单id")
* @ApiParams (name="content", type="string", required=true, description="评价内容")
* @ApiReturn ({
"code": 1,
... ...
... ... @@ -376,4 +376,25 @@ class Person extends Api
}
}
public function getPersonScore($type){
if($type == 'person_purchase'){
$scoreRule = Db::table('gc_score')
->where('set_rule','like','%购买%')
->field('set_score')
->find();
}else if($type == 'person_sell'){
$scoreRule = Db::table('gc_score')
->where('set_rule','like','%卖废品%')
->field('set_score')
->find();
}
$score = 0;
if($scoreRule){
$score = $scoreRule['set_score'];
}
$userModel = new \app\admin\model\User();
$userModel->where(['id'=>$this->user_id,'status'=>'normal'])->setInc('score', $score);
return true;
}
}
... ...
... ... @@ -48,8 +48,8 @@ class Sell extends Api
$this->error($validate->getError());
}
//如果携带分享uid,则按照积分增加,并成为下线
if(!empty($sell_data['share_uid'])){
$person = new Person();
if(!empty($sell_data['share_uid'])){
$person->getScore($sell_data['share_uid'],'share_sell');
}
$sell = new \app\admin\model\Sell();
... ... @@ -61,7 +61,9 @@ class Sell extends Api
$data['pre_time'] = $sell_data['pre_time'];
$data['images'] = $sell_data['images'];
$data = $sell::create($data);
if($data){
//给自己增加积分
$data1 = $person->getPersonScore('person_sell');
if($data && $data1){
$this->success('保存成功');
}else{
$this->error('保存失败');
... ...
... ... @@ -100,9 +100,11 @@ class Wxpay extends Api
//从账户扣取费用
$sur_money = $user['money'] - $total_price;
$res = $userModel->where(['openid'=>$openid])->update(['money'=>$sur_money]);
//更新订单状态
$porderModel = new Porder();
$res1 = $porderModel->where(['pay_order_sn'=>$pay_order_sn])->update(['status'=>$this->order_status[1]]);
//减库存,删相应购物车记录
$this->handle($pay_order_sn,$openid);
if($res && $res1){
... ... @@ -271,7 +273,31 @@ class Wxpay extends Api
//如果携带分享uid,则按照积分增加
$person = new Person();
$person->getScore($share_uid,'share_purchase');
$this->error('成功');
$this->success('成功');
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (本人购买成功调用,增加积分并获得相应的积分)
* @ApiSummary (本人购买成功调用,增加积分并获得相应的积分)
* @ApiMethod (GET)
* @ApiRoute (/api/wxpay/addPersonScore)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1554184134",
"data": null
})
*/
public function addPersonScore(){
if($this->request->isGet()){
//给自己增加积分
$person = new Person();
$person->getPersonScore('person_purchase');
$this->success('成功');
}else{
$this->error('请求方式错误');
}
... ...
此 diff 太大无法显示。
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'score/index',
add_url: 'score/add',
edit_url: 'score/edit',
del_url: 'score/del',
multi_url: 'score/multi',
table: 'score',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'set_rule', title: __('Set_rule')},
{field: 'set_score', title: __('Set_score')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...