xieruidong 2 年之前
父节点
当前提交
b53de1808f

+ 1 - 1
application/admin/controller/Coupon.php

@@ -55,7 +55,7 @@ class Coupon extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             $list = $this->model
-
+                ->with(['goods'])
                     ->where($where)
                     ->order($sort, $order)
                     ->paginate($limit);

+ 3 - 0
application/common/model/Coupon.php

@@ -26,6 +26,9 @@ class Coupon extends Model
     public function bindGoods(){
         return $this->hasMany(CouponGoods::class);
     }
+    public function goods(){
+        return $this->belongsToMany(Goods::class,CouponGoods::class,'goods_id','coupon_id');
+    }
 
     protected static function init()
     {

+ 3 - 1
application/common/model/CouponGoods.php

@@ -3,8 +3,10 @@
 namespace app\common\model;
 
 use think\Model;
+use think\model\Pivot;
 
 
-class CouponGoods extends Model
+class CouponGoods extends Pivot
 {
+    protected $pk=null;
 }

+ 8 - 1
public/assets/js/backend/coupon.js

@@ -31,11 +31,18 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'name', title: __('名称'), operate:'like'},
                         {field: 'type', title: __('类型'),searchList:types,formatter: Table.api.formatter.label},
                         {field: 'amount', title: __('金额'), operate:'BETWEEN'},
-                        {field: 'amount_full', title: __('金额'), operate:'BETWEEN'},
+                        {field: 'amount_full', title: __('多多少可用'), operate:'BETWEEN'},
                         {field: 'num', title: __('Num')},
                         {field: 'num_send', title: __('Num_send')},
                         {field: 'time_start', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                         {field: 'time_end', title: __('过期时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
+                        {field: 'goods', title: __('适用商品'), operate:false,formatter(goods){
+                            let a=[]
+                                goods.forEach(item=>{
+                                    a.push(`<div>${item.name}</div>`)
+                                })
+                                return a.join('')
+                            }},
                         {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]