Browse Source

Merge branch 'coupon_time_1013'

master
liangyuyan 5 years ago
parent
commit
67bc8aedef
  1. 11
      app/Admin/Controllers/CouponTieController.php
  2. 99
      app/Admin/Controllers/v3/CouponController.php
  3. 5
      app/Admin/Controllers/v3/CouponSettingController.php
  4. 2
      app/Admin/Forms/CouponTieForm.php
  5. 6
      app/Admin/Forms/v3/CouponPublishForm.php
  6. 27
      app/Admin/Repositories/CouponTie.php
  7. 1
      app/Admin/routes.php
  8. 37
      app/Models/v3/Coupon.php
  9. 9
      app/Models/v3/CouponSetting.php

11
app/Admin/Controllers/CouponTieController.php

@ -32,14 +32,17 @@ class CouponTieController extends AdminController
{
$grid = Grid::make(new CouponTie(), function (Grid $grid) {
$grid->id;
$grid->activity->sortable();
$grid->forward->sortable();
$grid->repay->sortable();
$grid->activity;
$grid->forward;
$grid->repay;
$grid->disableCreateButton();
$grid->disableViewButton();
$grid->disableEditButton();
$grid->disableDeleteButton();
$grid->paginate(1);
$grid->disablePagination();
$grid->disableRowSelector();
$grid->actions(new CouponTieEdit());
});
return $content

99
app/Admin/Controllers/v3/CouponController.php

@ -16,8 +16,6 @@ use App\Models\v3\Market as MarketModel;
use App\Models\v3\Category as CategoryModel;
use Dcat\Admin\Form\NestedForm;
use function GuzzleHttp\json_decode;
class CouponController extends AdminController
{
protected $receive_type = 0;
@ -28,12 +26,9 @@ class CouponController extends AdminController
*/
protected function grid()
{
// $model = new CouponModel();
// $list = $model->setAppends([])->select('id','title')->get();
// dd($list->toArray());
return Grid::make(new Coupon(), function (Grid $grid) {
$grid->id->sortable();
$grid->title;
$grid->title->width('12%');
$grid->start_time_text;
$grid->end_time_text;
@ -47,7 +42,7 @@ class CouponController extends AdminController
$grid->active_type_text;
$grid->status
->using(
CouponModel::$_STATUS
CouponModel::$status
)
->label(
config('label.status_label')
@ -67,10 +62,12 @@ class CouponController extends AdminController
}
});
$grid->filter(function (Grid\Filter $filter) {
$discountTypeList = CouponModel::$discountType;
$activeTypeList = CouponModel::$activeType;
$filter->like('title','标题');
$filter->equal('discount_type')->select(config('coupon.discount_type'));
$filter->equal('active_type')->select(config('coupon.active_type'));
$status = config('coupon.status');
$filter->equal('discount_type')->select($discountTypeList);
$filter->equal('active_type')->select($activeTypeList);
$status = CouponModel::$status;
unset($status[-1]);/* 去掉删除状态 */
$filter->in('status')->multipleSelect($status);
});
@ -78,7 +75,8 @@ class CouponController extends AdminController
$grid->disableBatchDelete();
$grid->disableCreateButton();
$grid->disableDeleteButton();
$grid->disableEditButton();
// $grid->disableEditButton();
$grid->disableRowSelector();
});
}
@ -90,9 +88,10 @@ class CouponController extends AdminController
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new Coupon(), function (Show $show) use($id){
// $show->id;
{
$builder = CouponModel::with('receiveType');
return Show::make($id, $builder, function (Show $show) use($id){
$show->id;
$show->title;
$show->introduce;
$show->full_amount;
@ -107,10 +106,17 @@ class CouponController extends AdminController
$show->usable_end_time_text;
$show->active_type_text;
$show->receive_type_text;
$show->column('receive_type.receive_type','')->as(function($receiveTypeId) use($show){
$text = '';
if($receiveTypeId > 0){
$receiveTypeName = SettingModel::getSettingInfo($receiveTypeId,'name');
$text = $receiveTypeName ? $receiveTypeName : $text;
}
return $text;
});
$show->type_text;
$show->category_text;
$show->market_id->as(function($marketId){
$show->market_ids->as(function($marketId){
$text = '全部市场';
if($marketId > 0){
$market = marketModel::select('name')->find($marketId)->toArray();
@ -118,14 +124,14 @@ class CouponController extends AdminController
}
return $text;
});
$show->storetype_id->as(function($storeTypeId){
$text = '全部店铺类型';
if($storeTypeId > 0){
$storeType = storeTypeModel::select('type_name')->find($storeTypeId)->toArray();
$text = $storeType ? $storeType['type_name'] : $text ;
}
return $text;
});
// $show->category_ids->as(function($storeTypeId){
// $text = '全部店铺类型';
// if($storeTypeId > 0){
// $storeType = storeTypeModel::select('type_name')->find($storeTypeId)->toArray();
// $text = $storeType ? $storeType['type_name'] : $text ;
// }
// return $text;
// });
$show->is_new_user_text;
$show->usable_number;
@ -152,25 +158,44 @@ class CouponController extends AdminController
$form->textarea('introduce')->required();
$form->currency('full_amount')->required()->symbol('¥');
$form->currency('discounts')->required()->symbol('¥');
$form->radio('discount_type')->options(CouponModel::$_DISCOUNTTYPE)->default(1);
$form->radio('discount_type')->options(CouponModel::$discountType)->default(1);
$form->number('inventory')->required()->type('number')->attribute('min', 1)->default(1);
$form->number('weigh')->type('number')->attribute('min', 0)->default(0);
$form->hidden('is_new_user')->options(CouponModel::$_ISNEWUSER)->default(2);
$form->hidden('is_new_user')->options(CouponModel::$isNewUser)->default(2);
});
$form->column(6,function(Form $form) {
$form->select('active_type')->required()->options(CouponModel::$_ACTIVETYPE)->default(1);
$form->datetimeRange('start_time','end_time','活动时间')->required();
// ->rules('after:now',[
// 'after' => '只能选择今天和之后的时间'
// ]);
$form->datetimeRange('usable_start_time','usable_end_time','可用时间')->required()->rules('after:start_time',[
'after' => '可用时间必须比活动开始时间晚'
]);
$receiveTypes = SettingModel::getSettingArray();
$form->select('active_type')->required()->options(CouponModel::$activeType)->default(1);
// $form->select('receive_type.receive_type','领取方式')->required()->options($receiveTypes)->default(2);
$form->datetime('start_time')->required()
->customFormat(function ($start_time){
return date('Y-m-d H:i:s',$start_time);
});
// ->rules('after:now',[
// 'after' => '只能选择今天和之后的时间'
// ]);
$form->datetime('end_time')->required()
->customFormat(function ($start_time){
return date('Y-m-d H:i:s',$start_time);
})
->rules('after:start_time',[
'after' => '只能选择活动开始之后的时间'
]);
$form->datetime('usable_start_time')->required()
->customFormat(function ($start_time){
return date('Y-m-d H:i:s',$start_time);
});
$form->datetime('usable_end_time')->required()
->customFormat(function ($start_time){
return date('Y-m-d H:i:s',$start_time);
})
->rules('after:end_time',[
'after' => '只能选择活动结束之后的时间'
]);
// $form->select('type')->options(CouponModel::$_TYPE)->default(1)->disable();
// $form->select('category')->options(CouponModel::$_CATEGORY)->default(1)->disable();
/* 默认全平台的市场 */
$marketList = MarketModel::getMarketArray();
$form->multipleSelect('market_ids')->options($marketList)->help('不选默认所有市场可用');
@ -180,7 +205,7 @@ class CouponController extends AdminController
});
$form->column(12,function(Form $form){
$form->tags('activity_available','可用活动')->options(CouponModel::$_ACTIVITY_AVAILABLE);
$form->tags('activity_available','可用活动')->options(CouponModel::$activityAvailable);
$form->tags('tags','标签')->options(['新人专享','满39减10','满19减5']);
$form->text('remark')->maxLength(500,'最多只能输入500个字')->default('');
});

5
app/Admin/Controllers/v3/CouponSettingController.php

@ -29,8 +29,11 @@ class CouponSettingController extends AdminController
$grid->model()->orderBy('id','desc');
$grid->filter(function (Grid\Filter $filter) {
// $categoryList = SettingModel::$category;
$filter->like('name');
// $filter->equal('category')->select($categoryList);
});
$grid->disableRowSelector();
});
}
@ -70,7 +73,7 @@ class CouponSettingController extends AdminController
{
return Form::make(new CouponSetting(), function (Form $form) {
$form->hidden('id');
$form->select('category')->width(6)->options(SettingModel::$_CATEGORY);
$form->select('category')->width(6)->options(SettingModel::$category);
$form->text('name')->width(6)->required()->maxLength(50);
$form->number('value')->required()->rules('min:1')->default(1);

2
app/Admin/Forms/CouponTieForm.php

@ -48,6 +48,8 @@ class CouponTieForm extends Form
$this->text('activity')->required()->value($coupon['activity']);
$this->text('forward')->required()->value($coupon['forward']);
$this->text('repay')->required()->value($coupon['repay']);
$this->disableResetButton();
}
/**

6
app/Admin/Forms/v3/CouponPublishForm.php

@ -33,7 +33,11 @@ class CouponPublishForm extends Form
switch($coupon->status){
case 0:
case 3:
// 判断活动时间 还未判断
$time = time();
// 判断活动时间
if($coupon->end_time <= $time + SettingModel::$publishTime){
return $this->error('活动时间已经接近,请重新设置!');
}
$coupon->status = 1;
if(!$coupon->save()){

27
app/Admin/Repositories/CouponTie.php

@ -26,17 +26,26 @@ class CouponTie extends Repository
'repay' => ''
];
}
return $model->makePaginator(
1,
$data = [
[
[
'id'=>1,
'activity'=>$coupon['activity'],
'forward'=>$coupon['forward'],
'repay' => $coupon['repay']
],
'id'=>1,
'activity'=>$coupon['activity'],
'forward'=>$coupon['forward'],
'repay' => $coupon['repay']
]
);
];
return $data;
// return $model->makePaginator(
// 1,
// [
// [
// 'id'=>1,
// 'activity'=>$coupon['activity'],
// 'forward'=>$coupon['forward'],
// 'repay' => $coupon['repay']
// ],
// ]
// );
}
}

1
app/Admin/routes.php

@ -88,6 +88,5 @@ Route::group([
// 订单统计
$router->resource('/order_report', 'v3\OrderReportController');
// $router->any('/order_report', 'v3\OrderReportController@index');
});

37
app/Models/v3/Coupon.php

@ -19,13 +19,13 @@ class Coupon extends Model
/* 查询记录数 limit */
protected $perPage = 10;
public static $_ACTIVITY_AVAILABLE = ['flash_sale'=>'秒杀','group_buy'=>'团购','new_product'=>'新品'];
public static $_CATEGORY = [1=>'订单'];
public static $_TYPE = [1=>'全平台',2=>'线上', 3=>'线下'];
public static $_ISNEWUSER = [1=>'是',2=>'否'];
public static $_DISCOUNTTYPE = [1=>'金额',2=>'打折(%)'];
public static $_ACTIVETYPE = [1=>'领取活动',2=>'转发活动',3=>'返券专用'];
public static $_STATUS = [ -1=> '已删除', 0=>'草稿', 1=>'正常',2=>'已领完',3=>'禁用'];
public static $activityAvailable = ['flash_sale'=>'秒杀','group_buy'=>'团购','new_product'=>'新品'];
public static $category = [1=>'订单'];
public static $type = [1=>'全平台',2=>'线上', 3=>'线下'];
public static $isNewUser = [1=>'是',2=>'否'];
public static $discountType = [1=>'金额',2=>'打折(%)'];
public static $activeType = [1=>'领取活动',2=>'转发活动',3=>'返券专用'];
public static $status = [ -1=> '已删除', 0=>'草稿', 1=>'正常',2=>'已领完',3=>'禁用'];
/* 添加转换字段 */
protected $appends = [
@ -54,32 +54,32 @@ class Coupon extends Model
public function getStatusTextAttribute()
{
$value = $this->status;
return isset(self::$_STATUS[$value])?self::$_STATUS[$value]:'';
return isset(self::$status[$value])?self::$status[$value]:'';
}
public function getTypeTextAttribute()
{
$value = $this->type;
return isset(self::$_TYPE[$value])?self::$_TYPE[$value]:'';
return isset(self::$type[$value])?self::$type[$value]:'';
}
public function getCategoryTextAttribute()
{
$value = $this->category;
return isset(self::$_CATEGORY[$value])?self::$_CATEGORY[$value]:'';
return isset(self::$category[$value])?self::$category[$value]:'';
}
public function getIsNewUserTextAttribute()
{
$value = $this->is_new_user;
return isset(self::$_ISNEWUSER[$value])?self::$_ISNEWUSER[$value]:'';
return isset(self::$isNewUser[$value])?self::$isNewUser[$value]:'';
}
public function getDiscountTypeTextAttribute()
{
$value = $this->discount_type;
return isset(self::$_DISCOUNTTYPE[$value])?self::$_DISCOUNTTYPE[$value]:'';
return isset(self::$discountType[$value])?self::$discountType[$value]:'';
}
public function getActiveTypeTextAttribute()
{
$value = $this->active_type;
return isset(self::$_ACTIVETYPE[$value])?self::$_ACTIVETYPE[$value]:'';
return isset(self::$activeType[$value])?self::$activeType[$value]:'';
}
public function getActivityAvailableTextAttribute()
{
@ -119,12 +119,13 @@ class Coupon extends Model
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getReceiveTypeTextAttribute()
public static function getReceiveTypeText($id)
{
$id = $this->getKey();
$receive = SettingModel::where('receive_type.system_coupon_user_id',$id)
->join('ims_system_coupon_user_receivetype as receive_type','receive_type.receive_type','ims_system_coupon_setting.id','inner')
->first('name');
// $id = $this->getKey();
// $receive = SettingModel::where('receive_type.coupon_id',$id)
// ->join('lanzu_coupon_receive_type as receive_type','receive_type.receive_type','lanzu_coupon_setting.id','inner')
// ->first('name');
$receive = SettingModel::getSettingInfo($id,'name');
return $receive ? $receive['name'] : '';
}

9
app/Models/v3/CouponSetting.php

@ -11,8 +11,9 @@ class CouponSetting extends Model
protected $table = 'lanzu_coupon_setting';
protected $dateFormat = 'U';
public static $_CATEGORY = [1=>'领取方式'];
public static $_STATUS = ['禁用','正常'];
public static $publishTime = 3600;// 发布优惠券时,优惠券的结束时间至少比当前时间多一个小时
public static $category = [1=>'领取方式'];
public static $status = ['禁用','正常'];
protected $appends = [
'category_text',
@ -22,12 +23,12 @@ class CouponSetting extends Model
public function getCategoryTextAttribute($value)
{
$value = $value ? $value : $this->category;
return isset(self::$_CATEGORY[$value]) ? self::$_CATEGORY[$value] : '';
return isset(self::$category[$value]) ? self::$category[$value] : '';
}
public function getStatusTextAttribute($value)
{
$value = $value ? $value : $this->status;
return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
return isset(self::$status[$value]) ? self::$status[$value] : '';
}
/**

Loading…
Cancel
Save