6 changed files with 96 additions and 5 deletions
@ -0,0 +1,50 @@ |
|||
<?php |
|||
declare (strict_types = 1); |
|||
|
|||
namespace app\controller; |
|||
|
|||
use app\BaseController; |
|||
use app\model\ZoneGoods; |
|||
use app\validate\Zone as ZoneValidate; |
|||
use think\exception\ValidateException; |
|||
use think\facade\Request; |
|||
|
|||
class AdminZoneManage extends BaseController |
|||
{ |
|||
/** |
|||
* 刮奖专区列表 |
|||
* @return array |
|||
*/ |
|||
public function zoneGoodsList() |
|||
{ |
|||
$param = Request::param(); |
|||
return $this->renderSuccess('数据返回成功',ZoneGoods::getList($param['zone_id'],true)); |
|||
} |
|||
|
|||
/** |
|||
* 刮奖专区启用禁用 |
|||
* @throws \think\db\exception\DataNotFoundException |
|||
* @throws \think\db\exception\DbException |
|||
* @throws \think\db\exception\ModelNotFoundException |
|||
*/ |
|||
public function zoneGoodsChangeStatus() |
|||
{ |
|||
$param = Request::param(); |
|||
|
|||
try { |
|||
validate(ZoneValidate::class)->scene('changeStatus')->check($param); |
|||
|
|||
$id = $param['zone_goods_id']; |
|||
$status = $param['status']; |
|||
|
|||
$ZoneGoods = new ZoneGoods(); |
|||
$ZoneGoodsUp = $ZoneGoods->find($id); |
|||
$ZoneGoodsUp->status = $status; |
|||
$ZoneGoodsUp->save(); |
|||
|
|||
return $this->renderSuccess($status == 1 ? '已启用' : '已禁用'); |
|||
} catch (ValidateException $validateException) { |
|||
return $this->renderError($validateException->getMessage()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?php |
|||
declare (strict_types = 1); |
|||
|
|||
namespace app\validate; |
|||
|
|||
use think\Validate; |
|||
|
|||
class Zone extends Validate |
|||
{ |
|||
|
|||
/** |
|||
* 定义验证规则 |
|||
* 格式:'字段名' => ['规则1','规则2'...] |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $rule = [ |
|||
'zone_id|专区id' => 'require|integer', |
|||
'status' => 'in:0,1', |
|||
'zone_goods_id|刮奖专区id' => 'require|integer' |
|||
]; |
|||
|
|||
/** |
|||
* 定义错误信息 |
|||
* 格式:'字段名.规则名' => '错误信息' |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $message = []; |
|||
|
|||
protected $scene = [ |
|||
'changeStatus' => ['zone_goods_id','status'] |
|||
]; |
|||
} |
|||
Loading…
Reference in new issue