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

增加本人购买获取积分

  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +
  5 +use app\common\controller\Backend;
  6 +
  7 +/**
  8 + * 设置本人获得积分管理
  9 + *
  10 + * @icon fa fa-circle-o
  11 + */
  12 +class Score extends Backend
  13 +{
  14 +
  15 + /**
  16 + * Score模型对象
  17 + * @var \app\admin\model\Score
  18 + */
  19 + protected $model = null;
  20 +
  21 + public function _initialize()
  22 + {
  23 + parent::_initialize();
  24 + $this->model = new \app\admin\model\Score;
  25 +
  26 + }
  27 +
  28 + /**
  29 + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32 + */
  33 +
  34 +
  35 + /**
  36 + * 查看
  37 + */
  38 + public function index()
  39 + {
  40 + //当前是否为关联查询
  41 + $this->relationSearch = false;
  42 + //设置过滤方法
  43 + $this->request->filter(['strip_tags']);
  44 + if ($this->request->isAjax())
  45 + {
  46 + //如果发送的来源是Selectpage,则转发到Selectpage
  47 + if ($this->request->request('keyField'))
  48 + {
  49 + return $this->selectpage();
  50 + }
  51 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  52 + $total = $this->model
  53 +
  54 + ->where($where)
  55 + ->order($sort, $order)
  56 + ->count();
  57 +
  58 + $list = $this->model
  59 +
  60 + ->where($where)
  61 + ->order($sort, $order)
  62 + ->limit($offset, $limit)
  63 + ->select();
  64 +
  65 + foreach ($list as $row) {
  66 + $row->visible(['id','set_rule','set_score','createtime','updatetime']);
  67 + }
  68 + $list = collection($list)->toArray();
  69 + $result = array("total" => $total, "rows" => $list);
  70 +
  71 + return json($result);
  72 + }
  73 + return $this->view->fetch();
  74 + }
  75 +}
  1 +<?php
  2 +
  3 +return [
  4 + 'Id' => 'ID',
  5 + 'Set_rule' => '积分规则',
  6 + 'Set_score' => '所获积分',
  7 + 'Createtime' => '创建时间',
  8 + 'Updatetime' => '更新时间',
  9 +];
  1 +<?php
  2 +
  3 +namespace app\admin\model;
  4 +
  5 +use think\Model;
  6 +
  7 +class Score extends Model
  8 +{
  9 + // 表名
  10 + protected $name = 'score';
  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 Score 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">{:__('Set_rule')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-set_rule" data-rule="required" class="form-control" name="row[set_rule]" type="text">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('Set_score')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-set_score" data-rule="required" class="form-control" name="row[set_score]" type="number" value="0">
  13 + </div>
  14 + </div>
  15 + <div class="form-group layer-footer">
  16 + <label class="control-label col-xs-12 col-sm-2"></label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  19 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  20 + </div>
  21 + </div>
  22 +</form>
  1 +<form id="edit-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">{:__('Set_rule')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-set_rule" data-rule="required" class="form-control" name="row[set_rule]" type="text" value="{$row.set_rule}">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('Set_score')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-set_score" data-rule="required" class="form-control" name="row[set_score]" type="number" value="{$row.set_score}">
  13 + </div>
  14 + </div>
  15 + <div class="form-group layer-footer">
  16 + <label class="control-label col-xs-12 col-sm-2"></label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  19 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  20 + </div>
  21 + </div>
  22 +</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('score/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('score/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('score/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
  13 + <!--<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>-->
  14 +
  15 + <div class="dropdown btn-group {:$auth->check('score/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('score/edit')}"
  25 + data-operate-del="{:$auth->check('score/del')}"
  26 + width="100%">
  27 + </table>
  28 + </div>
  29 + </div>
  30 +
  31 + </div>
  32 + </div>
  33 +</div>
@@ -29,6 +29,7 @@ class Comments extends Api @@ -29,6 +29,7 @@ class Comments extends Api
29 * @ApiRoute (/api/comments/comment) 29 * @ApiRoute (/api/comments/comment)
30 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 30 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
31 * @ApiParams (name="id", type="integer", required=true, description="商品id") 31 * @ApiParams (name="id", type="integer", required=true, description="商品id")
  32 + * @ApiParams (name="order_id", type="integer", required=true, description="订单id")
32 * @ApiParams (name="content", type="string", required=true, description="评价内容") 33 * @ApiParams (name="content", type="string", required=true, description="评价内容")
33 * @ApiReturn ({ 34 * @ApiReturn ({
34 "code": 1, 35 "code": 1,
@@ -376,4 +376,25 @@ class Person extends Api @@ -376,4 +376,25 @@ class Person extends Api
376 } 376 }
377 } 377 }
378 378
  379 + public function getPersonScore($type){
  380 + if($type == 'person_purchase'){
  381 + $scoreRule = Db::table('gc_score')
  382 + ->where('set_rule','like','%购买%')
  383 + ->field('set_score')
  384 + ->find();
  385 + }else if($type == 'person_sell'){
  386 + $scoreRule = Db::table('gc_score')
  387 + ->where('set_rule','like','%卖废品%')
  388 + ->field('set_score')
  389 + ->find();
  390 + }
  391 + $score = 0;
  392 + if($scoreRule){
  393 + $score = $scoreRule['set_score'];
  394 + }
  395 + $userModel = new \app\admin\model\User();
  396 + $userModel->where(['id'=>$this->user_id,'status'=>'normal'])->setInc('score', $score);
  397 + return true;
  398 + }
  399 +
379 } 400 }
@@ -48,8 +48,8 @@ class Sell extends Api @@ -48,8 +48,8 @@ class Sell extends Api
48 $this->error($validate->getError()); 48 $this->error($validate->getError());
49 } 49 }
50 //如果携带分享uid,则按照积分增加,并成为下线 50 //如果携带分享uid,则按照积分增加,并成为下线
  51 + $person = new Person();
