|
@@ -16,8 +16,10 @@ namespace app\adminapi\logic\coupon;
|
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\model\coupon\CouponCategory;
|
|
use app\common\model\coupon\CouponCategory;
|
|
|
|
|
+use app\common\model\coupon\CouponGoods;
|
|
|
use app\common\model\coupon\CouponRules;
|
|
use app\common\model\coupon\CouponRules;
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\logic\BaseLogic;
|
|
|
|
|
+use app\common\model\goods\Goods;
|
|
|
use think\db\Query;
|
|
use think\db\Query;
|
|
|
use think\facade\Db;
|
|
use think\facade\Db;
|
|
|
|
|
|
|
@@ -44,6 +46,7 @@ class CouponRulesLogic extends BaseLogic
|
|
|
try {
|
|
try {
|
|
|
$model = CouponRules::create([
|
|
$model = CouponRules::create([
|
|
|
'coupon_type'=> $params['coupon_type'],
|
|
'coupon_type'=> $params['coupon_type'],
|
|
|
|
|
+ 'coupon_target'=>!empty($params['coupon_target'])?$params['coupon_target']:'category',
|
|
|
'code' => generate_sn(CouponRules::class,'code'),
|
|
'code' => generate_sn(CouponRules::class,'code'),
|
|
|
'amount' => $params['amount'],
|
|
'amount' => $params['amount'],
|
|
|
'amount_require' => $params['amount_require'],
|
|
'amount_require' => $params['amount_require'],
|
|
@@ -65,6 +68,13 @@ class CouponRulesLogic extends BaseLogic
|
|
|
}
|
|
}
|
|
|
$model->couponWithCategory()->saveAll($categoryArr);
|
|
$model->couponWithCategory()->saveAll($categoryArr);
|
|
|
}
|
|
}
|
|
|
|
|
+ if(!empty($params['goods_id'])){
|
|
|
|
|
+ $goodsArr = [];
|
|
|
|
|
+ foreach($params['goods_id'] as $v){
|
|
|
|
|
+ $goodsArr[] = end($v);
|
|
|
|
|
+ }
|
|
|
|
|
+ $model->couponWithGoods()->saveAll($goodsArr);
|
|
|
|
|
+ }
|
|
|
Db::commit();
|
|
Db::commit();
|
|
|
return true;
|
|
return true;
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
@@ -88,6 +98,7 @@ class CouponRulesLogic extends BaseLogic
|
|
|
try {
|
|
try {
|
|
|
CouponRules::where('id', $params['id'])->update([
|
|
CouponRules::where('id', $params['id'])->update([
|
|
|
'coupon_type'=> $params['coupon_type'],
|
|
'coupon_type'=> $params['coupon_type'],
|
|
|
|
|
+ 'coupon_target'=>!empty($params['coupon_target'])?$params['coupon_target']:'category',
|
|
|
'amount' => $params['amount'],
|
|
'amount' => $params['amount'],
|
|
|
'amount_require' => $params['amount_require'],
|
|
'amount_require' => $params['amount_require'],
|
|
|
'discount_ratio' => $params['discount_ratio'],
|
|
'discount_ratio' => $params['discount_ratio'],
|
|
@@ -111,17 +122,22 @@ class CouponRulesLogic extends BaseLogic
|
|
|
}
|
|
}
|
|
|
$categoryArr[] = end($v);
|
|
$categoryArr[] = end($v);
|
|
|
}
|
|
}
|
|
|
-// $exitCategory = CouponRules::hasWhere("couponWithCategory",function(Query $query)use($categoryArr){
|
|
|
|
|
-// $query->whereIn('goods_category_id',$categoryArr);
|
|
|
|
|
-// })->where('id','<>',$params['id'])
|
|
|
|
|
-// ->where('begin_use','>=',time())
|
|
|
|
|
-// ->where('expire_time','<=','expire_time')
|
|
|
|
|
-// ->where('voucher_status', '<>',3)
|
|
|
|
|
-// ->findOrEmpty();
|
|
|
|
|
-
|
|
|
|
|
$model = CouponRules::find($params['id']);
|
|
$model = CouponRules::find($params['id']);
|
|
|
$model->couponWithCategory()->saveAll($categoryArr);
|
|
$model->couponWithCategory()->saveAll($categoryArr);
|
|
|
}
|
|
}
|
|
|
|
|
+ CouponGoods::where('coupon_id',$params['id'])->delete();
|
|
|
|
|
+ if(!empty($params['goods_id'])){
|
|
|
|
|
+ $goodsArr = [];
|
|
|
|
|
+ foreach($params['goods_id'] as $v){
|
|
|
|
|
+ if(!is_array($v)){
|
|
|
|
|
+ $goodsArr[] = $v;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $goodsArr[] = end($v);
|
|
|
|
|
+ }
|
|
|
|
|
+ $model = CouponRules::find($params['id']);
|
|
|
|
|
+ $model->couponWithGoods()->saveAll($goodsArr);
|
|
|
|
|
+ }
|
|
|
Db::commit();
|
|
Db::commit();
|
|
|
return true;
|
|
return true;
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
@@ -158,6 +174,7 @@ class CouponRulesLogic extends BaseLogic
|
|
|
$rules = CouponRules::findOrEmpty($params['id'])->toArray();
|
|
$rules = CouponRules::findOrEmpty($params['id'])->toArray();
|
|
|
if(!empty($rules)){
|
|
if(!empty($rules)){
|
|
|
$rules['goods_category_ids'] = CouponCategory::where('coupon_id',$params['id'])->column('goods_category_id');
|
|
$rules['goods_category_ids'] = CouponCategory::where('coupon_id',$params['id'])->column('goods_category_id');
|
|
|
|
|
+ $rules['goods'] = Goods::whereIn('goods_id',CouponGoods::where('coupon_id',$params['id'])->column('goods_id'))->column('*');
|
|
|
}
|
|
}
|
|
|
return $rules;
|
|
return $rules;
|
|
|
}
|
|
}
|