xieruidong 2 年之前
父节点
当前提交
8e9a08363b

+ 21 - 0
application/admin/controller/user/User.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller\user;
 
+use app\admin\model\Coupon;
 use app\common\controller\Backend;
 use app\common\library\Auth;
 use app\common\model\Programme;
@@ -169,4 +170,24 @@ class User extends Backend
             $this->success();
         }
     }
+
+    #赠送优惠券
+    public function send_coupon($ids){
+        if($this->request->isGet()) {
+            $coupon = Coupon::all();
+            $this->assign('coupon',$coupon);
+            return $this->fetch();
+        }else{
+            $data=input('row/a');
+            $this->validate($data,[
+                'coupon|券ID'=>['require','integer'],
+                'num|数量'=>['require','integer','gt:0'],
+            ]);
+            $coupon=Coupon::where('id',$data['coupon'])->find();
+            if(!$coupon){
+                $this->error('优惠券不存在');
+            }
+            $coupon->sendToUser([$ids],$data['num']);
+        }
+    }
 }

+ 1 - 1
application/common/model/Coupon.php

@@ -50,8 +50,8 @@ class Coupon extends Model
                 for ($i=0;$i<$num;$i++) {
                     UserCoupon::toUser($user, $this);
                 }
+                SiteMsg::sendMsg(SiteMsg::TYPE_COUPON,$user);
             }
-            SiteMsg::sendMsg(SiteMsg::TYPE_COUPON,$user);
         }
 
     }

+ 17 - 0
public/assets/js/backend/user/user.js

@@ -60,6 +60,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                         //返回true时按钮显示,返回false隐藏
                                         return true;
                                     }
+                                },
+                                {
+                                    name: 'detail',
+                                    text: __('赠送优惠券'),
+                                    title: __('赠送优惠券'),
+                                    classname: 'btn btn-xs btn-primary btn-dialog',
+                                    icon: 'fa',
+                                    url: 'user/user/send_coupon',
+                                    extend:`data-area='["800px","80%"]'`,
+                                    callback: function (data) {
+                                        //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
+                                        $('.btn-refresh').trigger('click')
+                                    },
+                                    visible: function (row) {
+                                        //返回true时按钮显示,返回false隐藏
+                                        return true;
+                                    }
                                 }
                             ]},
                     ]