51 if(!empty($sell_data['share_uid'])){ 52 if(!empty($sell_data['share_uid'])){
52 - $person = new Person();  
53 $person->getScore($sell_data['share_uid'],'share_sell'); 53 $person->getScore($sell_data['share_uid'],'share_sell');
54 } 54 }
55 $sell = new \app\admin\model\Sell(); 55 $sell = new \app\admin\model\Sell();
@@ -61,7 +61,9 @@ class Sell extends Api @@ -61,7 +61,9 @@ class Sell extends Api
61 $data['pre_time'] = $sell_data['pre_time']; 61 $data['pre_time'] = $sell_data['pre_time'];
62 $data['images'] = $sell_data['images']; 62 $data['images'] = $sell_data['images'];
63 $data = $sell::create($data); 63 $data = $sell::create($data);
64 - if($data){ 64 + //给自己增加积分
  65 + $data1 = $person->getPersonScore('person_sell');
  66 + if($data && $data1){
65 $this->success('保存成功'); 67 $this->success('保存成功');
66 }else{ 68 }else{
67 $this->error('保存失败'); 69 $this->error('保存失败');
@@ -100,9 +100,11 @@ class Wxpay extends Api @@ -100,9 +100,11 @@ class Wxpay extends Api
100 //从账户扣取费用 100 //从账户扣取费用
101 $sur_money = $user['money'] - $total_price; 101 $sur_money = $user['money'] - $total_price;
102 $res = $userModel->where(['openid'=>$openid])->update(['money'=>$sur_money]); 102 $res = $userModel->where(['openid'=>$openid])->update(['money'=>$sur_money]);
  103 +
103 //更新订单状态 104 //更新订单状态
104 $porderModel = new Porder(); 105 $porderModel = new Porder();
105 $res1 = $porderModel->where(['pay_order_sn'=>$pay_order_sn])->update(['status'=>$this->order_status[1]]); 106 $res1 = $porderModel->where(['pay_order_sn'=>$pay_order_sn])->update(['status'=>$this->order_status[1]]);
  107 +
106 //减库存,删相应购物车记录 108 //减库存,删相应购物车记录
107 $this->handle($pay_order_sn,$openid); 109 $this->handle($pay_order_sn,$openid);
108 if($res && $res1){ 110 if($res && $res1){
@@ -271,7 +273,31 @@ class Wxpay extends Api @@ -271,7 +273,31 @@ class Wxpay extends Api
271 //如果携带分享uid,则按照积分增加 273 //如果携带分享uid,则按照积分增加
272 $person = new Person(); 274 $person = new Person();
273 $person->getScore($share_uid,'share_purchase'); 275 $person->getScore($share_uid,'share_purchase');
274 - $this->error('成功'); 276 + $this->success('成功');
  277 + }else{
  278 + $this->error('请求方式错误');
  279 + }
  280 + }
  281 +
  282 + /**
  283 + * @ApiTitle (本人购买成功调用,增加积分并获得相应的积分)
  284 + * @ApiSummary (本人购买成功调用,增加积分并获得相应的积分)
  285 + * @ApiMethod (GET)
  286 + * @ApiRoute (/api/wxpay/addPersonScore)
  287 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  288 + * @ApiReturn ({
  289 + "code": 1,
  290 + "msg": "成功",
  291 + "time": "1554184134",
  292 + "data": null
  293 + })
  294 + */
  295 + public function addPersonScore(){
  296 + if($this->request->isGet()){
  297 + //给自己增加积分
  298 + $person = new Person();
  299 + $person->getPersonScore('person_purchase');
  300 + $this->success('成功');
275 }else{ 301 }else{
276 $this->error('请求方式错误'); 302 $this->error('请求方式错误');
277 } 303 }
此 diff 太大无法显示。
  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: 'score/index',
  9 + add_url: 'score/add',
  10 + edit_url: 'score/edit',
  11 + del_url: 'score/del',
  12 + multi_url: 'score/multi',
  13 + table: 'score',
  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: 'set_rule', title: __('Set_rule')},
  29 + {field: 'set_score', title: __('Set_score')},
  30 + {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  31 + {field: 'updatetime', title: __('Updatetime'), 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 +});