Browse Source
Merge branch 'hotfix-phoenix' of http://120.24.33.109:11081/hyzjshwo/mp_lanzu_cat into hotfix-phoenix
master
Merge branch 'hotfix-phoenix' of http://120.24.33.109:11081/hyzjshwo/mp_lanzu_cat into hotfix-phoenix
master
6 changed files with 225 additions and 52 deletions
-
39app/Admin/Actions/Grid/v3/CouponForbidden.php
-
42app/Admin/Actions/Grid/v3/CouponPublish.php
-
71app/Admin/Controllers/v3/CouponController.php
-
95app/Admin/Forms/v3/CouponPublishForm.php
-
8app/Models/v3/Coupon.php
-
22app/Models/v3/CouponReceiveType.php
@ -0,0 +1,39 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid\v3; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use App\Models\v3\Coupon as CouponModel; |
||||
|
|
||||
|
class CouponForbidden extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '禁用'; |
||||
|
|
||||
|
|
||||
|
public function handle() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
$coupon = CouponModel::getInfo($id); |
||||
|
if(!empty($coupon)){ |
||||
|
$coupon->status = 3; |
||||
|
if($coupon->save()){ |
||||
|
return $this->response()->success('禁用成功!','/coupon'); |
||||
|
} |
||||
|
} |
||||
|
return $this->response()->success('禁用失败!'); |
||||
|
} |
||||
|
|
||||
|
// 确认弹窗信息
|
||||
|
public function confirm() |
||||
|
{ |
||||
|
return '您确定要禁用吗?'; |
||||
|
} |
||||
|
|
||||
|
public function parameters() |
||||
|
{ |
||||
|
return ['status'=>3]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid\v3; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Widgets\Modal; |
||||
|
use App\Admin\Forms\v3\CouponPublishForm; |
||||
|
|
||||
|
class CouponPublish extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '发布'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
$modal = Modal::make() |
||||
|
->xl() |
||||
|
->title($this->title) |
||||
|
->body(CouponPublishForm::make()->setKey($id)) |
||||
|
->button($this->title); |
||||
|
|
||||
|
return $modal; |
||||
|
} |
||||
|
|
||||
|
// 确认弹窗信息
|
||||
|
public function confirm() |
||||
|
{ |
||||
|
return '您确定要发布吗?'; |
||||
|
} |
||||
|
|
||||
|
public function parameters() |
||||
|
{ |
||||
|
|
||||
|
return [ |
||||
|
|
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,95 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Forms\v3; |
||||
|
|
||||
|
use App\Models\v3\GoodsBanners; |
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
use Symfony\Component\HttpFoundation\Response; |
||||
|
use App\Models\v3\CouponReceiveType as ReceiveTypeModel; |
||||
|
use App\Models\v3\CouponSetting as SettingModel; |
||||
|
use App\Models\v3\Coupon as CouponModel; |
||||
|
|
||||
|
class CouponPublishForm extends Form |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* Handle the form request. |
||||
|
* |
||||
|
* @param array $input |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
// 获取外部传递参数
|
||||
|
$id = $input['id']; |
||||
|
$receiveType = $input['receive_type']; |
||||
|
|
||||
|
$coupon = CouponModel::find($id); |
||||
|
if(!$coupon){ |
||||
|
return $this->error('优惠券不存在或已删除!'); |
||||
|
} |
||||
|
|
||||
|
switch($coupon->status){ |
||||
|
case 0: |
||||
|
case 3: |
||||
|
// 判断活动时间 还未判断
|
||||
|
|
||||
|
$coupon->status = 1; |
||||
|
if(!$coupon->save()){ |
||||
|
return $this->error('发布失败!'); |
||||
|
} |
||||
|
// 删除领取方式
|
||||
|
$delRes = ReceiveTypeModel::where('coupon_id',$id)->delete(); |
||||
|
if($delRes === false){ |
||||
|
return $this->error('发布失败!'); |
||||
|
} |
||||
|
// 添加领取方式
|
||||
|
$receiveModel = new ReceiveTypeModel(); |
||||
|
$receiveModel->coupon_id = $id; |
||||
|
$receiveModel->receive_type = $receiveType; |
||||
|
// 获取一次可领取数量
|
||||
|
$receiveNumber = SettingModel::getSettingInfo($receiveType,'value'); |
||||
|
$receiveModel->one_receive_number = empty($receiveNumber) ? 1 : $receiveNumber->value; |
||||
|
|
||||
|
if($receiveModel->save()){ |
||||
|
return $this->success('发布成功','/coupon'); |
||||
|
} |
||||
|
break; |
||||
|
case 1: |
||||
|
return $this->error('优惠券已发布!'); |
||||
|
break; |
||||
|
case 2: |
||||
|
return $this->error('优惠券已领完!'); |
||||
|
break; |
||||
|
case -1: |
||||
|
return $this->error('优惠券已删除!'); |
||||
|
break; |
||||
|
} |
||||
|
return $this->error('发布失败!'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Build a form here. |
||||
|
*/ |
||||
|
public function form() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
$receiveTypeInfo = ReceiveTypeModel::getReceiveTypeInfo($id,'receive_type'); |
||||
|
$list = SettingModel::getSettingArray(); |
||||
|
$receiveType = empty($receiveTypeInfo->receive_type)? 0 :$receiveTypeInfo->receive_type; |
||||
|
$this->hidden('id')->value($id); |
||||
|
$this->select('receive_type','领取方式')->required()->options($list)->value($receiveType); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The data of the form. |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function default() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue