diff --git a/app/controller/AdminZoneManage.php b/app/controller/AdminZoneManage.php new file mode 100644 index 0000000..c9a83d8 --- /dev/null +++ b/app/controller/AdminZoneManage.php @@ -0,0 +1,50 @@ +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()); + } + } +} diff --git a/app/controller/Zone.php b/app/controller/Zone.php index a607856..dae7ca7 100644 --- a/app/controller/Zone.php +++ b/app/controller/Zone.php @@ -26,7 +26,6 @@ class Zone extends BaseController /** * 刮奖专区列表 - * @param $zone_id * @return array */ public function zoneGoodsList() diff --git a/app/model/User.php b/app/model/User.php index 694c72b..c9e9b5b 100644 --- a/app/model/User.php +++ b/app/model/User.php @@ -55,7 +55,7 @@ class User extends Model public function login($data) { // 根据用户名查询用户信息 - $user = $this->where('phone', $data['phone'])->field('id,avatar,phone,password,salt')->find(); + $user = $this->where('phone', $data['phone'])->field('id,avatar,phone,password,salt,status')->find(); if ($user) { if ($user['status'] != 1) return ['status' => false, 'msg' => '用户已被停用']; diff --git a/app/model/ZoneGoods.php b/app/model/ZoneGoods.php index 53fa9e9..b4485c7 100644 --- a/app/model/ZoneGoods.php +++ b/app/model/ZoneGoods.php @@ -5,15 +5,18 @@ namespace app\model; class ZoneGoods extends \think\Model { - public static function getList($param) + public static function getList($param,$is_manage = false) { - $where = ['status' => 1]; + $where = $is_manage ? ['status' => 1] : []; if (isset($param['zone_id'])) $where['zone_id'] = $param['zone_id']; - $field = 'id,title,important,price,cover_image'; + $field = 'id,title,important,price,cover_image,status'; $list = self::where($where)->field($field)->order('id desc')->select()->toArray(); foreach ($list as &$item) { if ($item['cover_image']) $item['cover_image'] = get_image_url($item['cover_image']); + if (!$is_manage) { + unset($item['status']); + } } return $list; } diff --git a/app/validate/Zone.php b/app/validate/Zone.php new file mode 100644 index 0000000..f32d02f --- /dev/null +++ b/app/validate/Zone.php @@ -0,0 +1,34 @@ + ['规则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'] + ]; +} diff --git a/route/app.php b/route/app.php index f787306..e68f099 100644 --- a/route/app.php +++ b/route/app.php @@ -79,6 +79,11 @@ Route::group('adminUser',function() { Route::post('downScoresList','adminUser/downScoresList')->middleware(CheckAdmin::class)->allowCrossDomain(); }); +Route::group('adminZoneManage',function() { + Route::post('zoneGoodsList','adminZoneManage/zoneGoodsList')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('zoneGoodsChangeStatus','adminZoneManage/zoneGoodsChangeStatus')->middleware(CheckAdmin::class)->allowCrossDomain(); +}); + # 支付(待开发) //Route::group('pay',function (){ // Route::post('pay','pay/pay');