Explorar el Código

add - 优惠券标签

liugc hace 1 año
padre
commit
f2ce771742

+ 9 - 1
app/adminapi/lists/coupon/CouponRulesLists.php

@@ -61,6 +61,15 @@ class CouponRulesLists extends BaseAdminDataLists implements ListsSearchInterfac
         if(isset($this->params['min_voucher_count']) && is_numeric($this->params['min_voucher_count'])){
             $where[] = ['voucher_count', '>=', $this->params['min_voucher_count']];
         }
+        if (isset($this->params['labels']) && !empty($this->params['labels'])) {
+            $sqls = [];
+            foreach ($this->params['labels'] as $item) {
+                $sqls[] = "FIND_IN_SET({$item}, labels) > 0";
+            }
+            $query_sql = implode(' OR ', $sqls);
+            $period_ids = CouponRules::where('labels','<>', '')->whereRaw($query_sql)->column('id');
+            $where[] = [ 'id','IN',$period_ids?:[0]];
+        }
         if(isset($this->params['max_voucher_count']) && is_numeric($this->params['max_voucher_count'])){
             $where[] = ['voucher_count', '<=', $this->params['max_voucher_count']];
         }
@@ -107,7 +116,6 @@ class CouponRulesLists extends BaseAdminDataLists implements ListsSearchInterfac
             $query->field('id,goods_name');
         }])->where($this->searchWhere)
             ->where($this->queryWhere())
-            ->field(['id','code', 'amount', 'coupon_target', 'coupon_type','amount_require', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_status', 'voucher_count','remaining_count','property_activity_id'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()

+ 2 - 0
app/adminapi/logic/coupon/CouponRulesLogic.php

@@ -60,6 +60,7 @@ class CouponRulesLogic extends BaseLogic
                 'voucher_count' => $params['voucher_count'],
                 'remaining_count' => $params['voucher_count'],
                 'property_activity_id' => $params['property_activity_id']??0,
+                'labels' => (isset($params['labels']) && $params['labels'])?implode(',',$params['labels']):'',
             ]);
             if(!empty($params['goods_category_ids'])){
                 $categoryArr = [];
@@ -111,6 +112,7 @@ class CouponRulesLogic extends BaseLogic
                 'voucher_count' => $params['voucher_count'],
                 'remaining_count' => $params['remaining_count'],
                 'property_activity_id' => $params['property_activity_id']??0,
+                'labels' => (isset($params['labels']) && $params['labels'])?implode(',',$params['labels']):'',
             ]);
             CouponCategory::where('coupon_id',$params['id'])->delete();
             if(!empty($params['goods_category_ids'])){

+ 10 - 0
app/common/logic/TableDataLogic.php

@@ -72,4 +72,14 @@ class TableDataLogic extends BaseLogic
     {
         return Labels::where('id','>',0)->where('label_type',2)->field('id,label_name as name,id as value,"data_table_masterWorkerLabels" as type_value')->select()->toArray();
     }
+    /**
+     * @notes 优惠券标签列表
+     */
+    public static function couponLabels()
+    {
+        return Labels::where('id','>',0)->where('label_type',3)->field('id,label_name as name,id as value,"data_table_couponLabels" as type_value')->select()->toArray();
+    }
+
+
+
 }

+ 4 - 1
app/common/model/coupon/CouponRules.php

@@ -54,5 +54,8 @@ class CouponRules extends BaseModel
     {
         return $this->hasOne(CouponCategory::class, 'coupon_id', 'id');
     }
-
+    public function getLabelsAttr($value)
+    {
+        return $value?array_map(function($item){ return (int)$item; },explode(',',$value)):[];
+    }
 }

+ 4 - 0
app/common/model/master_worker/MasterWorker.php

@@ -107,4 +107,8 @@ class MasterWorker extends BaseModel
     {
         return $this->hasOne(BankAccount::class, 'worker_id', 'id');
     }
+    public function getLabelsAttr($value)
+    {
+        return $value?array_map(function($item){ return (int)$item; },explode(',',$value)):[];
+    }
 }