Browse Source
			
			
			Merge branch 'coupon_1016'
			
				
		Merge branch 'coupon_1016'
	
		
	
			
				# Conflicts: # app/Admin/Forms/v3/GoodsImageForm.phpmaster
				 14 changed files with 272 additions and 45 deletions
			
			
		- 
					6app/Admin/Actions/Grid/v3/CouponForbidden.php
 - 
					2app/Admin/Actions/Grid/v3/CouponPublish.php
 - 
					51app/Admin/Actions/Grid/v3/CouponTime.php
 - 
					44app/Admin/Controllers/v3/CouponController.php
 - 
					2app/Admin/Forms/v3/CategoryTieForm.php
 - 
					60app/Admin/Forms/v3/CouponPublishForm.php
 - 
					125app/Admin/Forms/v3/CouponTimeForm.php
 - 
					2app/Admin/Forms/v3/GoodsActivityCopyForm.php
 - 
					1app/Admin/Forms/v3/GoodsImageForm.php
 - 
					2app/Admin/Forms/v3/GoodsSpecForm.php
 - 
					1app/Admin/Forms/v3/StoreUserPasswordForm.php
 - 
					8app/Models/v3/Coupon.php
 - 
					11app/Models/v3/CouponUse.php
 - 
					2app/Models/v3/SystemConfig.php
 
@ -0,0 +1,51 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Actions\Grid\v3; | 
				
			|||
 | 
				
			|||
use Dcat\Admin\Grid\RowAction; | 
				
			|||
use Dcat\Admin\Widgets\Modal; | 
				
			|||
use App\Admin\Forms\v3\CouponTimeForm; | 
				
			|||
 | 
				
			|||
