作者 景龙
1 个管道 的构建 失败 耗费 0 秒

修改积分增增加规则

1 -<?php  
2 -  
3 -namespace app\admin\controller;  
4 -  
5 -use app\common\controller\Backend;  
6 -use app\admin\model\User;  
7 -use think\Db;  
8 -  
9 -/**  
10 - * 系统消息管理  
11 - *  
12 - * @icon fa fa-circle-o  
13 - */  
14 -class Message extends Backend  
15 -{  
16 -  
17 - /**  
18 - * Message模型对象  
19 - * @var \app\admin\model\Message  
20 - */  
21 - protected $model = null;  
22 -  
23 - public function _initialize()  
24 - {  
25 - parent::_initialize();  
26 - $this->request->filter(['strip_tags']);  
27 - $this->model = new \app\admin\model\Message;  
28 -  
29 - }  
30 -  
31 - /**  
32 - * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法  
33 - * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑  
34 - * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改  
35 - */  
36 -  
37 -  
38 - /**  
39 - * 添加  
40 - */  
41 - public function add()  
42 - {  
43 - if ($this->request->isPost()) {  
44 - $params = $this->request->post("row/a");  
45 - $user_ids = $this->request->post("user_ids");  
46 - if ($params) {  
47 - if ($this->dataLimit && $this->dataLimitFieldAutoFill) {  
48 - $params[$this->dataLimitField] = $this->auth->id;  
49 - }  
50 - try {  
51 - //是否采用模型验证  
52 - if ($this->modelValidate) {  
53 - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));  
54 - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;  
55 - $this->model->validate($validate);  
56 - }  
57 - $result = $this->model->allowField(true)->save($params);  
58 - //系统推送消息  
59 - $id = $this->model->id;  
60 - $userModel = new User();  
61 - if(!empty($user_ids)){  
62 - $users = explode(',',$user_ids);  
63 - }else{  
64 - $users = $userModel->where(['status'=>'normal'])->column('id');  
65 - }  
66 - $logList = [];  
67 - foreach ($users as $value){  
68 - $log['message_id'] = $id;  
69 - $log['createtime'] = time();  
70 - $log['user_id'] = $value;  
71 - array_push($logList,$log);  
72 - }  
73 - $row = false;  
74 - if(!empty($logList)){  
75 - $row = Db::name('message_log')->insertAll($logList);  
76 - }  
77 -  
78 - if ($result !== false && $row) {  
79 - $this->success();  
80 - } else {  
81 - $this->error($this->model->getError());  
82 - }  
83 - } catch (\think\exception\PDOException $e) {  
84 - $this->error($e->getMessage());  
85 - } catch (\think\Exception $e) {  
86 - $this->error($e->getMessage());  
87 - }  
88 - }  
89 - $this->error(__('Parameter %s can not be empty', ''));  
90 - }  
91 - return $this->view->fetch();  
92 - }  
93 -  
94 - /**  
95 - * 编辑  
96 - */  
97 - public function edit($ids = NULL)  
98 - {  
99 - $row = $this->model->get($ids);  
100 - $userIds=Db::name('message_log')->where(['message_id'=>$ids])->column('user_id');  
101 - if (!$row)  
102 - $this->error(__('No Results were found'));  
103 - $adminIds = $this->getDataLimitAdminIds();  
104 - if (is_array($adminIds)) {  
105 - if (!in_array($row[$this->dataLimitField], $adminIds)) {  
106 - $this->error(__('You have no permission'));  
107 - }  
108 - }  
109 - if ($this->request->isPost()) {  
110 - $params = $this->request->post("row/a");  
111 - $user_ids = $this->request->post("user_ids");  
112 - if ($params) {  
113 - try {  
114 - //是否采用模型验证  
115 - if ($this->modelValidate) {  
116 - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));  
117 - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;  
118 - $row->validate($validate);  
119 - }  
120 - $userModel = new User();  
121 - if(!empty($user_ids)){  
122 - $users = explode(',',$user_ids);  
123 - }else{  
124 - $users = $userModel->where(['status'=>'normal'])->column('id');  
125 - }  
126 - $result = $row->allowField(true)->save($params);  
127 - $sameUsers = array_intersect($userIds,$users);  
128 - $needDeleteUsersIds = array_diff($userIds, $sameUsers);  
129 - $newUsersIds = array_diff($users, $sameUsers);  
130 - $logList = [];  
131 - foreach ($newUsersIds as $value){  
132 - $log['message_id'] = $ids;  
133 - $log['createtime'] = time();  
134 - $log['user_id'] = $value;  
135 - array_push($logList,$log);  
136 - }  
137 - //删除旧数据  
138 - $row2 = true;  
139 - if(!empty($needDeleteUsersIds)){  
140 - $row2 = Db::name('message_log')->where(['user_id'=>['in',$needDeleteUsersIds],'message_id'=>$ids])->delete();  
141 - }  
142 - //新增新数据  
143 - $row = true;  
144 - if(!empty($logList)){  
145 - $row = Db::name('message_log')->insertAll($logList);  
146 - }  
147 -  
148 - if ($result !== false && $row && $row2) {  
149 - $this->success();  
150 - } else {  
151 - $this->error($row->getError());  
152 - }  
153 - } catch (\think\exception\PDOException $e) {  
154 - $this->error($e->getMessage());  
155 - } catch (\think\Exception $e) {  
156 - $this->error($e->getMessage());  
157 - }  
158 - }  
159 - $this->error(__('Parameter %s can not be empty', ''));  
160 - }  
161 - $this->view->assign("userIds", implode(',',$userIds));  
162 - $this->view->assign("row", $row);  
163 - return $this->view->fetch();  
164 - }  
165 -  
166 - /**  
167 - * 删除  
168 - */  
169 - public function del($ids = "")  
170 - {  
171 - if ($ids) {  
172 - $pk = $this->model->getPk();  
173 - $adminIds = $this->getDataLimitAdminIds();  
174 - if (is_array($adminIds)) {  
175 - $count = $this->model->where($this->dataLimitField, 'in', $adminIds);  
176 - }  
177 - $list = $this->model->where($pk, 'in', $ids)->select();  
178 - $count = 0;  
179 - foreach ($list as $k => $v) {  
180 - $count += $v->delete();  
181 - Db::name('message_log')->where(['message_id'=>$v['id']])->delete();  
182 - }  
183 - if ($count) {  
184 - $this->success();  
185 - } else {  
186 - $this->error(__('No rows were deleted'));  
187 - }  
188 - }  
189 - $this->error(__('Parameter %s can not be empty', 'ids'));  
190 - }  
191 -  
192 -}  
1 -<?php  
2 -  
3 -return [  
4 - 'Id' => 'ID',  
5 - 'Souce' => '消息来源',  
6 - 'To_uid' => '接收对象',  
7 - 'Title' => '标题',  
8 - 'Description' => '内容',  
9 - 'Createtime' => '创建时间',  
10 -];  
1 -<?php  
2 -  
3 -namespace app\admin\model;  
4 -  
5 -use think\Model;  
6 -  
7 -class Message extends Model  
8 -{  
9 - // 表名  
10 - protected $name = 'message';  
11 -  
12 - // 自动写入时间戳字段  
13 - protected $autoWriteTimestamp = 'int';  
14 -  
15 - // 定义时间戳字段名  
16 - protected $createTime = 'createtime';  
17 - protected $updateTime = 'updatetime';  
18 -  
19 - // 追加属性  
20 - protected $append = [  
21 - 'deletetime_text'  
22 - ];  
23 -  
24 -  
25 -  
26 -  
27 -  
28 -  
29 - public function getDeletetimeTextAttr($value, $data)  
30 - {  
31 - $value = $value ? $value : (isset($data['deletetime']) ? $data['deletetime'] : '');  
32 - return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;  
33 - }  
34 -  
35 - protected function setDeletetimeAttr($value)  
36 - {  
37 - return $value && !is_numeric($value) ? strtotime($value) : $value;  
38 - }  
39 -  
40 -  
41 -}  
1 -<?php  
2 -  
3 -namespace app\admin\validate;  
4 -  
5 -use think\Validate;  
6 -  
7 -class Message extends Validate  
8 -{  
9 - /**  
10 - * 验证规则  
11 - */  
12 - protected $rule = [  
13 - ];  
14 - /**  
15 - * 提示消息  
16 - */  
17 - protected $message = [  
18 - ];  
19 - /**  
20 - * 验证场景  
21 - */  
22 - protected $scene = [  
23 - 'add' => [],  
24 - 'edit' => [],  
25 - ];  
26 -  
27 -}  
1 -<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">  
2 -  
3 - <div class="form-group">  
4 - <label class="control-label col-xs-12 col-sm-2">{:__('To_uid')}:</label>  
5 - <div class="col-xs-12 col-sm-8">  
6 - <input id="c-user_ids" data-source="user/user/index" placeholder="为空将发送给全部用户" type="text"  
7 - data-field="username" data-multiple="true" class="form-control selectpage" name="user_ids" value="">  
8 - </div>  
9 - </div>  
10 - <div class="form-group">  
11 - <label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>  
12 - <div class="col-xs-12 col-sm-8">  
13 - <input id="c-title" data-rule="required" class="form-control" name="row[title]" type="text">  
14 - </div>  
15 - </div>  
16 - <div class="form-group">  
17 - <label class="control-label col-xs-12 col-sm-2">{:__('Description')}:</label>  
18 - <div class="col-xs-12 col-sm-8">  
19 - <textarea id="c-description" data-rule="required" rows="5" class="form-control editor" name="row[description]" cols="50"></textarea>  
20 - </div>  
21 - </div>  
22 - <div class="form-group layer-footer">  
23 - <label class="control-label col-xs-12 col-sm-2"></label>  
24 - <div class="col-xs-12 col-sm-8">  
25 - <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>  
26 - <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>  
27 - </div>  
28 - </div>  
29 -</form>  
1 -<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">  
2 -  
3 - <div class="form-group">  
4 - <label class="control-label col-xs-12 col-sm-2">{:__('To_uid')}:</label>  
5 - <div class="col-xs-12 col-sm-8">  
6 - <input id="c-user_ids" data-source="user/user/index" placeholder="为空将发送给全部用户" type="text"  
7 - data-field="username" data-multiple="true" class="form-control selectpage" name="user_ids" value="{$userIds}">  
8 - </div>  
9 - </div>  
10 - <div class="form-group">  
11 - <label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>  
12 - <div class="col-xs-12 col-sm-8">  
13 - <input id="c-title" data-rule="required" class="form-control" name="row[title]" type="text" value="{$row.title}">  
14 - </div>  
15 - </div>  
16 - <div class="form-group">  
17 - <label class="control-label col-xs-12 col-sm-2">{:__('Description')}:</label>  
18 - <div class="col-xs-12 col-sm-8">  
19 - <textarea id="c-description" data-rule="required" rows="5" class="form-control editor" name="row[description]" cols="50">{$row.description}</textarea>  
20 - </div>  
21 - </div>  
22 - <div class="form-group layer-footer">  
23 - <label class="control-label col-xs-12 col-sm-2"></label>  
24 - <div class="col-xs-12 col-sm-8">  
25 - <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>  
26 - <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>  
27 - </div>  
28 - </div>  
29 -</form>  
1 -<div class="panel panel-default panel-intro">  
2 - {:build_heading()}  
3 -  
4 - <div class="panel-body">  
5 - <div id="myTabContent" class="tab-content">  
6 - <div class="tab-pane fade active in" id="one">  
7 - <div class="widget-body no-padding">  
8 - <div id="toolbar" class="toolbar">  
9 - <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>  
10 - <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('message/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>  
11 - <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('message/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>  
12 - <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('message/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>  
13 - <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('message/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>  
14 -  
15 - <div class="dropdown btn-group {:$auth->check('message/multi')?'':'hide'}">  
16 - <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>  
17 - <ul class="dropdown-menu text-left" role="menu">  
18 - <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>  
19 - <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>  
20 - </ul>  
21 - </div>  
22 - </div>  
23 - <table id="table" class="table table-striped table-bordered table-hover table-nowrap"  
24 - data-operate-edit="{:$auth->check('message/edit')}"  
25 - data-operate-del="{:$auth->check('message/del')}"  
26 - width="100%">  
27 - </table>  
28 - </div>  
29 - </div>  
30 -  
31 - </div>  
32 - </div>  
33 -</div>  
@@ -4,6 +4,7 @@ namespace app\api\controller; @@ -4,6 +4,7 @@ namespace app\api\controller;
4 4
5 use app\common\controller\Api; 5 use app\common\controller\Api;
6 use app\admin\model\Bank; 6 use app\admin\model\Bank;
  7 +use app\admin\model\off\Line;
7 use think\Db; 8 use think\Db;
8 use think\Validate; 9 use think\Validate;
9 /** 10 /**
@@ -11,8 +12,8 @@ use think\Validate; @@ -11,8 +12,8 @@ use think\Validate;
11 */ 12 */
12 class Person extends Api 13 class Person extends Api
13 { 14 {
14 - protected $noNeedLogin = [];  
15 - protected $noNeedRight = '*'; 15 + protected $noNeedLogin = ['getScore'];
  16 + protected $noNeedRight = ['getScore'];
16 protected $person = 0;//个人 17 protected $person = 0;//个人
17 protected $company = 1;//企业 18 protected $company = 1;//企业
18 protected $user_id = '';//token存贮user_id 19 protected $user_id = '';//token存贮user_id
@@ -240,4 +241,19 @@ class Person extends Api @@ -240,4 +241,19 @@ class Person extends Api
240 $this->error('请求方式错误'); 241 $this->error('请求方式错误');
241 } 242 }
242 } 243 }
  244 +
  245 + /**
  246 + * 根据规则获取积分
  247 + * @param $share_uid
  248 + * @param $type
  249 + */
  250 + public function getScore($share_uid,$type){
  251 + $score = config('site.'.$type);
  252 + //给分享用户增加积分
  253 + $user = new \app\admin\model\User();
  254 + $user->where(['id'=>$share_uid,'status'=>'normal'])->setInc('score', $score);
  255 + //成为分享用户的下线
  256 + $offlineModel = new Line();
  257 + $offlineModel->create(['uid'=>$share_uid,'s_score'=>$score,'off_uid'=>$this->user_id]);
  258 + }
243 } 259 }
@@ -3,8 +3,6 @@ @@ -3,8 +3,6 @@
3 namespace app\api\controller; 3 namespace app\api\controller;
4 4
5 use app\common\controller\Api; 5 use app\common\controller\Api;
6 -use app\admin\model\User;  
7 -use app\admin\model\off\Line;  
8 use think\Validate; 6 use think\Validate;
9 /** 7 /**
10 * 卖废品接口** 8 * 卖废品接口**
@@ -51,11 +49,8 @@ class Sell extends Api @@ -51,11 +49,8 @@ class Sell extends Api
51 } 49 }
52 //如果携带分享uid,则按照积分增加 50 //如果携带分享uid,则按照积分增加
53 if(!empty($sell_data['share_uid'])){ 51 if(!empty($sell_data['share_uid'])){
54 - $score = config('site.share_sell');  
55 - $user = new User();  
56 - $user->where(['id'=>$sell_data['share_uid'],'status'=>'normal'])->setInc('score', $score);  
57 - $offlineModel = new Line();  
58 - $offlineModel->create(['uid'=>$sell_data['share_uid'],'s_score'=>$score,'off_uid'=>$this->user_id]); 52 + $person = new Person();
  53 + $person->getScore($sell_data['share_uid'],'share_sell');
59 } 54 }
60 $sell = new \app\admin\model\Sell(); 55 $sell = new \app\admin\model\Sell();
61 $data['uid'] = $this->user_id; 56 $data['uid'] = $this->user_id;
@@ -10,7 +10,6 @@ use Yansongda\Pay\Pay; @@ -10,7 +10,6 @@ use Yansongda\Pay\Pay;
10 use app\admin\model\Account; 10 use app\admin\model\Account;
11 use app\admin\model\User; 11 use app\admin\model\User;
12 use app\admin\model\Message; 12 use app\admin\model\Message;
13 -use app\admin\model\off\Line;  
14 use think\Log; 13 use think\Log;
15 use fast\Http; 14 use fast\Http;
16 use think\Validate; 15 use think\Validate;
@@ -144,13 +143,8 @@ class Wxpay extends Api @@ -144,13 +143,8 @@ class Wxpay extends Api
144 143
145 //如果携带分享uid,则按照积分增加 144 //如果携带分享uid,则按照积分增加
146 if(!empty($share_uid)){ 145 if(!empty($share_uid)){
147 - $score = config('site.share_purchase');  
148 - //给分享用户增加积分  
149 - $user = new User();  
150 - $user->where(['id'=>$share_uid,'status'=>'normal'])->setInc('score', $score);  
151 - //成为分享用户的下线  
152 - $offlineModel = new Line();  
153 - $offlineModel->create(['uid'=>$share_uid,'s_score'=>$score,'off_uid'=>$this->user_id]); 146 + $person = new Person();
  147 + $person->getScore($share_uid,'share_purchase');
154 } 148 }
155 } 149 }
156 } catch (Exception $e) { 150 } catch (Exception $e) {
1 -define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {  
2 -  
3 - var Controller = {  
4 - index: function () {  
5 - // 初始化表格参数配置  
6 - Table.api.init({  
7 - extend: {  
8 - index_url: 'message/index',  
9 - add_url: 'message/add',  
10 - edit_url: 'message/edit',  
11 - del_url: 'message/del',  
12 - multi_url: 'message/multi',  
13 - table: 'message',  
14 - }  
15 - });  
16 -  
17 - var table = $("#table");  
18 -  
19 - // 初始化表格  
20 - table.bootstrapTable({  
21 - url: $.fn.bootstrapTable.defaults.extend.index_url,  
22 - pk: 'id',  
23 - sortName: 'id',  
24 - columns: [  
25 - [  
26 - {checkbox: true},  
27 - {field: 'id', title: __('Id')},  
28 - {field: 'souce', title: __('Souce'), formatter: Table.api.formatter.normal,searchList: {0: __('System'), 1: __('AdminPush')}},  
29 - {field: 'title', title: __('Title')},  
30 - // {field: 'description', title: __('Description')},  
31 - {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},  
32 - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}  
33 - ]  
34 - ]  
35 - });  
36 -  
37 - // 为表格绑定事件  
38 - Table.api.bindevent(table);  
39 - },  
40 - add: function () {  
41 - Controller.api.bindevent();  
42 - },  
43 - edit: function () {  
44 - Controller.api.bindevent();  
45 - },  
46 - api: {  
47 - bindevent: function () {  
48 - Form.api.bindevent($("form[role=form]"));  
49 - }  
50 - }  
51 - };  
52 - return Controller;  
53 -});