| // +------------------------------------------------+ namespace app\common\service; use app\common\model\ScoreRules as ScoreRulesModel; use app\common\validate\ScoreRules as ScoreRulesValidate; class ScoreRules extends _Init { /** * 添加信息 * @param [type] $data 积分规则数据 */ public static function create($data) { $validate = new ScoreRulesValidate(); if (!$validate->scene('add')->check($data)) { return $validate->getError(); } $info = ScoreRulesModel::create($data); if ($info) { return true; } else { return '创建积分规则失败'; } } /** * 编辑积分规则 * @param [type] $data 更新的数据 * @return [type] 返回 修改的结果 */ public static function edit($data) { $validate = new ScoreRulesValidate(); if (!$validate->scene('add')->check($data)) { return $validate->getError(); } $info = ScoreRulesModel::update($data); if ($info) { return true; } else { return '编辑积分规则失败'; } } /** * 修改积分规则状态 * @param [type] $id 积分规则id * @param [type] $status 状态 * @return [type] 返回结果 */ public static function status($id, $status) { $info = ScoreRulesModel::get($id); if (!$info) { return '积分规则不存在'; } elseif ($info->save(['status' => $status])) { Logs::write('修改状态', ['status' => $status]); return true; } else { return '修改状态失败'; } } /** * 删除积分规则 * @param [type] $id 要删除的积分规则id * @return [type] 返回 结果 */ public static function del($id) { $model = new ScoreRulesModel(); if ($model->destroy($id)) { return true; } else { return '删除失败'; } } }