class CouponTime extends RowAction | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * 修改优惠券活动时间 | 
				
			|||
     * @return string | 
				
			|||
     */ | 
				
			|||
    protected $title = ' 时间 '; | 
				
			|||
 | 
				
			|||
    public function render() | 
				
			|||
    { | 
				
			|||
        $id = $this->getKey(); | 
				
			|||
 | 
				
			|||
        $modal = Modal::make() | 
				
			|||
            ->xl() | 
				
			|||
            ->title($this->title) | 
				
			|||
            ->body(CouponTimeForm::make()->setKey($id)->payload([ | 
				
			|||
                'id'=>$this->row->id, | 
				
			|||
                'inventory'=>$this->row->inventory, | 
				
			|||
                'title'=>$this->row->title, | 
				
			|||
                'start_time'=>$this->row->start_time, | 
				
			|||
                'end_time'=>$this->row->end_time, | 
				
			|||
                'usable_start_time'=>$this->row->usable_start_time, | 
				
			|||
                'usable_end_time'=>$this->row->usable_end_time, | 
				
			|||
                ])) | 
				
			|||
            ->button($this->title); | 
				
			|||
 | 
				
			|||
        return $modal; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    // 确认弹窗信息
 | 
				
			|||
    public function confirm() | 
				
			|||
    { | 
				
			|||
        return '您确定要修改时间吗?'; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public function parameters() | 
				
			|||
    { | 
				
			|||
        | 
				
			|||
        return [ | 
				
			|||
              | 
				
			|||
        ]; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,125 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Forms\v3; | 
				
			|||
 | 
				
			|||
use Dcat\Admin\Widgets\Form; | 
				
			|||
use Symfony\Component\HttpFoundation\Response; | 
				
			|||
use App\Models\v3\Coupon as CouponModel; | 
				
			|||
use Dcat\Admin\Contracts\LazyRenderable; | 
				
			|||
use Dcat\Admin\Traits\LazyWidget; | 
				
			|||
 | 
				
			|||
class CouponTimeForm extends Form implements LazyRenderable | 
				
			|||
{ | 
				
			|||
    use LazyWidget; | 
				
			|||
    /** | 
				
			|||
     * Handle the form request. | 
				
			|||
     * | 
				
			|||
     * @param array $input | 
				
			|||
     * | 
				
			|||
     * @return Response | 
				
			|||
     */ | 
				
			|||
    public function handle(array $input) | 
				
			|||
    { | 
				
			|||
        // 获取外部传递参数
 | 
				
			|||
        $id = $input['id']; | 
				
			|||
        $inventory = $input['inventory'] ?? 0; | 
				
			|||
        $start_time = $input['start_time'] ?? ''; | 
				
			|||
        $end_time = $input['end_time'] ?? ''; | 
				
			|||
        $usable_start_time = $input['usable_start_time'] ?? ''; | 
				
			|||
        $usable_end_time = $input['usable_end_time'] ?? ''; | 
				
			|||
 | 
				
			|||
        $coupon = CouponModel::find($id); | 
				
			|||
        if(!$coupon){ | 
				
			|||
            return $this->error('优惠券不存在或已删除!'); | 
				
			|||
        } | 
				
			|||
         | 
				
			|||
        switch($coupon->status){ | 
				
			|||
            case 0: | 
				
			|||
            case 1:   | 
				
			|||
            case 3: | 
				
			|||
                if(!empty($inventory)){ | 
				
			|||
                    $coupon->inventory = $inventory; | 
				
			|||
                } | 
				
			|||
                if(!empty($inventory)){ | 
				
			|||
                    $coupon->start_time = $start_time; | 
				
			|||
                } | 
				
			|||
                if(!empty($inventory)){ | 
				
			|||
                    $coupon->end_time = $end_time; | 
				
			|||
                } | 
				
			|||
                if(!empty($inventory)){ | 
				
			|||
                    $coupon->usable_start_time = $usable_start_time; | 
				
			|||
                } | 
				
			|||
                if(!empty($inventory)){ | 
				
			|||
                    $coupon->usable_end_time = $usable_end_time; | 
				
			|||
                } | 
				
			|||
                 | 
				
			|||
                if($coupon->save()){ | 
				
			|||
                    return $this->success('修改成功','/coupon'); | 
				
			|||
                } | 
				
			|||
            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->payload['id'] ?? 0; | 
				
			|||
        $title = $this->payload['title'] ?? ''; | 
				
			|||
        $inventory = $this->payload['inventory'] ?? 0; | 
				
			|||
 | 
				
			|||
        $start_time = $this->payload['start_time'] ?? ''; | 
				
			|||
        $end_time = $this->payload['end_time'] ?? ''; | 
				
			|||
        $usable_start_time = $this->payload['usable_start_time'] ?? ''; | 
				
			|||
        $usable_end_time = $this->payload['usable_end_time'] ?? ''; | 
				
			|||
 | 
				
			|||
        $this->hidden('id')->value($id); | 
				
			|||
        $this->display('title','标题')->value($title); | 
				
			|||
 | 
				
			|||
        $this->number('inventory','发放数量')->required()->type('number')->attribute('min', 1)->value($inventory)->default(1); | 
				
			|||
 | 
				
			|||
        $this->datetime('start_time','活动开始时间')->required() | 
				
			|||
            ->customFormat(function () use($start_time){ | 
				
			|||
                return date('Y-m-d H:i:s',$start_time); | 
				
			|||
            }); | 
				
			|||
 | 
				
			|||
        $this->datetime('end_time','活动结束时间')->required() | 
				
			|||
            ->customFormat(function () use($end_time){ | 
				
			|||
                return date('Y-m-d H:i:s',$end_time); | 
				
			|||
            }) | 
				
			|||
            ->rules('after:start_time',[ | 
				
			|||
                'after' => '只能选择活动开始之后的时间' | 
				
			|||
            ]); | 
				
			|||
        $this->datetime('usable_start_time','可用开始时间')->required() | 
				
			|||
            ->customFormat(function () use($usable_start_time){ | 
				
			|||
                return date('Y-m-d H:i:s',$usable_start_time); | 
				
			|||
            }); | 
				
			|||
        $this->datetime('usable_end_time','可用结束时间')->required() | 
				
			|||
            ->customFormat(function () use($usable_end_time){ | 
				
			|||
                return date('Y-m-d H:i:s',$usable_end_time); | 
				
			|||
            }) | 
				
			|||
            ->rules('after:end_time',[ | 
				
			|||
                'after' => '只能选择活动结束之后的时间' | 
				
			|||
            ]); | 
				
			|||
        $this->disableResetButton(); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * The data of the form. | 
				
			|||
     * | 
				
			|||
     * @return array | 
				
			|||
     */ | 
				
			|||
    public function default() | 
				
			|||
    { | 
				
			|||
        return []; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue